From 7f5f5155edb853d7ae2b46939e268d93f0bccfa0 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Mon, 16 Dec 2024 15:41:17 -0500 Subject: [PATCH 01/10] feat: support pessimistic proofs --- observer/rpc.go | 4 +++- provider/rpc.go | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/observer/rpc.go b/observer/rpc.go index bf72af6..82b19b6 100644 --- a/observer/rpc.go +++ b/observer/rpc.go @@ -1125,7 +1125,9 @@ type RollupData struct { TrustedSequencerBalances TokenBalances - ChainID *uint64 + ChainID *uint64 + LastLocalExitRoot [32]byte + Pessimistic bool } type RollupManagerObserver struct { diff --git a/provider/rpc.go b/provider/rpc.go index f5f23cf..116dcdc 100644 --- a/provider/rpc.go +++ b/provider/rpc.go @@ -1161,10 +1161,10 @@ func runProvider(ctx context.Context, p *RPCProvider) { } } -func (r *RPCProvider) refreshZkEVMEtrog(ctx context.Context, c *ethclient.Client, address common.Address, co *bind.CallOpts, rollupID uint32, chainID uint64) error { - contract, err := contracts.NewPolygonZkEVMEtrog(address, c) +func (r *RPCProvider) refreshZkEVMEtrog(ctx context.Context, c *ethclient.Client, co *bind.CallOpts, rollupID uint32, rollup RollupData) error { + contract, err := contracts.NewPolygonZkEVMEtrog(rollup.RollupContract, c) if err != nil { - r.logger.Error().Err(err).Msg("Unable to bind zkEVM Etrog contract") + r.logger.Error().Err(err).Msg("Unable to bind PolygonConsensusBase contract") return nil } @@ -1172,7 +1172,8 @@ func (r *RPCProvider) refreshZkEVMEtrog(ctx context.Context, c *ethclient.Client r.rollupManager.Rollups[rollupID] = &observer.RollupData{} } - r.rollupManager.Rollups[rollupID].ChainID = &chainID + r.rollupManager.Rollups[rollupID].ChainID = &rollup.ChainID + r.rollupManager.Rollups[rollupID].LastLocalExitRoot = rollup.LastLocalExitRoot lfb, err := contract.LastForceBatch(co) if err != nil { @@ -1303,6 +1304,24 @@ func (r *RPCProvider) refreshZkEVMContracts(contract *contracts.PolygonRollupMan return nil } +// RollupData is the struct returned by the RollupIDToRollupData method. This is +// here because the abigen tool doesn't generate a named struct for this data. +// Update this value if the response ever changes. +type RollupData struct { + RollupContract common.Address + ChainID uint64 + Verifier common.Address + ForkID uint64 + LastLocalExitRoot [32]byte + LastBatchSequenced uint64 + LastVerifiedBatch uint64 + LastPendingState uint64 + LastPendingStateConsolidated uint64 + LastVerifiedBatchBeforeUpgrade uint64 + RollupTypeID uint64 + RollupCompatibilityID uint8 +} + func (r *RPCProvider) refreshRollups(ctx context.Context, c *ethclient.Client, contract *contracts.PolygonRollupManager, co *bind.CallOpts) { if r.rollupManager.RollupCount == nil { return @@ -1315,7 +1334,7 @@ func (r *RPCProvider) refreshRollups(ctx context.Context, c *ethclient.Client, c continue } - r.refreshZkEVMEtrog(ctx, c, rollup.RollupContract, co, id, rollup.ChainID) + r.refreshZkEVMEtrog(ctx, c, co, id, rollup) } } @@ -1510,10 +1529,15 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co } if rollup.LastVerifiedBatch != nil { - if *rollup.LastVerifiedBatch >= event.NumBatch { + // Here, the last local exit roots are check instead of the last verified + // batch because some changes (pessimistic) don't expose to use the last + // verified batch. + if rollup.LastLocalExitRoot == event.ExitRoot { continue } + rollup.Pessimistic = event.NumBatch == 0 && event.StateRoot == [32]byte{} + // At this point rollup.LastVerifiedBatch and rollup.LastVerifiedTimestamp // contain the data of the previous verified batch event, not the current // one (which is stored in event). This is used to calculate the time From ffce9641610942670f47f112b182a1ef649753aa Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Mon, 16 Dec 2024 15:46:30 -0500 Subject: [PATCH 02/10] feat: pessimistic flag --- observer/rpc.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/observer/rpc.go b/observer/rpc.go index 82b19b6..b303d80 100644 --- a/observer/rpc.go +++ b/observer/rpc.go @@ -1272,7 +1272,8 @@ func (o *RollupManagerObserver) notifyRollup(m Message, rollup *RollupData, id s if rollup.LastVerifiedTimestamp != nil { seconds := time.Since(time.Unix(int64(*rollup.LastVerifiedTimestamp), 0)).Seconds() - o.timeSinceLastVerified.WithLabelValues(m.Network().GetName(), m.Provider(), id).Set(seconds) + pessimistic := fmt.Sprint(rollup.Pessimistic) + o.timeSinceLastVerified.WithLabelValues(m.Network().GetName(), m.Provider(), id, pessimistic).Set(seconds) } for _, seconds := range rollup.TimeBetweenVerifiedBatches { @@ -1344,6 +1345,7 @@ func (o *RollupManagerObserver) Register(eb *EventBus) { "zkevm_time_since_last_verified", "The time since the last verified batch (in seconds)", "rollup", + "pessimistic", ) o.totalVerifiedBatches = metrics.NewGauge( metrics.RPC, From 231795ac749b0748f35bb7fbf55273659f70be37 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Mon, 16 Dec 2024 15:52:04 -0500 Subject: [PATCH 03/10] fix: metrics.md --- metrics.md | 1 + 1 file changed, 1 insertion(+) diff --git a/metrics.md b/metrics.md index 2b643bc..6d12bee 100644 --- a/metrics.md +++ b/metrics.md @@ -639,6 +639,7 @@ Variable Labels: - network - provider - rollup +- pessimistic ### panoptichain_rpc_zkevm_total_verified_batches The total number of verified batches From da90ac243caa5248469935fa863affde5a69d0e0 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Tue, 17 Dec 2024 01:51:21 -0500 Subject: [PATCH 04/10] fix: typo --- provider/rpc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/provider/rpc.go b/provider/rpc.go index 116dcdc..019b036 100644 --- a/provider/rpc.go +++ b/provider/rpc.go @@ -1529,8 +1529,8 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co } if rollup.LastVerifiedBatch != nil { - // Here, the last local exit roots are check instead of the last verified - // batch because some changes (pessimistic) don't expose to use the last + // Here, the last local exit roots are checked instead of the last + // verified batch because some chains (pessimistic) don't expose the last // verified batch. if rollup.LastLocalExitRoot == event.ExitRoot { continue From 9072f2b54e7778e60c65add9d2bd6efe44ffde7f Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Tue, 17 Dec 2024 12:13:14 -0500 Subject: [PATCH 05/10] reword --- provider/rpc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/rpc.go b/provider/rpc.go index 019b036..0235851 100644 --- a/provider/rpc.go +++ b/provider/rpc.go @@ -1530,7 +1530,7 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co if rollup.LastVerifiedBatch != nil { // Here, the last local exit roots are checked instead of the last - // verified batch because some chains (pessimistic) don't expose the last + // verified batch because some chains (pessimistic) don't have the last // verified batch. if rollup.LastLocalExitRoot == event.ExitRoot { continue From d429cd6833024a6920326485e9ed54f3c258dfe2 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Tue, 17 Dec 2024 16:00:16 -0500 Subject: [PATCH 06/10] fix: bug --- provider/rpc.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/provider/rpc.go b/provider/rpc.go index 0235851..143b5c1 100644 --- a/provider/rpc.go +++ b/provider/rpc.go @@ -1536,8 +1536,6 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co continue } - rollup.Pessimistic = event.NumBatch == 0 && event.StateRoot == [32]byte{} - // At this point rollup.LastVerifiedBatch and rollup.LastVerifiedTimestamp // contain the data of the previous verified batch event, not the current // one (which is stored in event). This is used to calculate the time @@ -1556,6 +1554,7 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co rollup.LastVerifiedTimestamp = &time rollup.LastVerifiedBatch = &event.NumBatch + rollup.Pessimistic = event.NumBatch == 0 && event.StateRoot == [32]byte{} receipt, err := c.TransactionReceipt(ctx, event.Raw.TxHash) if err != nil { From af33a86c4eb7b6bfb02c0d360a3fcf802a4c7bcc Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Tue, 17 Dec 2024 16:06:29 -0500 Subject: [PATCH 07/10] fix: revert log --- provider/rpc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/rpc.go b/provider/rpc.go index 143b5c1..6570ab0 100644 --- a/provider/rpc.go +++ b/provider/rpc.go @@ -1164,7 +1164,7 @@ func runProvider(ctx context.Context, p *RPCProvider) { func (r *RPCProvider) refreshZkEVMEtrog(ctx context.Context, c *ethclient.Client, co *bind.CallOpts, rollupID uint32, rollup RollupData) error { contract, err := contracts.NewPolygonZkEVMEtrog(rollup.RollupContract, c) if err != nil { - r.logger.Error().Err(err).Msg("Unable to bind PolygonConsensusBase contract") + r.logger.Error().Err(err).Msg("Unable to bind zkEVM Etrog contract") return nil } From 7d001dc20090e7985ddd74de2b729fdfc772b45f Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 18 Dec 2024 03:33:13 -0500 Subject: [PATCH 08/10] fix: skipping because of local state exit root not changing --- observer/rpc.go | 5 ++--- provider/rpc.go | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/observer/rpc.go b/observer/rpc.go index b303d80..62652ef 100644 --- a/observer/rpc.go +++ b/observer/rpc.go @@ -1125,9 +1125,8 @@ type RollupData struct { TrustedSequencerBalances TokenBalances - ChainID *uint64 - LastLocalExitRoot [32]byte - Pessimistic bool + ChainID *uint64 + Pessimistic bool } type RollupManagerObserver struct { diff --git a/provider/rpc.go b/provider/rpc.go index 6570ab0..2822c74 100644 --- a/provider/rpc.go +++ b/provider/rpc.go @@ -1173,7 +1173,6 @@ func (r *RPCProvider) refreshZkEVMEtrog(ctx context.Context, c *ethclient.Client } r.rollupManager.Rollups[rollupID].ChainID = &rollup.ChainID - r.rollupManager.Rollups[rollupID].LastLocalExitRoot = rollup.LastLocalExitRoot lfb, err := contract.LastForceBatch(co) if err != nil { @@ -1528,11 +1527,21 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co continue } + pessimistic := event.NumBatch == 0 && event.StateRoot == [32]byte{} + if rollup.LastVerifiedBatch != nil { - // Here, the last local exit roots are checked instead of the last - // verified batch because some chains (pessimistic) don't have the last - // verified batch. - if rollup.LastLocalExitRoot == event.ExitRoot { + // Here, pessimistic chains have to be handle differently because the + // NumBatch will always be 0. The last verified timestamp is used to + // determine if the event has already been seen. + // + // There is an edge case here where if both events are included in the + // same block, there will be a missing time between verified batches + // event. This will be rare and won't significantly impact the metric. + if pessimistic && *rollup.LastVerifiedTimestamp >= time { + continue + } + + if pessimistic && *rollup.LastVerifiedBatch >= event.NumBatch { continue } @@ -1554,7 +1563,7 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co rollup.LastVerifiedTimestamp = &time rollup.LastVerifiedBatch = &event.NumBatch - rollup.Pessimistic = event.NumBatch == 0 && event.StateRoot == [32]byte{} + rollup.Pessimistic = pessimistic receipt, err := c.TransactionReceipt(ctx, event.Raw.TxHash) if err != nil { From 6b19de1a199edd771b78a6b345a50f9c76e66dd7 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 18 Dec 2024 03:37:39 -0500 Subject: [PATCH 09/10] fix: typo --- provider/rpc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/rpc.go b/provider/rpc.go index 2822c74..6999746 100644 --- a/provider/rpc.go +++ b/provider/rpc.go @@ -1530,7 +1530,7 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co pessimistic := event.NumBatch == 0 && event.StateRoot == [32]byte{} if rollup.LastVerifiedBatch != nil { - // Here, pessimistic chains have to be handle differently because the + // Here, pessimistic chains have to be handled differently because the // NumBatch will always be 0. The last verified timestamp is used to // determine if the event has already been seen. // From f865c5b77c3586a014ff30b92af0601f9b50083f Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 18 Dec 2024 06:14:53 -0500 Subject: [PATCH 10/10] fix: missing bang --- provider/rpc.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/provider/rpc.go b/provider/rpc.go index 6999746..1c2c1fc 100644 --- a/provider/rpc.go +++ b/provider/rpc.go @@ -1530,9 +1530,9 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co pessimistic := event.NumBatch == 0 && event.StateRoot == [32]byte{} if rollup.LastVerifiedBatch != nil { - // Here, pessimistic chains have to be handled differently because the - // NumBatch will always be 0. The last verified timestamp is used to - // determine if the event has already been seen. + // Here, pessimistic chains are handled differently because the NumBatch + // will always be 0. The last verified timestamp is used to determine if + // the event has already been seen. // // There is an edge case here where if both events are included in the // same block, there will be a missing time between verified batches @@ -1541,7 +1541,7 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co continue } - if pessimistic && *rollup.LastVerifiedBatch >= event.NumBatch { + if !pessimistic && *rollup.LastVerifiedBatch >= event.NumBatch { continue }