Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check chain_ids on all networks (#507)
Browse files Browse the repository at this point in the history
* check chain_ids on all networks
a10zn8 authored Jun 11, 2024
1 parent c1ea446 commit cce2bcf
Showing 9 changed files with 172 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -115,7 +115,8 @@ 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")?.toBigInteger() ?: BigInteger(chainId.drop(2), 16)
val netVersion = getValueAsLong(node, "net-version")?.toBigInteger() ?:
if (chainId.startsWith("0x")) BigInteger(chainId.drop(2), 16) else BigInteger.ZERO
val shortNames = getListOfString(node, "short-names")
?: throw IllegalArgumentException("undefined shortnames for $blockchain")
val type = getValueAsString(node, "type")
53 changes: 38 additions & 15 deletions foundation/src/main/resources/chains.yaml
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ chain-settings:
settings:
expected-block-time: 12s
mev-critical: true
allow-pruning-requirement: true
lags:
syncing: 6
lagging: 1
@@ -76,6 +77,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 3s
allow-pruning-requirement: true
options:
validate-peers: false
lags:
@@ -101,6 +103,7 @@ chain-settings:
settings:
mev-critical: true
expected-block-time: 2.7s
allow-pruning-requirement: true
lags:
syncing: 20
lagging: 10
@@ -131,6 +134,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 260ms
allow-pruning-requirement: true
options:
validate-peers: false
lags:
@@ -155,6 +159,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 2s
allow-pruning-requirement: true
options:
validate-peers: false
lags:
@@ -179,6 +184,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 3s
allow-pruning-requirement: true
mev-critical: true
lags:
syncing: 20
@@ -206,6 +212,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 2.7s
allow-pruning-requirement: true
options:
disable-validation: true
lags:
@@ -232,6 +239,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 260ms
allow-pruning-requirement: true
options:
disable-validation: true
lags:
@@ -249,6 +257,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 5s
allow-pruning-requirement: true
lags:
syncing: 70
lagging: 50
@@ -273,6 +282,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 2s
allow-pruning-requirement: true
options:
validate-peers: false
lags:
@@ -297,6 +307,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 12s
allow-pruning-requirement: true
lags:
syncing: 6
lagging: 1
@@ -319,6 +330,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 6s
allow-pruning-requirement: true
options:
validate-peers: false
lags:
@@ -343,6 +355,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 2s
allow-pruning-requirement: true
options:
validate-peers: false
validate-syncing: false
@@ -392,6 +405,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 500ms
allow-pruning-requirement: true
options:
validate-peers: false
lags:
@@ -416,6 +430,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 1s
allow-pruning-requirement: true
options:
validate-peers: false
lags:
@@ -442,6 +457,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 5s
allow-pruning-requirement: true
lags:
syncing: 10
lagging: 5
@@ -464,6 +480,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 12s
allow-pruning-requirement: true
lags:
syncing: 6
lagging: 1
@@ -486,6 +503,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 12s
allow-pruning-requirement: true
lags:
syncing: 6
lagging: 1
@@ -554,6 +572,7 @@ chain-settings:
options:
validate-peers: false
expected-block-time: 30s
allow-pruning-requirement: true
lags:
syncing: 40
lagging: 20
@@ -600,6 +619,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 6s
allow-pruning-requirement: true
options:
validate-peers: false
lags:
@@ -613,8 +633,7 @@ chain-settings:
short-names: [kava]
chain-id: 0x8ae
grpcId: 1025
gas-price-condition:
- eq 1000000000
gas-price-condition: eq 1000000000
- id: Testnet
priority: 10
code: KAVA_TESTNET
@@ -683,13 +702,13 @@ chain-settings:
priority: 1
code: VARA_MAINNET
short-names: [vara]
chain-id: 0x0
chain-id: Vara Network
grpcId: 1027
- id: Testnet
priority: 1
code: VARA_TESTMET
short-names: [vara-testnet]
chain-id: 0x0
chain-id: Vara Network Testnet
grpcId: 10036
- id: solana
label: Solana
@@ -773,6 +792,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 5s
allow-pruning-requirement: true
lags:
syncing: 20
lagging: 10
@@ -835,6 +855,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 10s
allow-pruning-requirement: true
lags:
syncing: 10
lagging: 5
@@ -933,6 +954,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 2s
allow-pruning-requirement: true
options:
validate-peers: false
lags:
@@ -1022,6 +1044,7 @@ chain-settings:
type: eth
settings:
expected-block-time: 2s
allow-pruning-requirement: true
lags:
syncing: 40
lagging: 20
@@ -1282,19 +1305,19 @@ chain-settings:
code: NEAR_MAINNET
grpcId: 1050
short-names: [near]
chain-id: 0x0
chain-id: mainnet
- id: Testnet
priority: 5
code: NEAR_TESTNET
grpcId: 10064
short-names: [near-testnet]
chain-id: 0x0
chain-id: testnet
- id: Betanet
priority: 1
code: NEAR_BETANET
grpcId: 10065
short-names: [near-betanet]
chain-id: 0x0
chain-id: betanet
- id: opcelestia-raspberry
label: OP Celestia Raspberry
type: eth
@@ -1420,13 +1443,13 @@ chain-settings:
lagging: 1
chains:
- id: Mainnet
chain-id: 0x0
chain-id: cosmoshub-4
short-names: [ cosmos-hub ]
code: COSMOS_HUB
grpcId: 1057
priority: 100
- id: Testnet
chain-id: 0x0
chain-id: provider
short-names: [ cosmos-hub-testnet ]
code: COSMOS_HUB_TESTNET
grpcId: 10079
@@ -1441,13 +1464,13 @@ chain-settings:
lagging: 1
chains:
- id: Mainnet
chain-id: 0x0
chain-id: axelar-dojo-1
short-names: [ axelar ]
code: AXELAR
grpcId: 1059
priority: 100
- id: Testnet
chain-id: 0x0
chain-id: axelar-testnet-lisbon-3
short-names: [ axelar-testnet ]
code: AXELAR_TESTNET
grpcId: 10081
@@ -1462,13 +1485,13 @@ chain-settings:
lagging: 1
chains:
- id: Mainnet
chain-id: 0x0
chain-id: osmosis
short-names: [ osmosis ]
code: OSMOSIS
grpcId: 1060
priority: 100
- id: Testnet
chain-id: 0x0
chain-id: osmo-test-5
short-names: [ osmosis-testnet ]
code: OSMOSIS_TESTNET
grpcId: 10082
@@ -1483,13 +1506,13 @@ chain-settings:
lagging: 1
chains:
- id: Mainnet
chain-id: 0x0
chain-id: neutron-1
short-names: [ neutron ]
code: NEUTRON
grpcId: 1061
priority: 100
- id: Testnet
chain-id: 0x0
chain-id: pion-1
short-names: [ neutron-testnet ]
code: NEUTRON_TESTNET
grpcId: 10083
Original file line number Diff line number Diff line change
@@ -44,16 +44,21 @@ abstract class UpstreamValidator(
val cp = Comparator { avail1: UpstreamAvailability, avail2: UpstreamAvailability -> if (avail1.isBetterTo(avail2)) -1 else 1 }
return results.sortedWith(cp).last()
}

fun resolve(results: Iterable<ValidateUpstreamSettingsResult>): ValidateUpstreamSettingsResult {
val cp = Comparator { res1: ValidateUpstreamSettingsResult, res2: ValidateUpstreamSettingsResult -> if (res1.priority < res2.priority) -1 else 1 }
return results.sortedWith(cp).last()
}
}
}

enum class ValidateUpstreamSettingsResult {
UPSTREAM_VALID,
UPSTREAM_SETTINGS_ERROR,
UPSTREAM_FATAL_SETTINGS_ERROR,
enum class ValidateUpstreamSettingsResult(val priority: Int) {
UPSTREAM_VALID(0),
UPSTREAM_SETTINGS_ERROR(1),
UPSTREAM_FATAL_SETTINGS_ERROR(2),
}

data class SingleCallValidator(
data class SingleCallValidator<T>(
val method: ChainRequest,
val check: (ByteArray) -> UpstreamAvailability,
val check: (ByteArray) -> T,
)
Original file line number Diff line number Diff line change
@@ -14,15 +14,19 @@ import io.emeraldpay.dshackle.upstream.SingleCallValidator
import io.emeraldpay.dshackle.upstream.Upstream
import io.emeraldpay.dshackle.upstream.UpstreamAvailability.OK
import io.emeraldpay.dshackle.upstream.UpstreamValidator
import io.emeraldpay.dshackle.upstream.ValidateUpstreamSettingsResult
import io.emeraldpay.dshackle.upstream.generic.AbstractPollChainSpecific
import io.emeraldpay.dshackle.upstream.generic.GenericUpstreamValidator
import io.emeraldpay.dshackle.upstream.rpcclient.ListParams
import io.emeraldpay.dshackle.upstream.rpcclient.ObjectParams
import org.slf4j.LoggerFactory
import reactor.core.publisher.Mono
import java.math.BigInteger
import java.time.Instant

object CosmosChainSpecific : AbstractPollChainSpecific() {

val log = LoggerFactory.getLogger(this::class.java)
override fun latestBlockRequest(): ChainRequest = ChainRequest("block", ObjectParams())

override fun parseBlock(data: ByteArray, upstreamId: String): BlockContainer {
@@ -75,9 +79,24 @@ object CosmosChainSpecific : AbstractPollChainSpecific() {
return GenericUpstreamValidator(
upstream,
options,
SingleCallValidator(
ChainRequest("health", ListParams()),
) { _ -> OK },
listOf(
SingleCallValidator(
ChainRequest("health", ListParams()),
) { _ -> OK },
),
listOf(
SingleCallValidator(
ChainRequest("status", ListParams()),
) { data ->
val resp = Global.objectMapper.readValue(data, CosmosStatus::class.java)
if (chain.chainId.isNotEmpty() && resp.nodeInfo.network.lowercase() != chain.chainId.lowercase()) {
ValidateUpstreamSettingsResult.UPSTREAM_FATAL_SETTINGS_ERROR
} else {
ValidateUpstreamSettingsResult.UPSTREAM_VALID
}
},
),

)
}

@@ -115,6 +134,7 @@ data class CosmosStatus(
@JsonIgnoreProperties(ignoreUnknown = true)
data class CosmosNodeInfo(
@JsonProperty("version") var version: String,
@JsonProperty("network") var network: String,
)

@JsonIgnoreProperties(ignoreUnknown = true)
Loading

0 comments on commit cce2bcf

Please sign in to comment.