diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentUpstreams.kt index a65a3da0..baf2eb01 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentUpstreams.kt @@ -58,6 +58,9 @@ class CurrentUpstreams( } else { current.addUpstream(up) } + if (!callTargets.containsKey(chain)) { + setupDefaultMethods(chain) + } log.info("Upstream ${change.upstream.getId()} with chain $chain has been added") } } @@ -84,12 +87,13 @@ class CurrentUpstreams( } override fun getDefaultMethods(chain: Chain): CallMethods { - var current = callTargets[chain] - if (current == null) { - current = QuorumBasedMethods(objectMapper, chain) - callTargets[chain] = current - } - return current + return callTargets[chain] ?: return setupDefaultMethods(chain) + } + + fun setupDefaultMethods(chain: Chain): QuorumBasedMethods { + val created = QuorumBasedMethods(objectMapper, chain) + callTargets[chain] = created + return created } override fun isAvailable(chain: Chain): Boolean { diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentUpstreamsSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentUpstreamsSpec.groovy index a772fab3..56f6ea0e 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentUpstreamsSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentUpstreamsSpec.groovy @@ -52,4 +52,22 @@ class CurrentUpstreamsSpec extends Specification { current.getUpstream(Chain.ETHEREUM).getAll().toSet() == [up3].toSet() current.getUpstream(Chain.ETHEREUM_CLASSIC).getAll().toSet() == [up2].toSet() } + + def "available after adding"() { + setup: + def current = new CurrentUpstreams(TestingCommons.objectMapper()) + def up1 = new EthereumUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(Stub(ReactorRpcClient))) + + when: + def act = current.isAvailable(Chain.ETHEREUM) + then: + !act + + when: + current.update(new UpstreamChange(Chain.ETHEREUM, up1, UpstreamChange.ChangeType.ADDED)) + act = current.isAvailable(Chain.ETHEREUM) + + then: + act + } }