solution: allow configuring a quorum for custom methods

This commit is contained in:
Igor Artamonov
2021-08-04 14:58:28 -04:00
parent 96109d4013
commit 2f2a553cd4
12 changed files with 166 additions and 14 deletions

View File

@@ -233,6 +233,29 @@ class UpstreamsConfigReaderSpec extends Specification {
}
}
def "Parse config with methods and quorum"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("upstreams-methods-quorum.yaml")
when:
def act = reader.read(config)
then:
act != null
with(act.upstreams.get(0)) {
methods != null
with(methods) {
enabled.size() == 2
with(enabled[0]) {
it.name == "custom_foo"
it.quorum == "not_lagging"
}
with(enabled[1]) {
it.name == "custom_bar"
it.quorum == "not_empty"
}
}
}
}
def "Parse config with invalid ids"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("upstreams-no-id.yaml")

View File

@@ -0,0 +1,38 @@
package io.emeraldpay.dshackle.startup
import io.emeraldpay.dshackle.FileResolver
import io.emeraldpay.dshackle.cache.CachesFactory
import io.emeraldpay.dshackle.config.UpstreamsConfig
import io.emeraldpay.dshackle.quorum.NonEmptyQuorum
import io.emeraldpay.dshackle.upstream.CurrentMultistreamHolder
import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods
import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods
import io.emeraldpay.grpc.Chain
import spock.lang.Specification
class ConfiguredUpstreamsSpec extends Specification {
def "Applied quorum to extra methods"() {
setup:
def currentUpstreams = Mock(CurrentMultistreamHolder) {
_ * getDefaultMethods(Chain.ETHEREUM) >> new DefaultEthereumMethods(Chain.ETHEREUM)
}
def configurer = new ConfiguredUpstreams(
currentUpstreams, Stub(FileResolver), Stub(UpstreamsConfig), Stub(CachesFactory)
)
def methods = new UpstreamsConfig.Methods(
[
new UpstreamsConfig.Method("foo_bar", null),
new UpstreamsConfig.Method("foo_bar", "not_empty")
] as Set,
[] as Set
)
def upstream = new UpstreamsConfig.Upstream()
upstream.methods = methods
when:
def act = configurer.buildMethods(upstream, Chain.ETHEREUM)
then:
act instanceof ManagedCallMethods
act.getQuorumFor("foo_bar") instanceof NonEmptyQuorum
}
}

View File

@@ -18,8 +18,12 @@ package io.emeraldpay.dshackle.upstream.calls
import io.emeraldpay.dshackle.quorum.AlwaysQuorum
import io.emeraldpay.dshackle.quorum.BroadcastQuorum
import io.emeraldpay.dshackle.quorum.NonEmptyQuorum
import io.emeraldpay.dshackle.quorum.NonceQuorum
import io.emeraldpay.dshackle.quorum.NotLaggingQuorum
import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods
import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods
import io.emeraldpay.grpc.Chain
import spock.lang.Specification
class ManagedCallMethodsSpec extends Specification {
@@ -81,4 +85,29 @@ class ManagedCallMethodsSpec extends Specification {
act != null
act instanceof BroadcastQuorum
}
def "Use custom quorum if provided"() {
setup:
def managed = new ManagedCallMethods(
new DefaultEthereumMethods(Chain.ETHEREUM),
["eth_test", "eth_foo", "eth_bar"] as Set,
[] as Set
)
managed.setQuorum("eth_test", "not_empty")
managed.setQuorum("eth_foo", "not_lagging")
when:
def act = managed.getQuorumFor("eth_test")
then:
act instanceof NonEmptyQuorum
when:
act = managed.getQuorumFor("eth_foo")
then:
act instanceof NotLaggingQuorum
when:
act = managed.getQuorumFor("eth_bar")
then:
act instanceof AlwaysQuorum
}
}

View File

@@ -0,0 +1,18 @@
version: v1
upstreams:
- id: local
chain: ethereum
methods:
enabled:
- name: custom_foo
quorum: not_lagging
- name: custom_bar
quorum: not_empty
connection:
ethereum:
rpc:
url: "http://localhost:8545"
ws:
url: "ws://localhost:8546"
origin: "http://localhost"