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

Commit

Permalink
feat(prover): use --guardian.submissionDelay flag
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Apr 18, 2024
1 parent 24a8e1d commit f0bd887
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var (
GuardianProofSubmissionDelay = &cli.DurationFlag{
Name: "guardian.submissionDelay",
Usage: "Guardian proof submission delay",
Value: 0 * time.Second,
Value: 1 * time.Hour,
Category: proverCategory,
}
// Running mode
Expand Down
32 changes: 28 additions & 4 deletions prover/event_handler/block_proposed.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"math/rand"
"time"

"github.com/cenkalti/backoff/v4"
Expand All @@ -22,8 +23,9 @@ import (
)

var (
errL1Reorged = errors.New("L1 reorged")
proofExpirationDelay = 1 * time.Minute
errL1Reorged = errors.New("L1 reorged")
proofExpirationDelay = 1 * time.Minute
submissionDelayRandomBumpRange = 20
)

// BlockProposedEventHandler is responsible for handling the BlockProposed event as a prover.
Expand All @@ -41,6 +43,7 @@ type BlockProposedEventHandler struct {
contesterMode bool
proveUnassignedBlocks bool
tierToOverride uint16
submissionDelay time.Duration
}

// NewBlockProposedEventHandlerOps is the options for creating a new BlockProposedEventHandler.
Expand All @@ -57,6 +60,7 @@ type NewBlockProposedEventHandlerOps struct {
BackOffMaxRetrys uint64
ContesterMode bool
ProveUnassignedBlocks bool
SubmissionDelay time.Duration
}

// NewBlockProposedEventHandler creates a new BlockProposedEventHandler instance.
Expand All @@ -75,6 +79,7 @@ func NewBlockProposedEventHandler(opts *NewBlockProposedEventHandlerOps) *BlockP
opts.ContesterMode,
opts.ProveUnassignedBlocks,
0,
opts.SubmissionDelay,
}
}

Expand Down Expand Up @@ -216,6 +221,18 @@ func (h *BlockProposedEventHandler) checkL1Reorg(
return nil
}

// getRandomBumpedSubmissionDelay returns a random bumped submission delay.
func (h *BlockProposedEventHandler) getRandomBumpedSubmissionDelay() time.Duration {
if h.submissionDelay == 0 {
return h.submissionDelay
}

randomBump := rand.Intn(

Check failure on line 230 in prover/event_handler/block_proposed.go

View workflow job for this annotation

GitHub Actions / Lint

G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec)
int(h.submissionDelay.Seconds() * float64(submissionDelayRandomBumpRange) / 100),
)
return time.Duration(h.submissionDelay.Seconds()+float64(randomBump)) * time.Second
}

// checkExpirationAndSubmitProof checks whether the proposed block's proving window is expired,
// and submits a new proof if necessary.
func (h *BlockProposedEventHandler) checkExpirationAndSubmitProof(
Expand Down Expand Up @@ -310,7 +327,11 @@ func (h *BlockProposedEventHandler) checkExpirationAndSubmitProof(

// The current prover is the assigned prover, or the proving window is expired,
// try to submit a proof for this proposed block.
tier := e.Meta.MinTier
var (
tier = e.Meta.MinTier
submissionDelay = h.getRandomBumpedSubmissionDelay()
)

if h.tierToOverride != 0 {
tier = h.tierToOverride
}
Expand All @@ -320,12 +341,15 @@ func (h *BlockProposedEventHandler) checkExpirationAndSubmitProof(
"blockID", e.BlockId,
"assignProver", e.AssignedProver,
"minTier", e.Meta.MinTier,
"submissionDelay", submissionDelay,
"tier", tier,
)

metrics.ProverProofsAssigned.Add(1)

h.proofSubmissionCh <- &proofProducer.ProofRequestBody{Tier: tier, Event: e}
time.AfterFunc(submissionDelay, func() {
h.proofSubmissionCh <- &proofProducer.ProofRequestBody{Tier: tier, Event: e}
})

return nil
}
Expand Down
1 change: 1 addition & 0 deletions prover/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func (p *Prover) initEventHandlers() {
ProveUnassignedBlocks: p.cfg.ProveUnassignedBlocks,
}
if p.IsGuardianProver() {
opts.SubmissionDelay = p.cfg.GuardianProofSubmissionDelay
p.blockProposedHandler = handler.NewBlockProposedEventGuardianHandler(
&handler.NewBlockProposedGuardianEventHandlerOps{
NewBlockProposedEventHandlerOps: opts,
Expand Down

0 comments on commit f0bd887

Please sign in to comment.