Skip to content
This repository was archived by the owner on May 11, 2024. It is now read-only.

Commit 2644e60

Browse files
authored
feat(sender): add sender.GetOpts method (#613)
1 parent 1b21e4c commit 2644e60

File tree

5 files changed

+46
-28
lines changed

5 files changed

+46
-28
lines changed

internal/sender/common.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ func (s *Sender) adjustGas(txData types.TxData) {
4444
blobFeeCap = utils.Min(blobFeeCap, s.MaxBlobFee)
4545
baseTx.BlobFeeCap = uint256.NewInt(blobFeeCap)
4646
default:
47-
log.Warn("Unsupported transaction type when adjust gas fee", "from", s.Opts.From)
47+
log.Warn("Unsupported transaction type when adjust gas fee", "from", s.opts.From)
4848
}
4949
}
5050

5151
// SetNonce adjusts the nonce of the given transaction with the current nonce of the sender.
5252
func (s *Sender) SetNonce(txData types.TxData, adjust bool) (err error) {
5353
var nonce uint64
5454
if adjust {
55-
s.nonce, err = s.client.NonceAt(s.ctx, s.Opts.From, nil)
55+
s.nonce, err = s.client.NonceAt(s.ctx, s.opts.From, nil)
5656
if err != nil {
57-
log.Warn("Failed to get the nonce", "from", s.Opts.From, "err", err)
57+
log.Warn("Failed to get the nonce", "from", s.opts.From, "err", err)
5858
return err
5959
}
6060
}
@@ -97,8 +97,8 @@ func (s *Sender) updateGasTipGasFee(head *types.Header) error {
9797
gasTipCap = new(big.Int).Set(maxGasFee)
9898
}
9999

100-
s.Opts.GasTipCap = gasTipCap
101-
s.Opts.GasFeeCap = gasFeeCap
100+
s.opts.GasTipCap = gasTipCap
101+
s.opts.GasFeeCap = gasFeeCap
102102

103103
return nil
104104
}
@@ -111,8 +111,8 @@ func (s *Sender) buildTxData(tx *types.Transaction) (types.TxData, error) {
111111
ChainID: s.client.ChainID,
112112
To: tx.To(),
113113
Nonce: tx.Nonce(),
114-
GasFeeCap: s.Opts.GasFeeCap,
115-
GasTipCap: s.Opts.GasTipCap,
114+
GasFeeCap: s.opts.GasFeeCap,
115+
GasTipCap: s.opts.GasTipCap,
116116
Gas: tx.Gas(),
117117
Value: tx.Value(),
118118
Data: tx.Data(),
@@ -127,8 +127,8 @@ func (s *Sender) buildTxData(tx *types.Transaction) (types.TxData, error) {
127127
ChainID: uint256.MustFromBig(s.client.ChainID),
128128
To: to,
129129
Nonce: tx.Nonce(),
130-
GasFeeCap: uint256.MustFromBig(s.Opts.GasFeeCap),
131-
GasTipCap: uint256.MustFromBig(s.Opts.GasTipCap),
130+
GasFeeCap: uint256.MustFromBig(s.opts.GasFeeCap),
131+
GasTipCap: uint256.MustFromBig(s.opts.GasTipCap),
132132
Gas: tx.Gas(),
133133
Value: uint256.MustFromBig(tx.Value()),
134134
Data: tx.Data(),

internal/sender/sender.go

+24-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type Sender struct {
7979
client *rpc.EthClient
8080

8181
nonce uint64
82-
Opts *bind.TransactOpts
82+
opts *bind.TransactOpts
8383

8484
unconfirmedTxs cmap.ConcurrentMap[string, *TxToConfirm]
8585
txToConfirmCh cmap.ConcurrentMap[string, chan *TxToConfirm]
@@ -129,7 +129,7 @@ func NewSender(ctx context.Context, cfg *Config, client *rpc.EthClient, priv *ec
129129
head: head,
130130
client: client,
131131
nonce: nonce,
132-
Opts: opts,
132+
opts: opts,
133133
unconfirmedTxs: cmap.New[*TxToConfirm](),
134134
txToConfirmCh: cmap.New[chan *TxToConfirm](),
135135
stopCh: make(chan struct{}),
@@ -154,6 +154,22 @@ func (s *Sender) Close() {
154154
s.wg.Wait()
155155
}
156156

157+
// GetOpts returns the transaction options of the sender.
158+
func (s *Sender) GetOpts() *bind.TransactOpts {
159+
return &bind.TransactOpts{
160+
From: s.opts.From,
161+
Nonce: s.opts.Nonce,
162+
Signer: s.opts.Signer,
163+
Value: s.opts.Value,
164+
GasPrice: s.opts.GasPrice,
165+
GasFeeCap: s.opts.GasFeeCap,
166+
GasTipCap: s.opts.GasTipCap,
167+
GasLimit: s.opts.GasLimit,
168+
Context: s.opts.Context,
169+
NoSend: s.opts.NoSend,
170+
}
171+
}
172+
157173
// TxToConfirmChannel returns a channel to wait the given transaction's confirmation.
158174
func (s *Sender) TxToConfirmChannel(txID string) <-chan *TxToConfirm {
159175
ch, ok := s.txToConfirmCh.Get(txID)
@@ -191,12 +207,12 @@ func (s *Sender) SendRawTransaction(nonce uint64, target *common.Address, value
191207
if gasLimit == 0 {
192208
var err error
193209
gasLimit, err = s.client.EstimateGas(s.ctx, ethereum.CallMsg{
194-
From: s.Opts.From,
210+
From: s.opts.From,
195211
To: target,
196212
Value: value,
197213
Data: data,
198-
GasTipCap: s.Opts.GasTipCap,
199-
GasFeeCap: s.Opts.GasFeeCap,
214+
GasTipCap: s.opts.GasTipCap,
215+
GasFeeCap: s.opts.GasFeeCap,
200216
})
201217
if err != nil {
202218
return "", err
@@ -210,8 +226,8 @@ func (s *Sender) SendRawTransaction(nonce uint64, target *common.Address, value
210226
ChainID: s.client.ChainID,
211227
To: target,
212228
Nonce: nonce,
213-
GasFeeCap: s.Opts.GasFeeCap,
214-
GasTipCap: s.Opts.GasTipCap,
229+
GasFeeCap: s.opts.GasFeeCap,
230+
GasTipCap: s.opts.GasTipCap,
215231
Gas: gasLimit,
216232
Value: value,
217233
Data: data,
@@ -285,7 +301,7 @@ func (s *Sender) send(tx *TxToConfirm, resetNonce bool) error {
285301

286302
for i := 0; i < nonceIncorrectRetrys; i++ {
287303
// Retry when nonce is incorrect
288-
rawTx, err := s.Opts.Signer(s.Opts.From, types.NewTx(originalTx))
304+
rawTx, err := s.opts.Signer(s.opts.From, types.NewTx(originalTx))
289305
if err != nil {
290306
return err
291307
}

internal/sender/sender_test.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type SenderTestSuite struct {
2525

2626
func (s *SenderTestSuite) TestSendTransaction() {
2727
var (
28-
opts = s.sender.Opts
28+
opts = s.sender.GetOpts()
2929
client = s.RPCClient.L1
3030
eg errgroup.Group
3131
)
@@ -57,7 +57,7 @@ func (s *SenderTestSuite) TestSendTransaction() {
5757
}
5858

5959
func (s *SenderTestSuite) TestSendRawTransaction() {
60-
nonce, err := s.RPCClient.L1.NonceAt(context.Background(), s.sender.Opts.From, nil)
60+
nonce, err := s.RPCClient.L1.NonceAt(context.Background(), s.sender.GetOpts().From, nil)
6161
s.Nil(err)
6262

6363
var eg errgroup.Group
@@ -82,14 +82,15 @@ func (s *SenderTestSuite) TestSendRawTransaction() {
8282
func (s *SenderTestSuite) TestReplacement() {
8383
send := s.sender
8484
client := s.RPCClient.L1
85+
opts := send.GetOpts()
8586

8687
// Let max gas price be 2 times of the gas fee cap.
87-
send.MaxGasFee = send.Opts.GasFeeCap.Uint64() * 2
88+
send.MaxGasFee = opts.GasFeeCap.Uint64() * 2
8889

89-
nonce, err := client.NonceAt(context.Background(), send.Opts.From, nil)
90+
nonce, err := client.NonceAt(context.Background(), opts.From, nil)
9091
s.Nil(err)
9192

92-
pendingNonce, err := client.PendingNonceAt(context.Background(), send.Opts.From)
93+
pendingNonce, err := client.PendingNonceAt(context.Background(), opts.From)
9394
s.Nil(err)
9495
// Run test only if mempool has no pending transactions.
9596
if pendingNonce > nonce {
@@ -107,7 +108,7 @@ func (s *SenderTestSuite) TestReplacement() {
107108
Value: big.NewInt(1),
108109
Data: nil,
109110
}
110-
rawTx, err := send.Opts.Signer(send.Opts.From, types.NewTx(baseTx))
111+
rawTx, err := send.GetOpts().Signer(send.GetOpts().From, types.NewTx(baseTx))
111112
s.Nil(err)
112113
err = client.SendTransaction(context.Background(), rawTx)
113114
s.Nil(err)
@@ -138,10 +139,11 @@ func (s *SenderTestSuite) TestReplacement() {
138139
func (s *SenderTestSuite) TestNonceTooLow() {
139140
client := s.RPCClient.L1
140141
send := s.sender
142+
opts := s.sender.GetOpts()
141143

142-
nonce, err := client.NonceAt(context.Background(), send.Opts.From, nil)
144+
nonce, err := client.NonceAt(context.Background(), opts.From, nil)
143145
s.Nil(err)
144-
pendingNonce, err := client.PendingNonceAt(context.Background(), send.Opts.From)
146+
pendingNonce, err := client.PendingNonceAt(context.Background(), opts.From)
145147
s.Nil(err)
146148
// Run test only if mempool has no pending transactions.
147149
if pendingNonce > nonce {

proposer/proposer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (p *Proposer) makeBlobProposeBlockTx(
339339
return nil, err
340340
}
341341

342-
opts := p.sender.Opts
342+
opts := p.sender.GetOpts()
343343
opts.Value = maxFee
344344
rawTx, err := p.rpc.TaikoL1.ProposeBlock(
345345
opts,
@@ -375,7 +375,7 @@ func (p *Proposer) makeCalldataProposeBlockTx(
375375
return nil, err
376376
}
377377

378-
opts := p.sender.Opts
378+
opts := p.sender.GetOpts()
379379
opts.Value = maxFee
380380

381381
var parentMetaHash = [32]byte{}

proposer/proposer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (s *ProposerTestSuite) TestSendProposeBlockTx() {
159159
s.Nil(sender.SetNonce(nil, true))
160160

161161
fee := big.NewInt(10000)
162-
opts := sender.Opts
162+
opts := sender.GetOpts()
163163
opts.Value = fee
164164
s.Greater(opts.GasTipCap.Uint64(), uint64(0))
165165

0 commit comments

Comments
 (0)