From 64cc44befb680f73eb67c9246f1bb0fbc118d019 Mon Sep 17 00:00:00 2001 From: jeff <113397187+cyberhorsey@users.noreply.github.com> Date: Tue, 8 Aug 2023 23:51:11 -0700 Subject: [PATCH] feat(prover): prove block tx gas limit (#357) --- cmd/flags/prover.go | 6 ++ prover/config.go | 8 +++ .../proof_submitter/valid_proof_submitter.go | 67 ++++++++++--------- .../valid_proof_submitter_test.go | 1 + prover/prover.go | 1 + 5 files changed, 53 insertions(+), 30 deletions(-) diff --git a/cmd/flags/prover.go b/cmd/flags/prover.go index 2d33d097d..6d70e2d01 100644 --- a/cmd/flags/prover.go +++ b/cmd/flags/prover.go @@ -99,6 +99,11 @@ var ( Category: proverCategory, Value: false, } + ProveBlockTxGasLimit = &cli.Uint64Flag{ + Name: "prover.proveBlockTxGasLimit", + Usage: "Gas limit will be used for TaikoL1.proveBlock transactions", + Category: proverCategory, + } ) // All prover flags. @@ -121,4 +126,5 @@ var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{ TaikoProverPoolL1Address, CheckProofWindowExpiredInterval, ProveUnassignedBlocks, + ProveBlockTxGasLimit, }) diff --git a/prover/config.go b/prover/config.go index 0eb829584..0b7f15777 100644 --- a/prover/config.go +++ b/prover/config.go @@ -41,6 +41,7 @@ type Config struct { ProveUnassignedBlocks bool RPCTimeout *time.Duration WaitReceiptTimeout time.Duration + ProveBlockGasLimit *uint64 } // NewConfigFromCliContext creates a new config instance from command line flags. @@ -109,6 +110,12 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { timeout = &duration } + var proveBlockTxGasLimit *uint64 + if c.IsSet(flags.ProveBlockTxGasLimit.Name) { + gasLimit := c.Uint64(flags.ProveBlockTxGasLimit.Name) + proveBlockTxGasLimit = &gasLimit + } + return &Config{ L1WsEndpoint: c.String(flags.L1WSEndpoint.Name), L1HttpEndpoint: c.String(flags.L1HTTPEndpoint.Name), @@ -138,5 +145,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { ProveUnassignedBlocks: c.Bool(flags.ProveUnassignedBlocks.Name), RPCTimeout: timeout, WaitReceiptTimeout: time.Duration(c.Uint64(flags.WaitReceiptTimeout.Name)) * time.Second, + ProveBlockGasLimit: proveBlockTxGasLimit, }, nil } diff --git a/prover/proof_submitter/valid_proof_submitter.go b/prover/proof_submitter/valid_proof_submitter.go index aecc6a7c0..5be15fa8e 100644 --- a/prover/proof_submitter/valid_proof_submitter.go +++ b/prover/proof_submitter/valid_proof_submitter.go @@ -26,21 +26,22 @@ var _ ProofSubmitter = (*ValidProofSubmitter)(nil) // ValidProofSubmitter is responsible requesting zk proofs for the given valid L2 // blocks, and submitting the generated proofs to the TaikoL1 smart contract. type ValidProofSubmitter struct { - rpc *rpc.Client - proofProducer proofProducer.ProofProducer - resultCh chan *proofProducer.ProofWithHeader - anchorTxValidator *anchorTxValidator.AnchorTxValidator - proverPrivKey *ecdsa.PrivateKey - proverAddress common.Address - taikoL2Address common.Address - l1SignalService common.Address - l2SignalService common.Address - mutex *sync.Mutex - isOracleProver bool - graffiti [32]byte - submissionMaxRetry uint64 - retryInterval time.Duration - waitReceiptTimeout time.Duration + rpc *rpc.Client + proofProducer proofProducer.ProofProducer + resultCh chan *proofProducer.ProofWithHeader + anchorTxValidator *anchorTxValidator.AnchorTxValidator + proverPrivKey *ecdsa.PrivateKey + proverAddress common.Address + taikoL2Address common.Address + l1SignalService common.Address + l2SignalService common.Address + mutex *sync.Mutex + isOracleProver bool + graffiti [32]byte + submissionMaxRetry uint64 + retryInterval time.Duration + waitReceiptTimeout time.Duration + proveBlockTxGasLimit *uint64 } // NewValidProofSubmitter creates a new ValidProofSubmitter instance. @@ -56,6 +57,7 @@ func NewValidProofSubmitter( submissionMaxRetry uint64, retryInterval time.Duration, waitReceiptTimeout time.Duration, + proveBlockTxGasLimit *uint64, ) (*ValidProofSubmitter, error) { anchorValidator, err := anchorTxValidator.New(taikoL2Address, rpcClient.L2ChainID, rpcClient) if err != nil { @@ -73,21 +75,22 @@ func NewValidProofSubmitter( } return &ValidProofSubmitter{ - rpc: rpcClient, - proofProducer: proofProducer, - resultCh: resultCh, - anchorTxValidator: anchorValidator, - proverPrivKey: proverPrivKey, - proverAddress: crypto.PubkeyToAddress(proverPrivKey.PublicKey), - l1SignalService: l1SignalService, - l2SignalService: l2SignalService, - taikoL2Address: taikoL2Address, - mutex: mutex, - isOracleProver: isOracleProver, - graffiti: rpc.StringToBytes32(graffiti), - submissionMaxRetry: submissionMaxRetry, - retryInterval: retryInterval, - waitReceiptTimeout: waitReceiptTimeout, + rpc: rpcClient, + proofProducer: proofProducer, + resultCh: resultCh, + anchorTxValidator: anchorValidator, + proverPrivKey: proverPrivKey, + proverAddress: crypto.PubkeyToAddress(proverPrivKey.PublicKey), + l1SignalService: l1SignalService, + l2SignalService: l2SignalService, + taikoL2Address: taikoL2Address, + mutex: mutex, + isOracleProver: isOracleProver, + graffiti: rpc.StringToBytes32(graffiti), + submissionMaxRetry: submissionMaxRetry, + retryInterval: retryInterval, + waitReceiptTimeout: waitReceiptTimeout, + proveBlockTxGasLimit: proveBlockTxGasLimit, }, nil } @@ -251,6 +254,10 @@ func (s *ValidProofSubmitter) SubmitProof( return err } + if s.proveBlockTxGasLimit != nil { + txOpts.GasLimit = *s.proveBlockTxGasLimit + } + sendTx := func() (*types.Transaction, error) { s.mutex.Lock() defer s.mutex.Unlock() diff --git a/prover/proof_submitter/valid_proof_submitter_test.go b/prover/proof_submitter/valid_proof_submitter_test.go index 35c9a3214..9cc0a8489 100644 --- a/prover/proof_submitter/valid_proof_submitter_test.go +++ b/prover/proof_submitter/valid_proof_submitter_test.go @@ -51,6 +51,7 @@ func (s *ProofSubmitterTestSuite) SetupTest() { 1, 12*time.Second, 10*time.Second, + nil, ) s.Nil(err) diff --git a/prover/prover.go b/prover/prover.go index f978073e0..dc6c91bed 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -215,6 +215,7 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) { p.cfg.ProofSubmissionMaxRetry, p.cfg.BackOffRetryInterval, p.cfg.WaitReceiptTimeout, + p.cfg.ProveBlockGasLimit, ); err != nil { return err }