Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add keep-blocks archive params #13068

Closed
wants to merge 2 commits into from
Closed

Add keep-blocks archive params #13068

wants to merge 2 commits into from

Conversation

zjb0807
Copy link
Contributor

@zjb0807 zjb0807 commented Jan 4, 2023

a0ec652?diff=unified#diff-0e523389a21c9bd9fc1da47816eb73a5ad21637337bb938abecedfe7f936d824R1720

The logic of prune_blocks has changed, and the --keep-blocks=archive needs to be specified.

@bkchr
Copy link
Member

bkchr commented Jan 4, 2023

The logic of prune_blocks has changed, and the --keep-blocks=archive needs to be specified.

Yes the logic has changed, that is right. However, why does keep-blofks=archive needs to be specified? Could you please go more into detail. You are also talking about benchmarks, which kind of benchmarks are you talking about and how are they broken?

@zjb0807
Copy link
Contributor Author

zjb0807 commented Jan 4, 2023

substrate/client/db/src/lib.rs

Lines 1704 to 1738 in fbd7e5a

fn prune_blocks(
&self,
transaction: &mut Transaction<DbHash>,
finalized: NumberFor<Block>,
displaced: &FinalizationOutcome<Block::Hash, NumberFor<Block>>,
) -> ClientResult<()> {
if let BlocksPruning::Some(blocks_pruning) = self.blocks_pruning {
// Always keep the last finalized block
let keep = std::cmp::max(blocks_pruning, 1);
if finalized >= keep.into() {
let number = finalized.saturating_sub(keep.into());
self.prune_block(transaction, BlockId::<Block>::number(number))?;
}
// Also discard all blocks from displaced branches
for h in displaced.leaves() {
let mut number = finalized;
let mut hash = *h;
// Follow displaced chains back until we reach a finalized block.
// Since leaves are discarded due to finality, they can't have parents
// that are canonical, but not yet finalized. So we stop deleting as soon as
// we reach canonical chain.
while self.blockchain.hash(number)? != Some(hash) {
let id = BlockId::<Block>::hash(hash);
match self.blockchain.header(id)? {
Some(header) => {
self.prune_block(transaction, id)?;
number = header.number().saturating_sub(One::one());
hash = *header.parent_hash();
},
None => break,
}
}
}
}

The origin logic is that if self.blocks_pruning is some, the blocks will be pruned.

Now its default value is BlocksPruning::KeepFinalized. It only keeps the last finalized block. block history will be pruned.

--pruning=archive should be used with --keep-blocks=archive as RPC node. Otherwise, chain_getBlock cannot get historical blocks. I only want to tell the developers to keep this in mind.

@bkchr
Copy link
Member

bkchr commented Jan 5, 2023

Now its default value is BlocksPruning::KeepFinalized. It only keeps the last finalized block. block history will be pruned.

KeepFinalized is the default now, yes. But, it will not only keep the last finalized block. The docs are correct:
/// Keep full finalized block history.

This means that it will keep all blocks of the finalized chain.

@bkchr
Copy link
Member

bkchr commented Jan 5, 2023

It is also about block bodies, not state.

@lisa-parity
Copy link
Contributor

lisa-parity commented Jan 6, 2023

@bkchr, if the docs are okay as-is, should we close this issue or would it be more useful to add some examples about the use of the --keep-blocks=archive or add some clarification around keeping finalized block bodies not the actual state?
What is your recommendation (specifically for documentation)?
Related issue opened for docs: polkadot-developers/substrate-docs#1705

@bkchr
Copy link
Member

bkchr commented Jan 10, 2023

@bkchr, if the docs are okay as-is, should we close this issue or would it be more useful to add some examples about the use of the --keep-blocks=archive

We don't need this cli flag specified everywhere. So, I don't think we need to change any issue. Keeping non canonical block bodies is just wasting disk space.

@bkchr
Copy link
Member

bkchr commented Jan 10, 2023

What is your recommendation (specifically for documentation)?

I don't know 100%, but I think you don't need to change anything. block-pruning is also not really used anywhere up to now.

@zjb0807 zjb0807 closed this Feb 7, 2023
@zjb0807 zjb0807 deleted the add-archive-params branch February 7, 2023 23:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants