diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLowerBoundTxDetector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLowerBoundTxDetector.kt index 5e855c41..ffa2329f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLowerBoundTxDetector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLowerBoundTxDetector.kt @@ -1,5 +1,6 @@ package io.emeraldpay.dshackle.upstream.ethereum +import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.upstream.ChainRequest import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.lowerbound.LowerBoundData @@ -29,16 +30,32 @@ class EthereumLowerBoundTxDetector( return recursiveLowerBound.recursiveDetectLowerBoundWithOffset(MAX_OFFSET) { block -> upstream.getIngressReader() .read( - ChainRequest( - "eth_getBlockTransactionCountByNumber", - ListParams(block.toHex()), - ), + ChainRequest("eth_getBlockByNumber", ListParams(block.toHex(), false)), ) .doOnNext { - if (it.hasResult() && (it.getResult().contentEquals("null".toByteArray()) || it.getResultAsProcessedString().substring(2).toLong(16) == 0L)) { + if (it.hasResult() && it.getResult().contentEquals("null".toByteArray())) { throw IllegalStateException(NO_TX_DATA) } } + .handle { it, sink -> + val blockJson = BlockContainer.fromEthereumJson(it.getResult(), upstream.getId()) + if (blockJson.transactions.isEmpty()) { + sink.error(IllegalStateException(NO_TX_DATA)) + return@handle + } + sink.next(blockJson.transactions[0].toHexWithPrefix()) + } + .flatMap { tx -> + upstream.getIngressReader() + .read( + ChainRequest("eth_getTransactionByHash", ListParams(tx)), + ) + .doOnNext { + if (it.hasResult() && it.getResult().contentEquals("null".toByteArray())) { + throw IllegalStateException(NO_TX_DATA) + } + } + } } } diff --git a/src/test/kotlin/io/emeraldpay/dshackle/upstream/RecursiveLowerBoundServiceTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/upstream/RecursiveLowerBoundServiceTest.kt index ff39c5db..437e5e7f 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/upstream/RecursiveLowerBoundServiceTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/upstream/RecursiveLowerBoundServiceTest.kt @@ -1,6 +1,7 @@ package io.emeraldpay.dshackle.upstream import io.emeraldpay.dshackle.Chain +import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.reader.ChainReader import io.emeraldpay.dshackle.upstream.ethereum.EthereumLowerBoundService import io.emeraldpay.dshackle.upstream.ethereum.EthereumLowerBoundTxDetector.Companion.MAX_OFFSET @@ -21,6 +22,8 @@ import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import reactor.core.publisher.Mono import reactor.test.StepVerifier +import java.io.File +import java.nio.file.Files import java.time.Duration class RecursiveLowerBoundServiceTest { @@ -37,6 +40,9 @@ class RecursiveLowerBoundServiceTest { val head = mock
{ on { getCurrentHeight() } doReturn 18000000 } + val blockBytes = Files.readAllBytes( + File(this::class.java.getResource("/responses/get-by-number-response.json")!!.toURI()).toPath(), + ) val reader = mock