From 67aeb6bf6b1540c5f0342f69de629053fad44ccf Mon Sep 17 00:00:00 2001 From: realbigsean Date: Fri, 29 Sep 2023 12:55:12 -0400 Subject: [PATCH] insert cached child at the front of a chain of parent lookups (#4780) * insert cached child at the front of a chain of parent lookups * use vecdeque in parent lookup chain of blocks --- beacon_node/network/src/sync/block_lookups/mod.rs | 12 +++++++----- .../network/src/sync/block_lookups/parent_lookup.rs | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/beacon_node/network/src/sync/block_lookups/mod.rs b/beacon_node/network/src/sync/block_lookups/mod.rs index 2aa337e2f..aad300918 100644 --- a/beacon_node/network/src/sync/block_lookups/mod.rs +++ b/beacon_node/network/src/sync/block_lookups/mod.rs @@ -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; @@ -1122,7 +1122,7 @@ impl BlockLookups { 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); @@ -1177,9 +1177,9 @@ impl BlockLookups { fn add_child_block_to_chain( &mut self, chain_hash: Hash256, - mut blocks: Vec>, + mut blocks: VecDeque>, cx: &SyncNetworkContext, - ) -> Vec> { + ) -> VecDeque> { // 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 @@ -1193,7 +1193,9 @@ impl BlockLookups { }; 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); diff --git a/beacon_node/network/src/sync/block_lookups/parent_lookup.rs b/beacon_node/network/src/sync/block_lookups/parent_lookup.rs index 93f2615c0..2720ab0dd 100644 --- a/beacon_node/network/src/sync/block_lookups/parent_lookup.rs +++ b/beacon_node/network/src/sync/block_lookups/parent_lookup.rs @@ -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; @@ -145,7 +146,7 @@ impl ParentLookup { self, ) -> ( Hash256, - Vec>, + VecDeque>, Vec, SingleBlockLookup, ) { @@ -155,10 +156,10 @@ impl ParentLookup { 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)