Skip to content

Commit

Permalink
feat: support granite
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod authored and GrapeBaBa committed Sep 15, 2024
1 parent 9982b5c commit 8a20dfa
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 65 deletions.
18 changes: 0 additions & 18 deletions docker/.env.default
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
40 changes: 0 additions & 40 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 44 additions & 1 deletion src/main/java/io/optimism/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -271,6 +273,7 @@ public Map<String, String> 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
Expand All @@ -294,6 +297,7 @@ public record ChainConfig(
BigInteger deltaTime,
BigInteger ecotoneTime,
BigInteger fjordTime,
BigInteger graniteTime,
BigInteger blockTime,
String l2Tol1MessagePasser) {

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -418,6 +454,7 @@ public static ChainConfig optimism() {
BigInteger.valueOf(1708560000L),
BigInteger.valueOf(1710374401L),
BigInteger.valueOf(1720627201L),
BigInteger.valueOf(1726070401L),
BigInteger.valueOf(2L),
"0x4200000000000000000000000000000000000016");
}
Expand Down Expand Up @@ -459,6 +496,7 @@ public static ChainConfig base() {
BigInteger.valueOf(1708560000L),
BigInteger.valueOf(1710374401L),
BigInteger.valueOf(1720627201L),
BigInteger.valueOf(1726070401L),
BigInteger.valueOf(2L),
"0x4200000000000000000000000000000000000016");
}
Expand Down Expand Up @@ -500,6 +538,7 @@ public static ChainConfig optimismSepolia() {
BigInteger.valueOf(1703203200L),
BigInteger.valueOf(1708534800L),
BigInteger.valueOf(1716998400L),
BigInteger.valueOf(1723478400L),
BigInteger.valueOf(2L),
"0x4200000000000000000000000000000000000016");
}
Expand Down Expand Up @@ -541,6 +580,7 @@ public static ChainConfig baseSepolia() {
BigInteger.valueOf(1703203200L),
BigInteger.valueOf(1708534800L),
BigInteger.valueOf(1716998400L),
BigInteger.valueOf(1723478400L),
BigInteger.valueOf(2L),
"0x4200000000000000000000000000000000000016");
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -836,7 +877,8 @@ public Tuple2<BigInteger, BigInteger> 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
Expand All @@ -856,6 +898,7 @@ public record ExternalChainConfig(
BigInteger deltaTime,
BigInteger ecotoneTime,
BigInteger fjordTime,
BigInteger graniteTime,
String batchInboxAddress,
String depositContractAddress,
String l1SystemConfigAddress) {}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/io/optimism/derive/stages/Channels.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/optimism/driver/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ public class Driver<E extends Engine> extends AbstractExecutionThreadService {

private final MessagePassingQueue<ExecutionPayload> unsafeBlockQueue;

private BigInteger channelTimeout;

private final ExecutorService executor;

private volatile boolean isShutdownTriggered;
Expand Down Expand Up @@ -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<String, Function> rpcHandler = HashMap.newHashMap(1);
rpcHandler.put(RpcMethod.OP_SYNC_STATUS.getRpcMethodName(), unused -> this.getSyncStatus());
Expand Down Expand Up @@ -220,7 +217,7 @@ public static Driver<EngineApi> 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(),
Expand Down Expand Up @@ -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 -> {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/optimism/l1/InnerWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ private void getMetadataFromL2(BigInteger l2StartBlock) {
}

private void subscribeL1NewHeads() {
if (this.wsProvider == null) {
return;
}
this.l1HeadListener = this.wsProvider
.newHeadsNotifications()
.subscribe(
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/io/optimism/config/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 8a20dfa

Please sign in to comment.