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

[BCI-2235] Abandoned Transaction Tracking #11143

Merged
merged 90 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
d854e47
Create Abandoned Tracker
DylanTinianov Nov 1, 2023
26dcf69
Handle abandoned transactions
DylanTinianov Nov 1, 2023
ac23537
Update abandoned_tracker.go
DylanTinianov Nov 1, 2023
bfbb51c
fix tabbing
DylanTinianov Nov 1, 2023
3014be3
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 1, 2023
ecdf03b
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 1, 2023
9dcf4b9
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 1, 2023
1e664ab
Query for non-finalized txes
DylanTinianov Nov 2, 2023
fb8a294
fix tracker
DylanTinianov Nov 2, 2023
f023184
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 3, 2023
c76a422
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 4, 2023
65da815
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 6, 2023
98d897a
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 6, 2023
d966442
Resend abandoned txes
DylanTinianov Nov 7, 2023
bb04189
Merge branch 'BCI-2235-txm-abandoned-tx-tracking' of https://github.c…
DylanTinianov Nov 7, 2023
276f141
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 7, 2023
b0ee9c1
Add evm_tx_store test
DylanTinianov Nov 7, 2023
4ec46d8
Resend abandoned transactions
DylanTinianov Nov 7, 2023
be23d54
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 7, 2023
91c6bf2
add tracker testing
DylanTinianov Nov 7, 2023
c5d3087
presubmit
DylanTinianov Nov 7, 2023
f7a6fc0
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 7, 2023
1864a41
tidy
DylanTinianov Nov 7, 2023
e32d107
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 7, 2023
adaca5b
generate
DylanTinianov Nov 7, 2023
81a49e7
fix test
DylanTinianov Nov 7, 2023
e01bc79
lint
DylanTinianov Nov 7, 2023
d1b3f1d
tidy
DylanTinianov Nov 7, 2023
1585328
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 7, 2023
43dbf4b
fix txmgr tests
DylanTinianov Nov 8, 2023
988c218
generate
DylanTinianov Nov 8, 2023
c41be56
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 8, 2023
12092f3
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 9, 2023
5256cbd
Get tx by ID
DylanTinianov Nov 9, 2023
446e02a
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 9, 2023
fa144d5
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 9, 2023
077b8dd
generate
DylanTinianov Nov 9, 2023
2806d80
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 9, 2023
c494167
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 9, 2023
2c5db37
ensure tx attemps
DylanTinianov Nov 9, 2023
2c2cccd
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 10, 2023
62514bc
Confirm abandoned txes
DylanTinianov Nov 10, 2023
664b1da
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 10, 2023
6ebe03a
tracker reset
DylanTinianov Nov 10, 2023
347689e
lint
DylanTinianov Nov 10, 2023
a363119
Update tracker.go
DylanTinianov Nov 10, 2023
fcb2389
Get Tx by ID
DylanTinianov Nov 10, 2023
8275587
Update text
DylanTinianov Nov 10, 2023
eaa8ec5
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 10, 2023
b82b756
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 13, 2023
ae9f0a4
Make tracker its own component
DylanTinianov Nov 15, 2023
e1d2c74
check finality_depth
DylanTinianov Nov 17, 2023
491f25b
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
DylanTinianov Nov 17, 2023
df9221b
remove TxAbandoned state
DylanTinianov Nov 17, 2023
10355a9
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 20, 2023
36e65c9
generate
DylanTinianov Nov 20, 2023
5e96609
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 20, 2023
e5f90a5
Fix race conditions
DylanTinianov Nov 20, 2023
d207ab9
Update db functions
DylanTinianov Nov 21, 2023
bf28a80
Add state machine to tracker
DylanTinianov Nov 21, 2023
b176266
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 21, 2023
6161866
Delete coverage.txt
DylanTinianov Nov 21, 2023
000b418
lint
DylanTinianov Nov 22, 2023
ec7df7d
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 22, 2023
2a31c5e
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 22, 2023
38b8cf3
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 22, 2023
0c0cceb
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 22, 2023
4a8a643
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 22, 2023
6c897e5
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 23, 2023
2a2c589
count receipts in query
DylanTinianov Nov 23, 2023
aa0f2a9
add context
DylanTinianov Nov 23, 2023
fb4f879
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 24, 2023
7510072
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 27, 2023
969f50a
update cltest
DylanTinianov Nov 27, 2023
78c9606
Add tracker description
DylanTinianov Nov 27, 2023
8ade50c
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 27, 2023
cecee58
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 27, 2023
3668291
filter chainID
DylanTinianov Nov 28, 2023
2463fab
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 28, 2023
dba2239
update logger
DylanTinianov Nov 28, 2023
a10a5ca
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 28, 2023
545b189
generate
DylanTinianov Nov 28, 2023
95a8cec
Merge branch 'BCI-2235-txm-abandoned-tx-tracking' of https://github.c…
DylanTinianov Nov 28, 2023
d75aa1b
Update CHANGELOG.md
DylanTinianov Nov 28, 2023
77681ea
Test unstarted txes
DylanTinianov Nov 28, 2023
06a5fda
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 28, 2023
36d9f63
lint
DylanTinianov Nov 28, 2023
96c4f79
undo imports
DylanTinianov Nov 28, 2023
e14585a
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
amit-momin Nov 28, 2023
4400ccc
Merge branch 'develop' into BCI-2235-txm-abandoned-tx-tracking
DylanTinianov Nov 29, 2023
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
27 changes: 18 additions & 9 deletions common/txmgr/resender.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ type Resender[
ADDR types.Hashable,
TX_HASH types.Hashable,
BLOCK_HASH types.Hashable,
R txmgrtypes.ChainReceipt[TX_HASH, BLOCK_HASH],
SEQ types.Sequence,
FEE feetypes.Fee,
] struct {
txStore txmgrtypes.TransactionStore[ADDR, CHAIN_ID, TX_HASH, BLOCK_HASH, SEQ, FEE]
client txmgrtypes.TransactionClient[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]
tracker *Tracker[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]
ks txmgrtypes.KeyStore[ADDR, CHAIN_ID, SEQ]
chainID CHAIN_ID
interval time.Duration
Expand All @@ -64,25 +66,28 @@ func NewResender[
ADDR types.Hashable,
TX_HASH types.Hashable,
BLOCK_HASH types.Hashable,
R txmgrtypes.ChainReceipt[TX_HASH, BLOCK_HASH],
SEQ types.Sequence,
FEE feetypes.Fee,
](
lggr logger.Logger,
txStore txmgrtypes.TransactionStore[ADDR, CHAIN_ID, TX_HASH, BLOCK_HASH, SEQ, FEE],
client txmgrtypes.TransactionClient[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE],
tracker *Tracker[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE],
ks txmgrtypes.KeyStore[ADDR, CHAIN_ID, SEQ],
pollInterval time.Duration,
config txmgrtypes.ResenderChainConfig,
txConfig txmgrtypes.ResenderTransactionsConfig,
) *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE] {
) *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE] {
if txConfig.ResendAfterThreshold() == 0 {
panic("Resender requires a non-zero threshold")
}
// todo: add context to txStore https://smartcontract-it.atlassian.net/browse/BCI-1585
ctx, cancel := context.WithCancel(context.Background())
return &Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]{
return &Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]{
txStore,
client,
tracker,
ks,
client.ConfiguredChainID(),
pollInterval,
Expand All @@ -97,18 +102,18 @@ func NewResender[
}

// Start is a comment which satisfies the linter
func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) Start() {
func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Start() {
er.logger.Debugf("Enabled with poll interval of %s and age threshold of %s", er.interval, er.txConfig.ResendAfterThreshold())
go er.runLoop()
}

// Stop is a comment which satisfies the linter
func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) Stop() {
func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Stop() {
er.cancel()
<-er.chDone
}

func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) runLoop() {
func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) runLoop() {
defer close(er.chDone)

if err := er.resendUnconfirmed(); err != nil {
Expand All @@ -129,16 +134,20 @@ func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) runLoop() {
}
}

func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) resendUnconfirmed() error {
enabledAddresses, err := er.ks.EnabledAddressesForChain(er.chainID)
func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) resendUnconfirmed() error {
resendAddresses, err := er.ks.EnabledAddressesForChain(er.chainID)
if err != nil {
return fmt.Errorf("Resender failed getting enabled keys for chain %s: %w", er.chainID.String(), err)
}

resendAddresses = append(resendAddresses, er.tracker.GetAbandonedAddresses()...)

ageThreshold := er.txConfig.ResendAfterThreshold()
maxInFlightTransactions := er.txConfig.MaxInFlight()
olderThan := time.Now().Add(-ageThreshold)
var allAttempts []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]
for _, k := range enabledAddresses {

for _, k := range resendAddresses {
var attempts []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]
attempts, err = er.txStore.FindTxAttemptsRequiringResend(er.ctx, olderThan, maxInFlightTransactions, er.chainID, k)
if err != nil {
Expand Down Expand Up @@ -189,7 +198,7 @@ func logResendResult(lggr logger.Logger, codes []client.SendTxReturnCode) {
lggr.Debugw("Completed", "n", len(codes), "nNew", nNew, "nFatal", nFatal)
}

func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) logStuckAttempts(attempts []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], fromAddress ADDR) {
func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) logStuckAttempts(attempts []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], fromAddress ADDR) {
if time.Since(er.lastAlertTimestamps[fromAddress.String()]) >= unconfirmedTxAlertLogFrequency {
oldestAttempt, exists := findOldestUnconfirmedAttempt(attempts)
if exists {
Expand Down
11 changes: 10 additions & 1 deletion common/txmgr/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package txmgr

import (
"context"
"time"

txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
)
Expand All @@ -13,6 +14,14 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) XXX
ec.client = client
}

func (tr *Tracker[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) XXXTestSetTTL(ttl time.Duration) {
tr.ttl = ttl
}

func (tr *Tracker[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) XXXDeliverBlock(blockHeight int64) {
tr.mb.Deliver(blockHeight)
}

func (eb *Broadcaster[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) XXXTestStartInternal() error {
return eb.startInternal()
}
Expand All @@ -33,7 +42,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) XXX
return ec.closeInternal()
}

func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) XXXTestResendUnconfirmed() error {
func (er *Resender[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) XXXTestResendUnconfirmed() error {
return er.resendUnconfirmed()
}

Expand Down
Loading
Loading