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

fix(tree): retain max(additional, max_reorg_depth) block hashes #4612

Merged
merged 7 commits into from
Sep 21, 2023

Conversation

shekhirin
Copy link
Collaborator

The actual number of canonical hashes we need to retain in memory is the maximum of how many is required for reorg (64) and for EVM execution (256). So it's 256.

@shekhirin shekhirin added C-debt Refactor of code section that is hard to understand or maintain A-blockchain-tree Related to sidechains, reorgs and pending blocks labels Sep 15, 2023
@shekhirin shekhirin marked this pull request as draft September 15, 2023 16:34
@shekhirin shekhirin changed the title fix(tree): retain max(additional_canonical_block_hashes, max_reorg_depth) block hashes fix(tree): retain max(additional, max_reorg_depth) block hashes Sep 15, 2023
@shekhirin shekhirin marked this pull request as ready for review September 15, 2023 16:40
@codecov
Copy link

codecov bot commented Sep 15, 2023

Codecov Report

Merging #4612 (f0a9486) into main (5be8ae4) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

Files Changed Coverage Δ
crates/interfaces/src/blockchain_tree/mod.rs 42.10% <ø> (ø)
crates/blockchain-tree/src/blockchain_tree.rs 83.71% <100.00%> (-0.10%) ⬇️
crates/blockchain-tree/src/config.rs 88.88% <100.00%> (+0.79%) ⬆️

... and 13 files with indirect coverage changes

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

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

Components Coverage Δ
reth binary 32.17% <ø> (ø)
blockchain tree 83.73% <100.00%> (-0.02%) ⬇️
pipeline 88.53% <ø> (ø)
storage (db) 72.52% <ø> (ø)
trie 94.73% <ø> (ø)
txpool 50.28% <ø> (+0.46%) ⬆️
networking 77.14% <ø> (ø)
rpc 57.83% <ø> (-0.01%) ⬇️
consensus 63.09% <ø> (ø)
revm 28.38% <ø> (ø)
payload builder 8.35% <ø> (ø)
primitives 86.53% <ø> (-0.02%) ⬇️

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.

hmm, I get 64+256 but why the tree needs this I'm not convinced, because they should still be in the database and therefore available during execution?

@onbjerg
Copy link
Member

onbjerg commented Sep 18, 2023

seconding matt, if the block is not covered by max_reorg_depth, then it is present in the db

@rakita
Copy link
Collaborator

rakita commented Sep 18, 2023

@mattsse @onbjerg It is inside db, but with this, it is cached in memory. In general, clients cache block hash values. if desired we can go without it.

@shekhirin
Copy link
Collaborator Author

@rakita I can't find the place where we check the cache in implementations of DatabaseRef::block_hash, is it used now?

@rakita
Copy link
Collaborator

rakita commented Sep 18, 2023

@rakita I can't find the place where we check the cache in implementations of DatabaseRef::block_hash, is it used now?

We clone the hashmap, as it is small, and use it inside I think BundleStateDataProvider

@shekhirin
Copy link
Collaborator Author

@rakita I can't find the place where we check the cache in implementations of DatabaseRef::block_hash, is it used now?

We clone the hashmap, as it is small, and use it inside I think BundleStateDataProvider

ah, I was still looking at the outdated revm API 😄 I see it now, thanks.

@shekhirin
Copy link
Collaborator Author

@mattsse @onbjerg I added the comments explaining the need for 256, lmk if my understanding is wrong.

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.

okay, I get it now,

my issue was that it wasn't obvious to me where we're passing the canonical hashes to the state provider.

I think worth adding a note to this type as well

/// This keeps track of all blocks of the canonical chain.
///
/// This is a wrapper type around an ordered set of block numbers and hashes that belong to the
/// canonical chain.
#[derive(Debug, Clone, Default)]
pub(crate) struct CanonicalChain {
/// All blocks of the canonical chain in order.
chain: BTreeMap<BlockNumber, BlockHash>,
}

@shekhirin shekhirin added this pull request to the merge queue Sep 21, 2023
Merged via the queue into main with commit acd7470 Sep 21, 2023
22 checks passed
@shekhirin shekhirin deleted the alexey/bt-number-of-canonical-block-hashes branch September 21, 2023 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-blockchain-tree Related to sidechains, reorgs and pending blocks C-debt Refactor of code section that is hard to understand or maintain
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants