From bf9136bcd6dd53b26a71b7f4a408803784525b9e Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Fri, 15 Nov 2024 18:25:18 +0800 Subject: [PATCH 1/5] fix(rollup-relayer): check if previous batch or bundle is finalized in fake finalize mode --- common/version/version.go | 2 +- rollup/internal/controller/relayer/l2_relayer.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/common/version/version.go b/common/version/version.go index 83bff50de..57588b9c0 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.4.72" +var tag = "v4.4.73" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index b90e70f9e..434b1bb7e 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -568,6 +568,22 @@ func (r *Layer2Relayer) ProcessPendingBundles() { switch status { case types.ProvingTaskUnassigned, types.ProvingTaskAssigned: if r.cfg.EnableTestEnvBypassFeatures && utils.NowUTC().Sub(bundle.CreatedAt) > time.Duration(r.cfg.FinalizeBundleWithoutProofTimeoutSec)*time.Second { + // check if last batch is finalized, because in fake finalize bundle mode, we have not verified if the previous bundle or batch is finalized. + if bundle.StartBatchIndex == 0 { + log.Error("invalid args: start batch index of bundle is 0", "bundle index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex) + return + } + + lastBatch, err := r.batchOrm.GetBatchByIndex(r.ctx, bundle.StartBatchIndex-1) + if err != nil { + log.Error("failed to get last batch", "index", bundle.StartBatchIndex-1, "err", err) + return + } + + if types.RollupStatus(lastBatch.RollupStatus) != types.RollupFinalized { + log.Error("previous bundle or batch is not finalized", "index", lastBatch.Index, "hash", lastBatch.Hash, "rollup status", types.RollupStatus(lastBatch.RollupStatus)) + } + if err := r.finalizeBundle(bundle, false); err != nil { log.Error("Failed to finalize timeout bundle without proof", "index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "err", err) } From 912561a5a9bd19f38b0499cdf3546c05d4f03ea9 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Fri, 15 Nov 2024 18:36:02 +0800 Subject: [PATCH 2/5] tweak comments --- rollup/internal/controller/relayer/l2_relayer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index 434b1bb7e..bcab5e65f 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -568,7 +568,7 @@ func (r *Layer2Relayer) ProcessPendingBundles() { switch status { case types.ProvingTaskUnassigned, types.ProvingTaskAssigned: if r.cfg.EnableTestEnvBypassFeatures && utils.NowUTC().Sub(bundle.CreatedAt) > time.Duration(r.cfg.FinalizeBundleWithoutProofTimeoutSec)*time.Second { - // check if last batch is finalized, because in fake finalize bundle mode, we have not verified if the previous bundle or batch is finalized. + // check if last batch is finalized, because in fake finalize bundle mode, the contract does not verify if the previous bundle or batch is finalized. if bundle.StartBatchIndex == 0 { log.Error("invalid args: start batch index of bundle is 0", "bundle index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex) return From 31e1f16cab4aa15581a9d989f45f4a86fb838246 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Fri, 15 Nov 2024 20:59:31 +0800 Subject: [PATCH 3/5] add returns --- rollup/internal/controller/relayer/l2_relayer.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index bcab5e65f..1b2f0a5e2 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -582,10 +582,12 @@ func (r *Layer2Relayer) ProcessPendingBundles() { if types.RollupStatus(lastBatch.RollupStatus) != types.RollupFinalized { log.Error("previous bundle or batch is not finalized", "index", lastBatch.Index, "hash", lastBatch.Hash, "rollup status", types.RollupStatus(lastBatch.RollupStatus)) + return } if err := r.finalizeBundle(bundle, false); err != nil { log.Error("Failed to finalize timeout bundle without proof", "index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "err", err) + return } } @@ -594,6 +596,7 @@ func (r *Layer2Relayer) ProcessPendingBundles() { r.metrics.rollupL2RelayerProcessPendingBundlesFinalizedTotal.Inc() if err := r.finalizeBundle(bundle, true); err != nil { log.Error("Failed to finalize bundle with proof", "index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "err", err) + return } case types.ProvingTaskFailed: From 76952069a8f34698516490bcc5d69e1a85612585 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Mon, 18 Nov 2024 13:18:17 +0800 Subject: [PATCH 4/5] tweak logs --- rollup/internal/controller/relayer/l2_relayer.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index 1b2f0a5e2..4e4210cc7 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -576,17 +576,17 @@ func (r *Layer2Relayer) ProcessPendingBundles() { lastBatch, err := r.batchOrm.GetBatchByIndex(r.ctx, bundle.StartBatchIndex-1) if err != nil { - log.Error("failed to get last batch", "index", bundle.StartBatchIndex-1, "err", err) + log.Error("failed to get last batch", "batch index", bundle.StartBatchIndex-1, "err", err) return } if types.RollupStatus(lastBatch.RollupStatus) != types.RollupFinalized { - log.Error("previous bundle or batch is not finalized", "index", lastBatch.Index, "hash", lastBatch.Hash, "rollup status", types.RollupStatus(lastBatch.RollupStatus)) + log.Error("previous bundle or batch is not finalized", "batch index", lastBatch.Index, "batch hash", lastBatch.Hash, "rollup status", types.RollupStatus(lastBatch.RollupStatus)) return } if err := r.finalizeBundle(bundle, false); err != nil { - log.Error("Failed to finalize timeout bundle without proof", "index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "err", err) + 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) return } } @@ -595,7 +595,7 @@ func (r *Layer2Relayer) ProcessPendingBundles() { log.Info("Start to roll up zk proof", "bundle hash", bundle.Hash) r.metrics.rollupL2RelayerProcessPendingBundlesFinalizedTotal.Inc() if err := r.finalizeBundle(bundle, true); err != nil { - log.Error("Failed to finalize bundle with proof", "index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "err", err) + log.Error("Failed to finalize bundle with proof", "bundle index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "err", err) return } @@ -608,7 +608,7 @@ func (r *Layer2Relayer) ProcessPendingBundles() { // stop the ledger, fix the limit, revert all the violating blocks, // chunks, batches, bundles and all subsequent ones, and resume, // i.e. this case requires manual resolution. - log.Error("bundle proving failed", "index", bundle.Index, "hash", bundle.Hash, "proved at", bundle.ProvedAt, "proof time sec", bundle.ProofTimeSec) + log.Error("bundle proving failed", "bundle index", bundle.Index, "bundle hash", bundle.Hash, "proved at", bundle.ProvedAt, "proof time sec", bundle.ProofTimeSec) default: log.Error("encounter unreachable case in ProcessPendingBundles", "proving status", status) From ac482602c00448d266b3b4505d5aaabaddf0425e Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Mon, 18 Nov 2024 13:31:21 +0800 Subject: [PATCH 5/5] tweaks --- rollup/internal/controller/relayer/l2_relayer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index 4e4210cc7..879c4da9a 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -586,7 +586,7 @@ func (r *Layer2Relayer) ProcessPendingBundles() { } if err := r.finalizeBundle(bundle, false); err != nil { - 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) + 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) return } } @@ -595,7 +595,7 @@ func (r *Layer2Relayer) ProcessPendingBundles() { log.Info("Start to roll up zk proof", "bundle hash", bundle.Hash) r.metrics.rollupL2RelayerProcessPendingBundlesFinalizedTotal.Inc() if err := r.finalizeBundle(bundle, true); err != nil { - log.Error("Failed to finalize bundle with proof", "bundle index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "err", err) + log.Error("failed to finalize bundle with proof", "bundle index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "err", err) return }