From ef9c2e42a83e4751867f5a65349df28a185b5dbd Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Mon, 12 Aug 2024 00:04:46 +0300 Subject: [PATCH] lower block detection on filecoin (#546) --- .../ethereum/EthereumLowerBoundBlockDetector.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLowerBoundBlockDetector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLowerBoundBlockDetector.kt index 257dd98b7..c703a63a1 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLowerBoundBlockDetector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLowerBoundBlockDetector.kt @@ -1,5 +1,7 @@ package io.emeraldpay.dshackle.upstream.ethereum +import io.emeraldpay.dshackle.upstream.ChainCallError +import io.emeraldpay.dshackle.upstream.ChainCallUpstreamException import io.emeraldpay.dshackle.upstream.ChainRequest import io.emeraldpay.dshackle.upstream.ChainResponse import io.emeraldpay.dshackle.upstream.Upstream @@ -18,6 +20,11 @@ class EthereumLowerBoundBlockDetector( companion object { private const val NO_BLOCK_DATA = "No block data" + + private val NO_BLOCK_ERRORS = listOf( + "error loading messages for tipset", + "bad tipset height", + ) } private val recursiveLowerBound = RecursiveLowerBound(upstream, LowerBoundType.BLOCK, setOf(NO_BLOCK_DATA), lowerBounds) @@ -42,11 +49,19 @@ class EthereumLowerBoundBlockDetector( if (it.hasResult() && it.getResult().contentEquals("null".toByteArray())) { throw IllegalStateException(NO_BLOCK_DATA) } + }.doOnError { + if (it is ChainCallUpstreamException && handleError(it.error)) { + throw IllegalStateException(NO_BLOCK_DATA) + } } } } } + private fun handleError(error: ChainCallError): Boolean { + return NO_BLOCK_ERRORS.any { error.message.contains(it) } + } + override fun types(): Set { return setOf(LowerBoundType.BLOCK) }