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

Update finality depth check headtracker #13089

Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fc9c081
Update finality depth check headtracker
silaslenihan May 2, 2024
d84f8c4
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 2, 2024
b4a4e0e
added check for nil prevLatestFinalized
silaslenihan May 3, 2024
a80a646
added changeset
silaslenihan May 3, 2024
48a653b
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 3, 2024
c20bfd0
updated changeset
silaslenihan May 3, 2024
f8f4153
cleaned up nil protection in LatestFinalizedHead
silaslenihan May 8, 2024
55dcbdd
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 8, 2024
60f282e
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 8, 2024
a91d987
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 8, 2024
56dc83f
Added error tuple to LatestFinalizedHead
silaslenihan May 9, 2024
49e008f
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 9, 2024
df09276
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 9, 2024
a84595f
Added error tuple to LatestFinalizedHead
silaslenihan May 9, 2024
740b7f8
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 9, 2024
fa8afc2
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 10, 2024
db5a4a1
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 13, 2024
41a31a8
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 14, 2024
e50310d
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 14, 2024
39e2c79
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 20, 2024
216c11a
removed error from LatestFinalizedHead
silaslenihan May 20, 2024
e854293
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 20, 2024
bdaac13
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 20, 2024
1219f10
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 20, 2024
e49ef69
Merge branch 'develop' into BCI-2919-Update-FinalityDepth-check-logic…
silaslenihan May 20, 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/witty-onions-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

#internal Switched finality check in HeadTracker to use the underlying finality type
5 changes: 3 additions & 2 deletions common/headtracker/head_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ func (ht *headTracker[HTH, S, ID, BLOCK_HASH]) handleNewHead(ctx context.Context
}
} else {
ht.log.Debugw("Got out of order head", "blockNum", head.BlockNumber(), "head", head.BlockHash(), "prevHead", prevHead.BlockNumber())
prevUnFinalizedHead := prevHead.BlockNumber() - int64(ht.config.FinalityDepth())
if head.BlockNumber() < prevUnFinalizedHead {
prevLatestFinalized, err := prevHead.LatestFinalizedHead()

if err == nil && head.BlockNumber() <= prevLatestFinalized.BlockNumber() {
promOldHead.WithLabelValues(ht.chainID.String()).Inc()
ht.log.Criticalf("Got very old block with number %d (highest seen was %d). This is a problem and either means a very deep re-org occurred, one of the RPC nodes has gotten far out of sync, or the chain went backwards in block numbers. This node may not function correctly without manual intervention.", head.BlockNumber(), prevHead.BlockNumber())
ht.SvcErrBuffer.Append(errors.New("got very old block"))
Expand Down
3 changes: 3 additions & 0 deletions common/types/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ type Head[BLOCK_HASH Hashable] interface {
BlockDifficulty() *big.Int
// IsValid returns true if the head is valid.
IsValid() bool

// Returns the latest finalized based on finality tag or depth
LatestFinalizedHead() (Head[BLOCK_HASH], error)
}
30 changes: 30 additions & 0 deletions common/types/mocks/head.go

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

2 changes: 1 addition & 1 deletion core/chains/evm/types/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestHead_LatestFinalizedHead(t *testing.T) {

for _, tc := range cases {
t.Run(tc.Name, func(t *testing.T) {
actual := tc.Head.LatestFinalizedHead()
actual, _ := tc.Head.LatestFinalizedHead()
if tc.Finalized == nil {
assert.Nil(t, actual)
} else {
Expand Down
10 changes: 7 additions & 3 deletions core/chains/evm/types/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,16 @@ func (h *Head) ChainHashes() []common.Hash {
return hashes
}

func (h *Head) LatestFinalizedHead() commontypes.Head[common.Hash] {
silaslenihan marked this conversation as resolved.
Show resolved Hide resolved
for h != nil && !h.IsFinalized {
func (h *Head) LatestFinalizedHead() (commontypes.Head[common.Hash], error) {
for h != nil {
if h.IsFinalized {
return h, nil
}

h = h.Parent
silaslenihan marked this conversation as resolved.
Show resolved Hide resolved
}

return h
return nil, pkgerrors.New("no finalized head")
}

func (h *Head) ChainID() *big.Int {
Expand Down
2 changes: 1 addition & 1 deletion core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ func AssertEthTxAttemptCountStays(t testing.TB, txStore txmgr.TestEvmTxStore, wa
return txaIds
}

// Head given the value convert it into an Head
// Head given the value convert it into a Head
func Head(val interface{}) *evmtypes.Head {
var h evmtypes.Head
time := uint64(0)
Expand Down
Loading