Fixes lower data calculation (#410)

This commit is contained in:
KirillPamPam
2024-02-01 14:01:35 +04:00
committed by GitHub
parent aebd15f547
commit 7fba7dfe4e
8 changed files with 36 additions and 10 deletions

View File

@@ -244,7 +244,7 @@ chain-settings:
label: Arbitrum Nova label: Arbitrum Nova
type: eth type: eth
settings: settings:
expected-block-time: 1s expected-block-time: 260ms
options: options:
disable-validation: true disable-validation: true
lags: lags:
@@ -737,7 +737,7 @@ chain-settings:
type: solana type: solana
settings: settings:
currency: SOL currency: SOL
expected-block-time: 1s expected-block-time: 400ms
options: options:
validate-peers: false validate-peers: false
lags: lags:

View File

@@ -6,6 +6,7 @@ import reactor.core.publisher.Flux
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
import java.time.Duration import java.time.Duration
import java.time.Instant import java.time.Instant
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference import java.util.concurrent.atomic.AtomicReference
typealias LowerBoundBlockDetectorBuilder = (Chain, Upstream) -> LowerBoundBlockDetector typealias LowerBoundBlockDetectorBuilder = (Chain, Upstream) -> LowerBoundBlockDetector
@@ -21,11 +22,20 @@ abstract class LowerBoundBlockDetector(
protected val log = LoggerFactory.getLogger(this::class.java) protected val log = LoggerFactory.getLogger(this::class.java)
fun lowerBlock(): Flux<LowerBlockData> { fun lowerBlock(): Flux<LowerBlockData> {
val notProcessing = AtomicBoolean(true)
return Flux.interval( return Flux.interval(
Duration.ofSeconds(15), Duration.ofSeconds(15),
Duration.ofSeconds(60), Duration.ofMinutes(periodRequest()),
) )
.flatMap { lowerBlockDetect() } .filter { notProcessing.get() }
.flatMap {
notProcessing.set(false)
lowerBlockDetect()
}
.doOnNext {
notProcessing.set(true)
}
.filter { it.blockNumber > currentLowerBlock.get().blockNumber } .filter { it.blockNumber > currentLowerBlock.get().blockNumber }
.map { .map {
log.info("Lower block of ${upstream.getId()} $chain: block height - {}, slot - {}", it.blockNumber, it.slot ?: "NA") log.info("Lower block of ${upstream.getId()} $chain: block height - {}, slot - {}", it.blockNumber, it.slot ?: "NA")
@@ -39,6 +49,8 @@ abstract class LowerBoundBlockDetector(
protected abstract fun lowerBlockDetect(): Mono<LowerBlockData> protected abstract fun lowerBlockDetect(): Mono<LowerBlockData>
protected abstract fun periodRequest(): Long
data class LowerBlockData( data class LowerBlockData(
val blockNumber: Long, val blockNumber: Long,
val slot: Long?, val slot: Long?,

View File

@@ -27,7 +27,7 @@ abstract class RecursiveLowerBoundBlockDetector(
} else { } else {
val middle = middleBlock(data) val middle = middleBlock(data)
if (data.left > data.right) { if (data.left > data.right || middle == 0L) {
val current = if (data.current == 0L) 1 else data.current val current = if (data.current == 0L) 1 else data.current
Mono.just(LowerBoundData(current, true)) Mono.just(LowerBoundData(current, true))
} else { } else {
@@ -57,7 +57,7 @@ abstract class RecursiveLowerBoundBlockDetector(
Long.MAX_VALUE, Long.MAX_VALUE,
Duration.ofSeconds(1), Duration.ofSeconds(1),
) )
.maxBackoff(Duration.ofSeconds(3)) .maxBackoff(Duration.ofMinutes(3))
.filter { .filter {
!nonRetryableErrors.any { err -> it.message?.contains(err, true) ?: false } !nonRetryableErrors.any { err -> it.message?.contains(err, true) ?: false }
} }
@@ -71,5 +71,9 @@ abstract class RecursiveLowerBoundBlockDetector(
} }
} }
override fun periodRequest(): Long {
return 10
}
protected abstract fun hasState(blockNumber: Long): Mono<Boolean> protected abstract fun hasState(blockNumber: Long): Mono<Boolean>
} }

View File

@@ -34,6 +34,8 @@ class EthereumLowerBoundBlockDetector(
"after last accepted block", "after last accepted block",
"Version has either been pruned, or is for a future block", // cronos "Version has either been pruned, or is for a future block", // cronos
"no historical RPC is available for this historical", // optimism "no historical RPC is available for this historical", // optimism
"historical backend error", // optimism
"load state tree: failed to load state tree", // filecoin
) )
} }

View File

@@ -79,7 +79,7 @@ class SolanaLowerBoundBlockDetector(
.retryWhen( .retryWhen(
Retry Retry
.backoff(Long.MAX_VALUE, Duration.ofSeconds(1)) .backoff(Long.MAX_VALUE, Duration.ofSeconds(1))
.maxBackoff(Duration.ofSeconds(3)) .maxBackoff(Duration.ofMinutes(3))
.doAfterRetry { .doAfterRetry {
log.debug( log.debug(
"Error in calculation of lower block of upstream {}, retry attempt - {}, message - {}", "Error in calculation of lower block of upstream {}, retry attempt - {}, message - {}",
@@ -90,4 +90,8 @@ class SolanaLowerBoundBlockDetector(
}, },
) )
} }
override fun periodRequest(): Long {
return 3
}
} }

View File

@@ -14,4 +14,8 @@ class StarknetLowerBoundBlockDetector(
override fun lowerBlockDetect(): Mono<LowerBlockData> { override fun lowerBlockDetect(): Mono<LowerBlockData> {
return Mono.just(LowerBlockData(1)) return Mono.just(LowerBlockData(1))
} }
override fun periodRequest(): Long {
return 120
}
} }

View File

@@ -38,7 +38,7 @@ class RecursiveLowerBoundBlockDetectorTest {
StepVerifier.withVirtualTime { detector.lowerBlock() } StepVerifier.withVirtualTime { detector.lowerBlock() }
.expectSubscription() .expectSubscription()
.expectNoEvent(Duration.ofSeconds(15)) .expectNoEvent(Duration.ofSeconds(15))
.expectNext(LowerBoundBlockDetector.LowerBlockData(17964844L)) .expectNextMatches { it.blockNumber == 17964844L }
.thenCancel() .thenCancel()
.verify(Duration.ofSeconds(3)) .verify(Duration.ofSeconds(3))
@@ -64,7 +64,7 @@ class RecursiveLowerBoundBlockDetectorTest {
StepVerifier.withVirtualTime { detector.lowerBlock() } StepVerifier.withVirtualTime { detector.lowerBlock() }
.expectSubscription() .expectSubscription()
.expectNoEvent(Duration.ofSeconds(15)) .expectNoEvent(Duration.ofSeconds(15))
.expectNext(LowerBoundBlockDetector.LowerBlockData(1)) .expectNextMatches { it.blockNumber == 1L }
.thenCancel() .thenCancel()
.verify(Duration.ofSeconds(3)) .verify(Duration.ofSeconds(3))

View File

@@ -61,7 +61,7 @@ class SolanaLowerBoundBlockDetectorTest {
StepVerifier.withVirtualTime { detector.lowerBlock() } StepVerifier.withVirtualTime { detector.lowerBlock() }
.expectSubscription() .expectSubscription()
.expectNoEvent(Duration.ofSeconds(15)) .expectNoEvent(Duration.ofSeconds(15))
.expectNext(LowerBoundBlockDetector.LowerBlockData(21000000, 23000010)) .expectNextMatches { it.blockNumber == 21000000L && it.slot == 23000010L }
.thenCancel() .thenCancel()
.verify(Duration.ofSeconds(3)) .verify(Duration.ofSeconds(3))