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

Commit 790f540

Browse files
committed
Prune discarded blocks immediately
1 parent 6b85535 commit 790f540

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

client/db/src/lib.rs

+25-18
Original file line numberDiff line numberDiff line change
@@ -1705,25 +1705,25 @@ impl<Block: BlockT> Backend<Block> {
17051705
let number = finalized.saturating_sub(keep.into());
17061706
self.prune_block(transaction, BlockId::<Block>::number(number))?;
17071707
}
1708+
}
17081709

1709-
// Also discard all blocks from displaced branches
1710-
for h in displaced.leaves() {
1711-
let mut number = finalized;
1712-
let mut hash = *h;
1713-
// Follow displaced chains back until we reach a finalized block.
1714-
// Since leaves are discarded due to finality, they can't have parents
1715-
// that are canonical, but not yet finalized. So we stop deleting as soon as
1716-
// we reach canonical chain.
1717-
while self.blockchain.hash(number)? != Some(hash) {
1718-
let id = BlockId::<Block>::hash(hash);
1719-
match self.blockchain.header(id)? {
1720-
Some(header) => {
1721-
self.prune_block(transaction, id)?;
1722-
number = header.number().saturating_sub(One::one());
1723-
hash = *header.parent_hash();
1724-
},
1725-
None => break,
1726-
}
1710+
// Discard all blocks from displaced (discarded) branches
1711+
for h in displaced.leaves() {
1712+
let mut number = finalized;
1713+
let mut hash = *h;
1714+
// Follow displaced chains back until we reach a finalized block.
1715+
// Since leaves are discarded due to finality, they can't have parents
1716+
// that are canonical, but not yet finalized. So we stop deleting as soon as
1717+
// we reach canonical chain.
1718+
while self.blockchain.hash(number)? != Some(hash) {
1719+
let id = BlockId::<Block>::hash(hash);
1720+
match self.blockchain.header(id)? {
1721+
Some(header) => {
1722+
self.prune_block(transaction, id)?;
1723+
number = header.number().saturating_sub(One::one());
1724+
hash = *header.parent_hash();
1725+
},
1726+
None => break,
17271727
}
17281728
}
17291729
}
@@ -1743,6 +1743,13 @@ impl<Block: BlockT> Backend<Block> {
17431743
columns::BODY,
17441744
id,
17451745
)?;
1746+
utils::remove_from_db(
1747+
transaction,
1748+
&*self.storage.db,
1749+
columns::KEY_LOOKUP,
1750+
columns::JUSTIFICATIONS,
1751+
id,
1752+
)?;
17461753
if let Some(index) =
17471754
read_db(&*self.storage.db, columns::KEY_LOOKUP, columns::BODY_INDEX, id)?
17481755
{

0 commit comments

Comments
 (0)