diff --git a/beacon_node/beacon_chain/tests/attestation_production.rs b/beacon_node/beacon_chain/tests/attestation_production.rs index 5cab585b1..0b4744905 100644 --- a/beacon_node/beacon_chain/tests/attestation_production.rs +++ b/beacon_node/beacon_chain/tests/attestation_production.rs @@ -141,7 +141,7 @@ async fn produces_attestations() { .early_attester_cache .add_head_block( block_root, - Arc::new(block.clone()), + Arc::new(block.clone()).into(), None, proto_block, &state, @@ -198,7 +198,7 @@ async fn early_attester_cache_old_request() { .early_attester_cache .add_head_block( head.beacon_block_root, - head.beacon_block.clone(), + head.beacon_block.clone().into(), None, head_proto_block, &head.beacon_state, diff --git a/beacon_node/beacon_chain/tests/block_verification.rs b/beacon_node/beacon_chain/tests/block_verification.rs index 38a55e221..8bbdfa198 100644 --- a/beacon_node/beacon_chain/tests/block_verification.rs +++ b/beacon_node/beacon_chain/tests/block_verification.rs @@ -80,7 +80,7 @@ fn get_harness(validator_count: usize) -> BeaconChainHarness]) -> Vec>> { chain_segment .iter() - .map(|snapshot| snapshot.beacon_block.clone()) + .map(|snapshot| snapshot.beacon_block.clone().into()) .collect() } @@ -155,7 +155,7 @@ async fn chain_segment_full_segment() { harness .chain .process_chain_segment( - blocks.clone(), + blocks.clone().into(), CountUnrealized::True, NotifyExecutionLayer::Yes, ) @@ -188,7 +188,7 @@ async fn chain_segment_varying_chunk_size() { harness .chain .process_chain_segment( - chunk.to_vec(), + chunk.to_vec().into(), CountUnrealized::True, NotifyExecutionLayer::Yes, ) @@ -227,7 +227,11 @@ async fn chain_segment_non_linear_parent_roots() { matches!( harness .chain - .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) + .process_chain_segment( + blocks.into(), + CountUnrealized::True, + NotifyExecutionLayer::Yes + ) .await .into_block_error(), Err(BlockError::NonLinearParentRoots) @@ -247,7 +251,11 @@ async fn chain_segment_non_linear_parent_roots() { matches!( harness .chain - .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) + .process_chain_segment( + blocks.into(), + CountUnrealized::True, + NotifyExecutionLayer::Yes + ) .await .into_block_error(), Err(BlockError::NonLinearParentRoots) @@ -278,7 +286,11 @@ async fn chain_segment_non_linear_slots() { matches!( harness .chain - .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) + .process_chain_segment( + blocks.into(), + CountUnrealized::True, + NotifyExecutionLayer::Yes + ) .await .into_block_error(), Err(BlockError::NonLinearSlots) @@ -299,7 +311,11 @@ async fn chain_segment_non_linear_slots() { matches!( harness .chain - .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) + .process_chain_segment( + blocks.into(), + CountUnrealized::True, + NotifyExecutionLayer::Yes + ) .await .into_block_error(), Err(BlockError::NonLinearSlots) @@ -317,7 +333,7 @@ async fn assert_invalid_signature( ) { let blocks = snapshots .iter() - .map(|snapshot| snapshot.beacon_block.clone()) + .map(|snapshot| snapshot.beacon_block.clone().into()) .collect(); // Ensure the block will be rejected if imported in a chain segment. @@ -325,7 +341,11 @@ async fn assert_invalid_signature( matches!( harness .chain - .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) + .process_chain_segment( + blocks.into(), + CountUnrealized::True, + NotifyExecutionLayer::Yes + ) .await .into_block_error(), Err(BlockError::InvalidSignature) @@ -341,7 +361,7 @@ async fn assert_invalid_signature( let ancestor_blocks = chain_segment .iter() .take(block_index) - .map(|snapshot| snapshot.beacon_block.clone()) + .map(|snapshot| snapshot.beacon_block.clone().into()) .collect(); // We don't care if this fails, we just call this to ensure that all prior blocks have been // imported prior to this test. @@ -409,7 +429,7 @@ async fn invalid_signature_gossip_block() { let ancestor_blocks = chain_segment .iter() .take(block_index) - .map(|snapshot| snapshot.beacon_block.clone()) + .map(|snapshot| snapshot.beacon_block.clone().into()) .collect(); harness .chain @@ -457,14 +477,18 @@ async fn invalid_signature_block_proposal() { )); let blocks = snapshots .iter() - .map(|snapshot| snapshot.beacon_block.clone()) + .map(|snapshot| snapshot.beacon_block.clone().into()) .collect::>(); // Ensure the block will be rejected if imported in a chain segment. assert!( matches!( harness .chain - .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) + .process_chain_segment( + blocks.into(), + CountUnrealized::True, + NotifyExecutionLayer::Yes + ) .await .into_block_error(), Err(BlockError::InvalidSignature) @@ -656,13 +680,17 @@ async fn invalid_signature_deposit() { update_proposal_signatures(&mut snapshots, &harness); let blocks = snapshots .iter() - .map(|snapshot| snapshot.beacon_block.clone()) + .map(|snapshot| snapshot.beacon_block.clone().into()) .collect(); assert!( !matches!( harness .chain - .process_chain_segment(blocks, CountUnrealized::True, NotifyExecutionLayer::Yes) + .process_chain_segment( + blocks.into(), + CountUnrealized::True, + NotifyExecutionLayer::Yes + ) .await .into_block_error(), Err(BlockError::InvalidSignature) @@ -733,7 +761,7 @@ async fn block_gossip_verification() { for snapshot in &chain_segment[0..block_index] { let gossip_verified = harness .chain - .verify_block_for_gossip(snapshot.beacon_block.clone()) + .verify_block_for_gossip(snapshot.beacon_block.clone().into()) .await .expect("should obtain gossip verified block"); @@ -771,7 +799,7 @@ async fn block_gossip_verification() { *block.slot_mut() = expected_block_slot; assert!( matches!( - unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature))).await), + unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature)).into()).await), BlockError::FutureSlot { present_slot, block_slot, @@ -835,10 +863,9 @@ async fn block_gossip_verification() { unwrap_err( harness .chain - .verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block( - block, - junk_signature() - ))) + .verify_block_for_gossip( + Arc::new(SignedBeaconBlock::from_block(block, junk_signature())).into() + ) .await ), BlockError::ProposalSignatureInvalid @@ -863,7 +890,7 @@ async fn block_gossip_verification() { *block.parent_root_mut() = parent_root; assert!( matches!( - unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature))).await), + unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature)).into()).await), BlockError::ParentUnknown(block) if block.parent_root() == parent_root ), @@ -889,7 +916,7 @@ async fn block_gossip_verification() { *block.parent_root_mut() = parent_root; assert!( matches!( - unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature))).await), + unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature)).into()).await), BlockError::NotFinalizedDescendant { block_parent_root } if block_parent_root == parent_root ), @@ -927,7 +954,7 @@ async fn block_gossip_verification() { ); assert!( matches!( - unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone())).await), + unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone()).into()).await), BlockError::IncorrectBlockProposer { block, local_shuffling, @@ -939,7 +966,7 @@ async fn block_gossip_verification() { // Check to ensure that we registered this is a valid block from this proposer. assert!( matches!( - unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone())).await), + unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone()).into()).await), BlockError::RepeatProposal { proposer, slot, @@ -951,7 +978,11 @@ async fn block_gossip_verification() { let block = chain_segment[block_index].beacon_block.clone(); assert!( - harness.chain.verify_block_for_gossip(block).await.is_ok(), + harness + .chain + .verify_block_for_gossip(block.into()) + .await + .is_ok(), "the valid block should be processed" ); @@ -969,7 +1000,7 @@ async fn block_gossip_verification() { matches!( harness .chain - .verify_block_for_gossip(block.clone()) + .verify_block_for_gossip(block.clone().into()) .await .err() .expect("should error when processing known block"), @@ -1006,7 +1037,7 @@ async fn verify_block_for_gossip_slashing_detection() { let verified_block = harness .chain - .verify_block_for_gossip(Arc::new(block1)) + .verify_block_for_gossip(Arc::new(block1).into()) .await .unwrap(); harness @@ -1022,7 +1053,7 @@ async fn verify_block_for_gossip_slashing_detection() { unwrap_err( harness .chain - .verify_block_for_gossip(Arc::new(block2)) + .verify_block_for_gossip(Arc::new(block2).into()) .await, ); @@ -1045,7 +1076,7 @@ async fn verify_block_for_gossip_doppelganger_detection() { let verified_block = harness .chain - .verify_block_for_gossip(Arc::new(block)) + .verify_block_for_gossip(Arc::new(block).into()) .await .unwrap(); let attestations = verified_block.block.message().body().attestations().clone(); @@ -1184,7 +1215,7 @@ async fn add_base_block_to_altair_chain() { assert!(matches!( harness .chain - .verify_block_for_gossip(Arc::new(base_block.clone())) + .verify_block_for_gossip(Arc::new(base_block.clone()).into()) .await .err() .expect("should error when processing base block"), @@ -1218,7 +1249,7 @@ async fn add_base_block_to_altair_chain() { harness .chain .process_chain_segment( - vec![Arc::new(base_block)], + vec![Arc::new(base_block).into()], CountUnrealized::True, NotifyExecutionLayer::Yes, ) @@ -1322,7 +1353,7 @@ async fn add_altair_block_to_base_chain() { assert!(matches!( harness .chain - .verify_block_for_gossip(Arc::new(altair_block.clone())) + .verify_block_for_gossip(Arc::new(altair_block.clone()).into()) .await .err() .expect("should error when processing altair block"), @@ -1356,7 +1387,7 @@ async fn add_altair_block_to_base_chain() { harness .chain .process_chain_segment( - vec![Arc::new(altair_block)], + vec![Arc::new(altair_block).into()], CountUnrealized::True, NotifyExecutionLayer::Yes ) diff --git a/beacon_node/beacon_chain/tests/payload_invalidation.rs b/beacon_node/beacon_chain/tests/payload_invalidation.rs index 54d773447..d0f81652b 100644 --- a/beacon_node/beacon_chain/tests/payload_invalidation.rs +++ b/beacon_node/beacon_chain/tests/payload_invalidation.rs @@ -1040,7 +1040,7 @@ async fn invalid_parent() { // Ensure the block built atop an invalid payload is invalid for gossip. assert!(matches!( - rig.harness.chain.clone().verify_block_for_gossip(block.clone()).await, + rig.harness.chain.clone().verify_block_for_gossip(block.clone().into()).await, Err(BlockError::ParentExecutionPayloadInvalid { parent_root: invalid_root }) if invalid_root == parent_root )); diff --git a/beacon_node/network/src/beacon_processor/worker/gossip_methods.rs b/beacon_node/network/src/beacon_processor/worker/gossip_methods.rs index 5e84cbb5f..e406d7094 100644 --- a/beacon_node/network/src/beacon_processor/worker/gossip_methods.rs +++ b/beacon_node/network/src/beacon_processor/worker/gossip_methods.rs @@ -726,7 +726,7 @@ impl Worker { let verification_result = self .chain .clone() - .verify_block_for_gossip(block.clone()) + .verify_block_for_gossip(block.clone().into()) .await; let block_root = if let Ok(verified_block) = &verification_result { 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 8d5bd53ae..8aa414056 100644 --- a/beacon_node/network/src/beacon_processor/worker/sync_methods.rs +++ b/beacon_node/network/src/beacon_processor/worker/sync_methods.rs @@ -285,7 +285,7 @@ impl Worker { let blocks: Vec<_> = downloaded_blocks.cloned().collect(); match self .chain - .process_chain_segment(blocks, count_unrealized, notify_execution_layer) + .process_chain_segment(blocks.into(), count_unrealized, notify_execution_layer) .await { ChainSegmentResult::Successful { imported_blocks } => { diff --git a/beacon_node/network/src/sync/block_lookups/tests.rs b/beacon_node/network/src/sync/block_lookups/tests.rs index 48d02b4e7..a1dba588b 100644 --- a/beacon_node/network/src/sync/block_lookups/tests.rs +++ b/beacon_node/network/src/sync/block_lookups/tests.rs @@ -38,9 +38,11 @@ impl TestRig { fn test_setup(log_level: Option) -> (BlockLookups, SyncNetworkContext, Self) { let builder = NullLoggerBuilder; let log = builder.build().expect("should build logger"); - let store = store::HotColdDB::open_ephemeral(store::StoreConfig::default(), E::default_spec(), log).unwrap(); + let store = + store::HotColdDB::open_ephemeral(store::StoreConfig::default(), E::default_spec(), log) + .unwrap(); - // Initialise a new beacon chain from the finalized checkpoint + // Initialise a new beacon chain let chain = BeaconChainBuilder::new(E) .custom_spec(test_spec::()) .store(Arc::new(store)) diff --git a/beacon_node/network/src/sync/range_sync/range.rs b/beacon_node/network/src/sync/range_sync/range.rs index 358218541..b8d7b7edd 100644 --- a/beacon_node/network/src/sync/range_sync/range.rs +++ b/beacon_node/network/src/sync/range_sync/range.rs @@ -377,6 +377,7 @@ mod tests { use crate::beacon_processor::WorkEvent as BeaconWorkEvent; use crate::service::RequestId; use crate::NetworkMessage; + use beacon_chain::{builder::BeaconChainBuilder, test_utils::test_spec}; use beacon_chain::{ builder::Witness, eth1_chain::CachingEth1Backend, parking_lot::RwLock, EngineState, }; @@ -385,7 +386,9 @@ mod tests { NetworkGlobals, Request, }; use slog::{o, Drain}; - use slot_clock::SystemTimeSlotClock; + use sloggers::{null::NullLoggerBuilder, Build}; + use slot_clock::{SlotClock, SystemTimeSlotClock}; + use std::time::{Duration, SystemTime}; use std::{collections::HashSet, sync::Arc}; use store::MemoryStore; use tokio::sync::mpsc; @@ -590,11 +593,41 @@ mod tests { } fn range(log_enabled: bool) -> (TestRig, RangeSync) { - let chain = Arc::new(FakeStorage::default()); + let builder = NullLoggerBuilder; + let db_log = builder.build().expect("should build logger"); + let store = store::HotColdDB::open_ephemeral( + store::StoreConfig::default(), + E::default_spec(), + db_log, + ) + .unwrap(); + + // Initialise a new beacon chain from the finalized checkpoint + let chain = Arc::new( + BeaconChainBuilder::new(E) + .custom_spec(test_spec::()) + .store(Arc::new(store)) + .dummy_eth1_backend() + .expect("should build dummy backend") + .slot_clock(SystemTimeSlotClock::new( + types::Slot::new(0), + Duration::from_secs( + SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap() + .as_secs(), + ), + Duration::from_millis(400), + )) + .build() + .expect("should build"), + ); + let log = build_log(slog::Level::Trace, log_enabled); + let fake_store = Arc::new(FakeStorage::default()); let (beacon_processor_tx, beacon_processor_rx) = mpsc::channel(10); let range_sync = RangeSync::::new( - chain.clone(), + fake_store.clone(), log.new(o!("component" => "range")), ); let (network_tx, network_rx) = mpsc::unbounded_channel(); @@ -609,7 +642,7 @@ mod tests { let test_rig = TestRig { log, beacon_processor_rx, - chain, + chain: fake_store, cx, network_rx, globals, @@ -684,7 +717,7 @@ mod tests { range.add_peer(&mut rig.cx, local_info, peer1, head_info); let ((chain1, batch1), id1) = match rig.grab_request(&peer1).0 { RequestId::Sync(crate::sync::manager::RequestId::RangeBlocks { id }) => { - (rig.cx.range_sync_response(id, true).unwrap(), id) + (rig.cx.range_sync_block_response(id, true).unwrap(), id) } other => panic!("unexpected request {:?}", other), }; @@ -703,7 +736,7 @@ mod tests { range.add_peer(&mut rig.cx, local_info, peer2, finalized_info); let ((chain2, batch2), id2) = match rig.grab_request(&peer2).0 { RequestId::Sync(crate::sync::manager::RequestId::RangeBlocks { id }) => { - (rig.cx.range_sync_response(id, true).unwrap(), id) + (rig.cx.range_sync_block_response(id, true).unwrap(), id) } other => panic!("unexpected request {:?}", other), };