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

Commit

Permalink
feat(metrics): introduce ProverProvenByGuardianGauge (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed May 6, 2024
1 parent 7dd551e commit 6b320db
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
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"})
ProverProvenByGuardianGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover_proven_by_guardian"})
ProverSubmissionAcceptedCounter = factory.NewCounter(prometheus.CounterOpts{
Name: "prover_proof_submission_accepted",
})
Expand Down
8 changes: 8 additions & 0 deletions pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,14 @@ func (c *Client) GetTaikoDataSlotBByNumber(ctx context.Context, number uint64) (
return nil, fmt.Errorf("failed to get state variables by block number %d", number)
}

// GetGuardianProverAddress fetches the guardian prover address from the protocol.
func (c *Client) GetGuardianProverAddress(ctx context.Context) (common.Address, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout)
defer cancel()

return c.TaikoL1.Resolve0(&bind.CallOpts{Context: ctxWithTimeout}, StringToBytes32("tier_guardian"), false)
}

// WaitL1NewPendingTransaction waits until the L1 account has a new pending transaction.
func (c *Client) WaitL1NewPendingTransaction(
ctx context.Context,
Expand Down
13 changes: 12 additions & 1 deletion prover/event_handler/block_verified.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@ import (
)

// BlockVerifiedEventHandler is responsible for handling the BlockVerified event.
type BlockVerifiedEventHandler struct{}
type BlockVerifiedEventHandler struct {
guardianProverAddress common.Address
}

// NewBlockVerifiedEventHandler creates a new BlockVerifiedEventHandler instance.
func NewBlockVerifiedEventHandler(guardianProverAddress common.Address) *BlockVerifiedEventHandler {
return &BlockVerifiedEventHandler{guardianProverAddress: guardianProverAddress}
}

// Handle handles the BlockVerified event.
func (h *BlockVerifiedEventHandler) Handle(e *bindings.TaikoL1ClientBlockVerified) {
metrics.ProverLatestVerifiedIDGauge.Set(float64(e.BlockId.Uint64()))

if e.Prover == h.guardianProverAddress {
metrics.ProverProvenByGuardianGauge.Set(1)
}

log.Info(
"New verified block",
"blockID", e.BlockId,
Expand Down
11 changes: 9 additions & 2 deletions prover/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (p *Prover) initL1Current(startingBlockID *big.Int) error {
}

// initEventHandlers initialize all event handlers which will be used by the current prover.
func (p *Prover) initEventHandlers() {
func (p *Prover) initEventHandlers() error {
// ------- BlockProposed -------
opts := &handler.NewBlockProposedEventHandlerOps{
SharedState: p.sharedState,
Expand Down Expand Up @@ -240,6 +240,13 @@ func (p *Prover) initEventHandlers() {
p.proofContestCh,
p.cfg.ContesterMode,
)

// ------- BlockVerified -------
p.blockVerifiedHandler = new(handler.BlockVerifiedEventHandler)
guardianProverAddress, err := p.rpc.GetGuardianProverAddress(p.ctx)
if err != nil {
return err
}
p.blockVerifiedHandler = handler.NewBlockVerifiedEventHandler(guardianProverAddress)

return nil
}
4 changes: 3 additions & 1 deletion prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) {
}

// Initialize event handlers.
p.initEventHandlers()
if err := p.initEventHandlers(); err != nil {
return err
}

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions prover/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,14 @@ func (s *ProverTestSuite) TestOnBlockVerified() {
func (s *ProverTestSuite) TestContestWrongBlocks() {
s.T().Skip()
s.p.cfg.ContesterMode = false
s.p.initEventHandlers()
s.Nil(s.p.initEventHandlers())
e := s.ProposeAndInsertValidBlock(s.proposer, s.d.ChainSyncer().BlobSyncer())
s.Nil(s.p.transitionProvedHandler.Handle(context.Background(), &bindings.TaikoL1ClientTransitionProved{
BlockId: e.BlockId,
Tier: e.Meta.MinTier,
}))
s.p.cfg.ContesterMode = true
s.p.initEventHandlers()
s.Nil(s.p.initEventHandlers())

// Submit a wrong proof at first.
sink := make(chan *bindings.TaikoL1ClientTransitionProved)
Expand Down Expand Up @@ -284,7 +284,7 @@ func (s *ProverTestSuite) TestContestWrongBlocks() {
contesterKey,
))
s.p.cfg.ContesterMode = true
s.p.initEventHandlers()
s.Nil(s.p.initEventHandlers())

s.Greater(header.Number.Uint64(), uint64(0))
s.Nil(s.p.transitionProvedHandler.Handle(context.Background(), event))
Expand Down

0 comments on commit 6b320db

Please sign in to comment.