Skip to content

Commit

Permalink
insert cached child at the front of a chain of parent lookups (sigp#4780
Browse files Browse the repository at this point in the history
)

* insert cached child at the front of a chain of parent lookups

* use vecdeque in parent lookup chain of blocks
  • Loading branch information
realbigsean authored Sep 29, 2023
1 parent 57edc0f commit 67aeb6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 7 additions & 5 deletions beacon_node/network/src/sync/block_lookups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use single_block_lookup::CachedChildComponents;
pub use single_block_lookup::{BlobRequestState, BlockRequestState};
use slog::{debug, error, trace, warn, Logger};
use smallvec::SmallVec;
use std::collections::HashMap;
use std::collections::{HashMap, VecDeque};
use std::fmt::Debug;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -1122,7 +1122,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
let (chain_hash, blocks, hashes, block_request) =
parent_lookup.parts_for_processing();

let blocks = self.add_child_block_to_chain(chain_hash, blocks, cx);
let blocks = self.add_child_block_to_chain(chain_hash, blocks, cx).into();

let process_id = ChainSegmentProcessId::ParentLookup(chain_hash);

Expand Down Expand Up @@ -1177,9 +1177,9 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
fn add_child_block_to_chain(
&mut self,
chain_hash: Hash256,
mut blocks: Vec<RpcBlock<T::EthSpec>>,
mut blocks: VecDeque<RpcBlock<T::EthSpec>>,
cx: &SyncNetworkContext<T>,
) -> Vec<RpcBlock<T::EthSpec>> {
) -> VecDeque<RpcBlock<T::EthSpec>> {
// Find the child block that spawned the parent lookup request and add it to the chain
// to send for processing.
if let Some(child_lookup_id) = self
Expand All @@ -1193,7 +1193,9 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
};
match child_lookup.get_cached_child_block() {
CachedChild::Ok(rpc_block) => {
blocks.push(rpc_block);
// Insert this block at the front. This order is important because we later check
// for linear roots in `filter_chain_segment`
blocks.push_front(rpc_block);
}
CachedChild::DownloadIncomplete => {
trace!(self.log, "Parent lookup chain complete, awaiting child response"; "chain_hash" => ?chain_hash);
Expand Down
7 changes: 4 additions & 3 deletions beacon_node/network/src/sync/block_lookups/parent_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use beacon_chain::data_availability_checker::DataAvailabilityChecker;
use beacon_chain::BeaconChainTypes;
use itertools::Itertools;
use lighthouse_network::PeerId;
use std::collections::VecDeque;
use std::sync::Arc;
use store::Hash256;
use strum::IntoStaticStr;
Expand Down Expand Up @@ -145,7 +146,7 @@ impl<T: BeaconChainTypes> ParentLookup<T> {
self,
) -> (
Hash256,
Vec<RpcBlock<T::EthSpec>>,
VecDeque<RpcBlock<T::EthSpec>>,
Vec<Hash256>,
SingleBlockLookup<Parent, T>,
) {
Expand All @@ -155,10 +156,10 @@ impl<T: BeaconChainTypes> ParentLookup<T> {
current_parent_request,
} = self;
let block_count = downloaded_blocks.len();
let mut blocks = Vec::with_capacity(block_count);
let mut blocks = VecDeque::with_capacity(block_count);
let mut hashes = Vec::with_capacity(block_count);
for (hash, block) in downloaded_blocks.into_iter() {
blocks.push(block);
blocks.push_back(block);
hashes.push(hash);
}
(chain_hash, blocks, hashes, current_parent_request)
Expand Down

0 comments on commit 67aeb6b

Please sign in to comment.