chainHead: Report unique hashes for pruned blocks (#3667)
This PR ensures that the reported pruned blocks are unique. While at it, ensure that the best block event is properly generated when the last best block is a fork that will be pruned in the future. To achieve this, the chainHead keeps a LRU set of reported pruned blocks to ensure the following are not reported twice: ```bash finalized -> block 1 -> block 2 -> block 3 -> block 2 -> block 4 -> block 5 -> block 1 -> block 2_f -> block 6 -> block 7 -> block 8 ``` When block 7 is finalized the branch [block 2; block 3] is reported as pruned. When block 8 is finalized the branch [block 2; block 4; block 5] should be reported as pruned, however block 2 was already reported as pruned at the previous step. This is a side-effect of the pruned blocks being reported at level N - 1. For example, if all pruned forks would be reported with the first encounter (when block 6 is finalized we know that block 3 and block 5 are stale), we would not need the LRU cache. cc @paritytech/subxt-team Closes https://github.com/paritytech/polkadot-sdk/issues/3658 --------- Signed-off-by:Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by:
Sebastian Kunert <skunert49@gmail.com>
Showing
- Cargo.lock 1 addition, 0 deletionsCargo.lock
- substrate/client/rpc-spec-v2/Cargo.toml 1 addition, 0 deletionssubstrate/client/rpc-spec-v2/Cargo.toml
- substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs 1 addition, 1 deletionsubstrate/client/rpc-spec-v2/src/chain_head/chain_head.rs
- substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs 57 additions, 51 deletions...te/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
- substrate/client/rpc-spec-v2/src/chain_head/tests.rs 213 additions, 0 deletionssubstrate/client/rpc-spec-v2/src/chain_head/tests.rs
Please register or sign in to comment