Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TXM In-memory: address_state methods: step 3-04 #12178

Closed
wants to merge 77 commits into from
Closed
Changes from 14 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
2af9ffa
implement MoveInProgressToFatalError
poopoothegorilla Feb 23, 2024
1aa98d3
implement MoveConfirmedMissingReceiptToFatalError
poopoothegorilla Feb 23, 2024
3c301dd
implement MoveUnconfirmedToConfirmedMissingReceipt
poopoothegorilla Feb 23, 2024
659b2fb
implement MoveInProgressToConfirmedMissingReceipt
poopoothegorilla Feb 23, 2024
debfdc9
implement MoveConfirmedToUnconfirmed
poopoothegorilla Feb 23, 2024
c3611e3
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-04
poopoothegorilla Feb 27, 2024
e8ae7f4
implement MoveUnstartedToFatalError
poopoothegorilla Feb 27, 2024
66be6d3
implement UpdateTxFatalError
poopoothegorilla Feb 27, 2024
5153d24
implement SaveConfirmedMissingReceiptAttempts
poopoothegorilla Feb 27, 2024
f91d5ab
implement apply find and delete for address state
poopoothegorilla Feb 27, 2024
42c82ac
implement MarkOldTxesMissingReceiptAsErrored
poopoothegorilla Feb 27, 2024
ef987f4
implement ReapTxHistory
poopoothegorilla Feb 27, 2024
a65204a
implement DeleteInProgressAttempt
poopoothegorilla Feb 27, 2024
b971ee6
implement SaveReplacementInProgressAttempt
poopoothegorilla Feb 27, 2024
b43bdd3
refactor MoveXXXToFatal to MoveTxToFatal
poopoothegorilla Feb 29, 2024
07a2760
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-04
poopoothegorilla Feb 29, 2024
f139fe6
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-04
poopoothegorilla Mar 7, 2024
fbd76d6
address comments
poopoothegorilla Mar 7, 2024
8d3960f
address comments
poopoothegorilla Mar 7, 2024
18b8eb3
address new comments
poopoothegorilla Mar 7, 2024
5d473d8
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-04
poopoothegorilla Mar 13, 2024
433177a
Merge branch 'jtw/step-3-04' into jtw/step-3-04-save-replacement-in-p…
poopoothegorilla Mar 13, 2024
afe6280
initial implementation of SaveReplacementInProgressAttempt
poopoothegorilla Mar 13, 2024
0833ddd
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-04
poopoothegorilla Mar 13, 2024
0583a9f
Merge branch 'jtw/step-3-04' into jtw/step-3-04-save-replacement-in-p…
poopoothegorilla Mar 13, 2024
5af2106
update tests for SaveReplacementInProgressAttempt
poopoothegorilla Mar 13, 2024
09e2eac
Merge branch 'jtw/step-3-04' into jtw/step-3-04-delete-in-progress-at…
poopoothegorilla Mar 13, 2024
82521c3
implement tests for DeleteInProgressAttempt
poopoothegorilla Mar 13, 2024
8f4d145
Merge branch 'jtw/step-3-04' into jtw/step-3-04-reap-tx-history
poopoothegorilla Mar 13, 2024
1cae6ff
Merge branch 'jtw/step-3-04' into jtw/step-3-04-mark-old-txs-missing-…
poopoothegorilla Mar 16, 2024
f74f45a
implement tests for MarkOldTxesMissingReceiptAsErrored
poopoothegorilla Mar 18, 2024
051ebe2
add panic
poopoothegorilla Mar 21, 2024
cbacd55
fix linter issue
poopoothegorilla Mar 21, 2024
4e12e66
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-04
poopoothegorilla Mar 21, 2024
da6d235
address comments
poopoothegorilla Mar 21, 2024
0cc19ea
Merge branch 'jtw/step-3-04' into jtw/step-3-04-mark-old-txs-missing-…
poopoothegorilla Mar 21, 2024
39566e9
address comments
poopoothegorilla Mar 21, 2024
b8d09d8
Merge branch 'jtw/step-3-04' into jtw/step-3-04-delete-in-progress-at…
poopoothegorilla Mar 21, 2024
53e0657
address comments
poopoothegorilla Mar 21, 2024
0693806
TXM In-memory: step 3-04-UpdateTxForRebroadcast (#12231)
poopoothegorilla Mar 22, 2024
337f2e1
Merge branch 'jtw/step-3-04' into jtw/step-3-04-mark-old-txs-missing-…
poopoothegorilla Mar 22, 2024
2c485aa
Merge branch 'jtw/step-3-04' into jtw/step-3-04-delete-in-progress-at…
poopoothegorilla Mar 22, 2024
90f1726
Merge branch 'jtw/step-3-04' into jtw/step-3-04-reap-tx-history
poopoothegorilla Mar 22, 2024
9d59e02
TXM In-memory: step 3-04-MarkAllConfirmedMissingReceipt (#12232)
poopoothegorilla Mar 22, 2024
d22d62c
implement tests for ReapTxHistory
poopoothegorilla Mar 22, 2024
6a0b5ad
panic if wrong chain ID
poopoothegorilla Mar 22, 2024
ae2d267
Merge branch 'jtw/step-3-04' into jtw/step-3-04-mark-old-txs-missing-…
poopoothegorilla Mar 22, 2024
991a5f1
Merge pull request #12233 from smartcontractkit/jtw/step-3-04-mark-ol…
poopoothegorilla Mar 22, 2024
52faeec
Merge branch 'jtw/step-3-04' into jtw/step-3-04-delete-in-progress-at…
poopoothegorilla Mar 22, 2024
3381426
remove merge artifacts
poopoothegorilla Mar 22, 2024
0f1c005
fix in memory address stuff
poopoothegorilla Mar 22, 2024
9ea64b8
Merge branch 'jtw/step-3-04' into jtw/step-3-04-reap-tx-history
poopoothegorilla Mar 22, 2024
26d432a
fix merge conflict
poopoothegorilla Mar 22, 2024
f9bd7e6
implement tests for UpdateTxFatalError
poopoothegorilla Mar 25, 2024
056eaf5
Merge branch 'jtw/step-3-04' into jtw/step-3-04-save-confirmed-missin…
poopoothegorilla Mar 25, 2024
b634183
implement tests for SaveConfirmedMissingReceiptAttempt
poopoothegorilla Mar 26, 2024
f2c2e0b
update
poopoothegorilla Mar 26, 2024
6deab0d
Update common/txmgr/address_state.go
poopoothegorilla Apr 1, 2024
d4684a2
Merge pull request #12234 from smartcontractkit/jtw/step-3-04-reap-tx…
poopoothegorilla Apr 1, 2024
8b7af52
Merge branch 'jtw/step-3-04' into jtw/step-3-04-save-replacement-in-p…
poopoothegorilla Apr 1, 2024
b03e6fb
Merge branch 'jtw/step-3-04' into jtw/step-3-04-update-tx-fatal-error
poopoothegorilla Apr 1, 2024
661f877
Merge branch 'jtw/step-3-04' into jtw/step-3-04-save-confirmed-missin…
poopoothegorilla Apr 3, 2024
516c11a
Merge branch 'jtw/step-3-04' into jtw/step-3-04-delete-in-progress-at…
poopoothegorilla Apr 3, 2024
8ae9d72
address coments
poopoothegorilla Apr 3, 2024
3a93992
cleanup
poopoothegorilla Apr 3, 2024
d2e3152
Merge pull request #12235 from smartcontractkit/jtw/step-3-04-delete-…
poopoothegorilla Apr 3, 2024
8e8aea5
Merge branch 'jtw/step-3-04' into jtw/step-3-04-save-replacement-in-p…
poopoothegorilla Apr 3, 2024
9978e9b
address comments
poopoothegorilla Apr 3, 2024
a186281
Merge branch 'jtw/step-3-04' into jtw/step-3-04-save-confirmed-missin…
poopoothegorilla Apr 3, 2024
7de69a4
clean up
poopoothegorilla Apr 3, 2024
6d7923d
Merge branch 'jtw/step-3-04' into jtw/step-3-04-update-tx-fatal-error
poopoothegorilla Apr 3, 2024
493ffed
Merge pull request #12236 from smartcontractkit/jtw/step-3-04-save-re…
poopoothegorilla Apr 4, 2024
4a48dc4
check if transaction exists
poopoothegorilla Apr 4, 2024
33b085b
Merge branch 'jtw/step-3-04' into jtw/step-3-04-update-tx-fatal-error
poopoothegorilla Apr 4, 2024
09e6d61
Merge pull request #12226 from smartcontractkit/jtw/step-3-04-update-…
poopoothegorilla Apr 4, 2024
17fe719
Merge branch 'jtw/step-3-04' into jtw/step-3-04-save-confirmed-missin…
poopoothegorilla Apr 4, 2024
d0f6376
Merge pull request #12230 from smartcontractkit/jtw/step-3-04-save-co…
poopoothegorilla Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 237 additions & 4 deletions common/txmgr/address_state.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package txmgr

import (
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -124,12 +125,12 @@
}

// countTransactionsByState returns the number of transactions that are in the given state
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) countTransactionsByState(txState txmgrtypes.TxState) int {

Check failure on line 128 in common/txmgr/address_state.go

View workflow job for this annotation

GitHub Actions / lint

func (*addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]).countTransactionsByState is unused (unused)
return 0
}

// findTxWithIdempotencyKey returns the transaction with the given idempotency key. If no transaction is found, nil is returned.
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) findTxWithIdempotencyKey(key string) *txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE] {

Check failure on line 133 in common/txmgr/address_state.go

View workflow job for this annotation

GitHub Actions / lint

func (*addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]).findTxWithIdempotencyKey is unused (unused)
return nil
}

Expand All @@ -137,11 +138,40 @@
// If txIDs are provided, only the transactions with those IDs are considered.
// If no txIDs are provided, all transactions in the given states are considered.
// If no txStates are provided, all transactions are considered.
// This method does not handle transactions in the UnstartedTx state.
// Any transaction states that are unknown will cause a panic including UnstartedTx.
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) applyToTxsByState(

Check failure on line 143 in common/txmgr/address_state.go

View workflow job for this annotation

GitHub Actions / lint

func (*addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]).applyToTxsByState is unused (unused)
txStates []txmgrtypes.TxState,
fn func(*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]),
txIDs ...int64,
) {
as.Lock()
defer as.Unlock()

// if txStates is empty then apply the filter to only the as.allTransactions map
if len(txStates) == 0 {
as._applyToTxs(as.allTxs, fn, txIDs...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you are applying this func to allTxs, but in above comment on the function, you said that if applied to UnstartedTx, then this will panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeh i think we may want to think about this in the future, but I will the capability

return
}

for _, txState := range txStates {
switch txState {
case TxInProgress:
if as.inprogressTx != nil {
fn(as.inprogressTx)
}
case TxUnconfirmed:
as._applyToTxs(as.unconfirmedTxs, fn, txIDs...)
case TxConfirmedMissingReceipt:
as._applyToTxs(as.confirmedMissingReceiptTxs, fn, txIDs...)
case TxConfirmed:
as._applyToTxs(as.confirmedTxs, fn, txIDs...)
case TxFatalError:
as._applyToTxs(as.fatalErroredTxs, fn, txIDs...)
default:
panic("apply_to_txs_by_state: unknown transaction state")
}
}
}

// findTxAttempts returns all attempts for the given transactions that match the given filters.
Expand All @@ -149,7 +179,7 @@
// If no txIDs are provided, all transactions are considered.
// If no txStates are provided, all transactions are considered.
// The txFilter is applied to the transactions and the txAttemptFilter is applied to the attempts.
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) findTxAttempts(

Check failure on line 182 in common/txmgr/address_state.go

View workflow job for this annotation

GitHub Actions / lint

func (*addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]).findTxAttempts is unused (unused)
txStates []txmgrtypes.TxState,
txFilter func(*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) bool,
txAttemptFilter func(*txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) bool,
Expand All @@ -167,24 +197,56 @@
filter func(*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) bool,
txIDs ...int64,
) []txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE] {
return nil
as.RLock()
defer as.RUnlock()

// if txStates is empty then apply the filter to only the as.allTransactions map
if len(txStates) == 0 {
return as._findTxs(as.allTxs, filter, txIDs...)
poopoothegorilla marked this conversation as resolved.
Show resolved Hide resolved
}

var txs []txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]
for _, txState := range txStates {
switch txState {
case TxInProgress:
if as.inprogressTx != nil && filter(as.inprogressTx) {
txs = append(txs, *as.inprogressTx)
}
case TxUnconfirmed:
txs = append(txs, as._findTxs(as.unconfirmedTxs, filter, txIDs...)...)
case TxConfirmedMissingReceipt:
txs = append(txs, as._findTxs(as.confirmedMissingReceiptTxs, filter, txIDs...)...)
case TxConfirmed:
txs = append(txs, as._findTxs(as.confirmedTxs, filter, txIDs...)...)
case TxFatalError:
txs = append(txs, as._findTxs(as.fatalErroredTxs, filter, txIDs...)...)
default:
panic("find_txs: unknown transaction state")
}
}

return txs
}

// pruneUnstartedTxQueue removes the transactions with the given IDs from the unstarted transaction queue.
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) pruneUnstartedTxQueue(ids []int64) {

Check failure on line 232 in common/txmgr/address_state.go

View workflow job for this annotation

GitHub Actions / lint

func (*addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]).pruneUnstartedTxQueue is unused (unused)
}

// deleteTxs removes the transactions with the given IDs from the address state.
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) deleteTxs(txs ...txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) {

Check failure on line 236 in common/txmgr/address_state.go

View workflow job for this annotation

GitHub Actions / lint

func (*addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]).deleteTxs is unused (unused)
as.Lock()
defer as.Unlock()

as._deleteTxs(txs...)
}

// peekNextUnstartedTx returns the next unstarted transaction in the queue without removing it from the unstarted queue.
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) peekNextUnstartedTx() (*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], error) {

Check failure on line 244 in common/txmgr/address_state.go

View workflow job for this annotation

GitHub Actions / lint

func (*addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]).peekNextUnstartedTx is unused (unused)
return nil, nil
}

// peekInProgressTx returns the in-progress transaction without removing it from the in-progress state.
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) peekInProgressTx() (*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], error) {

Check failure on line 249 in common/txmgr/address_state.go

View workflow job for this annotation

GitHub Actions / lint

func (*addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]).peekInProgressTx is unused (unused)
return nil, nil
}

Expand Down Expand Up @@ -224,23 +286,194 @@
}

// moveTxToFatalError moves a transaction to the fatal error state.
// It returns an error if there is no transaction with the given ID.
// It returns an error if the transaction is not in an expected state.
// Unknown transaction states will cause a panic this includes Unconfirmed and Confirmed transactions.
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) moveTxToFatalError(
txID int64, txError null.String,
) error {
as.Lock()
defer as.Unlock()

tx := as.allTxs[txID]
if tx == nil {
return fmt.Errorf("move_tx_to_fatal_error: no transaction with ID %d", txID)
}

as._moveTxToFatalError(tx, txError)

switch tx.State {
case TxUnstarted:
_ = as.unstartedTxs.RemoveTxByID(txID)
case TxInProgress:
as.inprogressTx = nil
case TxConfirmedMissingReceipt:
delete(as.confirmedMissingReceiptTxs, tx.ID)
default:
panic("move_tx_to_fatal_error: unknown transaction state")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could you include the state we panic on in the message for easier debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call out

}

return nil
}

// 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My paranoia is getting the better of me here. Should we be wary of accepting the entire txAttempt here and updating our state with this object? If someone inadvertently makes a change to the txAttempt before calling this function, we'd store those changes without validation. It might be safer just accepting the hash and looking it up in our internal map and making the changes on that object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I noticed we append the attempt to the tx's attempt list. Wouldn't the attempt already exist in the list if it's an Unconfirmed tx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point cleaned up a bit

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 len(tx.TxAttempts) == 0 {
return fmt.Errorf("move_unconfirmed_to_confirmed_missing_receipt: no attempts for transaction with ID %d", txAttempt.TxID)
}
if tx.BroadcastAt.Before(broadcastAt) {
tx.BroadcastAt = &broadcastAt
}
tx.State = TxConfirmedMissingReceipt
txAttempt.State = txmgrtypes.TxAttemptBroadcast
tx.TxAttempts = append(tx.TxAttempts, txAttempt)

as.confirmedMissingReceiptTxs[tx.ID] = tx
delete(as.unconfirmedTxs, tx.ID)

return nil
}

// 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 len(tx.TxAttempts) == 0 {
return fmt.Errorf("move_in_progress_to_confirmed_missing_receipt: no attempts for transaction with ID %d", tx.ID)
}
if tx.BroadcastAt.Before(broadcastAt) {
tx.BroadcastAt = &broadcastAt
}
tx.State = TxConfirmedMissingReceipt
txAttempt.State = txmgrtypes.TxAttemptBroadcast
tx.TxAttempts = append(tx.TxAttempts, txAttempt)

as.confirmedMissingReceiptTxs[tx.ID] = tx
as.inprogressTx = nil

return nil
}

// moveConfirmedToUnconfirmed moves the confirmed transaction to the unconfirmed state.
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 {
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) moveConfirmedToUnconfirmed(txAttempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error {
as.Lock()
defer as.Unlock()

if txAttempt.State != txmgrtypes.TxAttemptBroadcast {
return fmt.Errorf("move_confirmed_to_unconfirmed: attempt must be in broadcast state")
}

tx, ok := as.confirmedTxs[txAttempt.TxID]
if !ok || tx == nil {
return fmt.Errorf("move_confirmed_to_unconfirmed: no confirmed transaction with ID %d", txAttempt.TxID)
}
if len(tx.TxAttempts) == 0 {
return fmt.Errorf("move_confirmed_to_unconfirmed: no attempts for transaction with ID %d", txAttempt.TxID)
}
tx.State = TxUnconfirmed

// Delete the receipt from the attempt
txAttempt.Receipts = nil
// Reset the broadcast information for the attempt
txAttempt.State = txmgrtypes.TxAttemptInProgress
txAttempt.BroadcastBeforeBlockNum = nil
tx.TxAttempts = append(tx.TxAttempts, txAttempt)

as.unconfirmedTxs[tx.ID] = tx
delete(as.confirmedTxs, tx.ID)

return nil
}

func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) _applyToTxs(

Check failure on line 402 in common/txmgr/address_state.go

View workflow job for this annotation

GitHub Actions / lint

func (*addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE])._applyToTxs is unused (unused)
txIDsToTx map[int64]*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE],
fn func(*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]),
txIDs ...int64,
) {
// if txIDs is not empty then only apply the filter to those transactions
if len(txIDs) > 0 {
for _, txID := range txIDs {
tx := txIDsToTx[txID]
if tx != nil {
fn(tx)
}
}
return
}

// if txIDs is empty then apply the filter to all transactions
for _, tx := range txIDsToTx {
fn(tx)
}
}

func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) _findTxs(
txIDsToTx map[int64]*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE],
filter func(*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) bool,
txIDs ...int64,
) []txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE] {
var txs []txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]
// if txIDs is not empty then only apply the filter to those transactions
if len(txIDs) > 0 {
for _, txID := range txIDs {
tx := txIDsToTx[txID]
if tx != nil && filter(tx) {
txs = append(txs, *tx)
}
}
return txs
}

// if txIDs is empty then apply the filter to all transactions
for _, tx := range txIDsToTx {
if filter(tx) {
txs = append(txs, *tx)
}
}

return txs
}

func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) _deleteTxs(txs ...txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) {

Check failure on line 451 in common/txmgr/address_state.go

View workflow job for this annotation

GitHub Actions / lint

func (*addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE])._deleteTxs is unused (unused)
for _, tx := range txs {
if tx.IdempotencyKey != nil {
delete(as.idempotencyKeyToTx, *tx.IdempotencyKey)
}
txID := tx.ID
if as.inprogressTx != nil && as.inprogressTx.ID == txID {
as.inprogressTx = nil
}
delete(as.allTxs, txID)
delete(as.unconfirmedTxs, txID)
delete(as.confirmedMissingReceiptTxs, txID)
delete(as.confirmedTxs, txID)
delete(as.fatalErroredTxs, txID)
as.unstartedTxs.RemoveTxByID(txID)
}
}

func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) _moveTxToFatalError(
tx *txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE],
txError null.String,
) {
tx.State = TxFatalError
tx.Sequence = nil
tx.TxAttempts = nil
tx.InitialBroadcastAt = nil
tx.Error = txError
as.fatalErroredTxs[tx.ID] = tx
}
Loading