lower block detection on filecoin (#546)

This commit is contained in:
a10zn8
2024-08-12 00:04:46 +03:00
committed by GitHub
parent f5d75e133b
commit ef9c2e42a8

View File

@@ -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<LowerBoundType> {
return setOf(LowerBoundType.BLOCK)
}