Skip to content

Commit 4a94ad7

Browse files
committed
feat: allow stopping fake finalization at fork boundary
1 parent 4d9df8d commit 4a94ad7

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

rollup/conf/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"base_url": "http://localhost:8750"
6363
},
6464
"enable_test_env_bypass_features": true,
65+
"test_env_bypass_only_until_fork_boundary": false,
6566
"finalize_batch_without_proof_timeout_sec": 7200,
6667
"finalize_bundle_without_proof_timeout_sec": 7200,
6768
"gas_oracle_sender_signer_config": {
@@ -114,4 +115,4 @@
114115
"maxOpenNum": 200,
115116
"maxIdleNum": 20
116117
}
117-
}
118+
}

rollup/internal/config/relayer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ type RelayerConfig struct {
6262

6363
// Indicates if bypass features specific to testing environments are enabled.
6464
EnableTestEnvBypassFeatures bool `json:"enable_test_env_bypass_features"`
65+
// Sets rollup-relayer to stop fake finalizing at the fork boundary
66+
TestEnvBypassOnlyUntilForkBoundary bool `json:"test_env_bypass_only_until_fork_boundary"`
6567
// The timeout in seconds for finalizing a batch without proof, only used when EnableTestEnvBypassFeatures is true.
6668
FinalizeBatchWithoutProofTimeoutSec uint64 `json:"finalize_batch_without_proof_timeout_sec"`
6769
// The timeout in seconds for finalizing a bundle without proof, only used when EnableTestEnvBypassFeatures is true.

rollup/internal/controller/relayer/l2_relayer.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,33 @@ func (r *Layer2Relayer) ProcessPendingBundles() {
527527
return
528528
}
529529

530+
lastFinalizedChunk, err := r.chunkOrm.GetChunkByIndex(r.ctx, lastBatch.EndChunkIndex)
531+
if err != nil {
532+
log.Error("failed to get last finalized chunk", "chunk index", lastBatch.EndChunkIndex)
533+
return
534+
}
535+
536+
firstUnfinalizedBatch, err := r.batchOrm.GetBatchByIndex(r.ctx, bundle.StartBatchIndex)
537+
if err != nil {
538+
log.Error("failed to get first unfinalized batch", "batch index", bundle.StartBatchIndex)
539+
return
540+
}
541+
542+
firstUnfinalizedChunk, err := r.chunkOrm.GetChunkByIndex(r.ctx, firstUnfinalizedBatch.StartChunkIndex)
543+
if err != nil {
544+
log.Error("failed to get firsr unfinalized chunk", "chunk index", firstUnfinalizedBatch.StartChunkIndex)
545+
return
546+
}
547+
548+
if r.cfg.TestEnvBypassOnlyUntilForkBoundary {
549+
lastFork := encoding.GetHardforkName(r.chainCfg, lastFinalizedChunk.StartBlockNumber, lastFinalizedChunk.StartBlockTime)
550+
nextFork := encoding.GetHardforkName(r.chainCfg, firstUnfinalizedChunk.StartBlockNumber, firstUnfinalizedChunk.StartBlockTime)
551+
if lastFork != nextFork {
552+
log.Info("not fake finalizing past the fork boundary", "last fork", lastFork, "next fork", nextFork)
553+
return
554+
}
555+
}
556+
530557
if err := r.finalizeBundle(bundle, false); err != nil {
531558
log.Error("failed to finalize timeout bundle without proof", "bundle index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "err", err)
532559
return

0 commit comments

Comments
 (0)