diff --git a/internal/sender/common.go b/internal/sender/common.go index 29cb1af4b..272aa4213 100644 --- a/internal/sender/common.go +++ b/internal/sender/common.go @@ -44,7 +44,7 @@ func (s *Sender) adjustGas(txData types.TxData) { blobFeeCap = utils.Min(blobFeeCap, s.MaxBlobFee) baseTx.BlobFeeCap = uint256.NewInt(blobFeeCap) default: - log.Warn("Unsupported transaction type when adjust gas fee", "from", s.Opts.From) + log.Warn("Unsupported transaction type when adjust gas fee", "from", s.opts.From) } } @@ -52,9 +52,9 @@ func (s *Sender) adjustGas(txData types.TxData) { func (s *Sender) SetNonce(txData types.TxData, adjust bool) (err error) { var nonce uint64 if adjust { - s.nonce, err = s.client.NonceAt(s.ctx, s.Opts.From, nil) + s.nonce, err = s.client.NonceAt(s.ctx, s.opts.From, nil) if err != nil { - log.Warn("Failed to get the nonce", "from", s.Opts.From, "err", err) + log.Warn("Failed to get the nonce", "from", s.opts.From, "err", err) return err } } @@ -97,8 +97,8 @@ func (s *Sender) updateGasTipGasFee(head *types.Header) error { gasTipCap = new(big.Int).Set(maxGasFee) } - s.Opts.GasTipCap = gasTipCap - s.Opts.GasFeeCap = gasFeeCap + s.opts.GasTipCap = gasTipCap + s.opts.GasFeeCap = gasFeeCap return nil } @@ -111,8 +111,8 @@ func (s *Sender) buildTxData(tx *types.Transaction) (types.TxData, error) { ChainID: s.client.ChainID, To: tx.To(), Nonce: tx.Nonce(), - GasFeeCap: s.Opts.GasFeeCap, - GasTipCap: s.Opts.GasTipCap, + GasFeeCap: s.opts.GasFeeCap, + GasTipCap: s.opts.GasTipCap, Gas: tx.Gas(), Value: tx.Value(), Data: tx.Data(), @@ -127,8 +127,8 @@ func (s *Sender) buildTxData(tx *types.Transaction) (types.TxData, error) { ChainID: uint256.MustFromBig(s.client.ChainID), To: to, Nonce: tx.Nonce(), - GasFeeCap: uint256.MustFromBig(s.Opts.GasFeeCap), - GasTipCap: uint256.MustFromBig(s.Opts.GasTipCap), + GasFeeCap: uint256.MustFromBig(s.opts.GasFeeCap), + GasTipCap: uint256.MustFromBig(s.opts.GasTipCap), Gas: tx.Gas(), Value: uint256.MustFromBig(tx.Value()), Data: tx.Data(), diff --git a/internal/sender/sender.go b/internal/sender/sender.go index dd46d7793..b90b88639 100644 --- a/internal/sender/sender.go +++ b/internal/sender/sender.go @@ -79,7 +79,7 @@ type Sender struct { client *rpc.EthClient nonce uint64 - Opts *bind.TransactOpts + opts *bind.TransactOpts unconfirmedTxs cmap.ConcurrentMap[string, *TxToConfirm] txToConfirmCh cmap.ConcurrentMap[string, chan *TxToConfirm] @@ -129,7 +129,7 @@ func NewSender(ctx context.Context, cfg *Config, client *rpc.EthClient, priv *ec head: head, client: client, nonce: nonce, - Opts: opts, + opts: opts, unconfirmedTxs: cmap.New[*TxToConfirm](), txToConfirmCh: cmap.New[chan *TxToConfirm](), stopCh: make(chan struct{}), @@ -154,6 +154,22 @@ func (s *Sender) Close() { s.wg.Wait() } +// GetOpts returns the transaction options of the sender. +func (s *Sender) GetOpts() *bind.TransactOpts { + return &bind.TransactOpts{ + From: s.opts.From, + Nonce: s.opts.Nonce, + Signer: s.opts.Signer, + Value: s.opts.Value, + GasPrice: s.opts.GasPrice, + GasFeeCap: s.opts.GasFeeCap, + GasTipCap: s.opts.GasTipCap, + GasLimit: s.opts.GasLimit, + Context: s.opts.Context, + NoSend: s.opts.NoSend, + } +} + // TxToConfirmChannel returns a channel to wait the given transaction's confirmation. func (s *Sender) TxToConfirmChannel(txID string) <-chan *TxToConfirm { ch, ok := s.txToConfirmCh.Get(txID) @@ -191,12 +207,12 @@ func (s *Sender) SendRawTransaction(nonce uint64, target *common.Address, value if gasLimit == 0 { var err error gasLimit, err = s.client.EstimateGas(s.ctx, ethereum.CallMsg{ - From: s.Opts.From, + From: s.opts.From, To: target, Value: value, Data: data, - GasTipCap: s.Opts.GasTipCap, - GasFeeCap: s.Opts.GasFeeCap, + GasTipCap: s.opts.GasTipCap, + GasFeeCap: s.opts.GasFeeCap, }) if err != nil { return "", err @@ -210,8 +226,8 @@ func (s *Sender) SendRawTransaction(nonce uint64, target *common.Address, value ChainID: s.client.ChainID, To: target, Nonce: nonce, - GasFeeCap: s.Opts.GasFeeCap, - GasTipCap: s.Opts.GasTipCap, + GasFeeCap: s.opts.GasFeeCap, + GasTipCap: s.opts.GasTipCap, Gas: gasLimit, Value: value, Data: data, @@ -285,7 +301,7 @@ func (s *Sender) send(tx *TxToConfirm, resetNonce bool) error { for i := 0; i < nonceIncorrectRetrys; i++ { // Retry when nonce is incorrect - rawTx, err := s.Opts.Signer(s.Opts.From, types.NewTx(originalTx)) + rawTx, err := s.opts.Signer(s.opts.From, types.NewTx(originalTx)) if err != nil { return err } diff --git a/internal/sender/sender_test.go b/internal/sender/sender_test.go index 325ae43d7..0cf15879b 100644 --- a/internal/sender/sender_test.go +++ b/internal/sender/sender_test.go @@ -25,7 +25,7 @@ type SenderTestSuite struct { func (s *SenderTestSuite) TestSendTransaction() { var ( - opts = s.sender.Opts + opts = s.sender.GetOpts() client = s.RPCClient.L1 eg errgroup.Group ) @@ -57,7 +57,7 @@ func (s *SenderTestSuite) TestSendTransaction() { } func (s *SenderTestSuite) TestSendRawTransaction() { - nonce, err := s.RPCClient.L1.NonceAt(context.Background(), s.sender.Opts.From, nil) + nonce, err := s.RPCClient.L1.NonceAt(context.Background(), s.sender.GetOpts().From, nil) s.Nil(err) var eg errgroup.Group @@ -82,14 +82,15 @@ func (s *SenderTestSuite) TestSendRawTransaction() { func (s *SenderTestSuite) TestReplacement() { send := s.sender client := s.RPCClient.L1 + opts := send.GetOpts() // Let max gas price be 2 times of the gas fee cap. - send.MaxGasFee = send.Opts.GasFeeCap.Uint64() * 2 + send.MaxGasFee = opts.GasFeeCap.Uint64() * 2 - nonce, err := client.NonceAt(context.Background(), send.Opts.From, nil) + nonce, err := client.NonceAt(context.Background(), opts.From, nil) s.Nil(err) - pendingNonce, err := client.PendingNonceAt(context.Background(), send.Opts.From) + pendingNonce, err := client.PendingNonceAt(context.Background(), opts.From) s.Nil(err) // Run test only if mempool has no pending transactions. if pendingNonce > nonce { @@ -107,7 +108,7 @@ func (s *SenderTestSuite) TestReplacement() { Value: big.NewInt(1), Data: nil, } - rawTx, err := send.Opts.Signer(send.Opts.From, types.NewTx(baseTx)) + rawTx, err := send.GetOpts().Signer(send.GetOpts().From, types.NewTx(baseTx)) s.Nil(err) err = client.SendTransaction(context.Background(), rawTx) s.Nil(err) @@ -138,10 +139,11 @@ func (s *SenderTestSuite) TestReplacement() { func (s *SenderTestSuite) TestNonceTooLow() { client := s.RPCClient.L1 send := s.sender + opts := s.sender.GetOpts() - nonce, err := client.NonceAt(context.Background(), send.Opts.From, nil) + nonce, err := client.NonceAt(context.Background(), opts.From, nil) s.Nil(err) - pendingNonce, err := client.PendingNonceAt(context.Background(), send.Opts.From) + pendingNonce, err := client.PendingNonceAt(context.Background(), opts.From) s.Nil(err) // Run test only if mempool has no pending transactions. if pendingNonce > nonce { diff --git a/proposer/proposer.go b/proposer/proposer.go index 16b2e6bf0..d3902d05e 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -339,7 +339,7 @@ func (p *Proposer) makeBlobProposeBlockTx( return nil, err } - opts := p.sender.Opts + opts := p.sender.GetOpts() opts.Value = maxFee rawTx, err := p.rpc.TaikoL1.ProposeBlock( opts, @@ -375,7 +375,7 @@ func (p *Proposer) makeCalldataProposeBlockTx( return nil, err } - opts := p.sender.Opts + opts := p.sender.GetOpts() opts.Value = maxFee var parentMetaHash = [32]byte{} diff --git a/proposer/proposer_test.go b/proposer/proposer_test.go index fe5a691d9..96c74ee56 100644 --- a/proposer/proposer_test.go +++ b/proposer/proposer_test.go @@ -159,7 +159,7 @@ func (s *ProposerTestSuite) TestSendProposeBlockTx() { s.Nil(sender.SetNonce(nil, true)) fee := big.NewInt(10000) - opts := sender.Opts + opts := sender.GetOpts() opts.Value = fee s.Greater(opts.GasTipCap.Uint64(), uint64(0))