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

HeadTracker finalization support #12082

Merged
merged 42 commits into from
Mar 13, 2024

Conversation

dhaidashenko
Copy link
Collaborator

@dhaidashenko dhaidashenko commented Feb 19, 2024

  • Mark block finalized based on FinalityTag or FinalityDepth
  • Add to Head function that returns LatestFinalizedHead in the chain
  • Previously, we've kept only historyDepth blocks in the cache. Such logic could have lead to redundant RPC calls on a chain with finalityTags if historyDepth was smaller than the actual finalityDepth. To address this issue, we only trim blocks that are older than latestFinalized - historyDepth

Copy link
Contributor

I see that you haven't updated any README files. Would it make sense to do so?

Copy link
Contributor

I see that you haven't updated any CHANGELOG files. Would it make sense to do so?

@dhaidashenko dhaidashenko marked this pull request as ready for review February 20, 2024 15:49
@dhaidashenko dhaidashenko requested review from a team as code owners February 20, 2024 15:49
@dhaidashenko dhaidashenko requested review from dimkouv, dimriou and prashantkumar1982 and removed request for a team February 20, 2024 15:50
}

// copy slice as we are going to modify it
newHeads := make([]*evmtypes.Head, len(h.heads))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we copy this to h.heads ? It seems like we do all the work but we don't actually update the original structure.

@@ -366,3 +367,7 @@ func (client *client) SuggestGasTipCap(ctx context.Context) (tipCap *big.Int, er
func (client *client) IsL2() bool {
return client.pool.ChainType().IsL2()
}

func (client *client) LatestFinalizedBlock(_ context.Context) (*evmtypes.Head, error) {
panic("not implemented. client was deprecated. New methods are added only to satisfy type constraints while we are migrating to new alternatives")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the entire app should crash if someone uses this method by mistake. It's better if we return nil & an error message so any user can handle this gracefully.

@dimriou
Copy link
Collaborator

dimriou commented Mar 1, 2024

Can you update the CHANGELOG stating that we've added Finality Tag support on the Head Tracker, but consumers will actually utilize it on a separate PR?

Is not it too internal to be mentioned in the CHANGELOG? I recall foundations asking me to remove similar entry. Also technically TXM uses FinalityTag feature right away, if it's enabled for the chain, as now we backfill heads up to tagged block instead of finality depth. I agree that we need to somehow communicate the change. I'm not sure that CHANGELOG is suitable for it.

This is a public PR so I don't see why this shouldn't be mentioned 😅 . Can you dm me the example?
Regarding finality, TXM still uses FinalityDepth to mark transactions as finalized, so it doesn't fully utilize the finalized blocks even if they are stored in the HeadTracker.

docs/CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Dimitris Grigoriou <[email protected]>
# Conflicts:
#	core/chains/evm/client/simulated_backend_client.go
@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue Mar 13, 2024
Merged via the queue into develop with commit 608ea0a Mar 13, 2024
97 checks passed
@prashantkumar1982 prashantkumar1982 deleted the feature/BCI-2649-latest-finalized-block branch March 13, 2024 18:52
ogtownsend pushed a commit that referenced this pull request Mar 14, 2024
* Add LatestFinalizedBlock to HeadTracker

* Added LatestFinalizedHead to Head

* remove unused func

* fix flakey nil pointer

* improve logs & address lint issue

* nitpicks

* fixed copy on heads on MarkFinalized

* error instead of panic

* return error instead of panic

* nitpicks

* Finalized block based history depth

* simplify trimming

* nit fixes

* fix build issues caused by merge

* regen

* FIx rpc client mock generation

* nit fixes

* nit fixes

* update comments

* ensure that we trim redundant blocks both in slice and in chain in Heads
handle corner case for multiple uncle blocks at the end of the slice

* nit fix

* Update common/headtracker/head_tracker.go

Co-authored-by: Dimitris Grigoriou <[email protected]>

* HeadTracker backfill test with 0 finality depth

* docs

* Update docs/CHANGELOG.md

Co-authored-by: Dimitris Grigoriou <[email protected]>

* ensure latest finalized block is valid on startup

* changeset

* switch from warn to debug level when we failed to makr block as finalized

---------

Co-authored-by: Dimitris Grigoriou <[email protected]>
kidambisrinivas pushed a commit that referenced this pull request Mar 27, 2024
* Add LatestFinalizedBlock to HeadTracker

* Added LatestFinalizedHead to Head

* remove unused func

* fix flakey nil pointer

* improve logs & address lint issue

* nitpicks

* fixed copy on heads on MarkFinalized

* error instead of panic

* return error instead of panic

* nitpicks

* Finalized block based history depth

* simplify trimming

* nit fixes

* fix build issues caused by merge

* regen

* FIx rpc client mock generation

* nit fixes

* nit fixes

* update comments

* ensure that we trim redundant blocks both in slice and in chain in Heads
handle corner case for multiple uncle blocks at the end of the slice

* nit fix

* Update common/headtracker/head_tracker.go

Co-authored-by: Dimitris Grigoriou <[email protected]>

* HeadTracker backfill test with 0 finality depth

* docs

* Update docs/CHANGELOG.md

Co-authored-by: Dimitris Grigoriou <[email protected]>

* ensure latest finalized block is valid on startup

* changeset

* switch from warn to debug level when we failed to makr block as finalized

---------

Co-authored-by: Dimitris Grigoriou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants