Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
poopoothegorilla committed Apr 3, 2024
1 parent 8e8aea5 commit 9978e9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
30 changes: 12 additions & 18 deletions common/txmgr/address_state.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package txmgr

import (
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -330,29 +329,24 @@ func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) delete
}

// addTxAttempt adds the given attempt to the transaction which matches its TxID.
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) addTxAttempts(txAttempts ...txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error {
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) addTxAttempt(txAttempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error {
as.Lock()
defer as.Unlock()

var errs error
for i := 0; i < len(txAttempts); i++ {
txAttempt := txAttempts[i]
tx := as.allTxs[txAttempt.TxID]
if tx == nil {
errs = errors.Join(errs, fmt.Errorf("no transaction with ID %d", txAttempt.TxID))
continue
}
tx, ok := as.allTxs[txAttempt.TxID]
if !ok || tx == nil {
return fmt.Errorf("no transaction with ID %d", txAttempt.TxID)
}

// add the attempt to the transaction
if tx.TxAttempts == nil {
tx.TxAttempts = []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]{}
}
tx.TxAttempts = append(tx.TxAttempts, txAttempt)
// add the attempt to the hash lookup map
as.attemptHashToTxAttempt[txAttempt.Hash] = &txAttempt
// add the attempt to the transaction
if tx.TxAttempts == nil {
tx.TxAttempts = []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]{}
}
tx.TxAttempts = append(tx.TxAttempts, txAttempt)
// add the attempt to the hash lookup map
as.attemptHashToTxAttempt[txAttempt.Hash] = &txAttempt

return errs
return nil
}

// peekNextUnstartedTx returns the next unstarted transaction in the queue without removing it from the unstarted queue.
Expand Down
2 changes: 1 addition & 1 deletion common/txmgr/inmemory_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (ms *inMemoryStore[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) SaveR
// delete the old attempt
as.deleteTxAttempt(oldAttempt.TxID, oldAttempt.ID)
// add the new attempt
if err := as.addTxAttempts(*replacementAttempt); err != nil {
if err := as.addTxAttempt(*replacementAttempt); err != nil {
return fmt.Errorf("save_replacement_in_progress_attempt: failed to add a replacement transaction attempt: %w", err)
}

Expand Down

0 comments on commit 9978e9b

Please sign in to comment.