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

feat(proposer,prover): make context.Context part of proposer.waitTillSynced && ProofProducer.RequestProof's parameters #169

Merged
merged 1 commit into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (p *Proposer) ProposeOp(ctx context.Context) error {
}

// Wait until L2 execution engine is synced at first.
if err := p.waitTillSynced(); err != nil {
if err := p.waitTillSynced(ctx); err != nil {
return fmt.Errorf("failed to wait until L2 execution engine synced: %w", err)
}

Expand Down Expand Up @@ -311,9 +311,12 @@ func (p *Proposer) ProposeTxList(
}

// waitTillSynced keeps waiting until the L2 execution engine is fully synced.
func (p *Proposer) waitTillSynced() error {
func (p *Proposer) waitTillSynced(ctx context.Context) error {
return backoff.Retry(
func() error {
if ctx.Err() != nil {
return nil
}
progress, err := p.rpc.L2ExecutionEngineSyncProgress(p.ctx)
if err != nil {
log.Error("Fetch L2 execution engine sync progress error", "error", err)
Expand Down
2 changes: 2 additions & 0 deletions prover/proof_producer/dummy_producer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package producer

import (
"context"
"math/big"
"math/rand"
"time"
Expand All @@ -18,6 +19,7 @@ type DummyProofProducer struct {

// RequestProof implements the ProofProducer interface.
func (d *DummyProofProducer) RequestProof(
ctx context.Context,
opts *ProofRequestOptions,
blockID *big.Int,
meta *bindings.TaikoDataBlockMetadata,
Expand Down
2 changes: 2 additions & 0 deletions prover/proof_producer/dummy_producer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package producer

import (
"context"
"crypto/rand"
"testing"
"time"
Expand Down Expand Up @@ -35,6 +36,7 @@ func TestRequestProof(t *testing.T) {
Nonce: types.BlockNonce{},
}
require.Nil(t, dummyProofProducer.RequestProof(
context.Background(),
&ProofRequestOptions{},
blockID,
&bindings.TaikoDataBlockMetadata{},
Expand Down
2 changes: 2 additions & 0 deletions prover/proof_producer/proof_producer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package producer

import (
"context"
"fmt"
"math/big"

Expand Down Expand Up @@ -34,6 +35,7 @@ type ProofWithHeader struct {

type ProofProducer interface {
RequestProof(
ctx context.Context,
opts *ProofRequestOptions,
blockID *big.Int,
meta *bindings.TaikoDataBlockMetadata,
Expand Down
2 changes: 2 additions & 0 deletions prover/proof_producer/zkevm_cmd_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package producer

import (
"bytes"
"context"
"encoding/json"
"fmt"
"math/big"
Expand Down Expand Up @@ -34,6 +35,7 @@ func NewZkevmCmdProducer(

// RequestProof implements the ProofProducer interface.
func (d *ZkevmCmdProducer) RequestProof(
ctx context.Context,
opts *ProofRequestOptions,
blockID *big.Int,
meta *bindings.TaikoDataBlockMetadata,
Expand Down
9 changes: 7 additions & 2 deletions prover/proof_producer/zkevm_rpcd_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package producer

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -98,6 +99,7 @@ func NewZkevmRpcdProducer(

// RequestProof implements the ProofProducer interface.
func (d *ZkevmRpcdProducer) RequestProof(
ctx context.Context,
opts *ProofRequestOptions,
blockID *big.Int,
meta *bindings.TaikoDataBlockMetadata,
Expand All @@ -120,7 +122,7 @@ func (d *ZkevmRpcdProducer) RequestProof(
if d.CustomProofHook != nil {
proof, degree, err = d.CustomProofHook()
} else {
proof, degree, err = d.callProverDaemon(opts)
proof, degree, err = d.callProverDaemon(ctx, opts)
}
if err != nil {
return err
Expand All @@ -138,13 +140,16 @@ func (d *ZkevmRpcdProducer) RequestProof(
}

// callProverDaemon keeps polling the proverd service to get the requested proof.
func (d *ZkevmRpcdProducer) callProverDaemon(opts *ProofRequestOptions) ([]byte, uint64, error) {
func (d *ZkevmRpcdProducer) callProverDaemon(ctx context.Context, opts *ProofRequestOptions) ([]byte, uint64, error) {
var (
proof []byte
degree uint64
start = time.Now()
)
if err := backoff.Retry(func() error {
if ctx.Err() != nil {
return nil
}
output, err := d.requestProof(opts)
if err != nil {
log.Error("Failed to request proof", "height", opts.Height, "err", err, "endpoint", d.RpcdEndpoint)
Expand Down
2 changes: 2 additions & 0 deletions prover/proof_producer/zkevm_rpcd_producer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package producer

import (
"context"
"testing"
"time"

Expand Down Expand Up @@ -41,6 +42,7 @@ func TestNewZkevmRpcdProducer(t *testing.T) {
Nonce: types.BlockNonce{},
}
require.Nil(t, dummpyZkevmRpcdProducer.RequestProof(
context.Background(),
&ProofRequestOptions{},
blockID,
&bindings.TaikoDataBlockMetadata{},
Expand Down
2 changes: 1 addition & 1 deletion prover/proof_submitter/invalid_proof_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s *InvalidProofSubmitter) RequestProof(ctx context.Context, event *binding
}

if err := s.proofProducer.RequestProof(
proofOpts, event.Id, &event.Meta, throwAwayBlock.Header(), s.reusltCh,
ctx, proofOpts, event.Id, &event.Meta, throwAwayBlock.Header(), s.reusltCh,
); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion prover/proof_submitter/valid_proof_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (s *ValidProofSubmitter) RequestProof(ctx context.Context, event *bindings.
ProposeBlockTxHash: event.Raw.TxHash,
}

if err := s.proofProducer.RequestProof(opts, event.Id, &event.Meta, header, s.reusltCh); err != nil {
if err := s.proofProducer.RequestProof(ctx, opts, event.Id, &event.Meta, header, s.reusltCh); err != nil {
return err
}

Expand Down