Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support pessimistic proofs #3

Merged
merged 10 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ Variable Labels:
- network
- provider
- rollup
- pessimistic

### panoptichain_rpc_zkevm_total_verified_batches
The total number of verified batches
Expand Down
7 changes: 5 additions & 2 deletions observer/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,8 @@ type RollupData struct {

TrustedSequencerBalances TokenBalances

ChainID *uint64
ChainID *uint64
Pessimistic bool
}

type RollupManagerObserver struct {
Expand Down Expand Up @@ -1270,7 +1271,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 {
Expand Down Expand Up @@ -1342,6 +1344,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,
Expand Down
42 changes: 37 additions & 5 deletions provider/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,8 @@ 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")
return nil
Expand All @@ -1172,7 +1172,7 @@ 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

lfb, err := contract.LastForceBatch(co)
if err != nil {
Expand Down Expand Up @@ -1303,6 +1303,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
Expand All @@ -1315,7 +1333,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)
}
}

Expand Down Expand Up @@ -1509,8 +1527,21 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co
continue
}

pessimistic := event.NumBatch == 0 && event.StateRoot == [32]byte{}

if rollup.LastVerifiedBatch != nil {
if *rollup.LastVerifiedBatch >= event.NumBatch {
// 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
// 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
}

Expand All @@ -1532,6 +1563,7 @@ func (r *RPCProvider) refreshRollupVerifyBatchesTrustedAggregator(ctx context.Co

rollup.LastVerifiedTimestamp = &time
rollup.LastVerifiedBatch = &event.NumBatch
rollup.Pessimistic = pessimistic

receipt, err := c.TransactionReceipt(ctx, event.Raw.TxHash)
if err != nil {
Expand Down
Loading