Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 3 additions & 22 deletions crates/net/p2p/src/req_resp/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;

use ethlambda_storage::Store;
use libp2p::{PeerId, request_response};
Expand Down Expand Up @@ -269,29 +269,10 @@ fn canonical_blocks_by_range(store: &Store, start_slot: u64, count: u64) -> Vec<
return Vec::new();
};

let mut roots_by_slot = HashMap::new();
let mut current_root = store.head();

while !current_root.is_zero() {
let Some(header) = store.get_block_header(&current_root) else {
break;
};

if header.slot < start_slot {
break;
}

if header.slot <= end_slot {
roots_by_slot.insert(header.slot, current_root);
}

current_root = header.parent_root;
}

(start_slot..=end_slot)
.filter_map(|slot| {
let root = roots_by_slot.get(&slot)?;
store.get_signed_block(root)
let root = store.get_block_root_by_slot(slot)?;
store.get_signed_block(&root)
})
.collect()
}
Expand Down
6 changes: 5 additions & 1 deletion crates/storage/src/api/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub enum Table {
/// Stored separately from blocks because the genesis block has no signatures.
/// All other blocks must have an entry in this table.
BlockSignatures,
/// Canonical block index: slot -> block root
BlockRoots,
/// State storage: H256 -> State
///
/// Holds full-state snapshots only: the bootstrap anchor plus one anchor per
Expand All @@ -32,10 +34,11 @@ pub enum Table {
}

/// All table variants.
pub const ALL_TABLES: [Table; 7] = [
pub const ALL_TABLES: [Table; 8] = [
Table::BlockHeaders,
Table::BlockBodies,
Table::BlockSignatures,
Table::BlockRoots,
Table::States,
Table::StateDiffs,
Table::Metadata,
Expand All @@ -49,6 +52,7 @@ impl Table {
Table::BlockHeaders => "block_headers",
Table::BlockBodies => "block_bodies",
Table::BlockSignatures => "block_signatures",
Table::BlockRoots => "block_roots",
Table::States => "states",
Table::StateDiffs => "state_diffs",
Table::Metadata => "metadata",
Expand Down
Loading