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

Commit

Permalink
feat(prover): improve retry policy for prover (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Jun 13, 2023
1 parent 6fa24ea commit 344bac1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
6 changes: 3 additions & 3 deletions prover/proof_submitter/valid_proof_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ func (s *ValidProofSubmitter) RequestProof(ctx context.Context, event *bindings.
// Get the header of the block to prove from L2 execution engine.
block, err := s.rpc.L2.BlockByHash(ctx, l1Origin.L2BlockHash)
if err != nil {
return err
return fmt.Errorf("failed to get the current L2 block by hash (%s): %w", l1Origin.L2BlockHash, err)
}

parent, err := s.rpc.L2.BlockByHash(ctx, block.ParentHash())
if err != nil {
return err
return fmt.Errorf("failed to get the L2 parent block by hash (%s): %w", block.ParentHash(), err)
}

blockInfo, err := s.rpc.TaikoL1.GetBlock(nil, event.Id)
Expand Down Expand Up @@ -142,7 +142,7 @@ func (s *ValidProofSubmitter) RequestProof(ctx context.Context, event *bindings.
}

if err := s.proofProducer.RequestProof(ctx, opts, event.Id, &event.Meta, block.Header(), s.resultCh); err != nil {
return err
return fmt.Errorf("failed to request proof (id: %d): %w", event.Id, err)
}

metrics.ProverQueuedProofCounter.Inc(1)
Expand Down
23 changes: 17 additions & 6 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ import (
"github.com/urfave/cli/v2"
)

const (
backOffMaxRetrys = 10
backOffRetryInterval = 12 * time.Second
)

type cancelFunc func()

// Prover keep trying to prove new proposed blocks valid/invalid.
Expand Down Expand Up @@ -332,7 +337,7 @@ func (p *Prover) onBlockProposed(
}

if _, err := p.rpc.WaitL1Origin(ctx, event.Id); err != nil {
return err
return fmt.Errorf("failed to wait L1Origin (eventID %d): %w", event.Id, err)
}

// Check whteher the L1 chain has been reorged.
Expand Down Expand Up @@ -365,7 +370,7 @@ func (p *Prover) onBlockProposed(

currentL1OriginHeader, err := p.rpc.L1.HeaderByNumber(ctx, new(big.Int).SetUint64(event.Meta.L1Height))
if err != nil {
return err
return fmt.Errorf("failed to get L1 header, height %d: %w", event.Meta.L1Height, err)
}

if currentL1OriginHeader.Hash() != event.Meta.L1Hash {
Expand Down Expand Up @@ -399,7 +404,7 @@ func (p *Prover) onBlockProposed(
// Check whether the block has been verified.
isVerified, err := p.isBlockVerified(event.Id)
if err != nil {
return err
return fmt.Errorf("failed to check if the current L2 block is verified: %w", err)
}

if isVerified {
Expand Down Expand Up @@ -447,7 +452,7 @@ func (p *Prover) onBlockProposed(
p.currentBlocksBeingProven[event.Id.Uint64()] = cancelFunc(func() {
defer cancelCtx()
if err := p.validProofSubmitter.CancelProof(ctx, event.Id); err != nil {
log.Error("error cancelling proof", "error", err, "blockID", event.Id)
log.Error("failed to cancel proof", "error", err, "blockID", event.Id)
}
})
p.currentBlocksBeingProvenMutex.Unlock()
Expand All @@ -461,7 +466,10 @@ func (p *Prover) onBlockProposed(
p.lastHandledBlockID = event.Id.Uint64()

go func() {
if err := handleBlockProposedEvent(); err != nil {
if err := backoff.Retry(
func() error { return handleBlockProposedEvent() },
backoff.WithMaxRetries(backoff.NewConstantBackOff(backOffRetryInterval), backOffMaxRetrys),
); err != nil {
p.currentBlocksBeingProvenMutex.Lock()
delete(p.currentBlocksBeingProven, event.Id.Uint64())
p.currentBlocksBeingProvenMutex.Unlock()
Expand All @@ -483,7 +491,10 @@ func (p *Prover) submitProofOp(ctx context.Context, proofWithHeader *proofProduc
p.currentBlocksBeingProvenMutex.Unlock()
}()

if err := p.validProofSubmitter.SubmitProof(p.ctx, proofWithHeader); err != nil {
if err := backoff.Retry(
func() error { return p.validProofSubmitter.SubmitProof(p.ctx, proofWithHeader) },
backoff.WithMaxRetries(backoff.NewConstantBackOff(backOffRetryInterval), backOffMaxRetrys),
); err != nil {
log.Error("Submit proof error", "error", err)
}
}()
Expand Down

0 comments on commit 344bac1

Please sign in to comment.