Skip to content

Commit

Permalink
Merge of #5534
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Apr 9, 2024
2 parents b74da14 + 5714e8e commit 124ebc2
Show file tree
Hide file tree
Showing 8 changed files with 948 additions and 1,024 deletions.
3 changes: 3 additions & 0 deletions beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2498,6 +2498,7 @@ pub fn build_log(level: slog::Level, enabled: bool) -> Logger {

pub enum NumBlobs {
Random,
Number(usize),
None,
}

Expand All @@ -2518,6 +2519,7 @@ pub fn generate_rand_block_and_blobs<E: EthSpec>(
let payload: &mut FullPayloadDeneb<E> = &mut message.body.execution_payload;
let num_blobs = match num_blobs {
NumBlobs::Random => rng.gen_range(1..=E::max_blobs_per_block()),
NumBlobs::Number(n) => n,
NumBlobs::None => 0,
};
let (bundle, transactions) =
Expand All @@ -2537,6 +2539,7 @@ pub fn generate_rand_block_and_blobs<E: EthSpec>(
let payload: &mut FullPayloadElectra<E> = &mut message.body.execution_payload;
let num_blobs = match num_blobs {
NumBlobs::Random => rng.gen_range(1..=E::max_blobs_per_block()),
NumBlobs::Number(n) => n,
NumBlobs::None => 0,
};
let (bundle, transactions) =
Expand Down
15 changes: 15 additions & 0 deletions beacon_node/lighthouse_network/src/peer_manager/peerdb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::discovery::CombinedKey;
use crate::{metrics, multiaddr::Multiaddr, types::Subnet, Enr, Gossipsub, PeerId};
use peer_info::{ConnectionDirection, PeerConnectionStatus, PeerInfo};
use rand::seq::SliceRandom;
Expand Down Expand Up @@ -671,6 +672,20 @@ impl<E: EthSpec> PeerDB<E> {
);
}

/// Updates the connection state. MUST ONLY BE USED IN TESTS.
pub fn __add_connected_peer_testing_only(&mut self, peer_id: &PeerId) -> Option<BanOperation> {
let enr_key = CombinedKey::generate_secp256k1();
let enr = Enr::builder().build(&enr_key).unwrap();
self.update_connection_state(
peer_id,
NewConnectionState::Connected {
enr: Some(enr),
seen_address: Multiaddr::empty(),
direction: ConnectionDirection::Outgoing,
},
)
}

/// The connection state of the peer has been changed. Modify the peer in the db to ensure all
/// variables are in sync with libp2p.
/// Updating the state can lead to a `BanOperation` which needs to be processed via the peer
Expand Down
1 change: 1 addition & 0 deletions beacon_node/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ environment = { workspace = true }
disable-backfill = []
fork_from_env = ["beacon_chain/fork_from_env"]
portable = ["beacon_chain/portable"]
test_logger = []
23 changes: 6 additions & 17 deletions beacon_node/network/src/network_beacon_processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ use crate::{
sync::{manager::BlockProcessType, SyncMessage},
};
use beacon_chain::block_verification_types::RpcBlock;
use beacon_chain::{
builder::Witness, eth1_chain::CachingEth1Backend, test_utils::BeaconChainHarness, BeaconChain,
};
use beacon_chain::{builder::Witness, eth1_chain::CachingEth1Backend, BeaconChain};
use beacon_chain::{BeaconChainTypes, NotifyExecutionLayer};
use beacon_processor::{
work_reprocessing_queue::ReprocessQueueMessage, BeaconProcessorChannels, BeaconProcessorSend,
DuplicateCache, GossipAggregatePackage, GossipAttestationPackage, Work,
WorkEvent as BeaconWorkEvent,
};
use environment::null_logger;
use lighthouse_network::rpc::methods::{BlobsByRangeRequest, BlobsByRootRequest};
use lighthouse_network::{
rpc::{BlocksByRangeRequest, BlocksByRootRequest, LightClientBootstrapRequest, StatusMessage},
Expand All @@ -24,7 +21,6 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
use store::MemoryStore;
use task_executor::test_utils::TestRuntime;
use task_executor::TaskExecutor;
use tokio::sync::mpsc::{self, error::TrySendError};
use types::*;
Expand Down Expand Up @@ -667,6 +663,9 @@ impl<E: EthSpec> NetworkBeaconProcessor<TestBeaconChainType<E>> {
// processor (but not much else).
pub fn null_for_testing(
network_globals: Arc<NetworkGlobals<E>>,
chain: Arc<BeaconChain<TestBeaconChainType<E>>>,
executor: TaskExecutor,
log: Logger,
) -> (Self, mpsc::Receiver<BeaconWorkEvent<E>>) {
let BeaconProcessorChannels {
beacon_processor_tx,
Expand All @@ -677,27 +676,17 @@ impl<E: EthSpec> NetworkBeaconProcessor<TestBeaconChainType<E>> {

let (network_tx, _network_rx) = mpsc::unbounded_channel();
let (sync_tx, _sync_rx) = mpsc::unbounded_channel();
let log = null_logger().unwrap();
let harness: BeaconChainHarness<TestBeaconChainType<E>> =
BeaconChainHarness::builder(E::default())
.spec(E::default_spec())
.deterministic_keypairs(8)
.logger(log.clone())
.fresh_ephemeral_store()
.mock_execution_layer()
.build();
let runtime = TestRuntime::default();

let network_beacon_processor = Self {
beacon_processor_send: beacon_processor_tx,
duplicate_cache: DuplicateCache::default(),
chain: harness.chain,
chain,
network_tx,
sync_tx,
reprocess_tx: work_reprocessing_tx,
network_globals,
invalid_block_storage: InvalidBlockStorage::Disabled,
executor: runtime.task_executor.clone(),
executor,
log,
};

Expand Down
18 changes: 18 additions & 0 deletions beacon_node/network/src/sync/block_lookups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
}
}

#[cfg(test)]
pub(crate) fn active_single_lookups(&self) -> Vec<Id> {
self.single_block_lookups.keys().cloned().collect()
}

#[cfg(test)]
pub(crate) fn active_parent_lookups(&self) -> Vec<Hash256> {
self.parent_lookups
.iter()
.map(|r| r.chain_hash())
.collect::<Vec<_>>()
}

#[cfg(test)]
pub(crate) fn failed_chains_contains(&mut self, chain_hash: &Hash256) -> bool {
self.failed_chains.contains(chain_hash)
}

/* Lookup requests */

/// Creates a lookup for the block with the given `block_root` and immediately triggers it.
Expand Down
Loading

0 comments on commit 124ebc2

Please sign in to comment.