Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(engine, tree): connect buffered blocks on pruner finish #4613

Merged
merged 5 commits into from
Sep 19, 2023

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Sep 15, 2023

Two main changes:

  1. Separate removing chains from blockchain tree and connecting buffered blocks to blockchain tree in restore_canonical_hashes, because we only need the buffered blocks part when pruner finishes.
  2. Rename restore_canonical_hashes to connect_buffered_blocks_to_canonical_hashes and restore_canonical_hashes_and_finalize to connect_buffered_blocks_to_canonical_hashes_and_finalize accordingly.

@codecov
Copy link

codecov bot commented Sep 18, 2023

Codecov Report

Merging #4613 (fcb3608) into main (d846199) will decrease coverage by 0.01%.
Report is 2 commits behind head on main.
The diff coverage is 100.00%.

Impacted file tree graph

Files Changed Coverage Δ
crates/consensus/beacon/src/engine/hooks/mod.rs 65.21% <ø> (ø)
crates/interfaces/src/blockchain_tree/mod.rs 42.10% <ø> (ø)
crates/blockchain-tree/src/blockchain_tree.rs 83.80% <100.00%> (+0.35%) ⬆️
crates/blockchain-tree/src/shareable.rs 56.52% <100.00%> (+0.31%) ⬆️
crates/consensus/beacon/src/engine/hooks/prune.rs 86.25% <100.00%> (ø)
crates/consensus/beacon/src/engine/mod.rs 74.42% <100.00%> (ø)
crates/storage/provider/src/providers/mod.rs 19.52% <100.00%> (ø)

... and 9 files with indirect coverage changes

Flag Coverage Δ
integration-tests 16.91% <0.00%> (-0.02%) ⬇️
unit-tests 63.24% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 32.17% <ø> (ø)
blockchain tree 83.75% <100.00%> (+0.16%) ⬆️
pipeline 88.52% <ø> (-0.02%) ⬇️
storage (db) 73.47% <100.00%> (ø)
trie 94.73% <ø> (ø)
txpool 49.91% <ø> (-0.02%) ⬇️
networking 77.20% <ø> (-0.02%) ⬇️
rpc 57.55% <ø> (-0.04%) ⬇️
consensus 62.58% <100.00%> (ø)
revm 19.66% <ø> (ø)
payload builder 9.06% <ø> (ø)
primitives 86.44% <ø> (ø)

@shekhirin shekhirin marked this pull request as ready for review September 18, 2023 17:41
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

what does this fix exactly?

Comment on lines +793 to +794
/// `N` is the `max_reorg_depth` plus the number of block hashes needed to satisfy the
/// `BLOCKHASH` opcode in the EVM.
Copy link
Collaborator

@mattsse mattsse Sep 18, 2023

Choose a reason for hiding this comment

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

I don't understand why we need this?

why do we need to store additional canonical hashes intended for execution in the tree?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

from my other PR, if I'm not mistaken:

/// It is calculated as the maximum of `max_reorg_depth` (which is the number of blocks required
/// for the deepest reorg possible according to the consensus protocol) and
/// `num_of_additional_canonical_block_hashes` (which is the number of block hashes needed to
/// satisfy the `BLOCKHASH` opcode in the EVM. See [`crate::BundleStateDataRef::block_hash`] and
/// [`crate::AppendableChain::new_canonical_head_fork`] where it's used).

@shekhirin
Copy link
Collaborator Author

@mattsse when we finish the pruner, we need to connect the blocks buffered during the pruning. We've already been doing it, but also doing this

let (mut remove_chains, _) =
self.block_indices.update_block_hashes(last_canonical_hashes.clone());
// remove all chains that got discarded
while let Some(chain_id) = remove_chains.first() {
if let Some(chain) = self.chains.remove(chain_id) {
remove_chains.extend(self.block_indices.remove_chain(&chain));
}
}
which is unnecessary, because canonical hashes in database didn't change while the pruner was running.

In case of scenario when the pipeline run is finished, we need to check the canonical hashes in database because they might've been changed:

/// Attempt to restore the tree with the given block hash.
///
/// This is invoked after a full pipeline to update the tree with the most recent canonical
/// hashes.
///
/// If the given block is missing from the database, this will return `false`. Otherwise, `true`
/// is returned: the database contains the hash and the tree was updated.
fn update_tree_on_finished_pipeline(&mut self, block_hash: H256) -> Result<bool, Error> {
let synced_to_finalized = match self.blockchain.block_number(block_hash)? {
Some(number) => {
// Attempt to restore the tree.
self.blockchain.restore_canonical_hashes_and_finalize(number)?;
true
}
None => false,
};
Ok(synced_to_finalized)
}


It wasn't a bug, we just did an unnecessary work and used one function for both cases (pipeline & pruner) which might be confusing.

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgmt, I like this naming better

Copy link
Collaborator

@rakita rakita left a comment

Choose a reason for hiding this comment

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

lgtm

@shekhirin shekhirin added this pull request to the merge queue Sep 19, 2023
Merged via the queue into main with commit 57c10e5 Sep 19, 2023
22 checks passed
@shekhirin shekhirin deleted the alexey/pruner-bt-update branch September 19, 2023 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants