added chains configuration

This commit is contained in:
a10zn8
2023-02-09 20:45:10 +04:00
parent 8649cc03aa
commit ff4c538568
25 changed files with 237 additions and 80 deletions

View File

@@ -0,0 +1,40 @@
/**
* Copyright (c) 2019 ETCDEV GmbH
* Copyright (c) 2020 EmeraldPay, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.emeraldpay.dshackle.config
import io.emeraldpay.dshackle.Chain
import spock.lang.Specification
class ChainsConfigReaderSpec extends Specification {
ChainsConfigReader reader = new ChainsConfigReader()
def "Parse standard config"() {
setup:
def stream = this.class.getClassLoader().getResourceAsStream("configs/chains-basic.yaml")
when:
def config = reader.read(stream)
def act = config.resolve(Chain.ETHEREUM)
def act2 = config.resolve(Chain.POLYGON)
then:
act.laggingLagSize == 5
act.syncingLagSize == 10
act2.laggingLagSize == 1
act2.syncingLagSize == 6
}
}

View File

@@ -1,6 +1,7 @@
package io.emeraldpay.dshackle.startup
import io.emeraldpay.dshackle.FileResolver
import io.emeraldpay.dshackle.config.ChainsConfig
import io.emeraldpay.dshackle.config.UpstreamsConfig
import io.emeraldpay.dshackle.quorum.NonEmptyQuorum
import io.emeraldpay.dshackle.upstream.CallTargetsHolder
@@ -23,7 +24,8 @@ class ConfiguredUpstreamsSpec extends Specification {
Stub(UpstreamsConfig),
callTargetsHolder,
Mock(ApplicationEventPublisher),
Executors.newFixedThreadPool(1)
Executors.newFixedThreadPool(1),
ChainsConfig.default()
)
def methods = new UpstreamsConfig.Methods(
[
@@ -49,7 +51,8 @@ class ConfiguredUpstreamsSpec extends Specification {
Stub(UpstreamsConfig),
callTargetsHolder,
Mock(ApplicationEventPublisher),
Executors.newFixedThreadPool(1)
Executors.newFixedThreadPool(1),
ChainsConfig.default()
)
def methods = new UpstreamsConfig.Methods(
[
@@ -74,7 +77,8 @@ class ConfiguredUpstreamsSpec extends Specification {
Stub(UpstreamsConfig),
callTargetsHolder,
Mock(ApplicationEventPublisher),
Executors.newFixedThreadPool(1)
Executors.newFixedThreadPool(1),
ChainsConfig.default()
)
expect:
configurer.getHash(node, src) == expected
@@ -94,7 +98,8 @@ class ConfiguredUpstreamsSpec extends Specification {
Stub(UpstreamsConfig),
callTargetsHolder,
Mock(ApplicationEventPublisher),
Executors.newFixedThreadPool(1)
Executors.newFixedThreadPool(1),
ChainsConfig.default()
)
when:
def h1 = configurer.getHash(null, "hohoho")
@@ -119,7 +124,8 @@ class ConfiguredUpstreamsSpec extends Specification {
Stub(UpstreamsConfig),
callTargetsHolder,
Mock(ApplicationEventPublisher),
Executors.newFixedThreadPool(1)
Executors.newFixedThreadPool(1),
ChainsConfig.default()
)
def methodsGroup = new UpstreamsConfig.MethodGroups(
["filter"] as Set,

View File

@@ -16,7 +16,7 @@
*/
package io.emeraldpay.dshackle.test
import io.emeraldpay.dshackle.config.ChainsConfig
import io.emeraldpay.dshackle.config.UpstreamsConfig
import io.emeraldpay.dshackle.data.BlockContainer
import io.emeraldpay.dshackle.upstream.calls.AggregatedCallMethods
@@ -73,7 +73,8 @@ class EthereumPosRpcUpstreamMock extends EthereumPosRpcUpstream {
UpstreamsConfig.UpstreamRole.PRIMARY,
methods,
new QuorumForLabels.QuorumItem(1, UpstreamsConfig.Labels.fromMap(labels)),
new ConnectorFactoryMock(api, new EthereumHeadMock()))
new ConnectorFactoryMock(api, new EthereumHeadMock()),
ChainsConfig.ChainConfig.default())
this.ethereumHeadMock = this.getHead() as EthereumHeadMock
setLag(0)
setStatus(UpstreamAvailability.OK)

View File

@@ -16,7 +16,7 @@
*/
package io.emeraldpay.dshackle.test
import io.emeraldpay.dshackle.config.ChainsConfig
import io.emeraldpay.dshackle.config.UpstreamsConfig
import io.emeraldpay.dshackle.data.BlockContainer
import io.emeraldpay.dshackle.upstream.calls.AggregatedCallMethods
@@ -65,7 +65,8 @@ class EthereumRpcUpstreamMock extends EthereumRpcUpstream {
UpstreamsConfig.UpstreamRole.PRIMARY,
methods,
new QuorumForLabels.QuorumItem(1, new UpstreamsConfig.Labels()),
new ConnectorFactoryMock(api, new EthereumHeadMock()))
new ConnectorFactoryMock(api, new EthereumHeadMock()),
ChainsConfig.ChainConfig.default())
this.ethereumHeadMock = this.getHead() as EthereumHeadMock
setLag(0)
setStatus(UpstreamAvailability.OK)

View File

@@ -16,6 +16,7 @@
*/
package io.emeraldpay.dshackle.upstream
import io.emeraldpay.dshackle.config.ChainsConfig
import io.emeraldpay.dshackle.config.UpstreamsConfig
import io.emeraldpay.dshackle.startup.QuorumForLabels
import io.emeraldpay.dshackle.test.EthereumApiStub
@@ -57,7 +58,8 @@ class FilteredApisSpec extends Specification {
UpstreamsConfig.UpstreamRole.PRIMARY,
ethereumTargets,
new QuorumForLabels.QuorumItem(1, UpstreamsConfig.Labels.fromMap(it)),
connectorFactory
connectorFactory,
ChainsConfig.ChainConfig.default()
)
}
def matcher = new Selector.LabelMatcher("test", ["foo"])

View File

@@ -22,6 +22,7 @@ import io.emeraldpay.api.proto.BlockchainGrpc
import io.emeraldpay.api.proto.BlockchainOuterClass
import io.emeraldpay.api.proto.Common
import io.emeraldpay.dshackle.Global
import io.emeraldpay.dshackle.config.ChainsConfig
import io.emeraldpay.dshackle.config.UpstreamsConfig
import io.emeraldpay.dshackle.data.BlockId
import io.emeraldpay.dshackle.test.MockGrpcServer
@@ -83,7 +84,7 @@ class EthereumGrpcUpstreamSpec extends Specification {
)
}
})
def upstream = new EthereumGrpcUpstream("test", hash, UpstreamsConfig.UpstreamRole.PRIMARY, chain, client, new JsonRpcGrpcClient(client, chain, metrics), null)
def upstream = new EthereumGrpcUpstream("test", hash, UpstreamsConfig.UpstreamRole.PRIMARY, chain, client, new JsonRpcGrpcClient(client, chain, metrics), null, ChainsConfig.ChainConfig.default())
upstream.setLag(0)
upstream.update(BlockchainOuterClass.DescribeChain.newBuilder()
.setStatus(BlockchainOuterClass.ChainStatus.newBuilder().setQuorum(1).setAvailabilityValue(UpstreamAvailability.OK.grpcId))
@@ -141,7 +142,7 @@ class EthereumGrpcUpstreamSpec extends Specification {
)
}
})
def upstream = new EthereumGrpcUpstream("test", hash, UpstreamsConfig.UpstreamRole.PRIMARY, Chain.ETHEREUM, client, new JsonRpcGrpcClient(client, Chain.ETHEREUM, metrics), null)
def upstream = new EthereumGrpcUpstream("test", hash, UpstreamsConfig.UpstreamRole.PRIMARY, Chain.ETHEREUM, client, new JsonRpcGrpcClient(client, Chain.ETHEREUM, metrics), null, ChainsConfig.ChainConfig.default())
upstream.setLag(0)
upstream.update(BlockchainOuterClass.DescribeChain.newBuilder()
.setStatus(BlockchainOuterClass.ChainStatus.newBuilder().setQuorum(1).setAvailabilityValue(UpstreamAvailability.OK.grpcId))
@@ -203,7 +204,7 @@ class EthereumGrpcUpstreamSpec extends Specification {
finished.complete(true)
}
})
def upstream = new EthereumGrpcUpstream("test", hash, UpstreamsConfig.UpstreamRole.PRIMARY, chain, client, new JsonRpcGrpcClient(client, chain, metrics), null)
def upstream = new EthereumGrpcUpstream("test", hash, UpstreamsConfig.UpstreamRole.PRIMARY, chain, client, new JsonRpcGrpcClient(client, chain, metrics), null, ChainsConfig.ChainConfig.default())
upstream.setLag(0)
upstream.update(BlockchainOuterClass.DescribeChain.newBuilder()
.setStatus(BlockchainOuterClass.ChainStatus.newBuilder().setQuorum(1).setAvailabilityValue(UpstreamAvailability.OK.grpcId))

View File

@@ -0,0 +1,7 @@
version: v1
chains:
- name: eth
syncing-size: 10
lagging-size: 5