From c8a9ede403cb1b1792250ae571b398a66356497e Mon Sep 17 00:00:00 2001 From: thinkAfCod Date: Wed, 8 Nov 2023 18:16:58 +0800 Subject: [PATCH] fix: support roll op devnet --- .../src/main/java/io/optimism/cli/Cli.java | 2 +- .../main/java/io/optimism/derive/State.java | 1 + .../main/java/io/optimism/driver/Driver.java | 5 +++-- .../java/io/optimism/l1/InnerWatcher.java | 21 +++++++++++++++---- .../rpc/RetryRateLimitInterceptor.java | 2 ++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/hildr-node/src/main/java/io/optimism/cli/Cli.java b/hildr-node/src/main/java/io/optimism/cli/Cli.java index a311e5be..e15d7b7a 100644 --- a/hildr-node/src/main/java/io/optimism/cli/Cli.java +++ b/hildr-node/src/main/java/io/optimism/cli/Cli.java @@ -203,7 +203,7 @@ private Config.CliConfig from(Cli cli) { cli.l1WsRpcUrl, cli.l2RpcUrl, cli.l2EngineUrl, - Cli.this.getJwtSecret(), + StringUtils.trim(Cli.this.getJwtSecret()), cli.checkpointSyncUrl, cli.rpcPort, cli.devnet); diff --git a/hildr-node/src/main/java/io/optimism/derive/State.java b/hildr-node/src/main/java/io/optimism/derive/State.java index fc0096b9..da56b509 100644 --- a/hildr-node/src/main/java/io/optimism/derive/State.java +++ b/hildr-node/src/main/java/io/optimism/derive/State.java @@ -232,6 +232,7 @@ public void setCurrentEpochNum(BigInteger currentEpochNum) { private void prune() { BigInteger pruneUntil = this.safeEpoch.number().subtract(config.chainConfig().seqWindowSize()); + pruneUntil = pruneUntil.compareTo(BigInteger.ZERO) < 0 ? BigInteger.ZERO : pruneUntil; Entry blockNumAndHash; while ((blockNumAndHash = this.l1Hashes.firstEntry()) != null) { if (blockNumAndHash.getKey().compareTo(pruneUntil) >= 0) { diff --git a/hildr-node/src/main/java/io/optimism/driver/Driver.java b/hildr-node/src/main/java/io/optimism/driver/Driver.java index a7405bce..44fdfeb2 100644 --- a/hildr-node/src/main/java/io/optimism/driver/Driver.java +++ b/hildr-node/src/main/java/io/optimism/driver/Driver.java @@ -210,9 +210,10 @@ public static Driver from(Config config, CountDownLatch latch) BigInteger finalizedSeq = head.sequenceNumber(); LOGGER.info("starting from head: {}", finalizedHead.hash()); - + BigInteger l1StartBlock = + finalizedEpoch.number().subtract(config.chainConfig().channelTimeout()); ChainWatcher watcher = new ChainWatcher( - finalizedEpoch.number().subtract(config.chainConfig().channelTimeout()), + l1StartBlock.compareTo(BigInteger.ZERO) < 0 ? BigInteger.ZERO : l1StartBlock, finalizedHead.number(), config); diff --git a/hildr-node/src/main/java/io/optimism/l1/InnerWatcher.java b/hildr-node/src/main/java/io/optimism/l1/InnerWatcher.java index 174fb016..a80814ee 100644 --- a/hildr-node/src/main/java/io/optimism/l1/InnerWatcher.java +++ b/hildr-node/src/main/java/io/optimism/l1/InnerWatcher.java @@ -256,7 +256,7 @@ public void tryIngestBlock() throws ExecutionException, InterruptedException { .collect(Collectors.toList()); } - if (this.currentBlock.compareTo(this.headBlock) > 0) { + if (this.currentBlock.compareTo(this.headBlock) > 0 || this.headBlock.equals(BigInteger.ZERO)) { LOGGER.debug("will get head block: currentBlock({}) > headBlock({})", this.currentBlock, this.headBlock); this.headBlock = this.getHead().getNumber(); } @@ -313,7 +313,11 @@ private void updateSystemConfig() throws ExecutionException, InterruptedExceptio BigInteger preLastUpdateBlock = this.systemConfigUpdate.component1(); if (preLastUpdateBlock.compareTo(this.currentBlock) < 0) { BigInteger toBlock = preLastUpdateBlock.add(BigInteger.valueOf(1000L)); - + LOGGER.debug( + "will get system update eth log: fromBlock={} -> toBlock={}; contract={}", + preLastUpdateBlock.add(BigInteger.ONE), + toBlock, + InnerWatcher.this.config.chainConfig().systemConfigContract()); EthLog updates = this.getLog( preLastUpdateBlock.add(BigInteger.ONE), toBlock, @@ -388,7 +392,8 @@ private boolean checkReorg() { } private EthBlock.Block getSafe() throws ExecutionException, InterruptedException { - return this.pollBlock(this.provider, DefaultBlockParameterName.SAFE, false); + var parameter = this.devnet ? DefaultBlockParameterName.LATEST : DefaultBlockParameterName.SAFE; + return this.pollBlock(this.provider, parameter, false); } private EthBlock.Block getFinalized() throws ExecutionException, InterruptedException { @@ -408,6 +413,7 @@ private EthBlock.Block pollBlockByNumber(final Web3j client, final BigInteger bl private EthBlock.Block pollBlock( final Web3j client, final DefaultBlockParameter parameter, final boolean fullTxObjectFlag) throws ExecutionException, InterruptedException { + LOGGER.debug("will poll block: {}", parameter.getValue()); EthBlock.Block block = this.executor .submit(() -> client.ethGetBlockByNumber(parameter, fullTxObjectFlag).send()) @@ -440,6 +446,11 @@ private List getDeposits(BigInteger blockNum) return removed; } final BigInteger endBlock = this.headBlock.min(blockNum.add(BigInteger.valueOf(1000L))); + LOGGER.debug( + "will get deposit eth logs: fromBlock={} -> toBlock={};contract={}", + blockNum, + endBlock, + this.config.chainConfig().depositContract()); EthLog result = this.getLog( blockNum, endBlock, this.config.chainConfig().depositContract(), TRANSACTION_DEPOSITED_TOPIC); @@ -454,7 +465,7 @@ private List getDeposits(BigInteger blockNum) throw new IllegalStateException("Unexpected result type: " + log.get() + " required LogObject"); } }); - var max = (int) endBlock.subtract(blockNum).longValue(); + var max = (int) endBlock.subtract(blockNum).add(BigInteger.ONE).longValue(); for (int i = 0; i < max; i++) { InnerWatcher.this.deposits.putIfAbsent(blockNum.add(BigInteger.valueOf(i)), new ArrayList<>()); } @@ -489,6 +500,8 @@ protected void run() { } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new HildrServiceExecutionException(e); + } catch (Exception e) { + LOGGER.error(String.format("excepted error while fetching L1 data for block %d", currentBlock), e); } finally { span.end(); } diff --git a/hildr-utilities/src/main/java/io/optimism/utilities/rpc/RetryRateLimitInterceptor.java b/hildr-utilities/src/main/java/io/optimism/utilities/rpc/RetryRateLimitInterceptor.java index 46889317..e84337e6 100644 --- a/hildr-utilities/src/main/java/io/optimism/utilities/rpc/RetryRateLimitInterceptor.java +++ b/hildr-utilities/src/main/java/io/optimism/utilities/rpc/RetryRateLimitInterceptor.java @@ -83,10 +83,12 @@ public Response intercept(@NotNull final Chain chain) throws IOException { try { return this.retryer.call(() -> { if (!this.rateLimiter.tryAcquire()) { + LOGGER.warn("there has reached rate limit, but will retry again later"); return new Response.Builder() .request(chain.request()) .protocol(Protocol.HTTP_1_1) .code(429) + .message("there has reached rate limit, but will retry") .build(); } return chain.proceed(chain.request());