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

Improve in memory block tracking #9752

Closed
Tracked by #8742
mattsse opened this issue Jul 24, 2024 · 0 comments · Fixed by #9773
Closed
Tracked by #8742

Improve in memory block tracking #9752

mattsse opened this issue Jul 24, 2024 · 0 comments · Fixed by #9773
Assignees
Labels
S-needs-design This issue requires design work to think about how it would best be accomplished

Comments

@mattsse
Copy link
Collaborator

mattsse commented Jul 24, 2024

The tree state contains all valid blocks including all sidechains

pub struct TreeState {
/// __All__ executed blocks by block hash.
///
/// This includes blocks of all forks.
blocks_by_hash: HashMap<B256, ExecutedBlock>,
/// Executed blocks grouped by their respective block number.
///
/// This maps unique block number to all known blocks for that height.
blocks_by_number: BTreeMap<BlockNumber, Vec<ExecutedBlock>>,

we need to update this on FCU and also detect reorgs

// walk back the chain until we reach the canonical block
while parent.hash != self.canonical_block_hash() {
if parent.number == self.canonical_head().number {
// we have a reorg
todo!("handle reorg")
}

with this data structure this no longer is trivial

we likely need an additional index that maps parent/child relationships, similar to

/// Map of any parent block hash (even the ones not currently in the buffer)
/// to the buffered children.
/// Allows connecting buffered blocks by parent.
pub(crate) parent_to_child: HashMap<BlockHash, HashSet<BlockHash>>,

so can easily travers a chain

@mattsse mattsse added the S-needs-design This issue requires design work to think about how it would best be accomplished label Jul 24, 2024
@fgimenez fgimenez self-assigned this Jul 24, 2024
@fgimenez fgimenez moved this from Todo to In Progress in Reth Tracker Jul 24, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-needs-design This issue requires design work to think about how it would best be accomplished
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants