Skip to content

Commit cd7c7fd

Browse files
committed
cleanup
1 parent 2e154e0 commit cd7c7fd

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

rpc/backend/call_tx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ func (b *Backend) SendRawTransaction(data hexutil.Bytes) (common.Hash, error) {
148148
syncCtx := b.ClientCtx.WithBroadcastMode(flags.BroadcastSync)
149149
rsp, err := syncCtx.BroadcastTx(txBytes)
150150
if rsp != nil && rsp.Code != 0 {
151-
if HandleBroadcastRawLog(rsp.RawLog, txHash) {
152-
b.Logger.Debug("transaction temporarily rejected or queued", "hash", txHash.Hex())
151+
if shouldSkip, msg := HandleBroadcastRawLog(rsp.RawLog, txHash); shouldSkip {
152+
b.Logger.Debug(msg, "hash", txHash.Hex())
153153
return txHash, nil
154154
}
155155
err = errorsmod.ABCIError(rsp.Codespace, rsp.Code, rsp.RawLog)

rpc/backend/sign_tx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ func (b *Backend) SendTransaction(args evmtypes.TransactionArgs) (common.Hash, e
104104
syncCtx := b.ClientCtx.WithBroadcastMode(flags.BroadcastSync)
105105
rsp, err := syncCtx.BroadcastTx(txBytes)
106106
if rsp != nil && rsp.Code != 0 {
107-
if HandleBroadcastRawLog(rsp.RawLog, txHash) {
108-
b.Logger.Debug("transaction temporarily rejected or queued", "hash", txHash.Hex())
107+
if shouldSkip, msg := HandleBroadcastRawLog(rsp.RawLog, txHash); shouldSkip {
108+
b.Logger.Debug(msg, "hash", txHash.Hex())
109109
return txHash, nil
110110
}
111111
err = errorsmod.ABCIError(rsp.Codespace, rsp.Code, rsp.RawLog)

rpc/backend/utils.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,18 @@ func GetHexProofs(proof *crypto.ProofOps) []string {
298298
// HandleBroadcastRawLog checks the RawLog for known temporary rejection or nonce gap error.
299299
// NOTE: make sure it sync with the latest go-ethereum logic when upgrade:
300300
// https://github.com/ethereum/go-ethereum/blob/master/core/txpool/locals/errors.go#L29
301-
func HandleBroadcastRawLog(rawLog string, txHash common.Hash) bool {
301+
func HandleBroadcastRawLog(rawLog string, txHash common.Hash) (bool, string) {
302+
if strings.Contains(rawLog, mempool.ErrNonceGap.Error()) {
303+
return true, "transaction queued due to nonce gap"
304+
}
302305
switch rawLog {
303306
case legacypool.ErrOutOfOrderTxFromDelegated.Error(),
304307
txpool.ErrInflightTxLimitReached.Error(),
305308
legacypool.ErrAuthorityReserved.Error(),
306309
txpool.ErrUnderpriced.Error(),
307310
legacypool.ErrTxPoolOverflow.Error(),
308311
legacypool.ErrFutureReplacePending.Error():
309-
return true
310-
case mempool.ErrNonceGap.Error():
311-
return true
312+
return true, "transaction temporarily rejected or queued"
312313
}
313-
return false
314+
return false, ""
314315
}

rpc/backend/utils_test.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,27 @@ import (
1313

1414
func TestHandleBroadcastRawLog(t *testing.T) {
1515
txHash := common.HexToHash("0x123")
16-
cases := []string{
17-
legacypool.ErrOutOfOrderTxFromDelegated.Error(),
18-
txpool.ErrInflightTxLimitReached.Error(),
19-
legacypool.ErrAuthorityReserved.Error(),
20-
txpool.ErrUnderpriced.Error(),
21-
legacypool.ErrTxPoolOverflow.Error(),
22-
legacypool.ErrFutureReplacePending.Error(),
23-
mempool.ErrNonceGap.Error(),
16+
tmpErrMsg := "transaction temporarily rejected or queued"
17+
cases := []struct {
18+
rawLog string
19+
wantMsg string
20+
}{
21+
{legacypool.ErrOutOfOrderTxFromDelegated.Error(), tmpErrMsg},
22+
{txpool.ErrInflightTxLimitReached.Error(), tmpErrMsg},
23+
{legacypool.ErrAuthorityReserved.Error(), tmpErrMsg},
24+
{txpool.ErrUnderpriced.Error(), tmpErrMsg},
25+
{legacypool.ErrTxPoolOverflow.Error(), tmpErrMsg},
26+
{legacypool.ErrFutureReplacePending.Error(), tmpErrMsg},
27+
{mempool.ErrNonceGap.Error(), "transaction queued due to nonce gap"},
2428
}
25-
for _, rawLog := range cases {
26-
require.True(t, HandleBroadcastRawLog(rawLog, txHash), "expected true for: %s", rawLog)
29+
30+
for _, tc := range cases {
31+
ok, msg := HandleBroadcastRawLog(tc.rawLog, txHash)
32+
require.True(t, ok, "expected true for: %s", tc.rawLog)
33+
require.Equal(t, tc.wantMsg, msg, "unexpected message for: %s", tc.rawLog)
2734
}
28-
require.False(t, HandleBroadcastRawLog("some other error", txHash))
35+
36+
ok, msg := HandleBroadcastRawLog("some other error", txHash)
37+
require.False(t, ok)
38+
require.Equal(t, "", msg)
2939
}

0 commit comments

Comments
 (0)