From 295f0ab32e489ec5511e397c754455bccf02c9f1 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 25 Jul 2023 10:51:23 +0800 Subject: [PATCH] test(driver): add more unit tests (#328) --- .github/workflows/test.yml | 2 +- driver/chain_syncer/calldata/syncer.go | 11 +- driver/driver.go | 14 +- driver/driver_test.go | 124 +++++++++++++++++- driver/state/state.go | 13 +- driver/state/state_test.go | 2 +- pkg/rpc/methods.go | 28 +++- pkg/rpc/methods_test.go | 6 + pkg/rpc/utils.go | 2 +- proposer/proposer.go | 6 +- .../proof_producer/special_proof_producer.go | 3 +- .../proof_submitter/valid_proof_submitter.go | 3 +- prover/prover.go | 29 ++-- 13 files changed, 204 insertions(+), 39 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 35b22273b..c25d87ca7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -85,7 +85,7 @@ jobs: - name: Install protocol dependencies working-directory: ${{ env.TAIKO_MONO_DIR }} - run: cd ./packages/protocol && pnpm install && ./script/download_solc.sh && forge install + run: cd ./packages/protocol && pnpm install --no-frozen-lockfile && ./script/download_solc.sh && forge install - name: Build working-directory: ${{ env.CLIENT_DIR }} diff --git a/driver/chain_syncer/calldata/syncer.go b/driver/chain_syncer/calldata/syncer.go index a0d542cb0..d76c504bf 100644 --- a/driver/chain_syncer/calldata/syncer.go +++ b/driver/chain_syncer/calldata/syncer.go @@ -47,7 +47,7 @@ func NewSyncer( progressTracker *beaconsync.SyncProgressTracker, signalServiceAddress common.Address, ) (*Syncer, error) { - configs, err := rpc.TaikoL1.GetConfig(nil) + configs, err := rpc.TaikoL1.GetConfig(&bind.CallOpts{Context: ctx}) if err != nil { return nil, fmt.Errorf("failed to get protocol configs: %w", err) } @@ -88,8 +88,6 @@ func (s *Syncer) ProcessL1Blocks(ctx context.Context, l1End *types.Header) error if err != nil { return err } - s.state.SetL1Current(newL1Current) - s.lastInsertedBlockID = nil log.Info( "Reorg detected", @@ -97,6 +95,9 @@ func (s *Syncer) ProcessL1Blocks(ctx context.Context, l1End *types.Header) error "newL1Current", startHeight, "l1Head", l1End.Number, ) + + s.state.SetL1Current(newL1Current) + s.lastInsertedBlockID = nil } iter, err := eventIterator.NewBlockProposedIterator(ctx, &eventIterator.BlockProposedIteratorConfig{ @@ -324,14 +325,14 @@ func (s *Syncer) insertNewHead( } } - parentTimestamp, err := s.rpc.TaikoL2.ParentTimestamp(&bind.CallOpts{BlockNumber: parent.Number}) + parentTimestamp, err := s.rpc.TaikoL2.ParentTimestamp(&bind.CallOpts{BlockNumber: parent.Number, Context: ctx}) if err != nil { return nil, err } // Get L2 baseFee baseFee, err := s.rpc.TaikoL2.GetBasefee( - &bind.CallOpts{BlockNumber: parent.Number}, + &bind.CallOpts{BlockNumber: parent.Number, Context: ctx}, uint32(event.Meta.Timestamp-parentTimestamp), event.Meta.GasLimit+uint32(s.anchorConstructor.GasLimit()), uint32(parent.GasUsed), diff --git a/driver/driver.go b/driver/driver.go index efd2ad8f3..ecb00e538 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -6,6 +6,7 @@ import ( "time" "github.com/cenkalti/backoff/v4" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -84,7 +85,11 @@ func InitFromConfig(ctx context.Context, d *Driver, cfg *Config) (err error) { log.Warn("P2P syncing verified blocks enabled, but no connected peer found in L2 execution engine") } - signalServiceAddress, err := d.rpc.TaikoL1.Resolve0(nil, rpc.StringToBytes32("signal_service"), false) + signalServiceAddress, err := d.rpc.TaikoL1.Resolve0( + &bind.CallOpts{Context: ctx}, + rpc.StringToBytes32("signal_service"), + false, + ) if err != nil { return err } @@ -192,7 +197,10 @@ func (d *Driver) reportProtocolStatus() { var maxNumBlocks uint64 if err := backoff.Retry( func() error { - configs, err := d.rpc.TaikoL1.GetConfig(nil) + if d.ctx.Err() != nil { + return nil + } + configs, err := d.rpc.TaikoL1.GetConfig(&bind.CallOpts{Context: d.ctx}) if err != nil { return err } @@ -211,7 +219,7 @@ func (d *Driver) reportProtocolStatus() { case <-d.ctx.Done(): return case <-ticker.C: - vars, err := d.rpc.GetProtocolStateVariables(nil) + vars, err := d.rpc.GetProtocolStateVariables(&bind.CallOpts{Context: d.ctx}) if err != nil { log.Error("Failed to get protocol state variables", "error", err) continue diff --git a/driver/driver_test.go b/driver/driver_test.go index 8a78bbc68..2537228f0 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -111,7 +111,7 @@ func (s *DriverTestSuite) TestProcessL1Blocks() { } } -func (s *DriverTestSuite) TestCheckL1Reorg() { +func (s *DriverTestSuite) TestCheckL1ReorgToHigherFork() { var testnetL1SnapshotID string s.Nil(s.RpcClient.L1RawRPC.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot")) s.NotEmpty(testnetL1SnapshotID) @@ -146,13 +146,132 @@ func (s *DriverTestSuite) TestCheckL1Reorg() { s.Equal(l1Head3.Number.Uint64(), l1Head1.Number.Uint64()) s.Equal(l1Head3.Hash(), l1Head1.Hash()) - // Propose two blocks in another fork + // Propose ten blocks on another fork + for i := 0; i < 10; i++ { + testutils.ProposeInvalidTxListBytes(&s.ClientTestSuite, s.p) + } + + l1Head4, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil) + s.Nil(err) + + s.Greater(l1Head4.Number.Uint64(), l1Head2.Number.Uint64()) + + s.Nil(s.d.ChainSyncer().CalldataSyncer().ProcessL1Blocks(context.Background(), l1Head4)) + + l2Head3, err := s.d.rpc.L2.HeaderByNumber(context.Background(), nil) + s.Nil(err) + + s.Equal(l2Head1.Number.Uint64()+10, l2Head3.Number.Uint64()) + + parent, err := s.d.rpc.L2.HeaderByNumber(context.Background(), new(big.Int).SetUint64(l2Head1.Number.Uint64()+1)) + s.Nil(err) + s.Equal(parent.ParentHash, l2Head1.Hash()) + s.NotEqual(parent.Hash(), l2Head2.ParentHash) +} + +func (s *DriverTestSuite) TestCheckL1ReorgToLowerFork() { + var testnetL1SnapshotID string + s.Nil(s.RpcClient.L1RawRPC.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot")) + s.NotEmpty(testnetL1SnapshotID) + + l1Head1, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil) + s.Nil(err) + l2Head1, err := s.d.rpc.L2.HeaderByNumber(context.Background(), nil) + s.Nil(err) + + // Propose two L2 blocks + testutils.ProposeAndInsertValidBlock(&s.ClientTestSuite, s.p, s.d.ChainSyncer().CalldataSyncer()) + time.Sleep(3 * time.Second) + testutils.ProposeAndInsertValidBlock(&s.ClientTestSuite, s.p, s.d.ChainSyncer().CalldataSyncer()) + + l1Head2, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil) + s.Nil(err) + l2Head2, err := s.d.rpc.L2.HeaderByNumber(context.Background(), nil) + s.Nil(err) + s.Greater(l2Head2.Number.Uint64(), l2Head1.Number.Uint64()) + s.Greater(l1Head2.Number.Uint64(), l1Head1.Number.Uint64()) + + reorged, _, _, err := s.RpcClient.CheckL1ReorgFromL2EE(context.Background(), l2Head2.Number) + s.Nil(err) + s.False(reorged) + + // Reorg back to l2Head1 + var revertRes bool + s.Nil(s.RpcClient.L1RawRPC.CallContext(context.Background(), &revertRes, "evm_revert", testnetL1SnapshotID)) + s.True(revertRes) + + l1Head3, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil) + s.Nil(err) + s.Equal(l1Head3.Number.Uint64(), l1Head1.Number.Uint64()) + s.Equal(l1Head3.Hash(), l1Head1.Hash()) + + // Propose one blocks on another fork testutils.ProposeInvalidTxListBytes(&s.ClientTestSuite, s.p) + + l1Head4, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil) + s.Nil(err) + + s.Greater(l1Head4.Number.Uint64(), l1Head3.Number.Uint64()) + s.Less(l1Head4.Number.Uint64(), l1Head2.Number.Uint64()) + + s.Nil(s.d.ChainSyncer().CalldataSyncer().ProcessL1Blocks(context.Background(), l1Head4)) + + l2Head3, err := s.d.rpc.L2.HeaderByNumber(context.Background(), nil) + s.Nil(err) + + parent, err := s.d.rpc.L2.HeaderByHash(context.Background(), l2Head3.ParentHash) + s.Nil(err) + s.Equal(l2Head3.Number.Uint64(), l2Head2.Number.Uint64()-1) + s.Equal(parent.Hash(), l2Head1.Hash()) +} + +func (s *DriverTestSuite) TestCheckL1ReorgToSameHeightFork() { + var testnetL1SnapshotID string + s.Nil(s.RpcClient.L1RawRPC.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot")) + s.NotEmpty(testnetL1SnapshotID) + + l1Head1, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil) + s.Nil(err) + l2Head1, err := s.d.rpc.L2.HeaderByNumber(context.Background(), nil) + s.Nil(err) + + // Propose two L2 blocks + testutils.ProposeAndInsertValidBlock(&s.ClientTestSuite, s.p, s.d.ChainSyncer().CalldataSyncer()) + time.Sleep(3 * time.Second) + testutils.ProposeAndInsertValidBlock(&s.ClientTestSuite, s.p, s.d.ChainSyncer().CalldataSyncer()) + + l1Head2, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil) + s.Nil(err) + l2Head2, err := s.d.rpc.L2.HeaderByNumber(context.Background(), nil) + s.Nil(err) + s.Greater(l2Head2.Number.Uint64(), l2Head1.Number.Uint64()) + s.Greater(l1Head2.Number.Uint64(), l1Head1.Number.Uint64()) + + reorged, _, _, err := s.RpcClient.CheckL1ReorgFromL2EE(context.Background(), l2Head2.Number) + s.Nil(err) + s.False(reorged) + + // Reorg back to l2Head1 + var revertRes bool + s.Nil(s.RpcClient.L1RawRPC.CallContext(context.Background(), &revertRes, "evm_revert", testnetL1SnapshotID)) + s.True(revertRes) + + l1Head3, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil) + s.Nil(err) + s.Equal(l1Head3.Number.Uint64(), l1Head1.Number.Uint64()) + s.Equal(l1Head3.Hash(), l1Head1.Hash()) + + // Propose two blocks on another fork + testutils.ProposeInvalidTxListBytes(&s.ClientTestSuite, s.p) + time.Sleep(3 * time.Second) testutils.ProposeInvalidTxListBytes(&s.ClientTestSuite, s.p) l1Head4, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil) s.Nil(err) + s.Greater(l1Head4.Number.Uint64(), l1Head3.Number.Uint64()) + s.Equal(l1Head4.Number.Uint64(), l1Head2.Number.Uint64()) + s.Nil(s.d.ChainSyncer().CalldataSyncer().ProcessL1Blocks(context.Background(), l1Head4)) l2Head3, err := s.d.rpc.L2.HeaderByNumber(context.Background(), nil) @@ -161,6 +280,7 @@ func (s *DriverTestSuite) TestCheckL1Reorg() { parent, err := s.d.rpc.L2.HeaderByHash(context.Background(), l2Head3.ParentHash) s.Nil(err) s.Equal(l2Head3.Number.Uint64(), l2Head2.Number.Uint64()) + s.NotEqual(l2Head3.Hash(), l2Head2.Hash()) s.Equal(parent.ParentHash, l2Head1.Hash()) } diff --git a/driver/state/state.go b/driver/state/state.go index 2951157e5..8642a776d 100644 --- a/driver/state/state.go +++ b/driver/state/state.go @@ -102,7 +102,7 @@ func (s *State) Close() { // init fetches the latest status and initializes the state instance. func (s *State) init(ctx context.Context) error { - stateVars, err := s.rpc.GetProtocolStateVariables(nil) + stateVars, err := s.rpc.GetProtocolStateVariables(&bind.CallOpts{Context: ctx}) if err != nil { return err } @@ -134,7 +134,7 @@ func (s *State) init(ctx context.Context) error { s.setL2Head(l2Head) latestVerifiedBlockHash, err := s.rpc.TaikoL1.GetCrossChainBlockHash( - nil, + &bind.CallOpts{Context: ctx}, new(big.Int).SetUint64(stateVars.LastVerifiedBlockId), ) if err != nil { @@ -182,7 +182,7 @@ func (s *State) startSubscriptions(ctx context.Context) { continue } } - id, err := s.getSyncedHeaderID(e.Raw.BlockNumber, e.BlockHash) + id, err := s.getSyncedHeaderID(ctx, e.Raw.BlockNumber, e.BlockHash) if err != nil { log.Error("Get synced header block ID error", "error", err) continue @@ -289,10 +289,11 @@ func (s *State) VerifyL2Block(ctx context.Context, height *big.Int, hash common. } // getSyncedHeaderID fetches the block ID of the synced L2 header. -func (s *State) getSyncedHeaderID(l1Height uint64, hash common.Hash) (*big.Int, error) { +func (s *State) getSyncedHeaderID(ctx context.Context, l1Height uint64, hash common.Hash) (*big.Int, error) { iter, err := s.rpc.TaikoL1.FilterBlockVerified(&bind.FilterOpts{ - Start: l1Height, - End: &l1Height, + Start: l1Height, + End: &l1Height, + Context: ctx, }, nil) if err != nil { return nil, fmt.Errorf("failed to filter BlockVerified event: %w", err) diff --git a/driver/state/state_test.go b/driver/state/state_test.go index 2da5c7743..58c560254 100644 --- a/driver/state/state_test.go +++ b/driver/state/state_test.go @@ -72,7 +72,7 @@ func (s *DriverStateTestSuite) TestGetSyncedHeaderID() { l2Genesis, err := s.RpcClient.L2.BlockByNumber(context.Background(), common.Big0) s.Nil(err) - id, err := s.s.getSyncedHeaderID(s.s.GenesisL1Height.Uint64(), l2Genesis.Hash()) + id, err := s.s.getSyncedHeaderID(context.Background(), s.s.GenesisL1Height.Uint64(), l2Genesis.Hash()) s.Nil(err) s.Zero(id.Uint64()) } diff --git a/pkg/rpc/methods.go b/pkg/rpc/methods.go index 84b21bd87..933d45631 100644 --- a/pkg/rpc/methods.go +++ b/pkg/rpc/methods.go @@ -34,14 +34,14 @@ var ( // ensureGenesisMatched fetches the L2 genesis block from TaikoL1 contract, // and checks whether the fetched genesis is same to the node local genesis. func (c *Client) ensureGenesisMatched(ctx context.Context) error { - stateVars, err := c.GetProtocolStateVariables(nil) + stateVars, err := c.GetProtocolStateVariables(&bind.CallOpts{Context: ctx}) if err != nil { return err } // Fetch the genesis `BlockVerified` event. iter, err := c.TaikoL1.FilterBlockVerified( - &bind.FilterOpts{Start: stateVars.GenesisHeight, End: &stateVars.GenesisHeight}, + &bind.FilterOpts{Start: stateVars.GenesisHeight, End: &stateVars.GenesisHeight, Context: ctx}, []*big.Int{common.Big0}, ) if err != nil { @@ -99,7 +99,7 @@ func (c *Client) WaitTillL2ExecutionEngineSynced(ctx context.Context) error { return nil }, - backoff.NewConstantBackOff(syncProgressRecheckDelay), + backoff.WithMaxRetries(backoff.NewConstantBackOff(syncProgressRecheckDelay), 10), ) } @@ -138,7 +138,7 @@ func (c *Client) LatestL2KnownL1Header(ctx context.Context) (*types.Header, erro // GetGenesisL1Header fetches the L1 header that including L2 genesis block. func (c *Client) GetGenesisL1Header(ctx context.Context) (*types.Header, error) { - stateVars, err := c.GetProtocolStateVariables(nil) + stateVars, err := c.GetProtocolStateVariables(&bind.CallOpts{Context: ctx}) if err != nil { return nil, err } @@ -271,7 +271,7 @@ func (c *Client) L2ExecutionEngineSyncProgress(ctx context.Context) (*L2SyncProg }) g.Go(func() error { - stateVars, err := c.GetProtocolStateVariables(nil) + stateVars, err := c.GetProtocolStateVariables(&bind.CallOpts{Context: ctx}) if err != nil { return err } @@ -305,6 +305,22 @@ func (c *Client) L2ExecutionEngineSyncProgress(ctx context.Context) (*L2SyncProg // GetProtocolStateVariables gets the protocol states from TaikoL1 contract. func (c *Client) GetProtocolStateVariables(opts *bind.CallOpts) (*bindings.TaikoDataStateVariables, error) { + var ( + ctxWithTimeout context.Context + cancel context.CancelFunc + ) + if opts != nil && opts.Context != nil { + if _, ok := opts.Context.Deadline(); !ok { + ctxWithTimeout, cancel = context.WithTimeout(opts.Context, defaultWaitReceiptTimeout) + defer cancel() + opts.Context = ctxWithTimeout + } + } else { + ctxWithTimeout, cancel = context.WithTimeout(context.Background(), defaultWaitReceiptTimeout) + defer cancel() + opts = &bind.CallOpts{Context: ctxWithTimeout} + } + return GetProtocolStateVariables(c.TaikoL1, opts) } @@ -338,7 +354,7 @@ func (c *Client) CheckL1ReorgFromL2EE(ctx context.Context, blockID *big.Int) (bo ) for { if blockID.Cmp(common.Big0) == 0 { - stateVars, err := c.TaikoL1.GetStateVariables(nil) + stateVars, err := c.TaikoL1.GetStateVariables(&bind.CallOpts{Context: ctx}) if err != nil { return false, nil, nil, err } diff --git a/pkg/rpc/methods_test.go b/pkg/rpc/methods_test.go index 93432e861..a7fc10117 100644 --- a/pkg/rpc/methods_test.go +++ b/pkg/rpc/methods_test.go @@ -90,3 +90,9 @@ func TestCheckL1ReorgFromL1Cursor(t *testing.T) { require.True(t, reorged) require.Equal(t, l1Head.ParentHash, newL1Current.Hash()) } + +func TestIsJustSyncedByP2P(t *testing.T) { + client := newTestClient(t) + _, err := client.IsJustSyncedByP2P(context.Background()) + require.Nil(t, err) +} diff --git a/pkg/rpc/utils.go b/pkg/rpc/utils.go index 575ae83ca..37694e4b5 100644 --- a/pkg/rpc/utils.go +++ b/pkg/rpc/utils.go @@ -96,7 +96,7 @@ func NeedNewProof( } } - fc, err := cli.TaikoL1.GetForkChoice(nil, id, parent.Hash(), uint32(parent.GasUsed)) + fc, err := cli.TaikoL1.GetForkChoice(&bind.CallOpts{Context: ctx}, id, parent.Hash(), uint32(parent.GasUsed)) if err != nil { if !strings.Contains(encoding.TryParsingCustomError(err).Error(), "L1_FORK_CHOICE_NOT_FOUND") { return false, encoding.TryParsingCustomError(err) diff --git a/proposer/proposer.go b/proposer/proposer.go index 4f6adf45f..134eaa50e 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -105,7 +105,7 @@ func InitFromConfig(ctx context.Context, p *Proposer, cfg *Config) (err error) { } // Protocol configs - protocolConfigs, err := p.rpc.TaikoL1.GetConfig(nil) + protocolConfigs, err := p.rpc.TaikoL1.GetConfig(&bind.CallOpts{Context: ctx}) if err != nil { return fmt.Errorf("failed to get protocol configs: %w", err) } @@ -500,7 +500,7 @@ func getTxOpts( // CheckTaikoTokenBalance checks if the current proposer has enough balance to pay // the current block fee. func (p *Proposer) CheckTaikoTokenBalance() error { - fee, err := p.rpc.TaikoL1.GetBlockFee(nil, p.protocolConfigs.BlockMaxGasLimit) + fee, err := p.rpc.TaikoL1.GetBlockFee(&bind.CallOpts{Context: p.ctx}, p.protocolConfigs.BlockMaxGasLimit) if err != nil { return fmt.Errorf("failed to get block fee: %w", err) } @@ -513,7 +513,7 @@ func (p *Proposer) CheckTaikoTokenBalance() error { metrics.ProposerBlockFeeGauge.Update(int64(fee)) } - balance, err := p.rpc.TaikoL1.GetTaikoTokenBalance(nil, p.l1ProposerAddress) + balance, err := p.rpc.TaikoL1.GetTaikoTokenBalance(&bind.CallOpts{Context: p.ctx}, p.l1ProposerAddress) if err != nil { return fmt.Errorf("failed to get tko balance: %w", err) } diff --git a/prover/proof_producer/special_proof_producer.go b/prover/proof_producer/special_proof_producer.go index e19336a49..2a0422eb0 100644 --- a/prover/proof_producer/special_proof_producer.go +++ b/prover/proof_producer/special_proof_producer.go @@ -9,6 +9,7 @@ import ( "time" "github.com/cenkalti/backoff/v4" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" @@ -125,7 +126,7 @@ func (p *SpecialProofProducer) requestSpecialProof( return err } - blockInfo, err := p.rpc.TaikoL1.GetBlock(nil, blockID) + blockInfo, err := p.rpc.TaikoL1.GetBlock(&bind.CallOpts{Context: ctx}, blockID) if err != nil { return err } diff --git a/prover/proof_submitter/valid_proof_submitter.go b/prover/proof_submitter/valid_proof_submitter.go index 5ef6c9a6d..d6d0375f9 100644 --- a/prover/proof_submitter/valid_proof_submitter.go +++ b/prover/proof_submitter/valid_proof_submitter.go @@ -9,6 +9,7 @@ import ( "sync" "time" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" @@ -103,7 +104,7 @@ func (s *ValidProofSubmitter) RequestProof(ctx context.Context, event *bindings. 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.BlockId) + blockInfo, err := s.rpc.TaikoL1.GetBlock(&bind.CallOpts{Context: ctx}, event.BlockId) if err != nil { return err } diff --git a/prover/prover.go b/prover/prover.go index c607232c6..e06a3c9ca 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -12,6 +12,7 @@ import ( "github.com/cenkalti/backoff/v4" "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" @@ -121,7 +122,7 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) { } // Configs - protocolConfigs, err := p.rpc.TaikoL1.GetConfig(nil) + protocolConfigs, err := p.rpc.TaikoL1.GetConfig(&bind.CallOpts{Context: ctx}) if err != nil { return fmt.Errorf("failed to get protocol configs: %w", err) } @@ -155,7 +156,12 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) { p.checkProofWindowExpiredInterval = p.cfg.CheckProofWindowExpiredInterval - oracleProverAddress, err := p.rpc.TaikoL1.Resolve(nil, p.rpc.L1ChainID, rpc.StringToBytes32("oracle_prover"), true) + oracleProverAddress, err := p.rpc.TaikoL1.Resolve( + &bind.CallOpts{Context: ctx}, + p.rpc.L1ChainID, + rpc.StringToBytes32("oracle_prover"), + true, + ) if err != nil { return err } @@ -471,7 +477,7 @@ func (p *Prover) onBlockProposed( p.cancelProof(ctx, event.Meta.Id) } - block, err := p.rpc.TaikoL1.GetBlock(nil, event.BlockId) + block, err := p.rpc.TaikoL1.GetBlock(&bind.CallOpts{Context: ctx}, event.BlockId) if err != nil { return err } @@ -494,7 +500,12 @@ func (p *Prover) onBlockProposed( // check if an invalid proof has been submitted, if so, we can skip proofWindowExpired check below // and always submit proof. otherwise, oracleProver follows same proof logic as regular. - forkChoice, err := p.rpc.TaikoL1.GetForkChoice(nil, event.BlockId, parent.Hash(), uint32(parent.GasUsed)) + forkChoice, err := p.rpc.TaikoL1.GetForkChoice( + &bind.CallOpts{Context: ctx}, + event.BlockId, + parent.Hash(), + uint32(parent.GasUsed), + ) if err != nil { if strings.Contains(encoding.TryParsingCustomError(err).Error(), "L1_FORK_CHOICE_NOT_FOUND") { // proof hasnt been submitted @@ -729,7 +740,7 @@ func (p *Prover) initL1Current(startingBlockID *big.Int) error { return err } - stateVars, err := p.rpc.GetProtocolStateVariables(nil) + stateVars, err := p.rpc.GetProtocolStateVariables(&bind.CallOpts{Context: p.ctx}) if err != nil { return err } @@ -775,7 +786,7 @@ func (p *Prover) initL1Current(startingBlockID *big.Int) error { // isBlockVerified checks whether the given block has been verified by other provers. func (p *Prover) isBlockVerified(id *big.Int) (bool, error) { - stateVars, err := p.rpc.GetProtocolStateVariables(nil) + stateVars, err := p.rpc.GetProtocolStateVariables(&bind.CallOpts{Context: p.ctx}) if err != nil { return false, err } @@ -810,7 +821,7 @@ func (p *Prover) checkChainVerification(lastLatestVerifiedL1Height uint64) error "proofCooldownPeriod", p.protocolConfigs.ProofRegularCooldown, ) - stateVar, err := p.rpc.TaikoL1.GetStateVariables(nil) + stateVar, err := p.rpc.TaikoL1.GetStateVariables(&bind.CallOpts{Context: p.ctx}) if err != nil { log.Error("Failed to get protocol state variables", "error", err) return err @@ -880,7 +891,7 @@ func (p *Prover) checkProofWindowsExpired(ctx context.Context) error { // checkProofWindowExpired checks a single instance of a block to see if its proof winodw has expired // and the proof is now able to be submitted by anyone, not just the blocks assigned prover. func (p *Prover) checkProofWindowExpired(ctx context.Context, l1Height, blockId uint64) error { - block, err := p.rpc.TaikoL1.GetBlock(nil, new(big.Int).SetUint64(blockId)) + block, err := p.rpc.TaikoL1.GetBlock(&bind.CallOpts{Context: ctx}, new(big.Int).SetUint64(blockId)) if err != nil { return encoding.TryParsingCustomError(err) } @@ -903,7 +914,7 @@ func (p *Prover) checkProofWindowExpired(ctx context.Context, l1Height, blockId } forkChoice, err := p.rpc.TaikoL1.GetForkChoice( - nil, + &bind.CallOpts{Context: ctx}, new(big.Int).SetUint64(blockId), parent.Hash(), uint32(parent.GasUsed),