chainHead: Ensure reasonable distance between leaf and finalized block (#3562)
This PR ensure that the distance between any leaf and the finalized block is within a reasonable distance. For a new subscription, the chainHead has to provide all blocks between the leaves of the chain and the finalized block. When the distance between a leaf and the finalized block is large: - The tree route is costly to compute - We could deliver an unbounded number of blocks (potentially millions) (For more details see https://github.com/paritytech/polkadot-sdk/pull/3445#discussion_r1507210283) The configuration of the ChainHead is extended with: - suspend on lagging distance: When the distance between any leaf and the finalized block is greater than this number, the subscriptions are suspended for a given duration. - All active subscriptions are terminated with the `Stop` event, all blocks are unpinned and data discarded. - For incoming subscriptions, until the suspended period expires the subscriptions will immediately receive the `Stop` event. - Defaults to 128 blocks - suspended duration: The amount of time for which subscriptions are suspended - Defaults to 30 seconds cc @paritytech/subxt-team --------- Signed-off-by:Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by:
Sebastian Kunert <skunert49@gmail.com>
parent
cdacfb9d
Showing
- Cargo.lock 5 additions, 4 deletionsCargo.lock
- substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs 21 additions, 4 deletionssubstrate/client/rpc-spec-v2/src/chain_head/chain_head.rs
- substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs 62 additions, 9 deletions...te/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
- substrate/client/rpc-spec-v2/src/chain_head/subscription/error.rs 4 additions, 0 deletions...e/client/rpc-spec-v2/src/chain_head/subscription/error.rs
- substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs 91 additions, 147 deletions...e/client/rpc-spec-v2/src/chain_head/subscription/inner.rs
- substrate/client/rpc-spec-v2/src/chain_head/subscription/mod.rs 9 additions, 0 deletions...ate/client/rpc-spec-v2/src/chain_head/subscription/mod.rs
- substrate/client/rpc-spec-v2/src/chain_head/tests.rs 121 additions, 0 deletionssubstrate/client/rpc-spec-v2/src/chain_head/tests.rs
Please register or sign in to comment