Skip to content

Commit

Permalink
fix: support roll op devnet
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod authored and GrapeBaBa committed Nov 9, 2023
1 parent e9be72a commit c8a9ede
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hildr-node/src/main/java/io/optimism/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions hildr-node/src/main/java/io/optimism/derive/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<BigInteger, String> blockNumAndHash;
while ((blockNumAndHash = this.l1Hashes.firstEntry()) != null) {
if (blockNumAndHash.getKey().compareTo(pruneUntil) >= 0) {
Expand Down
5 changes: 3 additions & 2 deletions hildr-node/src/main/java/io/optimism/driver/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ public static Driver<EngineApi> 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);

Expand Down
21 changes: 17 additions & 4 deletions hildr-node/src/main/java/io/optimism/l1/InnerWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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())
Expand Down Expand Up @@ -440,6 +446,11 @@ private List<Attributes.UserDeposited> 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);
Expand All @@ -454,7 +465,7 @@ private List<Attributes.UserDeposited> 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<>());
}
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit c8a9ede

Please sign in to comment.