From 659b2fb51844b92f878c22fd55c09a9a86df6963 Mon Sep 17 00:00:00 2001 From: James Walker Date: Fri, 23 Feb 2024 16:46:08 -0500 Subject: [PATCH] implement MoveInProgressToConfirmedMissingReceipt --- 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 74c77ad86fe..b4aba85a34a 100644 --- a/common/txmgr/address_state.go +++ b/common/txmgr/address_state.go @@ -299,7 +299,28 @@ func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveUn } // MoveInProgressToConfirmedMissingReceipt moves the in-progress transaction to the confirmed missing receipt state. -func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveInProgressToConfirmedMissingReceipt(attempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], broadcastAt time.Time) error { +// If there is no in-progress transaction, an error is returned. +func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveInProgressToConfirmedMissingReceipt(txAttempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], broadcastAt time.Time) error { + as.Lock() + defer as.Unlock() + + tx := as.inprogressTx + if tx == nil { + return fmt.Errorf("move_in_progress_to_confirmed_missing_receipt: no transaction in progress") + } + 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 + as.inprogressTx = nil + return nil }