From b129bba863759f51faddc5ed520b381cb8384f4c Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 13:35:59 +0800 Subject: [PATCH 01/13] feat(metrics): collect `txmgr` metrics --- internal/metrics/metrics.go | 5 +++++ proposer/proposer.go | 3 +-- prover/prover.go | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 5851148ba..fdccfef9e 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -7,6 +7,8 @@ import ( "strconv" "time" + opMetrics "github.com/ethereum-optimism/optimism/op-service/metrics" + txmgrMetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics/prometheus" @@ -42,6 +44,9 @@ var ( ProverSubmissionErrorCounter = metrics.NewRegisteredCounter("prover/proof/submission/error", nil) ProverSgxProofGeneratedCounter = metrics.NewRegisteredCounter("prover/proof/sgx/generated", nil) ProverSubmissionRevertedCounter = metrics.NewRegisteredCounter("prover/proof/submission/reverted", nil) + + // TxManager + TxMgrMetrics = txmgrMetrics.MakeTxMetrics("client", opMetrics.With(opMetrics.NewRegistry())) ) // Serve starts the metrics server on the given address, will be closed when the given diff --git a/proposer/proposer.go b/proposer/proposer.go index 7314ed5b7..b708c5c4f 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -10,7 +10,6 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/sender" "github.com/ethereum-optimism/optimism/op-service/txmgr" - txmgrMetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -107,7 +106,7 @@ func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config) (err error) txmgr, err := txmgr.NewSimpleTxManager( "proposer", log.Root(), - new(txmgrMetrics.NoopTxMetrics), + &metrics.TxMgrMetrics, *cfg.TxmgrConfigs, ) if err != nil { diff --git a/prover/prover.go b/prover/prover.go index f037f2b2d..efc9669d8 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -12,7 +12,6 @@ import ( "github.com/cenkalti/backoff/v4" "github.com/ethereum-optimism/optimism/op-service/txmgr" - "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" @@ -21,6 +20,7 @@ import ( "github.com/taikoxyz/taiko-client/bindings" "github.com/taikoxyz/taiko-client/bindings/encoding" + "github.com/taikoxyz/taiko-client/internal/metrics" "github.com/taikoxyz/taiko-client/internal/version" eventIterator "github.com/taikoxyz/taiko-client/pkg/chain_iterator/event_iterator" "github.com/taikoxyz/taiko-client/pkg/rpc" @@ -148,7 +148,7 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) { if p.txmgr, err = txmgr.NewSimpleTxManager( "prover", log.Root(), - new(metrics.NoopTxMetrics), + &metrics.TxMgrMetrics, *cfg.TxmgrConfigs, ); err != nil { return err From 6a7952c92e15c9d374017ab299ee02063698f083 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 13:37:01 +0800 Subject: [PATCH 02/13] feat(metrics): collect `txmgr` metrics --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1b1491c56..0670a1a86 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main] + branches: [main,txmgr-metrics] tags: - "v*" From 1185f24af6a609a6436409233b2bb8734be76230 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 13:37:04 +0800 Subject: [PATCH 03/13] feat(metrics): collect `txmgr` metrics --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0670a1a86..1b1491c56 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main,txmgr-metrics] + branches: [main] tags: - "v*" From 22722a6759f739cd94142d2b04d35afb8db3d6fb Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 14:26:59 +0800 Subject: [PATCH 04/13] feat: improve proposer --- proposer/proposer.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/proposer/proposer.go b/proposer/proposer.go index b708c5c4f..08a2248d2 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -230,6 +230,11 @@ func (p *Proposer) fetchPoolContent(filterPoolContent bool) ([]types.Transaction } // If the pool content is empty and the checkPoolContent flag is not set, return an empty list. if !filterPoolContent && len(txLists) == 0 { + log.Info( + "Pool content is empty, proposing an empty block", + "lastProposedAt", p.lastProposedAt, + "minProposingInternal", p.MinProposingInternal, + ) txLists = append(txLists, types.Transactions{}) } @@ -293,6 +298,11 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { return err } + // If the pool content is empty, return. + if len(txLists) == 0 { + return nil + } + // Propose all L2 transactions lists. for i, txs := range txLists { if i >= int(p.MaxProposedTxListsPerEpoch) { From fda06138c0a2e36250ca92df616e65a3180bb288 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 14:29:34 +0800 Subject: [PATCH 05/13] feat: improve proposer --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1b1491c56..0670a1a86 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main] + branches: [main,txmgr-metrics] tags: - "v*" From 49ce32f415fdb03edfe252c6d1fad605fa5cac6d Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 14:29:37 +0800 Subject: [PATCH 06/13] feat: improve proposer --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0670a1a86..1b1491c56 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main,txmgr-metrics] + branches: [main] tags: - "v*" From 580318fe8b20fa87b5f209f2f954619267ff2971 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 14:34:30 +0800 Subject: [PATCH 07/13] Update internal/metrics/metrics.go Co-authored-by: Gavin Yu --- internal/metrics/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index fdccfef9e..6f1592769 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -45,7 +45,7 @@ var ( ProverSgxProofGeneratedCounter = metrics.NewRegisteredCounter("prover/proof/sgx/generated", nil) ProverSubmissionRevertedCounter = metrics.NewRegisteredCounter("prover/proof/submission/reverted", nil) - // TxManager + // TxManager Metrics TxMgrMetrics = txmgrMetrics.MakeTxMetrics("client", opMetrics.With(opMetrics.NewRegistry())) ) From ee03923eb87216875b99de34d23ef65cb7320b49 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 16:20:00 +0800 Subject: [PATCH 08/13] feat(metrics): improve metrics --- .github/workflows/docker.yml | 2 +- driver/chain_syncer/calldata/syncer.go | 4 +- driver/state/state.go | 6 +- internal/metrics/metrics.go | 90 +++++++++++--------- proposer/proposer.go | 6 +- prover/event_handler/block_proposed.go | 4 +- prover/event_handler/block_verified.go | 2 +- prover/event_handler/transition_proved.go | 2 +- prover/proof_producer/sgx_producer.go | 2 +- prover/proof_submitter/proof_submitter.go | 10 +-- prover/proof_submitter/transaction/sender.go | 4 +- 11 files changed, 71 insertions(+), 61 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1b1491c56..0670a1a86 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main] + branches: [main,txmgr-metrics] tags: - "v*" diff --git a/driver/chain_syncer/calldata/syncer.go b/driver/chain_syncer/calldata/syncer.go index 4c2e94973..85862c596 100644 --- a/driver/chain_syncer/calldata/syncer.go +++ b/driver/chain_syncer/calldata/syncer.go @@ -148,7 +148,7 @@ func (s *Syncer) processL1Blocks(ctx context.Context) error { // If there is a L1 reorg, we don't update the L1Current cursor. if !s.reorgDetectedFlag { s.state.SetL1Current(l1End) - metrics.DriverL1CurrentHeightGauge.Update(s.state.GetL1Current().Number.Int64()) + metrics.DriverL1CurrentHeightGauge.Set(float64(s.state.GetL1Current().Number.Uint64())) } return nil @@ -300,7 +300,7 @@ func (s *Syncer) onBlockProposed( "withdrawals", len(payloadData.Withdrawals), ) - metrics.DriverL1CurrentHeightGauge.Update(int64(event.Raw.BlockNumber)) + metrics.DriverL1CurrentHeightGauge.Set(float64(event.Raw.BlockNumber)) s.lastInsertedBlockID = event.BlockId if s.progressTracker.Triggered() { diff --git a/driver/state/state.go b/driver/state/state.go index 80ce54045..9afd37e8c 100644 --- a/driver/state/state.go +++ b/driver/state/state.go @@ -161,7 +161,7 @@ func (s *State) setL1Head(l1Head *types.Header) { } log.Debug("New L1 head", "height", l1Head.Number, "hash", l1Head.Hash(), "timestamp", l1Head.Time) - metrics.DriverL1HeadHeightGauge.Update(l1Head.Number.Int64()) + metrics.DriverL1HeadHeightGauge.Set(float64(l1Head.Number.Int64())) s.l1Head.Store(l1Head) } @@ -179,7 +179,7 @@ func (s *State) setL2Head(l2Head *types.Header) { } log.Debug("New L2 head", "height", l2Head.Number, "hash", l2Head.Hash(), "timestamp", l2Head.Time) - metrics.DriverL2HeadHeightGauge.Update(l2Head.Number.Int64()) + metrics.DriverL2HeadHeightGauge.Set(float64(l2Head.Number.Uint64())) s.l2Head.Store(l2Head) } @@ -192,7 +192,7 @@ func (s *State) GetL2Head() *types.Header { // setHeadBlockID sets the last pending block ID concurrent safely. func (s *State) setHeadBlockID(id *big.Int) { log.Debug("New head block ID", "ID", id) - metrics.DriverL2HeadIDGauge.Update(id.Int64()) + metrics.DriverL2HeadIDGauge.Set(float64(id.Uint64())) s.l2HeadBlockID.Store(id) } diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 6f1592769..cfe1fec57 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -2,16 +2,12 @@ package metrics import ( "context" - "net" - "net/http" - "strconv" - "time" opMetrics "github.com/ethereum-optimism/optimism/op-service/metrics" + "github.com/ethereum-optimism/optimism/op-service/opio" txmgrMetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics" "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/metrics" - "github.com/ethereum/go-ethereum/metrics/prometheus" + "github.com/prometheus/client_golang/prometheus" "github.com/urfave/cli/v2" "github.com/taikoxyz/taiko-client/cmd/flags" @@ -19,34 +15,45 @@ import ( // Metrics var ( + registry = opMetrics.NewRegistry() + factory = opMetrics.With(registry) + // Driver - DriverL1HeadHeightGauge = metrics.NewRegisteredGauge("driver/l1Head/height", nil) - DriverL2HeadHeightGauge = metrics.NewRegisteredGauge("driver/l2Head/height", nil) - DriverL1CurrentHeightGauge = metrics.NewRegisteredGauge("driver/l1Current/height", nil) - DriverL2HeadIDGauge = metrics.NewRegisteredGauge("driver/l2Head/id", nil) - DriverL2VerifiedHeightGauge = metrics.NewRegisteredGauge("driver/l2Verified/id", nil) + DriverL1HeadHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver/l1Head/height"}) + DriverL2HeadHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver/l2Head/height"}) + DriverL1CurrentHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver/l1Current/height"}) + DriverL2HeadIDGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver/l2Head/id"}) + DriverL2VerifiedHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver/l2Verified/id"}) // Proposer - ProposerProposeEpochCounter = metrics.NewRegisteredCounter("proposer/epoch", nil) - ProposerProposedTxListsCounter = metrics.NewRegisteredCounter("proposer/proposed/txLists", nil) - ProposerProposedTxsCounter = metrics.NewRegisteredCounter("proposer/proposed/txs", nil) + ProposerProposeEpochCounter = factory.NewCounter(prometheus.CounterOpts{Name: "proposer/epoch"}) + ProposerProposedTxListsCounter = factory.NewCounter(prometheus.CounterOpts{Name: "proposer/proposed/txLists"}) + ProposerProposedTxsCounter = factory.NewCounter(prometheus.CounterOpts{Name: "proposer/proposed/txs"}) // Prover - ProverLatestVerifiedIDGauge = metrics.NewRegisteredGauge("prover/latestVerified/id", nil) - ProverLatestProvenBlockIDGauge = metrics.NewRegisteredGauge("prover/latestProven/id", nil) - ProverQueuedProofCounter = metrics.NewRegisteredCounter("prover/proof/all/queued", nil) - ProverReceivedProofCounter = metrics.NewRegisteredCounter("prover/proof/all/received", nil) - ProverSentProofCounter = metrics.NewRegisteredCounter("prover/proof/all/sent", nil) - ProverProofsAssigned = metrics.NewRegisteredCounter("prover/proof/assigned", nil) - ProverReceivedProposedBlockGauge = metrics.NewRegisteredGauge("prover/proposed/received", nil) - ProverReceivedProvenBlockGauge = metrics.NewRegisteredGauge("prover/proven/received", nil) - ProverSubmissionAcceptedCounter = metrics.NewRegisteredCounter("prover/proof/submission/accepted", nil) - ProverSubmissionErrorCounter = metrics.NewRegisteredCounter("prover/proof/submission/error", nil) - ProverSgxProofGeneratedCounter = metrics.NewRegisteredCounter("prover/proof/sgx/generated", nil) - ProverSubmissionRevertedCounter = metrics.NewRegisteredCounter("prover/proof/submission/reverted", nil) + ProverLatestVerifiedIDGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover/latestVerified/id"}) + ProverLatestProvenBlockIDGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover/latestProven/id"}) + ProverQueuedProofCounter = factory.NewCounter(prometheus.CounterOpts{Name: "prover/proof/all/queued"}) + ProverReceivedProofCounter = factory.NewCounter(prometheus.CounterOpts{Name: "prover/proof/all/received"}) + ProverSentProofCounter = factory.NewCounter(prometheus.CounterOpts{Name: "prover/proof/all/sent"}) + ProverProofsAssigned = factory.NewCounter(prometheus.CounterOpts{Name: "prover/proof/assigned"}) + ProverReceivedProposedBlockGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover/proposed/received"}) + ProverReceivedProvenBlockGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover/proven/received"}) + ProverSubmissionAcceptedCounter = factory.NewCounter(prometheus.CounterOpts{ + Name: "prover/proof/submission/accepted", + }) + ProverSubmissionErrorCounter = factory.NewCounter(prometheus.CounterOpts{ + Name: "prover/proof/submission/error", + }) + ProverSgxProofGeneratedCounter = factory.NewCounter(prometheus.CounterOpts{ + Name: "prover/proof/sgx/generated", + }) + ProverSubmissionRevertedCounter = factory.NewCounter(prometheus.CounterOpts{ + Name: "prover/proof/submission/reverted", + }) - // TxManager Metrics - TxMgrMetrics = txmgrMetrics.MakeTxMetrics("client", opMetrics.With(opMetrics.NewRegistry())) + // TxManager + TxMgrMetrics = txmgrMetrics.MakeTxMetrics("client", factory) ) // Serve starts the metrics server on the given address, will be closed when the given @@ -56,25 +63,28 @@ func Serve(ctx context.Context, c *cli.Context) error { return nil } - address := net.JoinHostPort( - c.String(flags.MetricsAddr.Name), - strconv.Itoa(c.Int(flags.MetricsPort.Name)), + log.Info( + "Starting metrics server", + "host", c.String(flags.MetricsAddr.Name), + "port", c.Int(flags.MetricsPort.Name), ) - server := http.Server{ - ReadHeaderTimeout: time.Minute, - Addr: address, - Handler: prometheus.Handler(metrics.DefaultRegistry), + server, err := opMetrics.StartServer( + registry, + c.String(flags.MetricsAddr.Name), + c.Int(flags.MetricsPort.Name), + ) + if err != nil { + return err } - go func() { - <-ctx.Done() - if err := server.Close(); err != nil { + defer func() { + if err := server.Stop(ctx); err != nil { log.Error("Failed to close metrics server", "error", err) } }() - log.Info("Starting metrics server", "address", address) + opio.BlockOnInterruptsContext(ctx) - return server.ListenAndServe() + return nil } diff --git a/proposer/proposer.go b/proposer/proposer.go index 08a2248d2..46c7ac5e0 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -181,7 +181,7 @@ func (p *Proposer) eventLoop() { return // proposing interval timer has been reached case <-p.proposingTimer.C: - metrics.ProposerProposeEpochCounter.Inc(1) + metrics.ProposerProposeEpochCounter.Add(1) // Attempt a proposing operation if err := p.ProposeOp(p.ctx); err != nil { @@ -323,8 +323,8 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { continue } - metrics.ProposerProposedTxListsCounter.Inc(1) - metrics.ProposerProposedTxsCounter.Inc(int64(len(txLists[i]))) + metrics.ProposerProposedTxListsCounter.Add(1) + metrics.ProposerProposedTxsCounter.Add(float64(len(txLists[i]))) log.Info("📝 Propose transactions succeeded", "txs", len(txLists[i])) p.lastProposedAt = time.Now() diff --git a/prover/event_handler/block_proposed.go b/prover/event_handler/block_proposed.go index b7ea8fde7..ec382a582 100644 --- a/prover/event_handler/block_proposed.go +++ b/prover/event_handler/block_proposed.go @@ -124,7 +124,7 @@ func (h *BlockProposedEventHandler) Handle( "minTier", e.Meta.MinTier, "blobUsed", e.Meta.BlobUsed, ) - metrics.ProverReceivedProposedBlockGauge.Update(e.BlockId.Int64()) + metrics.ProverReceivedProposedBlockGauge.Set(float64(e.BlockId.Uint64())) // Move l1Current cursor. newL1Current, err := h.rpc.L1.HeaderByHash(ctx, e.Raw.BlockHash) @@ -323,7 +323,7 @@ func (h *BlockProposedEventHandler) checkExpirationAndSubmitProof( "tier", tier, ) - metrics.ProverProofsAssigned.Inc(1) + metrics.ProverProofsAssigned.Add(1) h.proofSubmissionCh <- &proofProducer.ProofRequestBody{Tier: tier, Event: e} diff --git a/prover/event_handler/block_verified.go b/prover/event_handler/block_verified.go index 70f9c8e32..4a445fc99 100644 --- a/prover/event_handler/block_verified.go +++ b/prover/event_handler/block_verified.go @@ -12,7 +12,7 @@ type BlockVerifiedEventHandler struct{} // Handle handles the BlockVerified event. func (h *BlockVerifiedEventHandler) Handle(e *bindings.TaikoL1ClientBlockVerified) { - metrics.ProverLatestVerifiedIDGauge.Update(e.BlockId.Int64()) + metrics.ProverLatestVerifiedIDGauge.Set(float64(e.BlockId.Uint64())) log.Info( "New verified block", diff --git a/prover/event_handler/transition_proved.go b/prover/event_handler/transition_proved.go index 29972dc19..3f597f3f1 100644 --- a/prover/event_handler/transition_proved.go +++ b/prover/event_handler/transition_proved.go @@ -33,7 +33,7 @@ func (h *TransitionProvedEventHandler) Handle( ctx context.Context, e *bindings.TaikoL1ClientTransitionProved, ) error { - metrics.ProverReceivedProvenBlockGauge.Update(e.BlockId.Int64()) + metrics.ProverReceivedProvenBlockGauge.Set(float64(e.BlockId.Uint64())) // If this prover is in contest mode, we check the validity of this proof and if it's invalid, // contest it with a higher tier proof. diff --git a/prover/proof_producer/sgx_producer.go b/prover/proof_producer/sgx_producer.go index f9efabe07..f306a8dfa 100644 --- a/prover/proof_producer/sgx_producer.go +++ b/prover/proof_producer/sgx_producer.go @@ -99,7 +99,7 @@ func (s *SGXProofProducer) RequestProof( return nil, err } - metrics.ProverSgxProofGeneratedCounter.Inc(1) + metrics.ProverSgxProofGeneratedCounter.Add(1) return &ProofWithHeader{ BlockID: blockID, diff --git a/prover/proof_submitter/proof_submitter.go b/prover/proof_submitter/proof_submitter.go index 9085d881a..c48c3b637 100644 --- a/prover/proof_submitter/proof_submitter.go +++ b/prover/proof_submitter/proof_submitter.go @@ -114,7 +114,7 @@ func (s *ProofSubmitter) RequestProof(ctx context.Context, event *bindings.Taiko } s.resultCh <- result - metrics.ProverQueuedProofCounter.Inc(1) + metrics.ProverQueuedProofCounter.Add(1) return nil } @@ -135,7 +135,7 @@ func (s *ProofSubmitter) SubmitProof( "tier", proofWithHeader.Tier, ) - metrics.ProverReceivedProofCounter.Inc(1) + metrics.ProverReceivedProofCounter.Add(1) // Get the corresponding L2 block. block, err := s.rpc.L2.BlockByHash(ctx, proofWithHeader.Header.Hash()) @@ -176,12 +176,12 @@ func (s *ProofSubmitter) SubmitProof( if err.Error() == transaction.ErrUnretryableSubmission.Error() { return nil } - metrics.ProverSubmissionErrorCounter.Inc(1) + metrics.ProverSubmissionErrorCounter.Add(1) return err } - metrics.ProverSentProofCounter.Inc(1) - metrics.ProverLatestProvenBlockIDGauge.Update(proofWithHeader.BlockID.Int64()) + metrics.ProverSentProofCounter.Add(1) + metrics.ProverLatestProvenBlockIDGauge.Set(float64(proofWithHeader.BlockID.Uint64())) return nil } diff --git a/prover/proof_submitter/transaction/sender.go b/prover/proof_submitter/transaction/sender.go index 83b7f0493..d42ad45b5 100644 --- a/prover/proof_submitter/transaction/sender.go +++ b/prover/proof_submitter/transaction/sender.go @@ -66,7 +66,7 @@ func (s *Sender) Send( "tier", proofWithHeader.Tier, "txHash", receipt.TxHash, ) - metrics.ProverSubmissionRevertedCounter.Inc(1) + metrics.ProverSubmissionRevertedCounter.Add(1) return ErrUnretryableSubmission } @@ -81,7 +81,7 @@ func (s *Sender) Send( "isContest", len(proofWithHeader.Proof) == 0, ) - metrics.ProverSubmissionAcceptedCounter.Inc(1) + metrics.ProverSubmissionAcceptedCounter.Add(1) return nil } From b93fca73f2c617b8ea3987a2756568b359f47422 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 16:21:34 +0800 Subject: [PATCH 09/13] feat(metrics): improve metrics --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0670a1a86..1b1491c56 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main,txmgr-metrics] + branches: [main] tags: - "v*" From 0ca28c9a38c34f16307b8569ae28797ad81e2b7c Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 16:37:44 +0800 Subject: [PATCH 10/13] feat: improve proposer --- internal/docker/nodes/docker-compose.yml | 1 + internal/metrics/metrics.go | 40 ++++++++++++------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/internal/docker/nodes/docker-compose.yml b/internal/docker/nodes/docker-compose.yml index 7bd9e337d..fdf0b22b1 100644 --- a/internal/docker/nodes/docker-compose.yml +++ b/internal/docker/nodes/docker-compose.yml @@ -3,6 +3,7 @@ services: container_name: l1_node image: ghcr.io/foundry-rs/foundry:nightly restart: unless-stopped + platform: linux/amd64 pull_policy: always ports: - "8545" diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index cfe1fec57..61329df4e 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -19,37 +19,37 @@ var ( factory = opMetrics.With(registry) // Driver - DriverL1HeadHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver/l1Head/height"}) - DriverL2HeadHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver/l2Head/height"}) - DriverL1CurrentHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver/l1Current/height"}) - DriverL2HeadIDGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver/l2Head/id"}) - DriverL2VerifiedHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver/l2Verified/id"}) + DriverL1HeadHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver_l1Head_height"}) + DriverL2HeadHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver_l2Head_height"}) + DriverL1CurrentHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver_l1Current_height"}) + DriverL2HeadIDGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver_l2Head_id"}) + DriverL2VerifiedHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver_l2Verified_id"}) // Proposer - ProposerProposeEpochCounter = factory.NewCounter(prometheus.CounterOpts{Name: "proposer/epoch"}) - ProposerProposedTxListsCounter = factory.NewCounter(prometheus.CounterOpts{Name: "proposer/proposed/txLists"}) - ProposerProposedTxsCounter = factory.NewCounter(prometheus.CounterOpts{Name: "proposer/proposed/txs"}) + ProposerProposeEpochCounter = factory.NewCounter(prometheus.CounterOpts{Name: "proposer_epoch"}) + ProposerProposedTxListsCounter = factory.NewCounter(prometheus.CounterOpts{Name: "proposer_proposed_txLists"}) + ProposerProposedTxsCounter = factory.NewCounter(prometheus.CounterOpts{Name: "proposer_proposed_txs"}) // Prover - ProverLatestVerifiedIDGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover/latestVerified/id"}) - ProverLatestProvenBlockIDGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover/latestProven/id"}) - ProverQueuedProofCounter = factory.NewCounter(prometheus.CounterOpts{Name: "prover/proof/all/queued"}) - ProverReceivedProofCounter = factory.NewCounter(prometheus.CounterOpts{Name: "prover/proof/all/received"}) - ProverSentProofCounter = factory.NewCounter(prometheus.CounterOpts{Name: "prover/proof/all/sent"}) - ProverProofsAssigned = factory.NewCounter(prometheus.CounterOpts{Name: "prover/proof/assigned"}) - ProverReceivedProposedBlockGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover/proposed/received"}) - ProverReceivedProvenBlockGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover/proven/received"}) + ProverLatestVerifiedIDGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover_latestVerified_id"}) + ProverLatestProvenBlockIDGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover_latestProven_id"}) + ProverQueuedProofCounter = factory.NewCounter(prometheus.CounterOpts{Name: "prover_proof_all_queued"}) + ProverReceivedProofCounter = factory.NewCounter(prometheus.CounterOpts{Name: "prover_proof_all_received"}) + ProverSentProofCounter = factory.NewCounter(prometheus.CounterOpts{Name: "prover_proof_all_sent"}) + ProverProofsAssigned = factory.NewCounter(prometheus.CounterOpts{Name: "prover_proof_assigned"}) + ProverReceivedProposedBlockGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover_proposed_received"}) + ProverReceivedProvenBlockGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover_proven_received"}) ProverSubmissionAcceptedCounter = factory.NewCounter(prometheus.CounterOpts{ - Name: "prover/proof/submission/accepted", + Name: "prover_proof_submission_accepted", }) ProverSubmissionErrorCounter = factory.NewCounter(prometheus.CounterOpts{ - Name: "prover/proof/submission/error", + Name: "prover_proof_submission_error", }) ProverSgxProofGeneratedCounter = factory.NewCounter(prometheus.CounterOpts{ - Name: "prover/proof/sgx/generated", + Name: "prover_proof_sgx_generated", }) ProverSubmissionRevertedCounter = factory.NewCounter(prometheus.CounterOpts{ - Name: "prover/proof/submission/reverted", + Name: "prover_proof_submission_reverted", }) // TxManager From 6f9c33b0a5ac190dd69acd6cf61ce3734a2f249a Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 16:39:15 +0800 Subject: [PATCH 11/13] feat: improve proposer --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1b1491c56..0670a1a86 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main] + branches: [main,txmgr-metrics] tags: - "v*" From cfb515ef21eaf1607f09cb298290431133fdd637 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 16:39:25 +0800 Subject: [PATCH 12/13] feat: improve proposer --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0670a1a86..1b1491c56 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main,txmgr-metrics] + branches: [main] tags: - "v*" From e52d4aad3710329212b495ae3beea8cf079a73ed Mon Sep 17 00:00:00 2001 From: David Date: Wed, 17 Apr 2024 16:48:46 +0800 Subject: [PATCH 13/13] feat: update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0bb9bed97..7986f37b5 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/labstack/echo/v4 v4.11.1 github.com/modern-go/reflect2 v1.0.2 github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 + github.com/prometheus/client_golang v1.19.0 github.com/prysmaticlabs/prysm/v4 v4.2.0 github.com/stretchr/testify v1.9.0 github.com/swaggo/swag v1.16.2 @@ -174,7 +175,6 @@ require ( github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_golang v1.19.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.48.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect