Logs bound is block bound (#572)

This commit is contained in:
KirillPamPam
2024-09-19 15:56:51 +04:00
committed by GitHub
parent 6bbc771526
commit 89a11b85ae
6 changed files with 14 additions and 74 deletions

View File

@@ -57,6 +57,8 @@ class EthereumLowerBoundBlockDetector(
}
}
}
}.flatMap {
Flux.just(it, lowerBoundFrom(it, LowerBoundType.LOGS))
}
}
@@ -65,6 +67,6 @@ class EthereumLowerBoundBlockDetector(
}
override fun types(): Set<LowerBoundType> {
return setOf(LowerBoundType.BLOCK)
return setOf(LowerBoundType.BLOCK, LowerBoundType.LOGS)
}
}

View File

@@ -1,55 +0,0 @@
package io.emeraldpay.dshackle.upstream.ethereum
import io.emeraldpay.dshackle.Defaults
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
class EthereumLowerBoundLogsDetector(
private val upstream: Upstream,
) : LowerBoundDetector(upstream.getChain()) {
companion object {
const val MAX_OFFSET = 20
private const val NO_LOGS_DATA = "No logs data"
}
private val recursiveLowerBound = RecursiveLowerBound(upstream, LowerBoundType.LOGS, setOf(NO_LOGS_DATA), lowerBounds)
override fun period(): Long {
return 3
}
override fun internalDetectLowerBound(): Flux<LowerBoundData> {
return recursiveLowerBound.recursiveDetectLowerBoundWithOffset(MAX_OFFSET) { block ->
upstream.getIngressReader()
.read(
ChainRequest(
"eth_getLogs",
ListParams(
mapOf(
"fromBlock" to block.toHex(),
"toBlock" to block.toHex(),
),
),
),
)
.timeout(Defaults.internalCallsTimeout)
.doOnNext {
if (it.hasResult() && (it.getResult().contentEquals("null".toByteArray()) || it.getResult().contentEquals("[]".toByteArray()))) {
throw IllegalStateException(NO_LOGS_DATA)
}
}
}
}
override fun types(): Set<LowerBoundType> {
return setOf(LowerBoundType.LOGS)
}
}

View File

@@ -14,7 +14,6 @@ class EthereumLowerBoundService(
EthereumLowerBoundStateDetector(upstream),
EthereumLowerBoundBlockDetector(upstream),
EthereumLowerBoundTxDetector(upstream),
EthereumLowerBoundLogsDetector(upstream),
)
}
}

View File

@@ -70,18 +70,10 @@ class EthereumLowerBoundStateDetector(
}
}
}.flatMap {
Flux.just(it, lowerBoundFromState(it, LowerBoundType.TRACE))
Flux.just(it, lowerBoundFrom(it, LowerBoundType.TRACE))
}
}
private fun lowerBoundFromState(stateLowerBoundData: LowerBoundData, newType: LowerBoundType): LowerBoundData {
val currentBound = lowerBounds.getLastBound(newType)
if (currentBound == null || stateLowerBoundData.lowerBound >= currentBound.lowerBound) {
return stateLowerBoundData.copy(type = newType)
}
return LowerBoundData(currentBound.lowerBound, newType)
}
override fun types(): Set<LowerBoundType> {
return setOf(LowerBoundType.STATE, LowerBoundType.TRACE)
}

View File

@@ -50,6 +50,14 @@ abstract class LowerBoundDetector(
protected abstract fun internalDetectLowerBound(): Flux<LowerBoundData>
protected fun lowerBoundFrom(lowerBoundFrom: LowerBoundData, newType: LowerBoundType): LowerBoundData {
val currentBound = lowerBounds.getLastBound(newType)
if (currentBound == null || lowerBoundFrom.lowerBound >= currentBound.lowerBound) {
return lowerBoundFrom.copy(type = newType)
}
return LowerBoundData(currentBound.lowerBound, newType)
}
abstract fun types(): Set<LowerBoundType>
fun updateLowerBound(lowerBound: Long, type: LowerBoundType) {