diff --git a/driver/anchor_tx_constructor/anchor_tx_constructor.go b/driver/anchor_tx_constructor/anchor_tx_constructor.go index a543b3457..b9d2b132b 100644 --- a/driver/anchor_tx_constructor/anchor_tx_constructor.go +++ b/driver/anchor_tx_constructor/anchor_tx_constructor.go @@ -88,7 +88,7 @@ func (c *AnchorTxConstructor) transactOpts( baseFee *big.Int, ) (*bind.TransactOpts, error) { var ( - signer = types.LatestSignerForChainID(c.rpc.L2ChainID) + signer = types.LatestSignerForChainID(c.rpc.L2.ChainID) parentHeight = new(big.Int).Sub(l2Height, common.Big1) ) diff --git a/driver/chain_syncer/calldata/syncer.go b/driver/chain_syncer/calldata/syncer.go index 69255143c..0e9cea7b1 100644 --- a/driver/chain_syncer/calldata/syncer.go +++ b/driver/chain_syncer/calldata/syncer.go @@ -74,7 +74,7 @@ func NewSyncer( uint64(configs.BlockMaxGasLimit), defaultMaxTxPerBlock, configs.BlockMaxTxListBytes.Uint64(), - rpc.L2ChainID, + rpc.L2.ChainID, ), }, nil } diff --git a/driver/chain_syncer/chain_syncer_test.go b/driver/chain_syncer/chain_syncer_test.go index 53373779f..5218b8cc9 100644 --- a/driver/chain_syncer/chain_syncer_test.go +++ b/driver/chain_syncer/chain_syncer_test.go @@ -97,7 +97,7 @@ func (s *ChainSyncerTestSuite) TestAheadOfProtocolVerifiedHead2() { // generate transactopts to interact with TaikoL1 contract with. privKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROVER_PRIVATE_KEY"))) s.Nil(err) - opts, err := bind.NewKeyedTransactorWithChainID(privKey, s.RPCClient.L1ChainID) + opts, err := bind.NewKeyedTransactorWithChainID(privKey, s.RPCClient.L1.ChainID) s.Nil(err) head, err := s.RPCClient.L1.HeaderByNumber(context.Background(), nil) diff --git a/driver/config_test.go b/driver/config_test.go index 2130026bd..b290fc512 100644 --- a/driver/config_test.go +++ b/driver/config_test.go @@ -13,6 +13,7 @@ import ( var ( l1Endpoint = os.Getenv("L1_NODE_WS_ENDPOINT") l2Endpoint = os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT") + l2CheckPoint = os.Getenv("L2_EXECUTION_ENGINE_HTTP_ENDPOINT") l2EngineEndpoint = os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT") taikoL1 = os.Getenv("TAIKO_L1_ADDRESS") taikoL2 = os.Getenv("TAIKO_L2_ADDRESS") @@ -35,7 +36,7 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() { s.NotEmpty(c.JwtSecret) s.Nil(new(Driver).InitFromCli(context.Background(), ctx)) s.True(c.P2PSyncVerifiedBlocks) - s.Equal("http://localhost:8545", c.L2CheckPoint) + s.Equal(l2CheckPoint, c.L2CheckPoint) return err } @@ -51,7 +52,7 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() { "--" + flags.P2PSyncTimeout.Name, "120s", "--" + flags.RPCTimeout.Name, "5s", "--" + flags.P2PSyncVerifiedBlocks.Name, - "--" + flags.CheckPointSyncURL.Name, "http://localhost:8545", + "--" + flags.CheckPointSyncURL.Name, l2CheckPoint, })) } diff --git a/internal/testutils/helper.go b/internal/testutils/helper.go index 495946da1..3b28833b9 100644 --- a/internal/testutils/helper.go +++ b/internal/testutils/helper.go @@ -120,7 +120,7 @@ func ProposeAndInsertValidBlock( baseFee, []byte{}, ) - signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(s.RPCClient.L2ChainID), s.TestAddrPrivKey) + signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(s.RPCClient.L2.ChainID), s.TestAddrPrivKey) s.Nil(err) s.Nil(s.RPCClient.L2.SendTransaction(context.Background(), signedTx)) diff --git a/internal/testutils/suite.go b/internal/testutils/suite.go index a6ebb3d9a..c29bc3643 100644 --- a/internal/testutils/suite.go +++ b/internal/testutils/suite.go @@ -78,7 +78,7 @@ func (s *ClientTestSuite) SetupTest() { s.Nil(err) s.Greater(balance.Cmp(common.Big0), 0) - opts, err := bind.NewKeyedTransactorWithChainID(ownerPrivKey, rpcCli.L1ChainID) + opts, err := bind.NewKeyedTransactorWithChainID(ownerPrivKey, rpcCli.L1.ChainID) s.Nil(err) proverBalance := new(big.Int).Div(balance, common.Big2) s.Greater(proverBalance.Cmp(common.Big0), 0) @@ -102,7 +102,7 @@ func (s *ClientTestSuite) setAllowance(key *ecdsa.PrivateKey) { bigInt := new(big.Int).Exp(big.NewInt(1_000_000_000), new(big.Int).SetUint64(uint64(decimal)), nil) - opts, err := bind.NewKeyedTransactorWithChainID(key, s.RPCClient.L1ChainID) + opts, err := bind.NewKeyedTransactorWithChainID(key, s.RPCClient.L1.ChainID) s.Nil(err) _, err = s.RPCClient.TaikoToken.Approve( diff --git a/pkg/chain_iterator/block_batch_iterator.go b/pkg/chain_iterator/block_batch_iterator.go index d714fa5df..9ae7a9f6a 100644 --- a/pkg/chain_iterator/block_batch_iterator.go +++ b/pkg/chain_iterator/block_batch_iterator.go @@ -77,11 +77,6 @@ func NewBlockBatchIterator(ctx context.Context, cfg *BlockBatchIteratorConfig) ( return nil, errors.New("invalid callback") } - chainID, err := cfg.Client.ChainID(ctx) - if err != nil { - return nil, fmt.Errorf("failed to get chain ID, error: %w", err) - } - if cfg.StartHeight == nil { return nil, errors.New("invalid start height") } @@ -102,7 +97,7 @@ func NewBlockBatchIterator(ctx context.Context, cfg *BlockBatchIteratorConfig) ( iterator := &BlockBatchIterator{ ctx: ctx, client: cfg.Client, - chainID: chainID, + chainID: cfg.Client.ChainID, startHeight: cfg.StartHeight.Uint64(), onBlocks: cfg.OnBlocks, current: startHeader, diff --git a/pkg/rpc/client.go b/pkg/rpc/client.go index 2193da80f..4c39c0da2 100644 --- a/pkg/rpc/client.go +++ b/pkg/rpc/client.go @@ -3,13 +3,13 @@ package rpc import ( "context" "fmt" - "math/big" "time" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/prysmaticlabs/prysm/v4/api/client" "github.com/prysmaticlabs/prysm/v4/api/client/beacon" + "github.com/taikoxyz/taiko-client/bindings" ) @@ -32,9 +32,6 @@ type Client struct { TaikoL2 *bindings.TaikoL2Client TaikoToken *bindings.TaikoToken GuardianProver *bindings.GuardianProver - // Chain IDs - L1ChainID *big.Int - L2ChainID *big.Int } // ClientConfig contains all configs which will be used to initializing an @@ -71,16 +68,6 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) { return nil, err } - l1ChainID, err := l1Client.ChainID(ctxWithTimeout) - if err != nil { - return nil, err - } - - l2ChainID, err := l2Client.ChainID(ctxWithTimeout) - if err != nil { - return nil, err - } - taikoL1, err := bindings.NewTaikoL1Client(cfg.TaikoL1Address, l1Client) if err != nil { return nil, err @@ -153,8 +140,6 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) { TaikoL2: taikoL2, TaikoToken: taikoToken, GuardianProver: guardianProver, - L1ChainID: l1ChainID, - L2ChainID: l2ChainID, } if err := client.ensureGenesisMatched(ctxWithTimeout); err != nil { diff --git a/pkg/rpc/ethclient.go b/pkg/rpc/ethclient.go index 5d3fc3ca4..4b6c7b7e3 100644 --- a/pkg/rpc/ethclient.go +++ b/pkg/rpc/ethclient.go @@ -24,6 +24,8 @@ type ethClient struct { // EthClient is a wrapper for go-ethereum eth client with a timeout attached. type EthClient struct { + ChainID *big.Int + *rpc.Client *gethClient *ethClient @@ -42,22 +44,22 @@ func NewEthClient(ctx context.Context, url string, timeout time.Duration) (*EthC return nil, err } + ethClient := ðClient{ethclient.NewClient(client)} + // Get chainID. + chainID, err := ethClient.ChainID(ctx) + if err != nil { + return nil, err + } + return &EthClient{ + ChainID: chainID, Client: client, gethClient: &gethClient{gethclient.New(client)}, - ethClient: ðClient{ethclient.NewClient(client)}, + ethClient: ethClient, timeout: timeoutVal, }, nil } -// ChainID retrieves the current chain ID for transaction replay protection. -func (c *EthClient) ChainID(ctx context.Context) (*big.Int, error) { - ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout) - defer cancel() - - return c.ethClient.ChainID(ctxWithTimeout) -} - // BlockByHash returns the given full block. // // Note that loading full blocks requires two requests. Use HeaderByHash diff --git a/pkg/rpc/methods_test.go b/pkg/rpc/methods_test.go index 5d05811f5..3cd52aaaa 100644 --- a/pkg/rpc/methods_test.go +++ b/pkg/rpc/methods_test.go @@ -122,7 +122,7 @@ func TestGetSyncedL1SnippetFromAnchor(t *testing.T) { testAddrPrivKey, err := crypto.ToECDSA(common.Hex2Bytes(encoding.GoldenTouchPrivKey)) require.Nil(t, err) - opts, err := bind.NewKeyedTransactorWithChainID(testAddrPrivKey, client.L2ChainID) + opts, err := bind.NewKeyedTransactorWithChainID(testAddrPrivKey, client.L2.ChainID) require.Nil(t, err) opts.NoSend = true diff --git a/pkg/rpc/tx_blob_test.go b/pkg/rpc/tx_blob_test.go index 3a6109206..212f08975 100644 --- a/pkg/rpc/tx_blob_test.go +++ b/pkg/rpc/tx_blob_test.go @@ -31,10 +31,7 @@ func TestBlockTx(t *testing.T) { sk, err := crypto.ToECDSA(common.FromHex(priv)) assert.NoError(t, err) - chainID, err := l1Client.ChainID(ctx) - assert.NoError(t, err) - - opts, err := bind.NewKeyedTransactorWithChainID(sk, chainID) + opts, err := bind.NewKeyedTransactorWithChainID(sk, l1Client.ChainID) assert.NoError(t, err) opts.Context = ctx //opts.NoSend = true diff --git a/pkg/rpc/utils_test.go b/pkg/rpc/utils_test.go index 91a16908c..fcd263ada 100644 --- a/pkg/rpc/utils_test.go +++ b/pkg/rpc/utils_test.go @@ -59,7 +59,7 @@ func TestL1ContentFrom(t *testing.T) { baseFee, []byte{}, ) - signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(client.L2ChainID), testAddrPrivKey) + signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(client.L2.ChainID), testAddrPrivKey) require.Nil(t, err) require.Nil(t, client.L2.SendTransaction(context.Background(), signedTx)) diff --git a/proposer/proposer.go b/proposer/proposer.go index c07c1b8d3..a75f5d7a3 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -226,7 +226,7 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { if p.LocalAddressesOnly { var ( localTxsLists []types.Transactions - signer = types.LatestSignerForChainID(p.rpc.L2ChainID) + signer = types.LatestSignerForChainID(p.rpc.L2.ChainID) ) for _, txs := range txLists { var filtered types.Transactions @@ -329,7 +329,7 @@ func (p *Proposer) sendProposeBlockTxWithBlobHash( } // Propose the transactions list - opts, err := getTxOpts(ctx, p.rpc.L1, p.L1ProposerPrivKey, p.rpc.L1ChainID, maxFee) + opts, err := getTxOpts(ctx, p.rpc.L1, p.L1ProposerPrivKey, p.rpc.L1.ChainID, maxFee) if err != nil { return nil, err } @@ -433,7 +433,7 @@ func (p *Proposer) sendProposeBlockTx( } // Propose the transactions list - opts, err := getTxOpts(ctx, p.rpc.L1, p.L1ProposerPrivKey, p.rpc.L1ChainID, maxFee) + opts, err := getTxOpts(ctx, p.rpc.L1, p.L1ProposerPrivKey, p.rpc.L1.ChainID, maxFee) if err != nil { return nil, err } diff --git a/proposer/proposer_test.go b/proposer/proposer_test.go index 3c276fb09..ea7dab46f 100644 --- a/proposer/proposer_test.go +++ b/proposer/proposer_test.go @@ -93,7 +93,7 @@ func (s *ProposerTestSuite) TestProposeOp() { to := common.BytesToAddress(testutils.RandomBytes(32)) tx := types.NewTx(&types.DynamicFeeTx{ - ChainID: s.RPCClient.L2ChainID, + ChainID: s.RPCClient.L2.ChainID, Nonce: nonce, GasTipCap: common.Big0, GasFeeCap: new(big.Int).SetUint64(baseFee.Uint64() * 2), @@ -102,7 +102,7 @@ func (s *ProposerTestSuite) TestProposeOp() { Value: common.Big1, }) - signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(s.p.rpc.L2ChainID), s.TestAddrPrivKey) + signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(s.p.rpc.L2.ChainID), s.TestAddrPrivKey) s.Nil(err) s.Nil(s.p.rpc.L2.SendTransaction(context.Background(), signedTx)) @@ -160,7 +160,7 @@ func (s *ProposerTestSuite) TestSendProposeBlockTx() { context.Background(), s.p.rpc.L1, s.p.L1ProposerPrivKey, - s.RPCClient.L1ChainID, + s.RPCClient.L1.ChainID, fee, ) s.Nil(err) @@ -181,7 +181,7 @@ func (s *ProposerTestSuite) TestSendProposeBlockTx() { s.SetL1Automine(false) defer s.SetL1Automine(true) - signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(s.RPCClient.L1ChainID), s.p.L1ProposerPrivKey) + signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(s.RPCClient.L1.ChainID), s.p.L1ProposerPrivKey) s.Nil(err) s.Nil(s.RPCClient.L1.SendTransaction(context.Background(), signedTx)) diff --git a/prover/anchor_tx_validator/anchor_tx_validator_test.go b/prover/anchor_tx_validator/anchor_tx_validator_test.go index b3f8f0007..2d6f0cfda 100644 --- a/prover/anchor_tx_validator/anchor_tx_validator_test.go +++ b/prover/anchor_tx_validator/anchor_tx_validator_test.go @@ -22,7 +22,7 @@ type AnchorTxValidatorTestSuite struct { func (s *AnchorTxValidatorTestSuite) SetupTest() { s.ClientTestSuite.SetupTest() - validator, err := New(common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), s.RPCClient.L2ChainID, s.RPCClient) + validator, err := New(common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), s.RPCClient.L2.ChainID, s.RPCClient) s.Nil(err) s.v = validator } @@ -44,7 +44,7 @@ func (s *AnchorTxValidatorTestSuite) TestValidateAnchorTx() { // invalid sender dynamicFeeTxTx := &types.DynamicFeeTx{ - ChainID: s.v.rpc.L2ChainID, + ChainID: s.v.rpc.L2.ChainID, Nonce: 0, GasTipCap: common.Big1, GasFeeCap: common.Big1, @@ -55,7 +55,7 @@ func (s *AnchorTxValidatorTestSuite) TestValidateAnchorTx() { AccessList: types.AccessList{}, } - signer := types.LatestSignerForChainID(s.v.rpc.L2ChainID) + signer := types.LatestSignerForChainID(s.v.rpc.L2.ChainID) tx = types.MustSignNewTx(wrongPrivKey, signer, dynamicFeeTxTx) s.ErrorContains( diff --git a/prover/proof_submitter/proof_submitter.go b/prover/proof_submitter/proof_submitter.go index 976f3d91b..d61664e58 100644 --- a/prover/proof_submitter/proof_submitter.go +++ b/prover/proof_submitter/proof_submitter.go @@ -55,7 +55,7 @@ func New( txReplacementTipMultiplier uint64, proveBlockMaxTxGasTipCap *big.Int, ) (*ProofSubmitter, error) { - anchorValidator, err := validator.New(taikoL2Address, rpcClient.L2ChainID, rpcClient) + anchorValidator, err := validator.New(taikoL2Address, rpcClient.L2.ChainID, rpcClient) if err != nil { return nil, err } diff --git a/prover/proof_submitter/transaction/builder.go b/prover/proof_submitter/transaction/builder.go index 1e7904a9c..e62cb2418 100644 --- a/prover/proof_submitter/transaction/builder.go +++ b/prover/proof_submitter/transaction/builder.go @@ -63,7 +63,7 @@ func (a *ProveBlockTxBuilder) Build( a.mutex.Lock() defer a.mutex.Unlock() - txOpts, err := getProveBlocksTxOpts(ctx, a.rpc.L1, a.rpc.L1ChainID, a.proverPrivateKey) + txOpts, err := getProveBlocksTxOpts(ctx, a.rpc.L1, a.rpc.L1.ChainID, a.proverPrivateKey) if err != nil { return nil, err } diff --git a/prover/proof_submitter/transaction/builder_test.go b/prover/proof_submitter/transaction/builder_test.go index 1caec2544..dba504731 100644 --- a/prover/proof_submitter/transaction/builder_test.go +++ b/prover/proof_submitter/transaction/builder_test.go @@ -9,11 +9,11 @@ import ( ) func (s *TransactionTestSuite) TestGetProveBlocksTxOpts() { - optsL1, err := getProveBlocksTxOpts(context.Background(), s.RPCClient.L1, s.RPCClient.L1ChainID, s.TestAddrPrivKey) + optsL1, err := getProveBlocksTxOpts(context.Background(), s.RPCClient.L1, s.RPCClient.L1.ChainID, s.TestAddrPrivKey) s.Nil(err) s.Greater(optsL1.GasTipCap.Uint64(), uint64(0)) - optsL2, err := getProveBlocksTxOpts(context.Background(), s.RPCClient.L2, s.RPCClient.L2ChainID, s.TestAddrPrivKey) + optsL2, err := getProveBlocksTxOpts(context.Background(), s.RPCClient.L2, s.RPCClient.L2.ChainID, s.TestAddrPrivKey) s.Nil(err) s.Greater(optsL2.GasTipCap.Uint64(), uint64(0)) } diff --git a/prover/prover.go b/prover/prover.go index f19cb789d..e5ac87e85 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -344,7 +344,7 @@ func (p *Prover) setApprovalAmount(ctx context.Context, contract common.Address) opts, err := bind.NewKeyedTransactorWithChainID( p.cfg.L1ProverPrivKey, - p.rpc.L1ChainID, + p.rpc.L1.ChainID, ) if err != nil { return err diff --git a/prover/prover_test.go b/prover/prover_test.go index abdce4723..db8e8ccf2 100644 --- a/prover/prover_test.go +++ b/prover/prover_test.go @@ -362,7 +362,7 @@ func (s *ProverTestSuite) TestProveOp() { } func (s *ProverTestSuite) TestSetApprovalAmount() { - opts, err := bind.NewKeyedTransactorWithChainID(s.p.proverPrivateKey, s.p.rpc.L1ChainID) + opts, err := bind.NewKeyedTransactorWithChainID(s.p.proverPrivateKey, s.p.rpc.L1.ChainID) s.Nil(err) tx, err := s.p.rpc.TaikoToken.Approve(opts, s.p.cfg.AssignmentHookAddress, common.Big0)