From 45237592a3792f96bdeb1e8dd479a7ed7d90ffa4 Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Sun, 26 Dec 2021 15:32:18 -0500 Subject: [PATCH] solution: config option to disable an upstream --- docs/reference-configuration.adoc | 5 +++++ .../io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt | 3 +++ .../io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/docs/reference-configuration.adoc b/docs/reference-configuration.adoc index 00f26f23..af7c1b21 100644 --- a/docs/reference-configuration.adoc +++ b/docs/reference-configuration.adoc @@ -616,6 +616,11 @@ Fallback role mean that the upstream is used only after other upstreams failed o Cluster may have multiple upstreams for a single blockchain. Accepted types: `bitcoin`, `bitcoin-testnet`, `ethereum`, `ethereum-classic`, `kovan-testnet`, `rinkeby-testnet`, `ropsten-testnet`, or `goerli-testnet` +| `enabled` +| no +| `true` (default) or `false`. +Enable/disable the upstream. + | `labels` | no | Key-Value pairs that are assigned to the upstream. diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt index 2089d69d..c477fd66 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt @@ -194,6 +194,9 @@ class UpstreamsConfigReader( upstream.id = getValueAsString(upNode, "id") upstream.options = tryReadOptions(upNode) upstream.methods = tryReadMethods(upNode) + getValueAsBool(upNode, "enabled")?.let { + upstream.isEnabled = it + } } internal fun readUpstreamGrpc( diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt index 7a9cf8d9..489a79da 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt @@ -63,6 +63,10 @@ open class ConfiguredUpstreams( log.debug("Starting upstreams") val defaultOptions = buildDefaultOptions(config) config.upstreams.forEach { up -> + if (!up.isEnabled) { + log.debug("Upstream ${up.id} is disabled") + return@forEach + } log.debug("Start upstream ${up.id}") if (up.connection is UpstreamsConfig.GrpcConnection) { val options = up.options ?: UpstreamsConfig.Options()