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

Limit number of blocks per level (2nd attempt) #1559

Merged
merged 68 commits into from
Dec 20, 2022
Merged
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
b1db89b
Temporary hack to fetch leaves from parachain block import
davxy Jul 28, 2022
c211faa
Merge branch 'master' into davxy/remove-leaves
davxy Aug 1, 2022
e9bd438
Working temporary PoC implementation
davxy Aug 1, 2022
8aaf2e8
Merge branch 'master' into davxy/remove-leaves
davxy Aug 10, 2022
e0a7da1
TEMPORARY COMMIT
davxy Aug 10, 2022
48367c6
Test excercising leaves pruning feature
davxy Aug 11, 2022
0613b3b
Removed global backend hack and introduced configurable leaves level …
davxy Aug 12, 2022
0ddaedc
Cleanup
davxy Aug 12, 2022
e811887
Nitpicks
davxy Aug 12, 2022
be75d7b
Removed debug logs
davxy Aug 12, 2022
bd8852b
Adjust leaves per level default value to be equal to the substrate ba…
davxy Aug 12, 2022
5b299dd
Better docs
davxy Aug 12, 2022
6e3cef9
Don't rely on the backend implementation order for the leaves
davxy Aug 19, 2022
7437611
Merge branch 'master' into davxy/remove-leaves-portable
davxy Aug 19, 2022
7453fe0
Leaves monitoring code encapsulation
davxy Aug 19, 2022
45fc0d1
Fix panic for unsigned subtraction underflow
davxy Aug 19, 2022
12427d5
Cargo fmt
davxy Aug 19, 2022
b2c197f
Improval leaves cache insertion/deletion strategy
davxy Aug 21, 2022
0c81d6b
Apply suggestions from code review
davxy Aug 22, 2022
aabc69a
Fix to default level limit
davxy Aug 22, 2022
55e598e
Remove redundant type
davxy Aug 23, 2022
d939757
Allow removal of non-leaves blocks and restore from backend
davxy Aug 30, 2022
ca4b383
Encapsulate limit monitor in its own module
davxy Aug 30, 2022
9c13d60
Proper cleanup for descendants
davxy Aug 31, 2022
765b59a
Apply suggestions from code review
davxy Sep 1, 2022
ffeeb22
Optimization
davxy Sep 1, 2022
7e6ed47
Fix
davxy Sep 1, 2022
5dbfe14
Fix typo
davxy Sep 1, 2022
2d9242c
Nit. Rename some fresher to freshest
davxy Sep 1, 2022
eff06c5
Dedicated ParachainBlockImport constructor with explicit LevelLimit
davxy Sep 8, 2022
7a8d663
Apply suggestions from code review
davxy Sep 14, 2022
4f15278
Fmt
davxy Sep 14, 2022
cc60027
Fix typo
davxy Sep 14, 2022
48e0cc9
Apply suggestions from code review
davxy Sep 14, 2022
7b51bb0
Use block number instead of u64 for import counter
davxy Sep 14, 2022
a9d0b1e
Separate target find and removal logic
davxy Sep 14, 2022
27e8f04
Code adjustments
davxy Sep 14, 2022
b675d48
Refactory to reduce cognitive complexity
davxy Sep 15, 2022
5b5f1d0
Merge branch 'master' into davxy/remove-leaves-portable
davxy Sep 15, 2022
1029cff
Apply suggestions from code review
davxy Sep 28, 2022
1bc4e61
Fix type
davxy Sep 28, 2022
d8f1c84
Restore monitor within the constructor
davxy Sep 28, 2022
9766f86
Rename Monitor 'update' to 'block_imported'
davxy Sep 28, 2022
19695b4
Keep track of invalidated leaves
davxy Oct 1, 2022
77e2549
Check import before add block to the monitor
davxy Oct 1, 2022
8ecb772
Update test
davxy Oct 1, 2022
3d86b2e
Adjust log levels
davxy Oct 1, 2022
59fcb7a
[ci] Apply cargo-fmt
Oct 1, 2022
283d33b
Extra debugging logs
davxy Oct 5, 2022
fd939e9
Added target to debug logs
davxy Oct 5, 2022
bbde030
Report errors as such
davxy Oct 7, 2022
7dd4ebe
Added extra log to the monitor restore method
davxy Oct 13, 2022
c89b2c2
Merge branch 'master' into davxy/remove-leaves-portable
davxy Oct 13, 2022
f08c6e4
Fix after master merge
davxy Oct 13, 2022
3cd5d31
Bugfix: level monitor cache should use block 'post-hash'
davxy Oct 13, 2022
f0c18c1
TEMPORARY
davxy Oct 18, 2022
d945832
Merge branch 'master' into davxy/remove-leaves-portable
davxy Oct 21, 2022
01c37b7
Minor tweaks
davxy Oct 21, 2022
70c7c7e
Merge branch 'master' into davxy/remove-leaves-portable
davxy Nov 10, 2022
61304ec
Small code refactory
davxy Nov 11, 2022
e92d651
Invalidate leaf only on removal
davxy Nov 11, 2022
bc1643d
Removed temporary logs
davxy Nov 16, 2022
408580e
Explicit recovery for announced candidate blocks (#1891)
davxy Dec 9, 2022
f396157
Merge branch 'master' into davxy/remove-leaves-portable
davxy Dec 9, 2022
92bb6ac
Fix after master merge
davxy Dec 9, 2022
819ade6
Merge branch 'master' into davxy/remove-leaves-portable
davxy Dec 20, 2022
8886f67
Moved block recovery related types in pov-recovery crate
davxy Dec 20, 2022
0eff586
Fix after refactory
davxy Dec 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Nit. Rename some fresher to freshest
  • Loading branch information
davxy committed Sep 1, 2022
commit 2d9242c01a33686cb2cdb4b7fbc8cc506fc80441
22 changes: 11 additions & 11 deletions client/consensus/common/src/level_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ where
/// This will search for the less fresh block and removes it along with all its descendants.
/// Leaves should have already been ordered by "freshness" (older first).
fn remove_block(&mut self, number: NumberFor<Block>, leaves: &[Block::Hash]) {
let mut candidate_fresher_leaf_idx = usize::MAX;
let mut candidate_fresher_route = None;
let mut candidate_freshest_leaf_idx = usize::MAX;
let mut candidate_freshest_route = None;
davxy marked this conversation as resolved.
Show resolved Hide resolved

let blockchain = self.backend.blockchain();
let best_hash = blockchain.info().best_hash;
Expand All @@ -171,13 +171,13 @@ where
Ok(route) if route.retracted().is_empty() => {
// Skip this block if it is the ancestor of the best block or if it has
// a descendant leaf fresher (or equally fresh) than the current candidate.
if leaf_idx < candidate_fresher_leaf_idx &&
if leaf_idx < candidate_freshest_leaf_idx &&
route.common_block().hash != best_hash &&
route.enacted().iter().all(|entry| entry.hash != best_hash)
{
// We have a new candidate
candidate_fresher_leaf_idx = leaf_idx;
candidate_fresher_route = Some(route);
candidate_freshest_leaf_idx = leaf_idx;
candidate_freshest_route = Some(route);
}
break
},
Expand All @@ -191,20 +191,20 @@ where
_ => (),
};
}
if candidate_fresher_leaf_idx == 0 {
if candidate_freshest_leaf_idx == 0 {
// We can't find a candidate with an older leaf.
break
}
}

let candidate_fresher_route = match candidate_fresher_route {
let candidate_freshest_route = match candidate_freshest_route {
Some(route) => route,
None => return,
};

// We have a candidate, proceed removing the blocka and all its descendants.
// We have a candidate, proceed removing the block and all its descendants.

let candidate_hash = candidate_fresher_route.common_block().hash;
let candidate_hash = candidate_freshest_route.common_block().hash;

// Takes care of route removal. Starts from the leaf and stops as soon as an error is
// encountered. In this case an error is interpreted as the block being not a leaf
Expand All @@ -224,9 +224,9 @@ where
});
};

remove_route(candidate_fresher_route);
remove_route(candidate_freshest_route);

let to_skip = leaves.len() - candidate_fresher_leaf_idx;
let to_skip = leaves.len() - candidate_freshest_leaf_idx;
leaves.iter().rev().skip(to_skip).for_each(|leaf_hash| {
match sp_blockchain::tree_route(blockchain, candidate_hash, *leaf_hash) {
Ok(route) if route.retracted().is_empty() => {
Expand Down