From e4635838747e05ec55a38e78b963f3349f397bdf Mon Sep 17 00:00:00 2001 From: msizov Date: Mon, 29 Jul 2024 18:58:57 +0500 Subject: [PATCH] add tron evm, fix syncing validator for tron, add more messages for finalization detector (#534) --- emerald-grpc | 2 +- foundation/src/main/resources/public | 2 +- .../upstream/calls/DefaultEthereumMethods.kt | 3 +++ .../ethereum/EthereumChainSpecific.kt | 21 +++++++++++++++++-- .../ethereum/EthereumFinalizationDetector.kt | 12 ++++++++++- .../ethereum/EthereumUpstreamValidator.kt | 11 ++++++++-- 6 files changed, 44 insertions(+), 7 deletions(-) diff --git a/emerald-grpc b/emerald-grpc index 7ea77810..85b3220c 160000 --- a/emerald-grpc +++ b/emerald-grpc @@ -1 +1 @@ -Subproject commit 7ea7781064ba60eff58ce46e9f19cdcc10723e8e +Subproject commit 85b3220c276c7779ad974cec60ef08d49c3c43e4 diff --git a/foundation/src/main/resources/public b/foundation/src/main/resources/public index 4250696e..9e6453e3 160000 --- a/foundation/src/main/resources/public +++ b/foundation/src/main/resources/public @@ -1 +1 @@ -Subproject commit 4250696e577418e8f653ebeb49ad7a0e517a96e5 +Subproject commit 9e6453e3f2a8c332e5d6126aad2cca64b67acfb7 diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt index 0e3f9adf..926dc2ea 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt @@ -457,6 +457,9 @@ class DefaultEthereumMethods( "rsk_getRawBlockHeaderByNumber", "rsk_protocolVersion", ) + Chain.TRON__MAINNET, Chain.TRON__SHASTA -> listOf( + "buildTransaction", + ) else -> emptyList() } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumChainSpecific.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumChainSpecific.kt index dc9332de..92b0525e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumChainSpecific.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumChainSpecific.kt @@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory import org.springframework.cloud.sleuth.Tracer import reactor.core.publisher.Mono import reactor.core.scheduler.Scheduler +import java.math.BigInteger object EthereumChainSpecific : AbstractPollChainSpecific() { @@ -115,8 +116,24 @@ object EthereumChainSpecific : AbstractPollChainSpecific() { UpstreamAvailability.OK } } else { - log.warn("Received syncing object ${raw.toPrettyString()} for upstream ${upstream.getId()}") - UpstreamAvailability.SYNCING + when (chain) { + Chain.TRON__MAINNET, Chain.TRON__SHASTA -> { + var current = + BigInteger(raw.get("currentBlock")?.asText()?.lowercase()?.substringAfter("x"), 16) + var highest = + BigInteger(raw.get("highestBlock")?.asText()?.lowercase()?.substringAfter("x"), 16) + + if (highest - current > config.syncingLagSize.toBigInteger()) { + UpstreamAvailability.SYNCING + } else { + UpstreamAvailability.OK + } + } + else -> { + log.warn("Received syncing object ${raw.toPrettyString()} for upstream ${upstream.getId()}") + UpstreamAvailability.SYNCING + } + } } } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFinalizationDetector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFinalizationDetector.kt index 62fc36fa..f923c4bf 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFinalizationDetector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFinalizationDetector.kt @@ -29,6 +29,16 @@ class EthereumFinalizationDetector : FinalizationDetector { private val disableDetector: ConcurrentHashMap = ConcurrentHashMap() private val finalizationSink = Sinks.many().multicast().directBestEffort() + private val errorRegex = "(" + + ".*bad request.*" + + "|.*block not found.*" + + "|.*Unknown block.*" + + "|.*tag not supported on pre-merge network.*" + + "|.*hex string without 0x prefix.*" + + "|.*Invalid params.*" + + "|.*invalid syntax.*" + + "|.*invalid block number.*" + + ")" override fun detectFinalization( upstream: Upstream, blockTime: Duration, @@ -65,7 +75,7 @@ class EthereumFinalizationDetector : FinalizationDetector { .getIngressReader() .read(req) .onErrorResume { - if (it.message != null && it.message!!.matches(Regex("(.*bad request.*|.*block not found.*|.*Unknown block.*|.*tag not supported on pre-merge network.*)"))) { + if (it.message != null && it.message!!.matches(Regex(errorRegex))) { log.warn("Can't retrieve tagged block, finalization detector for upstream ${upstream.getId()} $chain tag $type disabled") disableDetector[type] = true } else { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt index ef04afff..52fc07ac 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt @@ -34,6 +34,7 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory import reactor.core.publisher.Mono import reactor.kotlin.extra.retry.retryRandomBackoff +import java.math.BigInteger import java.time.Duration import java.util.concurrent.TimeoutException interface CallLimitValidator : SingleValidator { @@ -155,13 +156,19 @@ class ChainIdValidator( netVersion(), ) .map { + var netver: BigInteger + if (it.t2.lowercase().contains("x")) { + netver = BigInteger(it.t2.lowercase().substringAfter("x"), 16) + } else { + netver = BigInteger(it.t2) + } val isChainValid = chain.chainId.lowercase() == it.t1.lowercase() && - chain.netVersion.toString() == it.t2 + chain.netVersion == netver if (!isChainValid) { val actualChain = Global.chainByChainId(it.t1).chainName log.warn( - "${chain.chainName} is specified for upstream ${upstream.getId()} " + + "${chain.chainName} is specified for upstream ${upstream.getId()} (${chain.chainId.lowercase()} $netver) " + "but actually it is $actualChain with chainId ${it.t1} and net_version ${it.t2}", ) }