From 3c301dd3656d8e862061969b493b8824ed343e54 Mon Sep 17 00:00:00 2001 From: James Walker Date: Fri, 23 Feb 2024 16:44:01 -0500 Subject: [PATCH] implement MoveUnconfirmedToConfirmedMissingReceipt --- common/txmgr/address_state.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/common/txmgr/address_state.go b/common/txmgr/address_state.go index 99b6b9d9f79..74c77ad86fe 100644 --- a/common/txmgr/address_state.go +++ b/common/txmgr/address_state.go @@ -273,7 +273,28 @@ func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveCo } // MoveUnconfirmedToConfirmedMissingReceipt moves the unconfirmed transaction to the confirmed missing receipt state. -func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveUnconfirmedToConfirmedMissingReceipt(attempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], broadcastAt time.Time) error { +// If there is no unconfirmed transaction with the given ID, an error is returned. +func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveUnconfirmedToConfirmedMissingReceipt(txAttempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], broadcastAt time.Time) error { + as.Lock() + defer as.Unlock() + + tx, ok := as.unconfirmedTxs[txAttempt.TxID] + if !ok || tx == nil { + return fmt.Errorf("move_unconfirmed_to_confirmed_missing_receipt: no unconfirmed transaction with ID %d", txAttempt.TxID) + } + if tx.BroadcastAt.Before(broadcastAt) { + tx.BroadcastAt = &broadcastAt + } + tx.State = TxConfirmedMissingReceipt + if len(tx.TxAttempts) == 0 { + tx.TxAttempts = []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]{} + } + txAttempt.State = txmgrtypes.TxAttemptBroadcast + tx.TxAttempts = append(tx.TxAttempts, txAttempt) + + as.confirmedMissingReceiptTxs[tx.ID] = tx + delete(as.unconfirmedTxs, tx.ID) + return nil }