From 66be6d3cb610afdf9d143cfde3161ec37a639582 Mon Sep 17 00:00:00 2001 From: James Walker Date: Mon, 26 Feb 2024 21:25:00 -0500 Subject: [PATCH 1/2] implement UpdateTxFatalError --- common/txmgr/inmemory_store.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/common/txmgr/inmemory_store.go b/common/txmgr/inmemory_store.go index cd783a25210..b82d6ff0be0 100644 --- a/common/txmgr/inmemory_store.go +++ b/common/txmgr/inmemory_store.go @@ -178,6 +178,37 @@ func (ms *InMemoryStore[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) SaveR // UpdateTxFatalError updates a transaction to fatal_error. func (ms *InMemoryStore[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) UpdateTxFatalError(ctx context.Context, tx *txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error { + if tx.State != TxInProgress && tx.State != TxUnstarted { + return fmt.Errorf("update_tx_fatal_error: can only transition to fatal_error from in_progress, transaction is currently %s", tx.State) + } + if !tx.Error.Valid { + return fmt.Errorf("update_tx_fatal_error: expected error field to be set") + } + + ms.addressStatesLock.RLock() + defer ms.addressStatesLock.RUnlock() + as, ok := ms.addressStates[tx.FromAddress] + if !ok { + return fmt.Errorf("update_tx_fatal_error: %w", ErrAddressNotFound) + } + + // Persist to persistent storage + if err := ms.txStore.UpdateTxFatalError(ctx, tx); err != nil { + return fmt.Errorf("update_tx_fatal_error: %w", err) + } + + // Update in memory store + switch tx.State { + case TxInProgress: + if err := as.MoveInProgressToFatalError(tx.Error); err != nil { + return fmt.Errorf("update_tx_fatal_error: %w", err) + } + case TxUnstarted: + if err := as.MoveUnstartedToFatalError(tx.ID, tx.Error); err != nil { + return fmt.Errorf("update_tx_fatal_error: %w", err) + } + } + return nil } From 4a48dc42e5bd3169c842440b1cd717ff09089c93 Mon Sep 17 00:00:00 2001 From: James Walker Date: Thu, 4 Apr 2024 09:17:28 -0400 Subject: [PATCH 2/2] check if transaction exists --- common/txmgr/inmemory_store.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/txmgr/inmemory_store.go b/common/txmgr/inmemory_store.go index 38c41c8fd08..f66e32f83cc 100644 --- a/common/txmgr/inmemory_store.go +++ b/common/txmgr/inmemory_store.go @@ -208,6 +208,9 @@ func (ms *inMemoryStore[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Updat if !ok { return fmt.Errorf("update_tx_fatal_error: %w", ErrAddressNotFound) } + if !as.hasTx(tx.ID) { + return fmt.Errorf("update_tx_fatal_error: %w: %q", ErrTxnNotFound, tx.ID) + } // Persist to persistent storage if err := ms.persistentTxStore.UpdateTxFatalError(ctx, tx); err != nil {