From 5aa243ac7ffb8bf28e3d181110cb32830fc1ac8a Mon Sep 17 00:00:00 2001 From: thinkAfCod Date: Thu, 12 Sep 2024 17:51:10 +0800 Subject: [PATCH] feat: support granite --- docker/.env.default | 18 -------- docker/docker-compose.yml | 40 ----------------- src/main/java/io/optimism/config/Config.java | 45 ++++++++++++++++++- .../io/optimism/derive/stages/Channels.java | 10 ++++- src/main/java/io/optimism/driver/Driver.java | 10 ++--- .../java/io/optimism/l1/InnerWatcher.java | 3 ++ .../java/io/optimism/config/ConfigTest.java | 13 ++++++ 7 files changed, 74 insertions(+), 65 deletions(-) diff --git a/docker/.env.default b/docker/.env.default index 8a8bf4c4..9e49362f 100644 --- a/docker/.env.default +++ b/docker/.env.default @@ -19,18 +19,6 @@ BATCH_INBOX_ADDRESS= # JWT secret for the engine API JWT_SECRET=bf549f5188556ce0951048ef467ec93067bc4ea21acebe46ef675cd4e8e015ff -# Execution client chain ID -L2_CHAIN_ID= - -# Execution client signer private key -L2_SIGNER= - -# Deployed l2 output oracle contract address -L2OO_ADDRESS= - -# Deployed l2 dispute game factory contract address -L2DGF_ADDRESS= - # Execution client: can be either `op-geth` or `op-erigon` EXECUTION_CLIENT=op-geth @@ -43,12 +31,6 @@ EXECUTION_CLIENT_RPC_PORT=8545 # The execution client WebSocket port. EXECUTION_CLIENT_WS_PORT=8546 -# The Roll up client. -ROLLUP_CLIENT=hildr-node - -# The Roll up client RPC port. -ROLLUP_RPC_PORT=11545 - # Sync mode: can be either `full` or `checkpoint` SYNC_MODE=full diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 0852cf97..3ea314bf 100755 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -32,46 +32,6 @@ services: - ${OP_ROLLUP_JSON_FILEPATH:-.}:/rollup.json <<: *logging - hildr-batcher: - container_name: hildr-batcher - build: - dockerfile: ./docker/batcher.dock - context: ../ - profiles: - - hildr-batcher - restart: unless-stopped - stop_grace_period: 3m - entrypoint: /scripts/start-hildr-batcher.sh - depends_on: - - op-geth - env_file: - - .env - ports: - - "9201:9201" - volumes: - - ./:/scripts - <<: *logging - - hildr-proposer: - container_name: hildr-proposer - build: - dockerfile: ./docker/proposer.dock - context: ../ - profiles: - - hildr-proposer - restart: unless-stopped - stop_grace_period: 3m - entrypoint: /scripts/start-hildr-batcher.sh - depends_on: - - op-geth - env_file: - - .env - ports: - - "9203:9203" - volumes: - - ./:/scripts - <<: *logging - op-geth: image: us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth:v1.101315.1 container_name: op-geth diff --git a/src/main/java/io/optimism/config/Config.java b/src/main/java/io/optimism/config/Config.java index 075877af..5c924f53 100644 --- a/src/main/java/io/optimism/config/Config.java +++ b/src/main/java/io/optimism/config/Config.java @@ -78,6 +78,8 @@ public record Config( private static final int MAX_SEQUENCER_DRIFT_FJORD = 1800; + private static final int CHANNEL_TIMEOUT_GRANITE = 50; + /** * Create Config. * @@ -271,6 +273,7 @@ public Map toConfigMap() { * @param deltaTime Timestamp of the deltaTime hardfork. * @param ecotoneTime Timestamp of the ecotone hardfork. * @param fjordTime Timestamp of the fjord hardfork. + * @param graniteTime Timestamp of the granite hardfork. * @param blockTime Network blocktime. * @param l2Tol1MessagePasser L2 To L1 Message passer address. * @author grapebaba @@ -294,6 +297,7 @@ public record ChainConfig( BigInteger deltaTime, BigInteger ecotoneTime, BigInteger fjordTime, + BigInteger graniteTime, BigInteger blockTime, String l2Tol1MessagePasser) { @@ -351,6 +355,28 @@ public boolean isFjordActivationBlock(BigInteger time) { && time.subtract(blockTime).compareTo(fjordTime) < 0; } + /** + * Check if the time is the granite activation block. + * + * @param time the block timestamp + * @return true if the time is the granite activation block, otherwise false. + */ + public boolean isGranite(BigInteger time) { + return graniteTime.compareTo(BigInteger.ZERO) >= 0 && time.compareTo(graniteTime) >= 0; + } + + /** + * Check if the time is the granite activation block. + * + * @param time the block timestamp + * @return true if the time is the granite activation block, otherwise false. + */ + public boolean isGraniteActivationBlock(BigInteger time) { + return isFjord(time) + && time.compareTo(blockTime) >= 0 + && time.subtract(blockTime).compareTo(fjordTime) < 0; + } + /** * Check if the time is the canyon activation block. * @@ -381,6 +407,16 @@ public BigInteger maxSequencerDrift(BigInteger time) { return isFjord(time) ? BigInteger.valueOf(MAX_SEQUENCER_DRIFT_FJORD) : this.maxSeqDrift(); } + /** + * Gets Channel timeout. + * + * @param time the current block timestamp + * @return the channel timeout + */ + public BigInteger channelTimeout(BigInteger time) { + return isGranite(time) ? BigInteger.valueOf(CHANNEL_TIMEOUT_GRANITE) : this.channelTimeout(); + } + /** * Optimism chain config. * @@ -418,6 +454,7 @@ public static ChainConfig optimism() { BigInteger.valueOf(1708560000L), BigInteger.valueOf(1710374401L), BigInteger.valueOf(1720627201L), + BigInteger.valueOf(1726070401L), BigInteger.valueOf(2L), "0x4200000000000000000000000000000000000016"); } @@ -459,6 +496,7 @@ public static ChainConfig base() { BigInteger.valueOf(1708560000L), BigInteger.valueOf(1710374401L), BigInteger.valueOf(1720627201L), + BigInteger.valueOf(1726070401L), BigInteger.valueOf(2L), "0x4200000000000000000000000000000000000016"); } @@ -500,6 +538,7 @@ public static ChainConfig optimismSepolia() { BigInteger.valueOf(1703203200L), BigInteger.valueOf(1708534800L), BigInteger.valueOf(1716998400L), + BigInteger.valueOf(1723478400L), BigInteger.valueOf(2L), "0x4200000000000000000000000000000000000016"); } @@ -541,6 +580,7 @@ public static ChainConfig baseSepolia() { BigInteger.valueOf(1703203200L), BigInteger.valueOf(1708534800L), BigInteger.valueOf(1716998400L), + BigInteger.valueOf(1723478400L), BigInteger.valueOf(2L), "0x4200000000000000000000000000000000000016"); } @@ -597,6 +637,7 @@ public static ChainConfig fromExternal(ExternalChainConfig external) { external.deltaTime == null ? BigInteger.valueOf(-1L) : external.deltaTime, external.ecotoneTime == null ? BigInteger.valueOf(-1L) : external.ecotoneTime, external.fjordTime == null ? BigInteger.valueOf(-1L) : external.fjordTime, + external.graniteTime == null ? BigInteger.valueOf(-1L) : external.graniteTime, external.blockTime, "0x4200000000000000000000000000000000000016"); } @@ -836,7 +877,8 @@ public Tuple2 ecotoneScalars() { * @param canyonTime canyon time * @param deltaTime delta time * @param ecotoneTime ecotone time - * @param fjordTime fjord time + * @param fjordTime fjord time + * @param graniteTime granite time * @param batchInboxAddress batch inbox address * @param depositContractAddress deposit contract address * @param l1SystemConfigAddress l1 system config address @@ -856,6 +898,7 @@ public record ExternalChainConfig( BigInteger deltaTime, BigInteger ecotoneTime, BigInteger fjordTime, + BigInteger graniteTime, String batchInboxAddress, String depositContractAddress, String l1SystemConfigAddress) {} diff --git a/src/main/java/io/optimism/derive/stages/Channels.java b/src/main/java/io/optimism/derive/stages/Channels.java index cca3e5a0..17a99481 100644 --- a/src/main/java/io/optimism/derive/stages/Channels.java +++ b/src/main/java/io/optimism/derive/stages/Channels.java @@ -80,7 +80,15 @@ protected void pushFrame(Frame frame) { // Otherwise, construct a new pending channel with the frame's id if (existedPc.isPresent()) { existedPc.get().pushFrame(frame); - if (existedPc.get().isTimedOut(this.config.chainConfig().channelTimeout())) { + var l1Info = this.state.get().l1Info(existedPc.get().highestL1Block); + BigInteger chTimeout; + if (l1Info == null) { + chTimeout = this.config.chainConfig().channelTimeout(); + } else { + BigInteger curTime = l1Info.blockInfo().timestamp(); + chTimeout = this.config.chainConfig().channelTimeout(curTime); + } + if (existedPc.get().isTimedOut(chTimeout)) { this.pendingChannels.remove(existedPc.get()); } } else { diff --git a/src/main/java/io/optimism/driver/Driver.java b/src/main/java/io/optimism/driver/Driver.java index b787236a..7f632150 100644 --- a/src/main/java/io/optimism/driver/Driver.java +++ b/src/main/java/io/optimism/driver/Driver.java @@ -95,8 +95,6 @@ public class Driver extends AbstractExecutionThreadService { private final MessagePassingQueue unsafeBlockQueue; - private BigInteger channelTimeout; - private final ExecutorService executor; private volatile boolean isShutdownTriggered; @@ -154,7 +152,6 @@ public Driver( this.executor = Executors.newVirtualThreadPerTaskExecutor(); this.latch = latch; this.config = config; - this.channelTimeout = config.chainConfig().channelTimeout(); this.opStackNetwork = opStackNetwork; HashMap rpcHandler = HashMap.newHashMap(1); rpcHandler.put(RpcMethod.OP_SYNC_STATUS.getRpcMethodName(), unused -> this.getSyncStatus()); @@ -220,7 +217,7 @@ public static Driver from(Config config, CountDownLatch latch) LOGGER.info("starting from head: number={}, hash={}", finalizedHead.number(), finalizedHead.hash()); BigInteger l1StartBlock = - finalizedEpoch.number().subtract(config.chainConfig().channelTimeout()); + finalizedEpoch.number().subtract(config.chainConfig().channelTimeout(finalizedEpoch.timestamp())); ChainWatcher watcher = new ChainWatcher( l1StartBlock.compareTo(BigInteger.ZERO) < 0 ? BigInteger.ZERO : l1StartBlock, finalizedHead.number(), @@ -608,8 +605,11 @@ private void handleNextBlockUpdate() { } private void restartChainWatcher() { + BigInteger channelTimeout = this.config + .chainConfig() + .channelTimeout(Driver.this.engineDriver.getFinalizedEpoch().timestamp()); Driver.this.chainWatcher.restart( - Driver.this.engineDriver.getFinalizedEpoch().number().subtract(this.channelTimeout), + Driver.this.engineDriver.getFinalizedEpoch().number().subtract(channelTimeout), Driver.this.engineDriver.getFinalizedHead().number()); Driver.this.state.getAndUpdate(state -> { diff --git a/src/main/java/io/optimism/l1/InnerWatcher.java b/src/main/java/io/optimism/l1/InnerWatcher.java index 8a4e4d09..84fc35f9 100644 --- a/src/main/java/io/optimism/l1/InnerWatcher.java +++ b/src/main/java/io/optimism/l1/InnerWatcher.java @@ -218,6 +218,9 @@ private void getMetadataFromL2(BigInteger l2StartBlock) { } private void subscribeL1NewHeads() { + if (this.wsProvider == null) { + return; + } this.l1HeadListener = this.wsProvider .newHeadsNotifications() .subscribe( diff --git a/src/test/java/io/optimism/config/ConfigTest.java b/src/test/java/io/optimism/config/ConfigTest.java index c05cfbf7..4e2a9958 100644 --- a/src/test/java/io/optimism/config/ConfigTest.java +++ b/src/test/java/io/optimism/config/ConfigTest.java @@ -156,6 +156,19 @@ void batchHash() { assertTrue(systemConfig.batcherHash().contains(Numeric.cleanHexPrefix(systemConfig.batchSender()))); } + @Test + void testOptimismChannelTimeout() { + ChainConfig chainConfig = ChainConfig.optimismSepolia(); + BigInteger bedrockChTimeout = chainConfig.channelTimeout(); + BigInteger fjordTimeChTimeout = + chainConfig.channelTimeout(chainConfig.graniteTime().subtract(BigInteger.ONE)); + BigInteger graniteChTimeout = + chainConfig.channelTimeout(chainConfig.graniteTime().add(BigInteger.ONE)); + assertEquals(bedrockChTimeout, BigInteger.valueOf(300L)); + assertEquals(fjordTimeChTimeout, BigInteger.valueOf(300L)); + assertEquals(graniteChTimeout, BigInteger.valueOf(50L)); + } + /** * Read external chain from json. */