Skip to content

Commit

Permalink
feat: improve submitter
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Jan 20, 2025
1 parent df623af commit a696dc5
Show file tree
Hide file tree
Showing 19 changed files with 510 additions and 379 deletions.
9 changes: 2 additions & 7 deletions packages/taiko-client/prover/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (p *Prover) initProofSubmitters(
return fmt.Errorf("unsupported tier: %d", tier.ID)
}

if submitter, err = proofSubmitter.NewProofSubmitter(
if submitter, err = proofSubmitter.NewProofSubmitterOntake(
p.rpc,
producer,
p.proofGenerationCh,
Expand All @@ -167,7 +167,7 @@ func (p *Prover) initProofSubmitters(
p.proofSubmittersOntake = append(p.proofSubmittersOntake, submitter)
}

if p.proofSubmitterPacaya, err = proofSubmitter.NewProofSubmitter(
if p.proofSubmitterPacaya, err = proofSubmitter.NewProofSubmitterPacaya(
p.rpc,
&proofProducer.OptimisticProofProducer{},
p.proofGenerationCh,
Expand All @@ -180,11 +180,6 @@ func (p *Prover) initProofSubmitters(
p.txmgr,
p.privateTxmgr,
txBuilder,
tiers,
p.IsGuardianProver(),
p.cfg.GuardianProofSubmissionDelay,
0,
p.cfg.ForceBatchProvingInterval,
); err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions packages/taiko-client/prover/proof_producer/dummy_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func (o *DummyProofProducer) RequestProof(
_ time.Time,
) (*ProofWithHeader, error) {
return &ProofWithHeader{
BlockID: blockID,
Meta: meta,
Header: header,
Proof: bytes.Repeat([]byte{0xff}, 100),
Opts: opts,
Tier: tier,
BlockID: blockID,
Meta: meta,
LastHeader: header,
Proof: bytes.Repeat([]byte{0xff}, 100),
Opts: opts,
Tier: tier,
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestDummyProducerRequestProof(t *testing.T) {
require.Nil(t, err)

require.Equal(t, res.BlockID, blockID)
require.Equal(t, res.Header, header)
require.Equal(t, res.LastHeader, header)
require.Equal(t, tier, res.Tier)
require.NotEmpty(t, res.Proof)
}
12 changes: 6 additions & 6 deletions packages/taiko-client/prover/proof_producer/guardian_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func (g *GuardianProofProducer) RequestProof(

if g.returnLivenessBond {
return &ProofWithHeader{
BlockID: blockID,
Meta: meta,
Header: header,
Proof: crypto.Keccak256([]byte("RETURN_LIVENESS_BOND")),
Opts: opts,
Tier: g.tier,
BlockID: blockID,
Meta: meta,
LastHeader: header,
Proof: crypto.Keccak256([]byte("RETURN_LIVENESS_BOND")),
Opts: opts,
Tier: g.tier,
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestGuardianProducerRequestProof(t *testing.T) {
require.Nil(t, err)

require.Equal(t, res.BlockID, blockID)
require.Equal(t, res.Header, header)
require.Equal(t, res.LastHeader, header)
require.Equal(t, res.Tier, encoding.TierGuardianMajorityID)
require.NotEmpty(t, res.Proof)
}
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestGuardianProducerRequestProofReturnLivenessBond(t *testing.T) {
require.Nil(t, err)

require.Equal(t, res.BlockID, blockID)
require.Equal(t, res.Header, header)
require.Equal(t, res.LastHeader, header)
require.Equal(t, res.Tier, encoding.TierGuardianMajorityID)
require.NotEmpty(t, res.Proof)
require.Equal(t, res.Proof, crypto.Keccak256([]byte("RETURN_LIVENESS_BOND")))
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestMinorityRequestProof(t *testing.T) {
require.Nil(t, err)

require.Equal(t, res.BlockID, blockID)
require.Equal(t, res.Header, header)
require.Equal(t, res.LastHeader, header)
require.Equal(t, res.Tier, encoding.TierGuardianMinorityID)
require.NotEmpty(t, res.Proof)
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestRequestMinorityProofReturnLivenessBond(t *testing.T) {
require.Nil(t, err)

require.Equal(t, res.BlockID, blockID)
require.Equal(t, res.Header, header)
require.Equal(t, res.LastHeader, header)
require.Equal(t, res.Tier, encoding.TierGuardianMinorityID)
require.NotEmpty(t, res.Proof)
require.Equal(t, res.Proof, crypto.Keccak256([]byte("RETURN_LIVENESS_BOND")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestOptimisticRequestProof(t *testing.T) {
require.Nil(t, err)

require.Equal(t, res.BlockID, blockID)
require.Equal(t, res.Header, header)
require.Equal(t, res.LastHeader, header)
require.Equal(t, res.Tier, encoding.TierOptimisticID)
require.NotEmpty(t, res.Proof)
}
Expand Down
36 changes: 18 additions & 18 deletions packages/taiko-client/prover/proof_producer/proof_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ type ContestRequestBody struct {

// ProofRequestOptions contains all options that need to be passed to a backend proof producer service.
type ProofRequestOptions struct {
BlockID *big.Int
ProverAddress common.Address
ProposeBlockTxHash common.Hash
MetaHash common.Hash
BlockHash common.Hash
ParentHash common.Hash
StateRoot common.Hash
EventL1Hash common.Hash
Graffiti string
GasUsed uint64
ParentGasUsed uint64
Compressed bool
LastBlockID *big.Int
ProverAddress common.Address
ProposeBlockTxHash common.Hash
MetaHash common.Hash
LastBlockHash common.Hash
LastParentHash common.Hash
LastBlockStateRoot common.Hash
EventL1Hash common.Hash
Graffiti string
LastBlockGasUsed uint64
FistBlockParentGasUsed uint64
Compressed bool
}

type ProofWithHeader struct {
BlockID *big.Int
Meta metadata.TaikoProposalMetaData
Header *types.Header
Proof []byte
Opts *ProofRequestOptions
Tier uint16
BlockID *big.Int
Meta metadata.TaikoProposalMetaData
LastHeader *types.Header
Proof []byte
Opts *ProofRequestOptions
Tier uint16
}

type BatchProofs struct {
Expand Down
26 changes: 13 additions & 13 deletions packages/taiko-client/prover/proof_producer/sgx_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ func (s *SGXProofProducer) RequestProof(
metrics.ProverSgxProofGeneratedCounter.Add(1)

return &ProofWithHeader{
BlockID: blockID,
Header: header,
Meta: meta,
Proof: proof,
Opts: opts,
Tier: s.Tier(),
BlockID: blockID,
LastHeader: header,
Meta: meta,
Proof: proof,
Opts: opts,
Tier: s.Tier(),
}, nil
}

Expand Down Expand Up @@ -178,7 +178,7 @@ func (s *SGXProofProducer) RequestCancel(
) error {
reqBody := RaikoRequestProofBody{
Type: s.ProofType,
Block: opts.BlockID,
Block: opts.LastBlockID,
Prover: opts.ProverAddress.Hex()[2:],
Graffiti: opts.Graffiti,
SGX: &SGXRequestProofBodyParam{
Expand Down Expand Up @@ -357,14 +357,14 @@ func (s *SGXProofProducer) callProverDaemon(

output, err := s.requestProof(ctx, opts)
if err != nil {
log.Error("Failed to request proof", "blockID", opts.BlockID, "error", err, "endpoint", s.RaikoHostEndpoint)
log.Error("Failed to request proof", "blockID", opts.LastBlockID, "error", err, "endpoint", s.RaikoHostEndpoint)
return nil, err
}

if output == nil {
log.Info(
"Proof generating",
"blockID", opts.BlockID,
"blockID", opts.LastBlockID,
"time", time.Since(requestAt),
"producer", "SGXProofProducer",
)
Expand All @@ -391,7 +391,7 @@ func (s *SGXProofProducer) callProverDaemon(

log.Info(
"Proof generated",
"blockID", opts.BlockID,
"blockID", opts.LastBlockID,
"time", time.Since(requestAt),
"producer", "SGXProofProducer",
)
Expand All @@ -407,7 +407,7 @@ func (s *SGXProofProducer) requestProof(
) (*RaikoRequestProofBodyResponseV2, error) {
reqBody := RaikoRequestProofBody{
Type: s.ProofType,
Block: opts.BlockID,
Block: opts.LastBlockID,
Prover: opts.ProverAddress.Hex()[2:],
Graffiti: opts.Graffiti,
SGX: &SGXRequestProofBodyParam{
Expand Down Expand Up @@ -440,7 +440,7 @@ func (s *SGXProofProducer) requestProof(

defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("failed to request proof, id: %d, statusCode: %d", opts.BlockID, res.StatusCode)
return nil, fmt.Errorf("failed to request proof, id: %d, statusCode: %d", opts.LastBlockID, res.StatusCode)
}

resBytes, err := io.ReadAll(res.Body)
Expand All @@ -450,7 +450,7 @@ func (s *SGXProofProducer) requestProof(

log.Debug(
"Proof generation output",
"blockID", opts.BlockID,
"blockID", opts.LastBlockID,
"proofType", "sgx",
"output", string(resBytes),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestSGXProducerRequestProof(t *testing.T) {
require.Nil(t, err)

require.Equal(t, res.BlockID, blockID)
require.Equal(t, res.Header, header)
require.Equal(t, res.LastHeader, header)
require.Equal(t, res.Tier, encoding.TierSgxID)
require.NotEmpty(t, res.Proof)
}
30 changes: 15 additions & 15 deletions packages/taiko-client/prover/proof_producer/zkvm_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func (s *ZKvmProofProducer) RequestProof(
}

return &ProofWithHeader{
BlockID: blockID,
Header: header,
Meta: meta,
Proof: proof,
Opts: opts,
Tier: s.Tier(),
BlockID: blockID,
LastHeader: header,
Meta: meta,
Proof: proof,
Opts: opts,
Tier: s.Tier(),
}, nil
}

Expand Down Expand Up @@ -177,7 +177,7 @@ func (s *ZKvmProofProducer) callProverDaemon(

output, err := s.requestProof(zkCtx, opts)
if err != nil {
log.Error("Failed to request proof", "blockID", opts.BlockID, "error", err, "endpoint", s.RaikoHostEndpoint)
log.Error("Failed to request proof", "blockID", opts.LastBlockID, "error", err, "endpoint", s.RaikoHostEndpoint)
return nil, err
}

Expand All @@ -196,7 +196,7 @@ func (s *ZKvmProofProducer) callProverDaemon(
}
log.Info(
"Proof generated",
"blockID", opts.BlockID,
"blockID", opts.LastBlockID,
"time", time.Since(requestAt),
"producer", "ZKvmProofProducer",
)
Expand Down Expand Up @@ -227,7 +227,7 @@ func (s *ZKvmProofProducer) requestProof(
case ZKProofTypeSP1:
reqBody = RaikoRequestProofBody{
Type: s.ZKProofType,
Block: opts.BlockID,
Block: opts.LastBlockID,
Prover: opts.ProverAddress.Hex()[2:],
Graffiti: opts.Graffiti,
SP1: &SP1RequestProofBodyParam{
Expand All @@ -239,7 +239,7 @@ func (s *ZKvmProofProducer) requestProof(
default:
reqBody = RaikoRequestProofBody{
Type: s.ZKProofType,
Block: opts.BlockID,
Block: opts.LastBlockID,
Prover: opts.ProverAddress.Hex()[2:],
Graffiti: opts.Graffiti,
RISC0: &RISC0RequestProofBodyParam{
Expand Down Expand Up @@ -269,7 +269,7 @@ func (s *ZKvmProofProducer) requestProof(

log.Debug(
"Send proof generation request",
"blockID", opts.BlockID,
"blockID", opts.LastBlockID,
"zkProofType", s.ZKProofType,
"input", string(jsonValue),
)
Expand All @@ -281,7 +281,7 @@ func (s *ZKvmProofProducer) requestProof(

defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("failed to request proof, id: %d, statusCode: %d", opts.BlockID, res.StatusCode)
return nil, fmt.Errorf("failed to request proof, id: %d, statusCode: %d", opts.LastBlockID, res.StatusCode)
}

resBytes, err := io.ReadAll(res.Body)
Expand All @@ -291,7 +291,7 @@ func (s *ZKvmProofProducer) requestProof(

log.Debug(
"Proof generation output",
"blockID", opts.BlockID,
"blockID", opts.LastBlockID,
"zkType", s.ZKProofType,
"output", string(resBytes),
)
Expand Down Expand Up @@ -328,7 +328,7 @@ func (s *ZKvmProofProducer) requestCancel(
case ZKProofTypeSP1:
reqBody = RaikoRequestProofBody{
Type: s.ZKProofType,
Block: opts.BlockID,
Block: opts.LastBlockID,
Prover: opts.ProverAddress.Hex()[2:],
Graffiti: opts.Graffiti,
SP1: &SP1RequestProofBodyParam{
Expand All @@ -340,7 +340,7 @@ func (s *ZKvmProofProducer) requestCancel(
default:
reqBody = RaikoRequestProofBody{
Type: s.ZKProofType,
Block: opts.BlockID,
Block: opts.LastBlockID,
Prover: opts.ProverAddress.Hex()[2:],
Graffiti: opts.Graffiti,
RISC0: &RISC0RequestProofBodyParam{
Expand Down
10 changes: 10 additions & 0 deletions packages/taiko-client/prover/proof_submitter/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ package submitter

import (
"context"
"errors"
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/metadata"
proofProducer "github.com/taikoxyz/taiko-mono/packages/taiko-client/prover/proof_producer"
)

var (
_ Submitter = (*ProofSubmitterOntake)(nil)
submissionDelayRandomBumpRange float64 = 20
proofPollingInterval = 10 * time.Second
ProofTimeout = 3 * time.Hour
ErrInvalidProof = errors.New("invalid proof found")
)

// Submitter is the interface for submitting proofs of the L2 blocks.
type Submitter interface {
RequestProof(ctx context.Context, meta metadata.TaikoProposalMetaData) error
Expand Down
Loading

0 comments on commit a696dc5

Please sign in to comment.