diff --git a/common/txmgr/address_state.go b/common/txmgr/address_state.go index 7a5e8fc665e..21f54627c3a 100644 --- a/common/txmgr/address_state.go +++ b/common/txmgr/address_state.go @@ -666,6 +666,32 @@ func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveIn return nil } +func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveConfirmedToUnconfirmed(attempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error { + as.Lock() + defer as.Unlock() + + if attempt.State != txmgrtypes.TxAttemptBroadcast { + return fmt.Errorf("move_confirmed_to_unconfirmed: attempt must be in broadcast state") + } + + tx, ok := as.confirmed[attempt.TxID] + if !ok || tx == nil { + return fmt.Errorf("move_confirmed_to_unconfirmed: no confirmed transaction with ID %d: %w", attempt.TxID, ErrTxnNotFound) + } + tx.State = TxUnconfirmed + + // Delete the receipt from the attempt + attempt.Receipts = nil + // Reset the broadcast information for the attempt + attempt.State = txmgrtypes.TxAttemptInProgress + attempt.BroadcastBeforeBlockNum = nil + tx.TxAttempts = []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]{attempt} + + as.unconfirmed[tx.ID] = tx + delete(as.confirmed, tx.ID) + + return nil +} func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) abandon() { as.Lock() diff --git a/common/txmgr/inmemory_store.go b/common/txmgr/inmemory_store.go index 76851bb6b9d..2be4cad47bf 100644 --- a/common/txmgr/inmemory_store.go +++ b/common/txmgr/inmemory_store.go @@ -1379,11 +1379,9 @@ func (ms *InMemoryStore[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Updat } // Update in memory store - - // TODO - // delete receipts - // update tx unconfirmed - // update tx_attempt unbroadcast + if err := as.MoveConfirmedToUnconfirmed(etxAttempt); err != nil { + return err + } return nil }