Skip to content

Commit

Permalink
address more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
poopoothegorilla committed Jan 9, 2024
1 parent 204d5ff commit 2535e27
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
9 changes: 0 additions & 9 deletions common/txmgr/address_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion common/txmgr/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions common/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package txmgr

import (
"context"
"database/sql"
"errors"
"fmt"
"math/big"
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions core/chains/evm/txmgr/evm_tx_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions core/chains/evm/txmgr/evm_tx_store_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package txmgr_test

import (
"database/sql"
"fmt"
"math/big"
"testing"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2535e27

Please sign in to comment.