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-3573] - Remove dependence on FinalityDepth in EVM TXM code #13794

Merged
merged 55 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
99cb0b6
removing finality within common/txmgr
Farber98 Jul 3, 2024
72f430e
remove finality from common/txmgr comment
Farber98 Jul 3, 2024
2de27e3
latestFinalizedBlockNum support within evm/txmgr txstore
Farber98 Jul 3, 2024
fe42945
refactor tests after evm/txmgr txstore changes
Farber98 Jul 3, 2024
1d14c4b
mocks for both common and core/evm
Farber98 Jul 3, 2024
6222291
remove comments that are still referencing to finalityDepth within ev…
Farber98 Jul 4, 2024
8e01631
add changeset
Farber98 Jul 9, 2024
b8fead5
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm the…
Farber98 Jul 10, 2024
55b069f
error if no LatestFinalizedHead was found
Farber98 Jul 11, 2024
43b3428
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
Farber98 Jul 11, 2024
9a97763
fix mocks version
Farber98 Jul 11, 2024
8ed35fe
fix mocks version
Farber98 Jul 11, 2024
09c3704
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
Farber98 Jul 11, 2024
1a694f7
mock versioning
Farber98 Jul 11, 2024
7f1b8b5
mock version
Farber98 Jul 11, 2024
e9c8daa
mock version
Farber98 Jul 11, 2024
fdb0d33
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
Farber98 Jul 11, 2024
5f13155
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
Farber98 Jul 12, 2024
b151dbe
mock version
Farber98 Jul 12, 2024
552a89f
mock version
Farber98 Jul 12, 2024
551a8c0
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
Farber98 Jul 12, 2024
7163d10
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
Farber98 Jul 30, 2024
8e91a75
inject head tracker trimmed API
Farber98 Jul 31, 2024
cb57245
fix tests
Farber98 Jul 31, 2024
1188b4b
mocks
Farber98 Jul 31, 2024
a4bb842
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
Farber98 Jul 31, 2024
a0673ce
remove unnecesary tests as finalized head is guaranteed
Farber98 Jul 31, 2024
b10c57d
ht in shell local
Farber98 Jul 31, 2024
a891e36
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
Farber98 Jul 31, 2024
62278e0
remove evm dep from confirmer and use generics instead
Farber98 Aug 1, 2024
2adcd80
make markOldTxesMissingReceiptAsErrored condition inclusive
Farber98 Aug 1, 2024
4fb2252
use already initialized head tracker within shell local
Farber98 Aug 1, 2024
f4ca5d9
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
Farber98 Aug 1, 2024
73aa556
fix mocking, fix unit test
huangzhen1997 Aug 2, 2024
9d99a29
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
huangzhen1997 Aug 2, 2024
242f41c
fix a potential bug
huangzhen1997 Aug 5, 2024
6a361f5
fix bug
huangzhen1997 Aug 5, 2024
f53f260
refactor
huangzhen1997 Aug 5, 2024
b7b7e56
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
huangzhen1997 Aug 5, 2024
6e71ff5
address comments
huangzhen1997 Aug 5, 2024
4663172
fix lint
huangzhen1997 Aug 5, 2024
805975d
rename
huangzhen1997 Aug 6, 2024
14bb96b
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
huangzhen1997 Aug 6, 2024
31d4569
have log back
huangzhen1997 Aug 6, 2024
cdeee6a
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
huangzhen1997 Aug 6, 2024
cebf699
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
huangzhen1997 Aug 6, 2024
0f98a46
update comments
huangzhen1997 Aug 6, 2024
dbbac95
remove nil check
huangzhen1997 Aug 6, 2024
14a5668
minor
huangzhen1997 Aug 6, 2024
2e1e92a
resolve merge conflicts
huangzhen1997 Aug 6, 2024
ebe7d59
fix test
huangzhen1997 Aug 6, 2024
e59e259
grammar
huangzhen1997 Aug 6, 2024
d70f6af
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
huangzhen1997 Aug 6, 2024
b0ed1e0
rephrase
huangzhen1997 Aug 6, 2024
5a079e9
Merge branch 'develop' into BCI-3573-remove-finalitydepth-evm-txm
huangzhen1997 Aug 9, 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
5 changes: 5 additions & 0 deletions .changeset/chatty-spiders-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

remove dependency on FinalityDepth in EVM TXM code. #internal
26 changes: 17 additions & 9 deletions common/txmgr/confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,11 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) pro
return fmt.Errorf("CheckConfirmedMissingReceipt failed: %w", err)
}

if err := ec.CheckForReceipts(ctx, head.BlockNumber()); err != nil {
if head.LatestFinalizedHead() == nil {
amit-momin marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("There is no LatestFinalizedHead")
}

if err := ec.CheckForReceipts(ctx, head.BlockNumber(), head.LatestFinalizedHead().BlockNumber()); err != nil {
return fmt.Errorf("CheckForReceipts failed: %w", err)
}

Expand Down Expand Up @@ -395,8 +399,8 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Che
return
}

// CheckForReceipts finds attempts that are still pending and checks to see if a receipt is present for the given block number
func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) CheckForReceipts(ctx context.Context, blockNum int64) error {
// CheckForReceipts finds attempts that are still pending and checks to see if a receipt is present for the given block number.
func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) CheckForReceipts(ctx context.Context, blockNum int64, latestFinalizedBlockNum int64) error {
attempts, err := ec.txStore.FindTxAttemptsRequiringReceiptFetch(ctx, ec.chainID)
if err != nil {
return fmt.Errorf("FindTxAttemptsRequiringReceiptFetch failed: %w", err)
Expand Down Expand Up @@ -443,7 +447,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Che
return fmt.Errorf("unable to mark txes as 'confirmed_missing_receipt': %w", err)
}

if err := ec.txStore.MarkOldTxesMissingReceiptAsErrored(ctx, blockNum, ec.chainConfig.FinalityDepth(), ec.chainID); err != nil {
if err := ec.txStore.MarkOldTxesMissingReceiptAsErrored(ctx, blockNum, latestFinalizedBlockNum, ec.chainID); err != nil {
return fmt.Errorf("unable to confirm buried unconfirmed txes': %w", err)
}
return nil
Expand Down Expand Up @@ -1000,22 +1004,26 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) han
}
}

// EnsureConfirmedTransactionsInLongestChain finds all confirmed txes up to the depth
// EnsureConfirmedTransactionsInLongestChain finds all confirmed txes up to the LatestFinalizedHead
huangzhen1997 marked this conversation as resolved.
Show resolved Hide resolved
// of the given chain and ensures that every one has a receipt with a block hash that is
// in the given chain.
//
// If any of the confirmed transactions does not have a receipt in the chain, it has been
// re-org'd out and will be rebroadcast.
func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) EnsureConfirmedTransactionsInLongestChain(ctx context.Context, head types.Head[BLOCK_HASH]) error {
if head.ChainLength() < ec.chainConfig.FinalityDepth() {
if head.LatestFinalizedHead() == nil {
amit-momin marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("There is no LatestFinalizedHead")
}

if head.ChainLength() < uint32(head.LatestFinalizedHead().BlockNumber()) {
logArgs := []interface{}{
"chainLength", head.ChainLength(), "finalityDepth", ec.chainConfig.FinalityDepth(),
"chainLength", head.ChainLength(), "latestFinalizedHead", head.LatestFinalizedHead().BlockNumber(),
}
if ec.nConsecutiveBlocksChainTooShort > logAfterNConsecutiveBlocksChainTooShort {
warnMsg := "Chain length supplied for re-org detection was shorter than FinalityDepth. Re-org protection is not working properly. This could indicate a problem with the remote RPC endpoint, a compatibility issue with a particular blockchain, a bug with this particular blockchain, heads table being truncated too early, remote node out of sync, or something else. If this happens a lot please raise a bug with the Chainlink team including a log output sample and details of the chain and RPC endpoint you are using."
warnMsg := "Chain length supplied for re-org detection was shorter than LatestFinalizedHead. Re-org protection is not working properly. This could indicate a problem with the remote RPC endpoint, a compatibility issue with a particular blockchain, a bug with this particular blockchain, heads table being truncated too early, remote node out of sync, or something else. If this happens a lot please raise a bug with the Chainlink team including a log output sample and details of the chain and RPC endpoint you are using."
ec.lggr.Warnw(warnMsg, append(logArgs, "nConsecutiveBlocksChainTooShort", ec.nConsecutiveBlocksChainTooShort)...)
} else {
logMsg := "Chain length supplied for re-org detection was shorter than FinalityDepth"
logMsg := "Chain length supplied for re-org detection was shorter than LatestFinalizedHead"
ec.lggr.Debugw(logMsg, append(logArgs, "nConsecutiveBlocksChainTooShort", ec.nConsecutiveBlocksChainTooShort)...)
}
ec.nConsecutiveBlocksChainTooShort++
Expand Down
2 changes: 1 addition & 1 deletion common/txmgr/mocks/tx_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/txmgr/types/tx_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type TransactionStore[
HasInProgressTransaction(ctx context.Context, account ADDR, chainID CHAIN_ID) (exists bool, err error)
LoadTxAttempts(ctx context.Context, etx *Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error
MarkAllConfirmedMissingReceipt(ctx context.Context, chainID CHAIN_ID) (err error)
MarkOldTxesMissingReceiptAsErrored(ctx context.Context, blockNum int64, finalityDepth uint32, chainID CHAIN_ID) error
MarkOldTxesMissingReceiptAsErrored(ctx context.Context, blockNum int64, latestFinalizedBlockNum int64, chainID CHAIN_ID) error
PreloadTxes(ctx context.Context, attempts []TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error
SaveConfirmedMissingReceiptAttempt(ctx context.Context, timeout time.Duration, attempt *TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], broadcastAt time.Time) error
SaveInProgressAttempt(ctx context.Context, attempt *TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error
Expand Down
Loading
Loading