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

Commit c0a5ddd

Browse files
authoredMay 6, 2024
feat(metrics): introduce ProverProvenByGuardianGauge (#794)
1 parent 2556df6 commit c0a5ddd

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed
 

‎internal/metrics/metrics.go

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var (
3939
ProverProofsAssigned = factory.NewCounter(prometheus.CounterOpts{Name: "prover_proof_assigned"})
4040
ProverReceivedProposedBlockGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover_proposed_received"})
4141
ProverReceivedProvenBlockGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover_proven_received"})
42+
ProverProvenByGuardianGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "prover_proven_by_guardian"})
4243
ProverSubmissionAcceptedCounter = factory.NewCounter(prometheus.CounterOpts{
4344
Name: "prover_proof_submission_accepted",
4445
})

‎pkg/rpc/methods.go

+8
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,14 @@ func (c *Client) GetTaikoDataSlotBByNumber(ctx context.Context, number uint64) (
725725
return nil, fmt.Errorf("failed to get state variables by block number %d", number)
726726
}
727727

728+
// GetGuardianProverAddress fetches the guardian prover address from the protocol.
729+
func (c *Client) GetGuardianProverAddress(ctx context.Context) (common.Address, error) {
730+
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout)
731+
defer cancel()
732+
733+
return c.TaikoL1.Resolve0(&bind.CallOpts{Context: ctxWithTimeout}, StringToBytes32("tier_guardian"), false)
734+
}
735+
728736
// WaitL1NewPendingTransaction waits until the L1 account has a new pending transaction.
729737
func (c *Client) WaitL1NewPendingTransaction(
730738
ctx context.Context,

‎prover/event_handler/block_verified.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@ import (
99
)
1010

1111
// BlockVerifiedEventHandler is responsible for handling the BlockVerified event.
12-
type BlockVerifiedEventHandler struct{}
12+
type BlockVerifiedEventHandler struct {
13+
guardianProverAddress common.Address
14+
}
15+
16+
// NewBlockVerifiedEventHandler creates a new BlockVerifiedEventHandler instance.
17+
func NewBlockVerifiedEventHandler(guardianProverAddress common.Address) *BlockVerifiedEventHandler {
18+
return &BlockVerifiedEventHandler{guardianProverAddress: guardianProverAddress}
19+
}
1320

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

25+
if e.Prover == h.guardianProverAddress {
26+
metrics.ProverProvenByGuardianGauge.Set(1)
27+
}
28+
1829
log.Info(
1930
"New verified block",
2031
"blockID", e.BlockId,

‎prover/init.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (p *Prover) initL1Current(startingBlockID *big.Int) error {
193193
}
194194

195195
// initEventHandlers initialize all event handlers which will be used by the current prover.
196-
func (p *Prover) initEventHandlers() {
196+
func (p *Prover) initEventHandlers() error {
197197
// ------- BlockProposed -------
198198
opts := &handler.NewBlockProposedEventHandlerOps{
199199
SharedState: p.sharedState,
@@ -240,6 +240,13 @@ func (p *Prover) initEventHandlers() {
240240
p.proofContestCh,
241241
p.cfg.ContesterMode,
242242
)
243+
243244
// ------- BlockVerified -------
244-
p.blockVerifiedHandler = new(handler.BlockVerifiedEventHandler)
245+
guardianProverAddress, err := p.rpc.GetGuardianProverAddress(p.ctx)
246+
if err != nil {
247+
return err
248+
}
249+
p.blockVerifiedHandler = handler.NewBlockVerifiedEventHandler(guardianProverAddress)
250+
251+
return nil
245252
}

‎prover/prover.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) {
203203
}
204204

205205
// Initialize event handlers.
206-
p.initEventHandlers()
206+
if err := p.initEventHandlers(); err != nil {
207+
return err
208+
}
207209

208210
return nil
209211
}

‎prover/prover_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,14 @@ func (s *ProverTestSuite) TestOnBlockVerified() {
234234
func (s *ProverTestSuite) TestContestWrongBlocks() {
235235
s.T().Skip()
236236
s.p.cfg.ContesterMode = false
237-
s.p.initEventHandlers()
237+
s.Nil(s.p.initEventHandlers())
238238
e := s.ProposeAndInsertValidBlock(s.proposer, s.d.ChainSyncer().BlobSyncer())
239239
s.Nil(s.p.transitionProvedHandler.Handle(context.Background(), &bindings.TaikoL1ClientTransitionProved{
240240
BlockId: e.BlockId,
241241
Tier: e.Meta.MinTier,
242242
}))
243243
s.p.cfg.ContesterMode = true
244-
s.p.initEventHandlers()
244+
s.Nil(s.p.initEventHandlers())
245245

246246
// Submit a wrong proof at first.
247247
sink := make(chan *bindings.TaikoL1ClientTransitionProved)
@@ -284,7 +284,7 @@ func (s *ProverTestSuite) TestContestWrongBlocks() {
284284
contesterKey,
285285
))
286286
s.p.cfg.ContesterMode = true
287-
s.p.initEventHandlers()
287+
s.Nil(s.p.initEventHandlers())
288288

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

0 commit comments

Comments
 (0)