Skip to content

Commit

Permalink
move MaxConfirmedSequence logic from addressState to caller
Browse files Browse the repository at this point in the history
  • Loading branch information
poopoothegorilla committed Jan 22, 2024
1 parent 041bf61 commit 970db2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
17 changes: 0 additions & 17 deletions common/txmgr/address_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,6 @@ func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) FindTx
return as.idempotencyKeyToTx[key]
}

func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MaxConfirmedSequence() SEQ {
as.RLock()
defer as.RUnlock()

var maxSeq SEQ
for _, tx := range as.confirmed {
if tx.Sequence == nil {
continue
}
if (*tx.Sequence).Int64() > maxSeq.Int64() {
maxSeq = *tx.Sequence
}
}

return maxSeq
}

func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) ApplyToTxsByState(
txStates []txmgrtypes.TxState,
fn func(*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]),
Expand Down
22 changes: 18 additions & 4 deletions common/txmgr/inmemory_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1718,8 +1718,22 @@ func (ms *InMemoryStore[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MarkA
wg.Add(1)
go func(as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) {
// TODO(jtw): THIS IS EVM SPECIFIC THIS SHOULD BE GENERALIZED
maxConfirmedSequence := as.MaxConfirmedSequence()
filter := func(tx *txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) bool {
// Get the max confirmed sequence
filter := func(tx *txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) bool { return true }
states := []txmgrtypes.TxState{TxConfirmed}
txs := as.FetchTxs(states, filter)
var maxConfirmedSequence SEQ
for _, tx := range txs {
if tx.Sequence == nil {
continue
}
if (*tx.Sequence).Int64() > maxConfirmedSequence.Int64() {
maxConfirmedSequence = *tx.Sequence
}
}

// Mark all unconfirmed txs with a sequence less than the max confirmed sequence as confirmed_missing_receipt
filter = func(tx *txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) bool {
if tx.Sequence == nil {
return false
}
Expand All @@ -1729,8 +1743,8 @@ func (ms *InMemoryStore[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MarkA

return (*tx.Sequence).Int64() < maxConfirmedSequence.Int64()
}
states := []txmgrtypes.TxState{TxUnconfirmed}
txs := as.FetchTxs(states, filter)
states = []txmgrtypes.TxState{TxUnconfirmed}
txs = as.FetchTxs(states, filter)
for _, tx := range txs {
attempt := tx.TxAttempts[0]

Expand Down

0 comments on commit 970db2b

Please sign in to comment.