Skip to content

Commit

Permalink
implement updateTxForRebroadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
poopoothegorilla committed Jan 4, 2024
1 parent 52e0c2a commit a47f98a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
26 changes: 26 additions & 0 deletions common/txmgr/address_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 3 additions & 5 deletions common/txmgr/inmemory_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit a47f98a

Please sign in to comment.