Skip to content

Commit

Permalink
lower block detection on filecoin (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
a10zn8 authored Aug 11, 2024
1 parent f5d75e1 commit ef9c2e4
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit ef9c2e4

Please sign in to comment.