From 83c3ee173fd9f6960c8863a7ecbb7900d3feff3c Mon Sep 17 00:00:00 2001 From: realbigsean Date: Wed, 26 Apr 2023 12:05:07 -0400 Subject: [PATCH] fix lints --- .../network/src/beacon_processor/mod.rs | 11 ++---- .../beacon_processor/worker/sync_methods.rs | 12 ++----- .../network/src/sync/block_lookups/mod.rs | 12 +++---- .../src/sync/block_lookups/parent_lookup.rs | 20 +++-------- .../sync/block_lookups/single_block_lookup.rs | 35 ++++++------------- .../network/src/sync/block_lookups/tests.rs | 8 ++--- beacon_node/network/src/sync/manager.rs | 32 ++++++++--------- 7 files changed, 44 insertions(+), 86 deletions(-) diff --git a/beacon_node/network/src/beacon_processor/mod.rs b/beacon_node/network/src/beacon_processor/mod.rs index 969a522ab1..64efc37776 100644 --- a/beacon_node/network/src/beacon_processor/mod.rs +++ b/beacon_node/network/src/beacon_processor/mod.rs @@ -65,6 +65,7 @@ use std::{cmp, collections::HashSet}; use task_executor::TaskExecutor; use tokio::sync::mpsc; use tokio::sync::mpsc::error::TrySendError; +use types::blob_sidecar::FixedBlobSidecarList; use types::{ Attestation, AttesterSlashing, BlobSidecar, EthSpec, Hash256, LightClientFinalityUpdate, LightClientOptimisticUpdate, ProposerSlashing, SignedAggregateAndProof, SignedBeaconBlock, @@ -632,10 +633,7 @@ impl WorkEvent { pub fn rpc_blobs( block_root: Hash256, - blobs: FixedVector< - Option>>, - <::EthSpec as EthSpec>::MaxBlobsPerBlock, - >, + blobs: FixedBlobSidecarList, seen_timestamp: Duration, process_type: BlockProcessType, ) -> Self { @@ -951,10 +949,7 @@ pub enum Work { }, RpcBlobs { block_root: Hash256, - blobs: FixedVector< - Option>>, - <::EthSpec as EthSpec>::MaxBlobsPerBlock, - >, + blobs: FixedBlobSidecarList, seen_timestamp: Duration, process_type: BlockProcessType, }, diff --git a/beacon_node/network/src/beacon_processor/worker/sync_methods.rs b/beacon_node/network/src/beacon_processor/worker/sync_methods.rs index 1946111067..e8c07d99b8 100644 --- a/beacon_node/network/src/beacon_processor/worker/sync_methods.rs +++ b/beacon_node/network/src/beacon_processor/worker/sync_methods.rs @@ -22,6 +22,7 @@ use ssz_types::FixedVector; use std::sync::Arc; use std::time::{SystemTime, UNIX_EPOCH}; use tokio::sync::mpsc; +use types::blob_sidecar::FixedBlobSidecarList; use types::{BlobSidecar, Epoch, EthSpec, Hash256, SignedBeaconBlock}; /// Id associated to a batch processing request, either a sync batch or a parent lookup. @@ -205,19 +206,12 @@ impl Worker { pub async fn process_rpc_blobs( self, block_root: Hash256, - blobs: FixedVector< - Option>>, - <::EthSpec as EthSpec>::MaxBlobsPerBlock, - >, + blobs: FixedBlobSidecarList, _seen_timestamp: Duration, process_type: BlockProcessType, ) { let Some(slot) = blobs.iter().find_map(|blob|{ - if let Some(blob) = blob { - Some(blob.slot) - } else { - None - } + blob.as_ref().map(|blob| blob.slot) }) else { return; }; diff --git a/beacon_node/network/src/sync/block_lookups/mod.rs b/beacon_node/network/src/sync/block_lookups/mod.rs index 7d909a90cc..b8ee17c652 100644 --- a/beacon_node/network/src/sync/block_lookups/mod.rs +++ b/beacon_node/network/src/sync/block_lookups/mod.rs @@ -6,13 +6,13 @@ use lighthouse_network::{PeerAction, PeerId}; use lru_cache::LRUTimeCache; use slog::{debug, error, trace, warn, Logger}; use smallvec::SmallVec; -use ssz_types::FixedVector; use std::collections::HashMap; use std::fmt::Debug; use std::sync::Arc; use std::time::Duration; use store::Hash256; -use types::{BlobSidecar, EthSpec, SignedBeaconBlock, Slot}; +use types::blob_sidecar::FixedBlobSidecarList; +use types::{BlobSidecar, SignedBeaconBlock, Slot}; use self::parent_lookup::{LookupDownloadStatus, PARENT_FAIL_TOLERANCE}; use self::parent_lookup::{ParentLookup, ParentVerifyError}; @@ -34,6 +34,7 @@ mod tests; pub type DownloadedBlocks = (Hash256, BlockWrapper); pub type RootBlockTuple = (Hash256, Arc>); +pub type RootBlobsTuple = (Hash256, FixedBlobSidecarList); const FAILED_CHAINS_CACHE_EXPIRY_SECONDS: u64 = 60; const SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS: u8 = 3; @@ -802,7 +803,7 @@ impl BlockLookups { block_id_opt .as_mut() .or(blob_id_opt.as_mut()) - .and_then(|id_ref| (*id_ref != id).then(|| (index, id_ref, req))) + .and_then(|id_ref| (*id_ref != id).then_some((index, id_ref, req))) }, ); let (index, request_id_ref, request_ref) = match lookup_components_opt { @@ -1161,10 +1162,7 @@ impl BlockLookups { fn send_blobs_for_processing( &self, block_root: Hash256, - blobs: FixedVector< - Option>>, - <::EthSpec as EthSpec>::MaxBlobsPerBlock, - >, + blobs: FixedBlobSidecarList, duration: Duration, process_type: BlockProcessType, cx: &mut SyncNetworkContext, 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 00f729885b..66b97ac8c7 100644 --- a/beacon_node/network/src/sync/block_lookups/parent_lookup.rs +++ b/beacon_node/network/src/sync/block_lookups/parent_lookup.rs @@ -1,6 +1,6 @@ use super::single_block_lookup::{LookupRequestError, LookupVerifyError, SingleBlockLookup}; use super::{DownloadedBlocks, PeerShouldHave, ResponseType}; -use crate::sync::block_lookups::{single_block_lookup, RootBlockTuple}; +use crate::sync::block_lookups::{single_block_lookup, RootBlobsTuple, RootBlockTuple}; use crate::sync::{ manager::{Id, SLOT_IMPORT_TOLERANCE}, network_context::SyncNetworkContext, @@ -10,10 +10,10 @@ use beacon_chain::blob_verification::BlockWrapper; use beacon_chain::data_availability_checker::DataAvailabilityChecker; use beacon_chain::BeaconChainTypes; use lighthouse_network::PeerId; -use ssz_types::FixedVector; use std::sync::Arc; use store::Hash256; use strum::IntoStaticStr; +use types::blob_sidecar::FixedBlobSidecarList; use types::{BlobSidecar, EthSpec, SignedBeaconBlock}; /// How many attempts we try to find a parent of a block before we give up trying. @@ -180,10 +180,7 @@ impl ParentLookup { pub fn add_blobs( &mut self, block_root: Hash256, - blobs: FixedVector< - Option>>, - <::EthSpec as EthSpec>::MaxBlobsPerBlock, - >, + blobs: FixedBlobSidecarList, ) -> Result, ParentVerifyError> { self.current_parent_blob_request_id = None; self.current_parent_request @@ -290,16 +287,7 @@ impl ParentLookup { &mut self, blob: Option>>, failed_chains: &mut lru_cache::LRUTimeCache, - ) -> Result< - Option<( - Hash256, - FixedVector< - Option>>, - <::EthSpec as EthSpec>::MaxBlobsPerBlock, - >, - )>, - ParentVerifyError, - > { + ) -> Result>, ParentVerifyError> { let blobs = self.current_parent_request.verify_blob(blob)?; // check if the parent of this block isn't in the failed cache. If it is, this chain should diff --git a/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs b/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs index 1921e9acab..eb90f8b467 100644 --- a/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs +++ b/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs @@ -1,28 +1,25 @@ use crate::sync::block_lookups::parent_lookup::LookupDownloadStatus; -use crate::sync::block_lookups::RootBlockTuple; +use crate::sync::block_lookups::{RootBlobsTuple, RootBlockTuple}; use beacon_chain::blob_verification::BlockWrapper; use beacon_chain::data_availability_checker::{AvailabilityCheckError, DataAvailabilityChecker}; use beacon_chain::{get_block_root, BeaconChainTypes}; use lighthouse_network::rpc::methods::BlobsByRootRequest; use lighthouse_network::{rpc::BlocksByRootRequest, PeerId}; use rand::seq::IteratorRandom; -use ssz_types::{FixedVector, VariableList}; +use ssz_types::VariableList; use std::collections::HashSet; use std::sync::Arc; use store::Hash256; use strum::IntoStaticStr; -use types::blob_sidecar::BlobIdentifier; -use types::{BlobSidecar, EthSpec, SignedBeaconBlock}; +use types::blob_sidecar::{BlobIdentifier, FixedBlobSidecarList}; +use types::{BlobSidecar, SignedBeaconBlock}; use super::{PeerShouldHave, ResponseType}; pub struct SingleBlockLookup { pub requested_block_root: Hash256, pub requested_ids: Vec, - pub downloaded_blobs: FixedVector< - Option>>, - <::EthSpec as EthSpec>::MaxBlobsPerBlock, - >, + pub downloaded_blobs: FixedBlobSidecarList, pub downloaded_block: Option>>, pub block_request_state: SingleLookupRequestState, pub blob_request_state: SingleLookupRequestState, @@ -129,17 +126,14 @@ impl SingleBlockLookup>>, - <::EthSpec as EthSpec>::MaxBlobsPerBlock, - >, + blobs: FixedBlobSidecarList, ) -> Result, LookupVerifyError> { for (index, blob_opt) in self.downloaded_blobs.iter_mut().enumerate() { if let Some(Some(downloaded_blob)) = blobs.get(index) { @@ -247,16 +241,7 @@ impl SingleBlockLookup>>, - ) -> Result< - Option<( - Hash256, - FixedVector< - Option>>, - <::EthSpec as EthSpec>::MaxBlobsPerBlock, - >, - )>, - LookupVerifyError, - > { + ) -> Result>, LookupVerifyError> { match self.block_request_state.state { State::AwaitingDownload => { self.blob_request_state.register_failure_downloading(); @@ -278,7 +263,7 @@ impl SingleBlockLookup SignedBeaconBlock { diff --git a/beacon_node/network/src/sync/block_lookups/tests.rs b/beacon_node/network/src/sync/block_lookups/tests.rs index 5b55e6190d..fe5db49a6f 100644 --- a/beacon_node/network/src/sync/block_lookups/tests.rs +++ b/beacon_node/network/src/sync/block_lookups/tests.rs @@ -262,7 +262,7 @@ fn test_single_block_lookup_failure() { fn test_single_block_lookup_becomes_parent_request() { let (mut bl, mut cx, mut rig) = TestRig::test_setup(false); - let block = rig.rand_block(); + let block = Arc::new(rig.rand_block()); let peer_id = PeerId::random(); // Trigger the request @@ -276,7 +276,7 @@ fn test_single_block_lookup_becomes_parent_request() { // The peer provides the correct block, should not be penalized. Now the block should be sent // for processing. - bl.single_block_lookup_response(id, peer_id, Some(block.clone().into()), D, &mut cx); + bl.single_block_lookup_response(id, peer_id, Some(block.clone()), D, &mut cx); rig.expect_empty_network(); rig.expect_block_process(); @@ -637,7 +637,7 @@ fn test_parent_lookup_too_deep() { for block in blocks.into_iter().rev() { let id = rig.expect_parent_request(); // the block - bl.parent_lookup_response(id, peer_id, Some(block.clone().into()), D, &mut cx); + bl.parent_lookup_response(id, peer_id, Some(block.clone()), D, &mut cx); // the stream termination bl.parent_lookup_response(id, peer_id, None, D, &mut cx); // the processing request @@ -798,7 +798,7 @@ fn test_same_chain_race_condition() { for (i, block) in blocks.into_iter().rev().enumerate() { let id = rig.expect_parent_request(); // the block - bl.parent_lookup_response(id, peer_id, Some(block.clone().into()), D, &mut cx); + bl.parent_lookup_response(id, peer_id, Some(block.clone()), D, &mut cx); // the stream termination bl.parent_lookup_response(id, peer_id, None, D, &mut cx); // the processing request diff --git a/beacon_node/network/src/sync/manager.rs b/beacon_node/network/src/sync/manager.rs index 8c37dd284e..6334f0c269 100644 --- a/beacon_node/network/src/sync/manager.rs +++ b/beacon_node/network/src/sync/manager.rs @@ -790,21 +790,19 @@ impl SyncManager { .chain .slot_clock .now_with_future_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY); - let should_delay_lookup = - if let (Some(earliest_slot), Some(latest_slot)) = (earliest_slot, latest_slot) { - let msg_for_current_slot = slot >= earliest_slot && slot <= latest_slot; - let delay_threshold_unmet = self - .chain - .slot_clock - .seconds_from_current_slot_start() - .map_or(false, |secs_into_slot| { - secs_into_slot < self.chain.slot_clock.unagg_attestation_production_delay() - }); - msg_for_current_slot && delay_threshold_unmet - } else { - false - }; - should_delay_lookup + if let (Some(earliest_slot), Some(latest_slot)) = (earliest_slot, latest_slot) { + let msg_for_current_slot = slot >= earliest_slot && slot <= latest_slot; + let delay_threshold_unmet = self + .chain + .slot_clock + .seconds_from_current_slot_start() + .map_or(false, |secs_into_slot| { + secs_into_slot < self.chain.slot_clock.unagg_attestation_production_delay() + }); + msg_for_current_slot && delay_threshold_unmet + } else { + false + } } fn synced_and_connected_within_tolerance( @@ -826,13 +824,13 @@ impl SyncManager { } } - self.network_globals.peers.read().is_connected(&peer_id) + self.network_globals.peers.read().is_connected(peer_id) && self.network.is_execution_engine_online() } fn synced_and_connected(&mut self, peer_id: &PeerId) -> bool { self.network_globals.sync_state.read().is_synced() - && self.network_globals.peers.read().is_connected(&peer_id) + && self.network_globals.peers.read().is_connected(peer_id) && self.network.is_execution_engine_online() }