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-02 #12176

Closed
wants to merge 45 commits into from
Closed
Changes from 9 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
dced7b7
implement PruneUnstartedTxQueue
poopoothegorilla Feb 23, 2024
d537a89
implement DeleteTxs
poopoothegorilla Feb 23, 2024
74d6b1e
implement PeekNextUnstartedTx
poopoothegorilla Feb 23, 2024
d187dad
implement PeekInProgressTx
poopoothegorilla Feb 23, 2024
fd32104
implement AddTxToUnstartedQueue
poopoothegorilla Feb 23, 2024
24444c3
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-2-02
poopoothegorilla Feb 26, 2024
eb4d436
add CreateTransaction initial logic
poopoothegorilla Feb 26, 2024
01c79c7
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-02
poopoothegorilla Feb 26, 2024
71b509a
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-02
poopoothegorilla Feb 26, 2024
7095808
Merge branch 'jtw/step-3-02' into jtw/step-3-02-create-transaction
poopoothegorilla Feb 26, 2024
154d514
cleanup
poopoothegorilla Feb 26, 2024
362dbe1
add tests for create transaction
poopoothegorilla Feb 26, 2024
320be20
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-02
poopoothegorilla Feb 26, 2024
ca3eec7
Merge branch 'jtw/step-3-02' into jtw/step-3-02-create-transaction
poopoothegorilla Feb 26, 2024
e8a2b41
implement PruneUnstartedTxQueue
poopoothegorilla Feb 27, 2024
ddf02a3
add panic if incorrect ChainID
poopoothegorilla Feb 27, 2024
13aa9b9
implement methods which are read only
poopoothegorilla Feb 29, 2024
16e05b8
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-02
poopoothegorilla Mar 7, 2024
4dfffee
Merge branch 'jtw/step-3-02' into jtw/step-3-02-create-transaction
poopoothegorilla Mar 11, 2024
2577538
clean up test for CreateTransaction
poopoothegorilla Mar 11, 2024
0f1725d
Merge branch 'jtw/step-3-02' into jtw/step-3-02-non-persistent
poopoothegorilla Mar 11, 2024
4e642a3
add tests for GetTxInProgress
poopoothegorilla Mar 11, 2024
4a39135
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-02
poopoothegorilla Mar 11, 2024
88a136d
Merge branch 'jtw/step-3-02' into jtw/step-3-02-non-persistent
poopoothegorilla Mar 11, 2024
523354d
add tests for FindNextUnstartedTransactionFromAddress
poopoothegorilla Mar 11, 2024
ee4d834
Merge branch 'jtw/step-3-02' into jtw/step-3-02-prune-unstarted-tx-queue
poopoothegorilla Mar 11, 2024
36c2523
add test for pruning
poopoothegorilla Mar 11, 2024
4d9577a
add test for pruning
poopoothegorilla Mar 11, 2024
c550580
fix delete method
poopoothegorilla Mar 11, 2024
4d3d0bb
Merge branch 'jtw/step-3-02' into jtw/step-3-02-create-transaction
poopoothegorilla Mar 21, 2024
b470da7
address comments
poopoothegorilla Mar 21, 2024
0fcd77a
Merge branch 'jtw/step-3-in-memory-work' into jtw/step-3-02
poopoothegorilla Mar 21, 2024
395d35f
fix address state issue if from address not available
poopoothegorilla Mar 21, 2024
bbc0c35
simplify addTxToUnstartedQueue
poopoothegorilla Mar 21, 2024
ec76f10
Merge branch 'jtw/step-3-02' into jtw/step-3-02-create-transaction
poopoothegorilla Mar 21, 2024
f7eb968
address comments
poopoothegorilla Mar 21, 2024
ef3b6a3
Merge branch 'jtw/step-3-02' into jtw/step-3-02-prune-unstarted-tx-queue
poopoothegorilla Mar 22, 2024
93900d5
cleanup context usage in tests
poopoothegorilla Mar 22, 2024
854225a
Merge pull request #12227 from smartcontractkit/jtw/step-3-02-prune-u…
poopoothegorilla Mar 29, 2024
4737097
Merge branch 'jtw/step-3-02' into jtw/step-3-02-create-transaction
poopoothegorilla Apr 1, 2024
bffcc71
clean up
poopoothegorilla Apr 1, 2024
ef5b26a
Merge pull request #12181 from smartcontractkit/jtw/step-3-02-create-…
poopoothegorilla Apr 1, 2024
e6fcbe7
Merge branch 'jtw/step-3-02' into jtw/step-3-02-non-persistent
poopoothegorilla Apr 4, 2024
482f9a1
panic on chainID mismatch
poopoothegorilla Apr 4, 2024
5341bbd
Merge pull request #12216 from smartcontractkit/jtw/step-3-02-non-per…
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
67 changes: 61 additions & 6 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 @@ -166,24 +167,60 @@ func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) FetchT

// 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) {
as.Lock()
defer as.Unlock()

txs := as.unstartedTxs.PruneByTxIDs(ids)
as.deleteTxs(txs...)
}

// 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]) {
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) {
return nil, nil
// If there are no unstarted transactions, nil is returned.
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] {
as.RLock()
defer as.RUnlock()

return as.unstartedTxs.PeekNextTx()
}

// 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) {
return nil, nil
// If there is no in-progress transaction, nil is returned.
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] {
as.RLock()
defer as.RUnlock()

return as.inprogressTx
}

// AddTxToUnstarted adds the given transaction to the unstarted queue.
func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) AddTxToUnstarted(tx *txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error {
// AddTxToUnstartedQueue adds the given transaction to the unstarted queue.
// If the queue is full, an error is returned.
// If the transaction was successfully added, nil is returned.
// If the transaction's idempotency key already exists, an error is returned.
func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) AddTxToUnstartedQueue(tx *txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error {
as.Lock()
defer as.Unlock()

if tx.IdempotencyKey != nil && as.idempotencyKeyToTx[*tx.IdempotencyKey] != nil {
return fmt.Errorf("add_tx_to_unstarted_queue: address %s idempotency key %s already exists", as.fromAddress, *tx.IdempotencyKey)
}
if as.unstartedTxs.Len() >= as.unstartedTxs.Cap() {
return fmt.Errorf("add_tx_to_unstarted_queue: address %s unstarted queue capacity has been reached", as.fromAddress)
}

as.unstartedTxs.AddTx(tx)
as.allTxs[tx.ID] = tx
if tx.IdempotencyKey != nil {
as.idempotencyKeyToTx[*tx.IdempotencyKey] = tx
}

return nil
}

Expand Down Expand Up @@ -252,3 +289,21 @@ func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveIn
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
}

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]) {
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)
}
}
Loading