-
Notifications
You must be signed in to change notification settings - Fork 16
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
cbfb77d
commit c377083
Showing
6 changed files
with
133 additions
and
61 deletions.
There are no files selected for viewing
Submodule emerald-grpc
updated
from 2ed74d to 5b3b52
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/EthereumLowerBoundBlockDetector.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.ChainResponse | ||
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 | ||
import reactor.core.publisher.Mono | ||
|
||
class EthereumLowerBoundBlockDetector( | ||
private val upstream: Upstream, | ||
) : LowerBoundDetector() { | ||
private val recursiveLowerBound = RecursiveLowerBound(upstream, LowerBoundType.BLOCK, setOf("No block data")) | ||
|
||
override fun period(): Long { | ||
return 5 | ||
} | ||
|
||
override fun internalDetectLowerBound(): Flux<LowerBoundData> { | ||
return recursiveLowerBound.recursiveDetectLowerBound { block -> | ||
if (block == 0L) { | ||
Mono.just(ChainResponse(ByteArray(0), null)) | ||
} else { | ||
upstream.getIngressReader() | ||
.read( | ||
ChainRequest( | ||
"eth_getBlockByNumber", | ||
ListParams(block.toHex(), false), | ||
), | ||
) | ||
.doOnNext { | ||
if (it.hasResult() && it.getResult().contentEquals("null".toByteArray())) { | ||
throw IllegalStateException("No block data") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,5 @@ data class LowerBoundData( | |
} | ||
|
||
enum class LowerBoundType { | ||
UNKNOWN, STATE, SLOT | ||
UNKNOWN, STATE, SLOT, BLOCK | ||
} |
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