Skip to content

Do not prune blocks with Grandpa justifications#10893

Merged
skunert merged 17 commits intomasterfrom
skunert/warp-sync-pruning-improvements
Feb 18, 2026
Merged

Do not prune blocks with Grandpa justifications#10893
skunert merged 17 commits intomasterfrom
skunert/warp-sync-pruning-improvements

Conversation

@skunert
Copy link
Copy Markdown
Contributor

@skunert skunert commented Jan 23, 2026

Warp sync requires GRANDPA justifications at authority set change boundaries to construct proofs. When block pruning is enabled, all block bodies are removed regardless of whether they contain important justifications. The pruned nodes can then not be used to fetch warp proofs.

In this PR I add the capability to filter which blocks can be safely pruned. For parachain nodes, everything can be pruned, solochain nodes using grandpa keep blocks with justifications.

Overview:

sc-client-db

  • Add BlockPruningFilter trait with blanket impl for closures
  • Add block_pruning_filters field to DatabaseSettings and Backend
  • Check filters in prune_blocks() before removing block bodies

sc-consensus-grandpa

  • Add GrandpaBlockPruningFilter that preserves blocks with GRANDPA justifications

sc-service

  • Add block_pruning_filters parameter to new_full_parts and new_full_parts_record_import

Nodes updated

  • polkadot-service: uses GrandpaBlockPruningFilter
  • staging-node-cli (kitchensink): uses GrandpaBlockPruningFilter
  • solochain-template: uses GrandpaBlockPruningFilter
  • parachain-template / omni-node / polkadot-parachain: empty filters

fixes #2733

@skunert skunert added the T0-node This PR/Issue is related to the topic “node”. label Jan 23, 2026
@skunert
Copy link
Copy Markdown
Contributor Author

skunert commented Jan 23, 2026

/cmd prdoc --audience node_dev node_operator

@skunert skunert marked this pull request as ready for review January 23, 2026 14:53
@skunert skunert changed the title Do not prune blocks with GrandPa justifications Do not prune blocks with Grandpa justifications Jan 23, 2026
@skunert
Copy link
Copy Markdown
Contributor Author

skunert commented Jan 23, 2026

/cmd fmt

@paritytech-workflow-stopper
Copy link
Copy Markdown

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/21290929518
Failed job name: cargo-clippy

@skunert skunert requested a review from a team January 23, 2026 17:56
Comment thread substrate/client/db/src/lib.rs Outdated
where
F: Fn(&Justifications) -> bool + Send + Sync,
{
fn should_preserve(&self, justifications: &Justifications) -> bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: how about: keep or retain ?

Comment thread substrate/client/db/src/lib.rs Outdated
Comment on lines +2001 to +2014
let should_preserve = if let Some(justification) =
current_transaction_justifications.get(&hash)
{
let justifications = Justifications::from(justification.clone());
self.block_pruning_filters
.iter()
.any(|f| f.should_preserve(&justifications))
} else if let Some(justifications) = self.blockchain.justifications(hash)? {
self.block_pruning_filters
.iter()
.any(|f| f.should_preserve(&justifications))
} else {
false
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: some duplication could be avoided here, by something like this, probably this reads more smoothly:

let justifications = current_transaction_justifications
    .get(&hash)
    .map(|j| Justifications::from(j.clone()))
    .or_else(|| self.blockchain.justifications(hash)?);

let should_preserve = justifications
    .map(|j| {
        self.block_pruning_filters
            .iter()
            .any(|f| f.should_preserve(&j))
    })
    .unwrap_or(false);

Copy link
Copy Markdown
Contributor

@lrubasze lrubasze left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment thread polkadot/node/service/src/builder/partial.rs Outdated
Copy link
Copy Markdown
Contributor

@lexnv lexnv left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Hmm, I don't like the approach :D It works right now because we keep the headers around, but in a "perfect" world we would also not need the headers anymore. Right now they are just kept to support "fast sync".

IMO it would make more sense to be able to tell the db to keep certain headers/justification around forever and that it can not prune them. So, something we say at import/maybe also setable later. But this makes it more flexible for the future.

@skunert skunert requested a review from a team as a code owner February 12, 2026 11:42
@skunert
Copy link
Copy Markdown
Contributor Author

skunert commented Feb 12, 2026

Hmm, I don't like the approach :D It works right now because we keep the headers around, but in a "perfect" world we would also not need the headers anymore. Right now they are just kept to support "fast sync".

IMO it would make more sense to be able to tell the db to keep certain headers/justification around forever and that it can not prune them. So, something we say at import/maybe also setable later. But this makes it more flexible for the future.

As per quick discussion yesterday, header pruning should not be a problem. I expect it to be in line with the blocks pruning, so we can use the closure to decide an all-or-nothing pruning approach. Chose some more generic naming though.

@skunert skunert enabled auto-merge February 18, 2026 09:39
@skunert skunert added this pull request to the merge queue Feb 18, 2026
Merged via the queue into master with commit 3ee8c82 Feb 18, 2026
240 of 245 checks passed
@skunert skunert deleted the skunert/warp-sync-pruning-improvements branch February 18, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T0-node This PR/Issue is related to the topic “node”.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Do not prune session change justifications

8 participants