generic upstreams introduced (#317)

- added base implementation of upstreams/multistreams
- connectors were generalised, chain specific logic was extracted to ChainSpecific class
- StarkNet network support based on generic upstreams added
This commit is contained in:
a10zn8
2023-10-09 23:17:16 +04:00
committed by GitHub
parent 222e046e32
commit f3bf34768a
56 changed files with 864 additions and 364 deletions

View File

@@ -1,6 +1,7 @@
package io.emeraldpay.dshackle.config
import io.emeraldpay.dshackle.foundation.ChainOptions
import java.math.BigInteger
import java.time.Duration
data class ChainsConfig(private val chains: List<ChainConfig>) : Iterable<ChainsConfig.ChainConfig> {
@@ -22,7 +23,7 @@ data class ChainsConfig(private val chains: List<ChainConfig>) : Iterable<Chains
val laggingLagSize: Int,
val options: ChainOptions.PartialOptions,
val chainId: String,
val netVersion: Long,
val netVersion: BigInteger,
val grpcId: Int,
val code: String,
val shortNames: List<String>,
@@ -38,7 +39,7 @@ data class ChainsConfig(private val chains: List<ChainConfig>) : Iterable<Chains
1,
ChainOptions.PartialOptions(),
"0x0",
0,
BigInteger.ZERO,
0,
"UNKNOWN",
emptyList(),

View File

@@ -8,6 +8,7 @@ import org.yaml.snakeyaml.nodes.MappingNode
import org.yaml.snakeyaml.nodes.NodeTuple
import org.yaml.snakeyaml.nodes.ScalarNode
import org.yaml.snakeyaml.nodes.Tag
import java.math.BigInteger
class ChainsConfigReader(
private val chainsOptionsReader: ChainOptionsReader,
@@ -74,7 +75,7 @@ class ChainsConfigReader(
?: throw IllegalArgumentException("undefined code for $blockchain")
val grpcId = getValueAsInt(node, "grpcId")
?: throw IllegalArgumentException("undefined code for $blockchain")
val netVersion = getValueAsLong(node, "net-version") ?: chainId.drop(2).toLong(radix = 16)
val netVersion = getValueAsLong(node, "net-version")?.toBigInteger() ?: BigInteger(chainId.drop(2), 16)
val shortNames = getListOfString(node, "short-names")
?: throw IllegalArgumentException("undefined shortnames for $blockchain")
return ChainsConfig.ChainConfig(

View File

@@ -551,3 +551,30 @@ chain-settings:
short-names: [kava-testnet]
chain-id: 0x8ad
grpcId: 10033
- id: starknet
label: StarkNet
settings:
currency: ETH
expected-block-time: 20s
lags:
syncing: 5
lagging: 1
chains:
- id: Mainnet
priority: 100
code: STARKNET_MAINNET
short-names: [starknet]
chain-id: 0x534e5f4d41494e
grpcId: 1014
- id: Testnet
priority: 2
code: STARKNET_TESTNET
short-names: [starknet-testnet]
chain-id: 0x534e5f474f45524c49
grpcId: 10019
- id: Testnet 2
priority: 1
code: STARKNET_TESTNET2
short-names: [starknet-testnet2]
chain-id: 0x534e5f474f45524c4932
grpcId: 10020

View File

@@ -4,6 +4,7 @@ import io.emeraldpay.dshackle.config.ChainsConfigReader
import io.emeraldpay.dshackle.foundation.ChainOptionsReader
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.math.BigInteger
internal class ChainsConfigReaderTest {
@@ -19,7 +20,7 @@ internal class ChainsConfigReaderTest {
val ethc = config.resolve("ethereum-classic")
assertEquals(ethc.chainId, "0x3d")
assertEquals(ethc.netVersion, 1)
assertEquals(ethc.netVersion, BigInteger.valueOf(1))
assertEquals(ethc.code, "ETC")
assertEquals(ethc.grpcId, 101)
assertEquals(ethc.expectedBlockTime.seconds, 12)
@@ -39,6 +40,6 @@ internal class ChainsConfigReaderTest {
assertEquals(config.laggingLagSize, 4)
assertEquals(config.code, "FTA")
assertEquals(config.grpcId, 102)
assertEquals(config.netVersion, 251)
assertEquals(config.netVersion, BigInteger.valueOf(251))
}
}