mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-21 23:08:23 +00:00
fix lints
This commit is contained in:
@@ -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<T> = (Hash256, BlockWrapper<T>);
|
||||
pub type RootBlockTuple<T> = (Hash256, Arc<SignedBeaconBlock<T>>);
|
||||
pub type RootBlobsTuple<T> = (Hash256, FixedBlobSidecarList<T>);
|
||||
|
||||
const FAILED_CHAINS_CACHE_EXPIRY_SECONDS: u64 = 60;
|
||||
const SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS: u8 = 3;
|
||||
@@ -802,7 +803,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
||||
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<T: BeaconChainTypes> BlockLookups<T> {
|
||||
fn send_blobs_for_processing(
|
||||
&self,
|
||||
block_root: Hash256,
|
||||
blobs: FixedVector<
|
||||
Option<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
<<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxBlobsPerBlock,
|
||||
>,
|
||||
blobs: FixedBlobSidecarList<T::EthSpec>,
|
||||
duration: Duration,
|
||||
process_type: BlockProcessType,
|
||||
cx: &mut SyncNetworkContext<T>,
|
||||
|
||||
@@ -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<T: BeaconChainTypes> ParentLookup<T> {
|
||||
pub fn add_blobs(
|
||||
&mut self,
|
||||
block_root: Hash256,
|
||||
blobs: FixedVector<
|
||||
Option<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
<<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxBlobsPerBlock,
|
||||
>,
|
||||
blobs: FixedBlobSidecarList<T::EthSpec>,
|
||||
) -> Result<LookupDownloadStatus<T::EthSpec>, ParentVerifyError> {
|
||||
self.current_parent_blob_request_id = None;
|
||||
self.current_parent_request
|
||||
@@ -290,16 +287,7 @@ impl<T: BeaconChainTypes> ParentLookup<T> {
|
||||
&mut self,
|
||||
blob: Option<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
failed_chains: &mut lru_cache::LRUTimeCache<Hash256>,
|
||||
) -> Result<
|
||||
Option<(
|
||||
Hash256,
|
||||
FixedVector<
|
||||
Option<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
<<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxBlobsPerBlock,
|
||||
>,
|
||||
)>,
|
||||
ParentVerifyError,
|
||||
> {
|
||||
) -> Result<Option<RootBlobsTuple<T::EthSpec>>, 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
|
||||
|
||||
@@ -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<const MAX_ATTEMPTS: u8, T: BeaconChainTypes> {
|
||||
pub requested_block_root: Hash256,
|
||||
pub requested_ids: Vec<BlobIdentifier>,
|
||||
pub downloaded_blobs: FixedVector<
|
||||
Option<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
<<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxBlobsPerBlock,
|
||||
>,
|
||||
pub downloaded_blobs: FixedBlobSidecarList<T::EthSpec>,
|
||||
pub downloaded_block: Option<Arc<SignedBeaconBlock<T::EthSpec>>>,
|
||||
pub block_request_state: SingleLookupRequestState<MAX_ATTEMPTS>,
|
||||
pub blob_request_state: SingleLookupRequestState<MAX_ATTEMPTS>,
|
||||
@@ -129,17 +126,14 @@ impl<const MAX_ATTEMPTS: u8, T: BeaconChainTypes> SingleBlockLookup<MAX_ATTEMPTS
|
||||
Ok(LookupDownloadStatus::SearchBlock(block_root))
|
||||
}
|
||||
} else {
|
||||
return Err(LookupVerifyError::InvalidIndex(blob.index));
|
||||
Err(LookupVerifyError::InvalidIndex(blob.index))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_blobs(
|
||||
&mut self,
|
||||
block_root: Hash256,
|
||||
blobs: FixedVector<
|
||||
Option<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
<<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxBlobsPerBlock,
|
||||
>,
|
||||
blobs: FixedBlobSidecarList<T::EthSpec>,
|
||||
) -> Result<LookupDownloadStatus<T::EthSpec>, 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<const MAX_ATTEMPTS: u8, T: BeaconChainTypes> SingleBlockLookup<MAX_ATTEMPTS
|
||||
pub fn verify_blob(
|
||||
&mut self,
|
||||
blob: Option<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
) -> Result<
|
||||
Option<(
|
||||
Hash256,
|
||||
FixedVector<
|
||||
Option<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
<<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxBlobsPerBlock,
|
||||
>,
|
||||
)>,
|
||||
LookupVerifyError,
|
||||
> {
|
||||
) -> Result<Option<RootBlobsTuple<T::EthSpec>>, LookupVerifyError> {
|
||||
match self.block_request_state.state {
|
||||
State::AwaitingDownload => {
|
||||
self.blob_request_state.register_failure_downloading();
|
||||
@@ -278,7 +263,7 @@ impl<const MAX_ATTEMPTS: u8, T: BeaconChainTypes> SingleBlockLookup<MAX_ATTEMPTS
|
||||
self.downloaded_blobs.clone(),
|
||||
)))
|
||||
} else {
|
||||
return Err(LookupVerifyError::InvalidIndex(blob.index));
|
||||
Err(LookupVerifyError::InvalidIndex(blob.index))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -515,7 +500,7 @@ mod tests {
|
||||
use store::MemoryStore;
|
||||
use types::{
|
||||
test_utils::{SeedableRng, TestRandom, XorShiftRng},
|
||||
MinimalEthSpec as E, SignedBeaconBlock, Slot,
|
||||
EthSpec, MinimalEthSpec as E, SignedBeaconBlock, Slot,
|
||||
};
|
||||
|
||||
fn rand_block() -> SignedBeaconBlock<E> {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user