From c551609e17f04e132057b4d2f46a4c0315776e98 Mon Sep 17 00:00:00 2001 From: colin <102356659+colinlyguo@users.noreply.github.com> Date: Fri, 29 Sep 2023 15:33:08 +0800 Subject: [PATCH 1/2] feat(watcher&rollup): add block commit calldata size and commit/finalize batch revert metrics (#974) Co-authored-by: colinlyguo --- common/version/version.go | 2 +- .../internal/controller/relayer/l2_relayer.go | 6 ++++-- .../controller/relayer/l2_relayer_metrics.go | 10 ++++++++++ .../internal/controller/watcher/l2_watcher.go | 3 +++ .../controller/watcher/l2_watcher_metrics.go | 17 +++++++++++------ 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/common/version/version.go b/common/version/version.go index 5250033b3a..d39dd5823a 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.3.26" +var tag = "v4.3.27" 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 7bdeb0e8a1..d1600b55c1 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -582,7 +582,8 @@ func (r *Layer2Relayer) handleConfirmation(confirmation *sender.Confirmation) { status = types.RollupCommitted } else { status = types.RollupCommitFailed - log.Warn("transaction confirmed but failed in layer1", "confirmation", confirmation) + r.metrics.rollupL2BatchesCommittedConfirmedFailedTotal.Inc() + log.Warn("commitBatch transaction confirmed but failed in layer1", "confirmation", confirmation) } // @todo handle db error err := r.batchOrm.UpdateCommitTxHashAndRollupStatus(r.ctx, batchHash.(string), confirmation.TxHash.String(), status) @@ -603,7 +604,8 @@ func (r *Layer2Relayer) handleConfirmation(confirmation *sender.Confirmation) { status = types.RollupFinalized } else { status = types.RollupFinalizeFailed - log.Warn("transaction confirmed but failed in layer1", "confirmation", confirmation) + r.metrics.rollupL2BatchesFinalizedConfirmedFailedTotal.Inc() + log.Warn("finalizeBatchWithProof transaction confirmed but failed in layer1", "confirmation", confirmation) } // @todo handle db error diff --git a/rollup/internal/controller/relayer/l2_relayer_metrics.go b/rollup/internal/controller/relayer/l2_relayer_metrics.go index 012a167f87..3ad71c684b 100644 --- a/rollup/internal/controller/relayer/l2_relayer_metrics.go +++ b/rollup/internal/controller/relayer/l2_relayer_metrics.go @@ -16,7 +16,9 @@ type l2RelayerMetrics struct { rollupL2RelayerProcessCommittedBatchesFinalizedTotal prometheus.Counter rollupL2RelayerProcessCommittedBatchesFinalizedSuccessTotal prometheus.Counter rollupL2BatchesCommittedConfirmedTotal prometheus.Counter + rollupL2BatchesCommittedConfirmedFailedTotal prometheus.Counter rollupL2BatchesFinalizedConfirmedTotal prometheus.Counter + rollupL2BatchesFinalizedConfirmedFailedTotal prometheus.Counter rollupL2BatchesGasOraclerConfirmedTotal prometheus.Counter rollupL2ChainMonitorLatestFailedCall prometheus.Counter rollupL2ChainMonitorLatestFailedBatchStatus prometheus.Counter @@ -62,10 +64,18 @@ func initL2RelayerMetrics(reg prometheus.Registerer) *l2RelayerMetrics { Name: "rollup_layer2_process_committed_batches_confirmed_total", Help: "The total number of layer2 process committed batches confirmed total", }), + rollupL2BatchesCommittedConfirmedFailedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Name: "rollup_layer2_process_committed_batches_confirmed_failed_total", + Help: "The total number of layer2 process committed batches confirmed failed total", + }), rollupL2BatchesFinalizedConfirmedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "rollup_layer2_process_finalized_batches_confirmed_total", Help: "The total number of layer2 process finalized batches confirmed total", }), + rollupL2BatchesFinalizedConfirmedFailedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Name: "rollup_layer2_process_finalized_batches_confirmed_failed_total", + Help: "The total number of layer2 process finalized batches confirmed failed total", + }), rollupL2BatchesGasOraclerConfirmedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "rollup_layer2_process_gras_oracler_confirmed_total", Help: "The total number of layer2 process finalized batches confirmed total", diff --git a/rollup/internal/controller/watcher/l2_watcher.go b/rollup/internal/controller/watcher/l2_watcher.go index 8cd5cd00a0..347633e3dc 100644 --- a/rollup/internal/controller/watcher/l2_watcher.go +++ b/rollup/internal/controller/watcher/l2_watcher.go @@ -180,6 +180,9 @@ func (w *L2WatcherClient) getAndStoreBlockTraces(ctx context.Context, from, to u } if len(blocks) > 0 { + for _, block := range blocks { + w.metrics.rollupL2BlockL1CommitCalldataSize.Set(float64(block.EstimateL1CommitCalldataSize())) + } if err := w.l2BlockOrm.InsertL2Blocks(w.ctx, blocks); err != nil { return fmt.Errorf("failed to batch insert BlockTraces: %v", err) } diff --git a/rollup/internal/controller/watcher/l2_watcher_metrics.go b/rollup/internal/controller/watcher/l2_watcher_metrics.go index 627382349d..7375d12e50 100644 --- a/rollup/internal/controller/watcher/l2_watcher_metrics.go +++ b/rollup/internal/controller/watcher/l2_watcher_metrics.go @@ -8,12 +8,13 @@ import ( ) type l2WatcherMetrics struct { - fetchRunningMissingBlocksTotal prometheus.Counter - fetchRunningMissingBlocksHeight prometheus.Gauge - fetchContractEventTotal prometheus.Counter - fetchContractEventHeight prometheus.Gauge - rollupL2MsgsRelayedEventsTotal prometheus.Counter - rollupL2BlocksFetchedGap prometheus.Gauge + fetchRunningMissingBlocksTotal prometheus.Counter + fetchRunningMissingBlocksHeight prometheus.Gauge + fetchContractEventTotal prometheus.Counter + fetchContractEventHeight prometheus.Gauge + rollupL2MsgsRelayedEventsTotal prometheus.Counter + rollupL2BlocksFetchedGap prometheus.Gauge + rollupL2BlockL1CommitCalldataSize prometheus.Gauge } var ( @@ -48,6 +49,10 @@ func initL2WatcherMetrics(reg prometheus.Registerer) *l2WatcherMetrics { Name: "rollup_l2_watcher_blocks_fetched_gap", Help: "The gap of l2 fetch", }), + rollupL2BlockL1CommitCalldataSize: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ + Name: "rollup_l2_block_l1_commit_calldata_size", + Help: "The l1 commitBatch calldata size of the l2 block", + }), } }) return l2WatcherMetric From 76d66eba58420459e965d415aac9c5879124c25d Mon Sep 17 00:00:00 2001 From: georgehao Date: Fri, 29 Sep 2023 08:55:10 -0500 Subject: [PATCH 2/2] feat: add chunk/batch get_task index (#976) Co-authored-by: maskpp --- database/migrate/migrate_test.go | 2 +- .../00014_add_chunk_get_task_index.sql | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 database/migrate/migrations/00014_add_chunk_get_task_index.sql diff --git a/database/migrate/migrate_test.go b/database/migrate/migrate_test.go index 4434ce334f..df449a927c 100644 --- a/database/migrate/migrate_test.go +++ b/database/migrate/migrate_test.go @@ -63,7 +63,7 @@ func testResetDB(t *testing.T) { cur, err := Current(pgDB.DB) assert.NoError(t, err) // total number of tables. - assert.Equal(t, 13, int(cur)) + assert.Equal(t, 14, int(cur)) } func testMigrate(t *testing.T) { diff --git a/database/migrate/migrations/00014_add_chunk_get_task_index.sql b/database/migrate/migrations/00014_add_chunk_get_task_index.sql new file mode 100644 index 0000000000..23050e1e8f --- /dev/null +++ b/database/migrate/migrations/00014_add_chunk_get_task_index.sql @@ -0,0 +1,27 @@ +-- +goose Up +-- +goose StatementBegin + +drop index if exists idx_total_attempts_active_attempts_end_block_number; +drop index if exists idx_total_attempts_active_attempts_chunk_proofs_status; + +create index if not exists idx_chunk_proving_status_index on chunk (proving_status, index) where deleted_at IS NULL; +create index if not exists idx_batch_proving_status_index on batch (proving_status, chunk_proofs_status, index) where deleted_at IS NULL; + +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin + +create index if not exists idx_total_attempts_active_attempts_end_block_number + on chunk (total_attempts, active_attempts, end_block_number) + where deleted_at IS NULL; + +create index if not exists idx_total_attempts_active_attempts_chunk_proofs_status + on batch (total_attempts, active_attempts, chunk_proofs_status) + where deleted_at IS NULL; + + +drop index if exists idx_chunk_proving_status_index; +drop index if exists idx_batch_proving_status_index; + +-- +goose StatementEnd