Skip to content

Commit

Permalink
feat: added async retryer for currentL2BlockNumber in case the contra…
Browse files Browse the repository at this point in the history
…ct variable is not initialized yet
  • Loading branch information
jonesho committed Dec 13, 2024
1 parent 447c222 commit 93af0f5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ class L1BasedLastFinalizedBlockProvider(
override fun getLastFinalizedBlock(): SafeFuture<ULong> {
lineaRollupSmartContractWeb3jClient.setDefaultBlockParameter(DefaultBlockParameterName.LATEST)

return SafeFuture.of(lineaRollupSmartContractWeb3jClient.currentL2BlockNumber().sendAsync())
return AsyncRetryer.retry(
vertx,
maxRetries = numberOfRetries.toInt(),
backoffDelay = pollingInterval
) {
SafeFuture.of(lineaRollupSmartContractWeb3jClient.currentL2BlockNumber().sendAsync())
}
.thenCompose { blockNumber ->
log.info(
"Rollup lastFinalizedBlockNumber={} waiting {} blocks for confirmation for no updates",
Expand All @@ -45,18 +51,18 @@ class L1BasedLastFinalizedBlockProvider(
)
val lastObservedBlock = AtomicReference(blockNumber)
val numberOfObservations = AtomicInteger(1)
val isConsistentEnough = { lasPolledBlockNumber: BigInteger ->
if (lasPolledBlockNumber == lastObservedBlock.get()) {
val isConsistentEnough = { lastPolledBlockNumber: BigInteger ->
if (lastPolledBlockNumber == lastObservedBlock.get()) {
numberOfObservations.incrementAndGet().toUInt() >= consistentNumberOfBlocksOnL1
} else {
log.info(
"Rollup finalized block updated from {} to {}, waiting {} blocks for confirmation",
blockNumber,
lasPolledBlockNumber,
lastPolledBlockNumber,
consistentNumberOfBlocksOnL1
)
numberOfObservations.set(1)
lastObservedBlock.set(lasPolledBlockNumber)
lastObservedBlock.set(lastPolledBlockNumber)
false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FeeHistoryFetcherImpl(
}

private var cacheIsValidForBlockNumber: BigInteger = BigInteger.ZERO
private var feesCache: FeeHistory = getRecentFees().get()
private lateinit var feesCache: FeeHistory

private fun getRecentFees(): SafeFuture<FeeHistory> {
val blockNumberFuture = web3jClient.ethBlockNumber().sendAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.consensys.zkevm.ethereum.finalization

import build.linea.contract.LineaRollupV5
import io.vertx.core.Vertx
import net.consensys.linea.async.AsyncRetryer
import net.consensys.linea.async.toSafeFuture
import net.consensys.toULong
import net.consensys.zkevm.PeriodicPollingService
Expand Down Expand Up @@ -32,8 +33,8 @@ data class FinalizationUpdatePollerConfig(
}

class FinalizationUpdatePoller(
vertx: Vertx,
config: FinalizationUpdatePollerConfig,
private val vertx: Vertx,
private val config: FinalizationUpdatePollerConfig,
private val lineaRollup: LineaRollupV5,
private val finalizationHandler: (ULong) -> CompletableFuture<*>,
private val log: Logger = LogManager.getLogger(FinalizationUpdatePoller::class.java)
Expand All @@ -49,7 +50,12 @@ class FinalizationUpdatePoller(
}

override fun action(): SafeFuture<*> {
return lineaRollup.currentL2BlockNumber().sendAsync()
return AsyncRetryer.retry(
vertx,
backoffDelay = config.pollingInterval
) {
SafeFuture.of(lineaRollup.currentL2BlockNumber().sendAsync())
}
.thenCompose { lineaFinalizedBlockNumber ->
val prevFinalizedBlockNumber = lastFinalizationRef.get()
lastFinalizationRef.set(lineaFinalizedBlockNumber.toULong())
Expand Down

0 comments on commit 93af0f5

Please sign in to comment.