This repository was archived by the owner on Nov 15, 2023. It is now read-only.
rpc/chainHead: Fix pruned blocks events from forks#13379
Merged
Conversation
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
skunert
reviewed
Feb 14, 2023
Contributor
skunert
left a comment
There was a problem hiding this comment.
Logic looks good to me, just some nits.
davxy
reviewed
Feb 14, 2023
Member
|
Looks like some tests are not passing on this branch but are passing on master (at least "in my machine™️") |
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This reverts commit 425d6e7.
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
davxy
reviewed
Feb 28, 2023
Member
davxy
left a comment
There was a problem hiding this comment.
Not 100% familiar with this code part. But I've done my best 😁
Mostly looks good to me. Green light after the review points are resolved (or justified)
melekes
reviewed
Mar 1, 2023
Co-authored-by: Davide Galassi <davxy@datawok.net>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
ukint-vs
pushed a commit
to gear-tech/substrate
that referenced
this pull request
Apr 10, 2023
* rpc/chainhead: Test unpin for noncanonical prunned blocks Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/tests: Ensure fork is not reported by the Finalized event Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chainhead: Detect pruned forks to ignore from events Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/tests: Check unpin can be called on pruned hashes Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Fix clippy Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Handle race with memory blocks and notifications Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Add data config for the `follow` future Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Address feedback Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Move best block cache on the data config Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Send new events from the finalized stream Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chian_head: Report all pruned blocks Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Move `chainHead_follow` logic on dedicated file Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Delegate follow logic to `chain_head_follow` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Remove subscriptions on drop Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/tests: Ignore pruned blocks for a longer fork Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/tests: Check all pruned blocks are reported, not just stale heads Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/tests: Remove println debug and fix indentation Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Remove unnecessary trait bounds Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Add debug log for pruned forks Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Revert "rpc/chain_head: Add debug log for pruned forks" This reverts commit 425d6e7. * Adjust blockID for testing Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update client/rpc-spec-v2/src/chain_head/chain_head_follow.rs Co-authored-by: Davide Galassi <davxy@datawok.net> * rpc/chain_head: Rename `ChainHeadFollow` to `ChainHeadFollower` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Remove subscriptions manually Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Improve log messages by adding subID and errors Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Ensure `follow` stops sending events on first error Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Use default constructor Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Add `StartupPoint` structure Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Rename `in_memory_blocks` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Fix comment typo Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Keep unique blocks and remove itertools Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Make sure `bestBlocks` events are generated in order Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Maintain order of reported blocks Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Parent of finalized block could be unpinned Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Fix warning Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by: Davide Galassi <davxy@datawok.net>
15 tasks
nathanwhit
pushed a commit
to nathanwhit/substrate
that referenced
this pull request
Jul 19, 2023
* rpc/chainhead: Test unpin for noncanonical prunned blocks Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/tests: Ensure fork is not reported by the Finalized event Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chainhead: Detect pruned forks to ignore from events Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/tests: Check unpin can be called on pruned hashes Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Fix clippy Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Handle race with memory blocks and notifications Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Add data config for the `follow` future Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Address feedback Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Move best block cache on the data config Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Send new events from the finalized stream Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chian_head: Report all pruned blocks Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Move `chainHead_follow` logic on dedicated file Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Delegate follow logic to `chain_head_follow` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Remove subscriptions on drop Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/tests: Ignore pruned blocks for a longer fork Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/tests: Check all pruned blocks are reported, not just stale heads Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/tests: Remove println debug and fix indentation Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Remove unnecessary trait bounds Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Add debug log for pruned forks Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Revert "rpc/chain_head: Add debug log for pruned forks" This reverts commit 425d6e7. * Adjust blockID for testing Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update client/rpc-spec-v2/src/chain_head/chain_head_follow.rs Co-authored-by: Davide Galassi <davxy@datawok.net> * rpc/chain_head: Rename `ChainHeadFollow` to `ChainHeadFollower` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Remove subscriptions manually Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Improve log messages by adding subID and errors Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Ensure `follow` stops sending events on first error Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Use default constructor Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Add `StartupPoint` structure Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Rename `in_memory_blocks` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Fix comment typo Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Keep unique blocks and remove itertools Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Make sure `bestBlocks` events are generated in order Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Maintain order of reported blocks Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Parent of finalized block could be unpinned Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc/chain_head: Fix warning Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by: Davide Galassi <davxy@datawok.net>
Closed
46 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes the
chainHead::followedge cases:Issue 1
The
chainHead::followmethod returns theFinalizedevent containing both finalized hashes and pruned block hashes. The substrate database will perform the pruning of height N at the finalization N + 1.Considering the following tree structure:
Initial Condition:
Initializedevent containing the finalized hash (A2)NewBlockevents for children of finalized (A3)The
NewBlockevent contains the hash of the block + the parent hash. Taken from the spec:Issues:
Solution:
Issue 2
chainHead::followmethod reported just the stale heads when declaring the pruned hashes.To fix this issue, the tree route is determined from the stale heads to the canonical chain and all blocks are reported.
Additional
Because the complexity of generating the follow events grew, the logic is moved to the
chain_head_follow.rsfile.This also helps with code readability and maintenance.
Under intensive testing, it was possible for the
Finalizedevent to be received before theNewBlockthat led to flaky scenarios. To close the gap, theFinalizedbranch can now also generateNewBlockevents.Testing Done
follow_forks_pruned_blockandfollow_report_multiple_pruned_blockcover the issues described abovecargo testtogether withstress-ng --cpu 8 --cpu-load 100 --io 4to filter out any flakinessReview Notes
The entry point of the
followlogic is moved to a dedicated file. While at it, have also simplified the notification stream logic:substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Lines 565 to 566 in 33f5f10
The blocks to ignore as pruned are collected initially here:
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Lines 179 to 180 in 33f5f10
Both issues are handled by this method:
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Lines 392 to 395 in 33f5f10
Additionally, the
finalizedstream could also generate theNewBlockevents here:substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Lines 447 to 448 in 33f5f10
The other logic is moved from the
chain_headto thechain_head_followwith minimal additions (mostly better error reporting).Thanks @skunert and @davxy for the initial feedback and for raising the flakiness of the tests after the fix; plus the stale heads!
// CC: @paritytech/tools-team