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-01 #12177

Closed
wants to merge 127 commits into from
Closed
Changes from 19 commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
f4912ad
add count transactions by state
poopoothegorilla Feb 23, 2024
cc453d9
add FindTxWithIdempotencyKey
poopoothegorilla Feb 23, 2024
a98bfea
implement ApplyToTxsByState
poopoothegorilla Feb 23, 2024
6fbebff
implement FetchTxAttempts
poopoothegorilla Feb 23, 2024
0e87297
implement FetchTxs
poopoothegorilla Feb 23, 2024
2a33a73
cleanup
poopoothegorilla Feb 23, 2024
0d2b0ba
Merge branch 'jtw/step-2-in-memory-work' into jtw/step-2-01
poopoothegorilla Feb 23, 2024
21d01c0
Merge branch 'jtw/step-2-in-memory-work' into jtw/step-2-01
poopoothegorilla Feb 23, 2024
ac445d7
fix naming
poopoothegorilla Feb 23, 2024
1fdb6d6
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-01
poopoothegorilla Feb 27, 2024
0864c99
implement SetBroadcastBeforeBlockNum
poopoothegorilla Feb 27, 2024
03f218f
implement UpdateBroadcastAts
poopoothegorilla Feb 27, 2024
c4baf9c
implement UpdateTxCallbackCompleted
poopoothegorilla Feb 27, 2024
83ab7f5
implement SaveInProgressAttempt
poopoothegorilla Feb 27, 2024
83a78c7
implement SaveInsufficientFundsAttempt
poopoothegorilla Feb 27, 2024
24e1869
implement SaveSentAttempt
poopoothegorilla Feb 27, 2024
0f1c0ee
implement close for address state
poopoothegorilla Feb 27, 2024
46af61e
implement abandon
poopoothegorilla Feb 27, 2024
6a1477b
implement Abandon
poopoothegorilla Feb 27, 2024
9cfa388
implement Close
poopoothegorilla Feb 27, 2024
7f614e4
implement read only in memory store methods
poopoothegorilla Feb 29, 2024
07d399b
return -1 for unknown states
poopoothegorilla Mar 4, 2024
965b4ce
Merge branch 'jtw/step-3-01' into jtw/step-3-01-non-persistent
poopoothegorilla Mar 4, 2024
bd2a5c6
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-01
poopoothegorilla Mar 4, 2024
745710c
Merge branch 'jtw/step-3-01' into jtw/step-3-01-non-persistent
poopoothegorilla Mar 4, 2024
c37666b
add tests for FindTxWithIdempotencyKey
poopoothegorilla Mar 4, 2024
4acd096
add test for CheckTxQueueCapacity
poopoothegorilla Mar 5, 2024
0ef6869
implement tests for CountUnstartedTransactions and CountUnconfirmedTr…
poopoothegorilla Mar 5, 2024
1bd8ac4
implment tests for FindTxAttemptsConfirmedMissingReceipt
poopoothegorilla Mar 6, 2024
04e5930
add comment
poopoothegorilla Mar 6, 2024
559a542
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-01
poopoothegorilla Mar 7, 2024
10195bf
address comments
poopoothegorilla Mar 7, 2024
d9b19c1
change convention
poopoothegorilla Mar 7, 2024
80b5117
unexport more methods
poopoothegorilla Mar 7, 2024
0343a0b
make sure unsafe methods have _
poopoothegorilla Mar 7, 2024
d75bbd8
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-01
poopoothegorilla Mar 8, 2024
a2321b1
Merge branch 'jtw/step-3-01' into jtw/step-3-01-non-persistent
poopoothegorilla Mar 8, 2024
7a35db5
clean FindTxWithIdempotencyKey
poopoothegorilla Mar 8, 2024
c2a1949
some test cleanup
poopoothegorilla Mar 8, 2024
9ca93e0
remove unused pkgs
poopoothegorilla Mar 11, 2024
950a9b1
add filtering for unstarted Txs
poopoothegorilla Mar 11, 2024
2a57985
Merge branch 'jtw/step-3-01' into jtw/step-3-01-save-in-progress-attempt
poopoothegorilla Mar 11, 2024
6f4ee88
add tests for SaveInProgressAttempt
poopoothegorilla Mar 12, 2024
daefc8c
Merge branch 'jtw/step-3-01' into jtw/step-3-01-save-sent-attempt
poopoothegorilla Mar 12, 2024
9e7298a
add tests for SaveSentAttempt
poopoothegorilla Mar 12, 2024
eab47f2
Merge branch 'jtw/step-3-01' into jtw/step-3-01-close-abandon
poopoothegorilla Mar 12, 2024
a864b27
add tests for abandon
poopoothegorilla Mar 12, 2024
ae3c38d
Merge branch 'jtw/step-3-01' into jtw/step-3-01-save-insufficient-fun…
poopoothegorilla Mar 12, 2024
075b1f7
add tests for SaveInsufficientFundsAttempt
poopoothegorilla Mar 12, 2024
d43646f
Merge branch 'jtw/step-3-01' into jtw/step-3-01-set-update-broadcast-ats
poopoothegorilla Mar 12, 2024
de560a0
add tests for UpdateBroadcastAts
poopoothegorilla Mar 12, 2024
c447c8b
Merge branch 'jtw/step-3-01' into jtw/step-3-01-update-tx-callback-co…
poopoothegorilla Mar 12, 2024
918f2df
implement tests for updateTxCallbackCompleted
poopoothegorilla Mar 12, 2024
2c858b6
Merge branch 'jtw/step-3-01' into jtw/step-3-01-set-broadcast-before-…
poopoothegorilla Mar 12, 2024
45e2b0d
implement tests for SetBroadcastBeforeBlockNum
poopoothegorilla Mar 12, 2024
5a24821
Merge branch 'jtw/step-3-01' into jtw/step-3-01-non-persistent
poopoothegorilla Mar 19, 2024
dff17a1
implement tests for FindTxAttemptsRequiringReceiptFetch
poopoothegorilla Mar 19, 2024
ed9ad22
implement tests for GetInProgressTxAttempts
poopoothegorilla Mar 19, 2024
dca5e1f
implement tests for HasInProgressTransaction
poopoothegorilla Mar 19, 2024
1df21a2
implement tests for GetTxByID
poopoothegorilla Mar 19, 2024
e3438b4
implement tests for FindTxWithSequence
poopoothegorilla Mar 19, 2024
f017ea1
implement tests for CountTransactionsByState
poopoothegorilla Mar 19, 2024
81b6359
implement tests for FindTxsRequiringResubmissionDueToInsufficientFunds
poopoothegorilla Mar 20, 2024
158972f
implement tests for GetNonFatalTransactions
poopoothegorilla Mar 20, 2024
431776b
add test for wrong chain id and clean up
poopoothegorilla Mar 20, 2024
676917b
implement FindTransactionsConfirmedInBlockRange
poopoothegorilla Mar 20, 2024
164f48d
implement tests for FindEarliestUnconfirmedBroadcastTime
poopoothegorilla Mar 20, 2024
fe601b2
implements tests for FindEarliestUnconfirmedTxAttemptBlock
poopoothegorilla Mar 20, 2024
2011e06
implement tests for LoadTxAttempts
poopoothegorilla Mar 20, 2024
c28a5e7
implement tests for PreloadTxes
poopoothegorilla Mar 20, 2024
bf5299f
implement tests for IsTxFinalized
poopoothegorilla Mar 20, 2024
47c1e9a
implement tests for FindTxsRequiringGasBump
poopoothegorilla Mar 21, 2024
79997c3
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-01
poopoothegorilla Mar 21, 2024
d6051a9
Merge branch 'jtw/step-3-01' into jtw/step-3-01-close-abandon
poopoothegorilla Mar 21, 2024
94b9c6b
address comments
poopoothegorilla Mar 21, 2024
23dbf19
cleanup
poopoothegorilla Mar 21, 2024
1639f6c
Merge branch 'jtw/step-3-01' into jtw/step-3-01-set-broadcast-before-…
poopoothegorilla Mar 21, 2024
354e10f
address comments
poopoothegorilla Mar 21, 2024
ca36124
Merge branch 'jtw/step-3-01' into jtw/step-3-01-set-update-broadcast-ats
poopoothegorilla Mar 21, 2024
83ca9e9
address comments
poopoothegorilla Mar 21, 2024
2bb1a09
Merge branch 'jtw/step-3-01' into jtw/step-3-01-update-tx-callback-co…
poopoothegorilla Mar 21, 2024
311e1aa
address comments
poopoothegorilla Mar 21, 2024
943eb98
Merge branch 'jtw/step-3-01' into jtw/step-3-01-save-in-progress-attempt
poopoothegorilla Mar 21, 2024
69d0a9c
address comments
poopoothegorilla Mar 21, 2024
8656668
Merge branch 'jtw/step-3-01' into jtw/step-3-01-save-insufficient-fun…
poopoothegorilla Mar 21, 2024
7b4e81a
address comments
poopoothegorilla Mar 21, 2024
9352c8e
Merge branch 'jtw/step-3-01' into jtw/step-3-01-save-sent-attempt
poopoothegorilla Mar 21, 2024
e30f622
address comments
poopoothegorilla Mar 21, 2024
5ea7b15
address comments
poopoothegorilla Mar 22, 2024
66e60da
clean up contexts to use testutils
poopoothegorilla Mar 22, 2024
29834c9
implement tests for FindTxesByMetaFieldAndStates
poopoothegorilla Mar 22, 2024
46cf23e
implement tests for FindTxesWithMetaFieldByStates
poopoothegorilla Mar 23, 2024
e8804c9
implement test for FindTxesWithMetaFieldByReceiptBlockNum
poopoothegorilla Mar 24, 2024
cdb374a
implement tests for FindTxAttemptsRequiringResend
poopoothegorilla Mar 25, 2024
eca0d81
Merge branch 'jtw/step-3-01' into jtw/step-3-01-non-persistent
poopoothegorilla Mar 25, 2024
89b8f22
add comment about figuring out sorting issues
poopoothegorilla Mar 25, 2024
6609492
clean up merge issues
poopoothegorilla Mar 25, 2024
163fb0e
implement tests for FindTxesPendingCallback
poopoothegorilla Mar 25, 2024
1430b7d
remove initials from NOTE
poopoothegorilla Mar 25, 2024
ad2ae5d
fix loop iteration
poopoothegorilla Mar 26, 2024
6920a21
Add enabledAddresses
DylanTinianov Mar 28, 2024
7bbe2bd
Merge pull request #12218 from smartcontractkit/jtw/step-3-01-close-a…
poopoothegorilla Mar 29, 2024
513f2fc
Merge branch 'jtw/step-3-01' into jtw/step-3-01-save-sent-attempt
poopoothegorilla Mar 29, 2024
6c0c773
Merge pull request #12224 from smartcontractkit/jtw/step-3-01-save-se…
poopoothegorilla Mar 29, 2024
44fd73a
Merge branch 'jtw/step-3-01' into jtw/step-3-01-save-insufficient-fun…
poopoothegorilla Mar 29, 2024
a1997ad
fix merge issues
poopoothegorilla Mar 29, 2024
7caa015
Merge pull request #12223 from smartcontractkit/jtw/step-3-01-save-in…
poopoothegorilla Mar 29, 2024
3157c89
Merge branch 'jtw/step-3-01' into jtw/step-3-01-update-tx-callback-co…
poopoothegorilla Mar 29, 2024
0829216
Merge pull request #12221 from smartcontractkit/jtw/step-3-01-update-…
poopoothegorilla Mar 29, 2024
7a8247d
Merge branch 'jtw/step-3-01' into jtw/step-3-01-set-update-broadcast-ats
poopoothegorilla Apr 1, 2024
900a197
fix errors
poopoothegorilla Apr 1, 2024
fdb59e6
address comments
poopoothegorilla Apr 1, 2024
bc0b266
Merge branch 'jtw/step-3-01' into jtw/step-3-01-save-in-progress-attempt
poopoothegorilla Apr 1, 2024
6a38c80
Merge branch 'jtw/step-3-01' into jtw/step-3-01-set-broadcast-before-…
poopoothegorilla Apr 1, 2024
3c4554d
Merge pull request #12219 from smartcontractkit/jtw/step-3-01-set-bro…
poopoothegorilla Apr 1, 2024
6941fd0
Merge branch 'jtw/step-3-01' into jtw/step-3-01-set-update-broadcast-ats
poopoothegorilla Apr 1, 2024
f95a448
Merge pull request #12220 from smartcontractkit/jtw/step-3-01-set-upd…
poopoothegorilla Apr 1, 2024
2faf9c2
Merge branch 'jtw/step-3-01' into jtw/step-3-01-save-in-progress-attempt
poopoothegorilla Apr 4, 2024
e287b53
Merge pull request #12222 from smartcontractkit/jtw/step-3-01-save-in…
poopoothegorilla Apr 4, 2024
6080271
Merge branch 'jtw/step-3-01' into jtw/step-3-01-non-persistent
poopoothegorilla Apr 4, 2024
85ff0e1
remove wrong chain id test cases
poopoothegorilla Apr 4, 2024
759b962
remove setting Tx in txAttempts
poopoothegorilla Apr 4, 2024
431fdf3
bypass all functions that cant replicate sorting
poopoothegorilla Apr 4, 2024
41949b9
update TODO comments
poopoothegorilla Apr 19, 2024
e17ae31
apply refactor
poopoothegorilla Apr 19, 2024
483637c
Merge pull request #12215 from smartcontractkit/jtw/step-3-01-non-per…
poopoothegorilla May 1, 2024
b2e7606
Generated mocks and fixed lint errors
amit-momin Jun 27, 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
271 changes: 265 additions & 6 deletions common/txmgr/address_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,77 @@
return &as
}

// countTransactionsByState returns the number of transactions that are in the given state
// 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 127 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
as.RLock()
defer as.RUnlock()

switch txState {
case TxUnstarted:
return as.unstartedTxs.Len()
case TxInProgress:
if as.inprogressTx != nil {
return 1
}
return 0
case TxUnconfirmed:
return len(as.unconfirmedTxs)
case TxConfirmedMissingReceipt:
return len(as.confirmedMissingReceiptTxs)
case TxConfirmed:
return len(as.confirmedTxs)
case TxFatalError:
return len(as.fatalErroredTxs)
default:
panic("countTransactionByState: unknown transaction state")
}
}

// findTxWithIdempotencyKey returns the transaction with the given idempotency key. If no transaction is found, nil is returned.
// 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 154 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
as.RLock()
defer as.RUnlock()

return as.idempotencyKeyToTx[key]
}

// applyToTxsByState calls the given function for each transaction in the given states.
// 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.
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) applyToTxsByState(

Check failure on line 165 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...)
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("applyToTxsByState: unknown transaction state")
}
}
}

// findTxAttempts returns all attempts for the given transactions that match the given filters.
Expand All @@ -149,13 +201,46 @@
// 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 204 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,
txIDs ...int64,
) []txmgrtypes.TxAttempt[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._findTxAttempts(as.allTxs, txFilter, txAttemptFilter, txIDs...)
}

var txAttempts []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]
for _, txState := range txStates {
switch txState {
case TxInProgress:
if as.inprogressTx != nil && txFilter(as.inprogressTx) {
for i := 0; i < len(as.inprogressTx.TxAttempts); i++ {
txAttempt := as.inprogressTx.TxAttempts[i]
if txAttemptFilter(&txAttempt) {
txAttempts = append(txAttempts, txAttempt)
}
}
}
case TxUnconfirmed:
txAttempts = append(txAttempts, as._findTxAttempts(as.unconfirmedTxs, txFilter, txAttemptFilter, txIDs...)...)
case TxConfirmedMissingReceipt:
txAttempts = append(txAttempts, as._findTxAttempts(as.confirmedMissingReceiptTxs, txFilter, txAttemptFilter, txIDs...)...)
case TxConfirmed:
txAttempts = append(txAttempts, as._findTxAttempts(as.confirmedTxs, txFilter, txAttemptFilter, txIDs...)...)
case TxFatalError:
txAttempts = append(txAttempts, as._findTxAttempts(as.fatalErroredTxs, txFilter, txAttemptFilter, txIDs...)...)
default:
panic("findTxAttempts: unknown transaction state")
}
}

return txAttempts
}

// findTxs returns all transactions that match the given filters.
Expand All @@ -167,24 +252,52 @@
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...)
}

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("findTxs: 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 287 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 291 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)
}

// 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 295 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 300 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 @@ -244,3 +357,149 @@
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 {
return nil
}

// close releases all resources held by the address state.
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) close() {
clear(as.idempotencyKeyToTx)

as.unstartedTxs.Close()
as.unstartedTxs = nil
as.inprogressTx = nil

clear(as.unconfirmedTxs)
clear(as.confirmedMissingReceiptTxs)
clear(as.confirmedTxs)
clear(as.allTxs)
clear(as.fatalErroredTxs)

as.idempotencyKeyToTx = nil
as.unconfirmedTxs = nil
as.confirmedMissingReceiptTxs = nil
as.confirmedTxs = nil
as.allTxs = nil
as.fatalErroredTxs = nil
}

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

for as.unstartedTxs.Len() > 0 {
tx := as.unstartedTxs.RemoveNextTx()
as._abandonTx(tx)
}

if as.inprogressTx != nil {
tx := as.inprogressTx
as._abandonTx(tx)
as.inprogressTx = nil
}
for _, tx := range as.unconfirmedTxs {
as._abandonTx(tx)
}

clear(as.unconfirmedTxs)
}

// This method is not concurrent safe and should only be called from within a lock
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) _abandonTx(tx *txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) {
if tx == nil {
return
}

tx.State = TxFatalError
tx.Sequence = nil
tx.Error = null.NewString("abandoned", true)

as.fatalErroredTxs[tx.ID] = tx
}

// This method is not concurrent safe and should only be called from within a lock
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) _applyToTxs(

Check failure on line 418 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)
}
}

// This method is not concurrent safe and should only be called from within a lock
func (as *addressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) _findTxAttempts(

Check failure on line 441 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)
txIDsToTx map[int64]*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE],
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,
txIDs ...int64,
) []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE] {
var txAttempts []txmgrtypes.TxAttempt[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 && txFilter(tx) {
for i := 0; i < len(tx.TxAttempts); i++ {
txAttempt := tx.TxAttempts[i]
if txAttemptFilter(&txAttempt) {
txAttempts = append(txAttempts, txAttempt)
}
}
}
}
return txAttempts
}

// if txIDs is empty then apply the filter to all transactions
for _, tx := range txIDsToTx {
if txFilter(tx) {
for i := 0; i < len(tx.TxAttempts); i++ {
txAttempt := tx.TxAttempts[i]
if txAttemptFilter(&txAttempt) {
txAttempts = append(txAttempts, txAttempt)
}
}
}
}

return txAttempts
}

// This method is not concurrent safe and should only be called from within a lock
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
}
Loading