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

Commit 8461019

Browse files
committed
fix bug
1 parent 4d13ff7 commit 8461019

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

internal/sender/sender.go

+24-27
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ func (s *Sender) SendTransaction(tx *types.Transaction) (string, error) {
169169
return "", fmt.Errorf("too many pending transactions")
170170
}
171171

172-
// Update the gas tip and gas fee.
173-
if err := s.updateGasTipGasFee(s.header); err != nil {
174-
return "", err
175-
}
176-
177172
txData, err := s.makeTxData(tx)
178173
if err != nil {
179174
return "", err
@@ -202,31 +197,33 @@ func (s *Sender) sendTx(confirmTx *TxConfirm) error {
202197

203198
baseTx := confirmTx.baseTx
204199

205-
// Try 3 RetryTimes if nonce is not correct.
206-
rawTx, err := s.Opts.Signer(s.Opts.From, types.NewTx(baseTx))
207-
if err != nil {
208-
return err
209-
}
210-
confirmTx.Tx = rawTx
211-
err = s.client.SendTransaction(s.ctx, rawTx)
212-
confirmTx.Err = err
213-
// Check if the error is nonce too low.
214-
if err != nil {
215-
if strings.Contains(err.Error(), "nonce too low") {
216-
s.AdjustNonce(baseTx)
217-
log.Warn("nonce is not correct, retry to send transaction", "tx_hash", rawTx.Hash().String(), "err", err)
218-
return nil
200+
for i := 0; i < 3; i++ {
201+
// Try 3 RetryTimes if nonce is not correct.
202+
rawTx, err := s.Opts.Signer(s.Opts.From, types.NewTx(baseTx))
203+
if err != nil {
204+
return err
219205
}
220-
if err.Error() == "replacement transaction underpriced" {
221-
s.adjustGas(baseTx)
222-
log.Warn("replacement transaction underpriced", "tx_hash", rawTx.Hash().String(), "err", err)
223-
return nil
206+
confirmTx.Tx = rawTx
207+
err = s.client.SendTransaction(s.ctx, rawTx)
208+
confirmTx.Err = err
209+
// Check if the error is nonce too low.
210+
if err != nil {
211+
if strings.Contains(err.Error(), "nonce too low") {
212+
s.AdjustNonce(baseTx)
213+
log.Warn("nonce is not correct, retry to send transaction", "tx_hash", rawTx.Hash().String(), "err", err)
214+
continue
215+
}
216+
if err.Error() == "replacement transaction underpriced" {
217+
s.adjustGas(baseTx)
218+
log.Warn("replacement transaction underpriced", "tx_hash", rawTx.Hash().String(), "err", err)
219+
continue
220+
}
221+
log.Error("failed to send transaction", "tx_hash", rawTx.Hash().String(), "err", err)
222+
return err
224223
}
225-
log.Error("failed to send transaction", "tx_hash", rawTx.Hash().String(), "err", err)
226-
return err
224+
s.Opts.Nonce = big.NewInt(s.Opts.Nonce.Int64() + 1)
225+
break
227226
}
228-
s.Opts.Nonce = big.NewInt(s.Opts.Nonce.Int64() + 1)
229-
230227
return nil
231228
}
232229

proposer/proposer_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func (s *ProposerTestSuite) TestSendProposeBlockTx() {
172172

173173
var txID string
174174
txID, err = s.p.Sender.SendRaw(nonce, &common.Address{}, common.Big1, nil)
175+
s.Nil(err)
175176
tx := s.p.Sender.GetUnconfirmedTx(txID)
176177

177178
pendingNonce, err := s.RPCClient.L1.PendingNonceAt(context.Background(), s.p.proposerAddress)

0 commit comments

Comments
 (0)