diff --git a/common/txmgr/address_state.go b/common/txmgr/address_state.go index f61628af889..e75b9b0622a 100644 --- a/common/txmgr/address_state.go +++ b/common/txmgr/address_state.go @@ -756,15 +756,6 @@ func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) abando for _, tx := range as.unconfirmed { as.abandonTx(tx) } - for _, tx := range as.idempotencyKeyToTx { - as.abandonTx(tx) - } - for _, tx := range as.confirmedMissingReceipt { - as.abandonTx(tx) - } - for _, tx := range as.confirmed { - as.abandonTx(tx) - } clear(as.unconfirmed) } diff --git a/common/txmgr/broadcaster.go b/common/txmgr/broadcaster.go index 4a2cec75179..1a23c4aaa24 100644 --- a/common/txmgr/broadcaster.go +++ b/common/txmgr/broadcaster.go @@ -698,7 +698,7 @@ func (eb *Broadcaster[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) next defer cancel() etx := &txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]{} if err := eb.txStore.FindNextUnstartedTransactionFromAddress(ctx, etx, fromAddress, eb.chainID); err != nil { - if errors.Is(err, sql.ErrNoRows) || errors.Is(err, ErrTxnNotFound) { + if errors.Is(err, ErrTxnNotFound) { // Finish. No more transactions left to process. Hoorah! return nil, nil } diff --git a/common/txmgr/txmgr.go b/common/txmgr/txmgr.go index ca12e5ffaae..19ffd7942fd 100644 --- a/common/txmgr/txmgr.go +++ b/common/txmgr/txmgr.go @@ -2,7 +2,6 @@ package txmgr import ( "context" - "database/sql" "errors" "fmt" "math/big" @@ -477,7 +476,7 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) CreateTran if txRequest.IdempotencyKey != nil { var existingTx *txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE] existingTx, err = b.txStore.FindTxWithIdempotencyKey(ctx, *txRequest.IdempotencyKey, b.chainID) - if err != nil && !errors.Is(err, sql.ErrNoRows) && !errors.Is(err, ErrTxnNotFound) { + if err != nil && !errors.Is(err, ErrTxnNotFound) { return tx, fmt.Errorf("Failed to search for transaction with IdempotencyKey: %w", err) } if existingTx != nil { diff --git a/core/chains/evm/txmgr/evm_tx_store.go b/core/chains/evm/txmgr/evm_tx_store.go index 152834f3a5b..b3c2f925868 100644 --- a/core/chains/evm/txmgr/evm_tx_store.go +++ b/core/chains/evm/txmgr/evm_tx_store.go @@ -476,7 +476,7 @@ func (o *evmTxStore) UnstartedTransactions(offset, limit int, fromAddress common return } - sql = `SELECT * FROM evm.txes WHERE state = 'unstarted' AND from_address = $1 AND evm_chain_id = $2 ORDER BY value ASC, created_at ASC, id ASC LIMIT $3 OFFSET $4` + sql = `SELECT * FROM evm.txes WHERE state = 'unstarted' AND from_address = $1 AND evm_chain_id = $2 ORDER BY id desc LIMIT $3 OFFSET $4` var dbTxs []DbEthTx if err = o.q.Select(&dbTxs, sql, fromAddress, chainID.String(), limit, offset); err != nil { return @@ -1653,8 +1653,14 @@ func (o *evmTxStore) FindNextUnstartedTransactionFromAddress(ctx context.Context qq := o.q.WithOpts(pg.WithParentCtx(ctx)) var dbEtx DbEthTx err := qq.Get(&dbEtx, `SELECT * FROM evm.txes WHERE from_address = $1 AND state = 'unstarted' AND evm_chain_id = $2 ORDER BY value ASC, created_at ASC, id ASC`, fromAddress, chainID.String()) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return txmgr.ErrTxnNotFound + } + return pkgerrors.Wrap(err, "failed to FindNextUnstartedTransactionFromAddress") + } dbEtx.ToTx(etx) - return pkgerrors.Wrap(err, "failed to FindNextUnstartedTransactionFromAddress") + return nil } func (o *evmTxStore) UpdateTxFatalError(ctx context.Context, etx *Tx) error { diff --git a/core/chains/evm/txmgr/evm_tx_store_test.go b/core/chains/evm/txmgr/evm_tx_store_test.go index 0b4287b6f6c..54f9512a763 100644 --- a/core/chains/evm/txmgr/evm_tx_store_test.go +++ b/core/chains/evm/txmgr/evm_tx_store_test.go @@ -1,7 +1,6 @@ package txmgr_test import ( - "database/sql" "fmt" "math/big" "testing" @@ -1264,7 +1263,7 @@ func TestORM_FindNextUnstartedTransactionFromAddress(t *testing.T) { resultEtx := new(txmgr.Tx) err := txStore.FindNextUnstartedTransactionFromAddress(testutils.Context(t), resultEtx, fromAddress, ethClient.ConfiguredChainID()) - assert.ErrorIs(t, err, sql.ErrNoRows) + assert.ErrorIs(t, err, txmgrcommon.ErrTxnNotFound) }) t.Run("finds unstarted tx", func(t *testing.T) {