Improve solana lower bound detection (#416)

This commit is contained in:
KirillPamPam
2024-02-12 17:26:20 +04:00
committed by GitHub
parent f1c3c07cd7
commit db94d36097
4 changed files with 25 additions and 47 deletions

View File

@@ -4,6 +4,7 @@ import io.emeraldpay.dshackle.Chain
import org.slf4j.LoggerFactory
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import reactor.kotlin.core.publisher.switchIfEmpty
import java.time.Duration
import java.time.Instant
import java.util.concurrent.atomic.AtomicBoolean
@@ -32,6 +33,8 @@ abstract class LowerBoundBlockDetector(
.flatMap {
notProcessing.set(false)
lowerBlockDetect()
.onErrorResume { Mono.just(LowerBlockData.default()) }
.switchIfEmpty { Mono.just(LowerBlockData.default()) } // just to trigger onNext event
}
.doOnNext {
notProcessing.set(true)

View File

@@ -33,52 +33,29 @@ class SolanaLowerBoundBlockDetector(
slot
}
}
.flatMap { slot ->
val from = if (slot <= 10) {
1
} else {
slot - 10
}
.flatMap {
reader.read(
JsonRpcRequest(
"getBlocks",
"getBlock", // since getFirstAvailableBlock returns the slot of the lowest confirmed block we can directly call getBlock
listOf(
from,
slot,
it,
mapOf(
"showRewards" to false,
"transactionDetails" to "none",
"maxSupportedTransactionVersion" to 0,
),
),
),
)
}
.flatMap(JsonRpcResponse::requireResult)
.flatMap {
val response = Global.objectMapper.readValue(it, LongArray::class.java)
if (response == null || response.isEmpty()) {
Mono.empty()
} else {
val maxSlot = response.max()
reader.read(
JsonRpcRequest(
"getBlock",
listOf(
maxSlot,
mapOf(
"showRewards" to false,
"transactionDetails" to "none",
"maxSupportedTransactionVersion" to 0,
),
),
),
)
.flatMap(JsonRpcResponse::requireResult)
.map { blockData ->
val block = Global.objectMapper.readValue(blockData, SolanaBlock::class.java)
LowerBlockData(max(block.height, 1), maxSlot)
}
}
.flatMap(JsonRpcResponse::requireResult)
.map { blockData ->
val block = Global.objectMapper.readValue(blockData, SolanaBlock::class.java)
LowerBlockData(max(block.height, 1), it)
}
}
.retryWhen(
Retry
.backoff(Long.MAX_VALUE, Duration.ofSeconds(1))
.backoff(20, Duration.ofSeconds(1))
.maxBackoff(Duration.ofMinutes(3))
.doAfterRetry {
log.debug(