-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9e2e7f
commit 160dd34
Showing
4 changed files
with
178 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLowerBoundTxDetector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.emeraldpay.dshackle.upstream.ethereum | ||
|
||
import io.emeraldpay.dshackle.upstream.ChainRequest | ||
import io.emeraldpay.dshackle.upstream.Upstream | ||
import io.emeraldpay.dshackle.upstream.lowerbound.LowerBoundData | ||
import io.emeraldpay.dshackle.upstream.lowerbound.LowerBoundDetector | ||
import io.emeraldpay.dshackle.upstream.lowerbound.LowerBoundType | ||
import io.emeraldpay.dshackle.upstream.lowerbound.detector.RecursiveLowerBound | ||
import io.emeraldpay.dshackle.upstream.lowerbound.toHex | ||
import io.emeraldpay.dshackle.upstream.rpcclient.ListParams | ||
import reactor.core.publisher.Flux | ||
|
||
const val MAX_OFFSET = 20 | ||
|
||
class EthereumLowerBoundTxDetector( | ||
private val upstream: Upstream, | ||
) : LowerBoundDetector() { | ||
private val recursiveLowerBound = RecursiveLowerBound(upstream, LowerBoundType.TX, setOf("No tx data"), lowerBounds) | ||
|
||
override fun period(): Long { | ||
return 3 | ||
} | ||
|
||
override fun internalDetectLowerBound(): Flux<LowerBoundData> { | ||
return recursiveLowerBound.recursiveDetectLowerBoundWithOffset(MAX_OFFSET) { block -> | ||
upstream.getIngressReader() | ||
.read( | ||
ChainRequest( | ||
"eth_getBlockTransactionCountByNumber", | ||
ListParams(block.toHex()), | ||
), | ||
) | ||
.doOnNext { | ||
if (it.hasResult() && (it.getResult().contentEquals("null".toByteArray()) || it.getResultAsProcessedString().substring(2).toLong(16) == 0L)) { | ||
throw IllegalStateException("No tx data") | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun types(): Set<LowerBoundType> { | ||
return setOf(LowerBoundType.TX) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters