Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into update-mod
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Apr 17, 2024
2 parents 1c411e3 + 7fb762a commit 3df4cba
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 63 deletions.
4 changes: 2 additions & 2 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions driver/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/docker/nodes/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
91 changes: 53 additions & 38 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,58 @@ 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"
)

// 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
TxMgrMetrics = txmgrMetrics.MakeTxMetrics("client", factory)
)

// Serve starts the metrics server on the given address, will be closed when the given
Expand All @@ -51,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
}
19 changes: 14 additions & 5 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -182,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 {
Expand Down Expand Up @@ -231,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{})
}

Expand Down Expand Up @@ -294,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) {
Expand All @@ -314,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()
Expand Down
4 changes: 2 additions & 2 deletions prover/event_handler/block_proposed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}

Expand Down
2 changes: 1 addition & 1 deletion prover/event_handler/block_verified.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion prover/event_handler/transition_proved.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion prover/proof_producer/sgx_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *SGXProofProducer) RequestProof(
return nil, err
}

metrics.ProverSgxProofGeneratedCounter.Inc(1)
metrics.ProverSgxProofGeneratedCounter.Add(1)

return &ProofWithHeader{
BlockID: blockID,
Expand Down
10 changes: 5 additions & 5 deletions prover/proof_submitter/proof_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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())
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions prover/proof_submitter/transaction/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *Sender) Send(
"tier", proofWithHeader.Tier,
"txHash", receipt.TxHash,
)
metrics.ProverSubmissionRevertedCounter.Inc(1)
metrics.ProverSubmissionRevertedCounter.Add(1)
return ErrUnretryableSubmission
}

Expand All @@ -81,7 +81,7 @@ func (s *Sender) Send(
"isContest", len(proofWithHeader.Proof) == 0,
)

metrics.ProverSubmissionAcceptedCounter.Inc(1)
metrics.ProverSubmissionAcceptedCounter.Add(1)

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3df4cba

Please sign in to comment.