Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make network globals available in da checker #5438

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions beacon_node/beacon_chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ hex = { workspace = true }
oneshot_broadcast = { path = "../../common/oneshot_broadcast/" }
slog-term = { workspace = true }
slog-async = { workspace = true }
lighthouse_network = { workspace = true }

[[test]]
name = "beacon_chain_tests"
Expand Down
15 changes: 15 additions & 0 deletions beacon_node/beacon_chain/src/data_availability_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::data_availability_checker::overflow_lru_cache::OverflowLRUCache;
use crate::data_availability_checker::processing_cache::ProcessingCache;
use crate::{BeaconChain, BeaconChainTypes, BeaconStore};
use kzg::Kzg;
use lighthouse_network::{Enr, NetworkGlobals};
use parking_lot::RwLock;
pub use processing_cache::ProcessingComponents;
use slasher::test_utils::E;
Expand Down Expand Up @@ -55,6 +56,7 @@ pub const STATE_LRU_CAPACITY: usize = STATE_LRU_CAPACITY_NON_ZERO.get();
pub struct DataAvailabilityChecker<T: BeaconChainTypes> {
processing_cache: RwLock<ProcessingCache<T::EthSpec>>,
availability_cache: Arc<OverflowLRUCache<T>>,
network_globals: RwLock<Option<Arc<NetworkGlobals<T::EthSpec>>>>,
slot_clock: T::SlotClock,
kzg: Option<Arc<Kzg>>,
log: Logger,
Expand Down Expand Up @@ -94,6 +96,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
Ok(Self {
processing_cache: <_>::default(),
availability_cache: Arc::new(overflow_cache),
network_globals: <_>::default(),
slot_clock,
log: log.clone(),
kzg,
Expand All @@ -106,6 +109,18 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
self.processing_cache.read().has_block(block_root)
}

pub fn set_network_globals(&self, network_globals: Arc<NetworkGlobals<T::EthSpec>>) {
let _ = self.network_globals.write().insert(network_globals);
}

pub fn get_local_enr(&self) -> Option<Enr> {
if let Some(network_globals) = self.network_globals.read().as_ref().or(None) {
return Some(network_globals.local_enr());
}

None
}

/// Get the processing info for a block.
pub fn get_processing_components(
&self,
Expand Down
7 changes: 5 additions & 2 deletions beacon_node/client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ where
};

let (network_globals, network_senders) = NetworkService::start(
beacon_chain,
beacon_chain.clone(),
config,
context.executor,
libp2p_registry.as_mut(),
Expand All @@ -652,9 +652,12 @@ where
.await
.map_err(|e| format!("Failed to start network: {:?}", e))?;

self.network_globals = Some(network_globals);
self.network_globals = Some(network_globals.clone());
self.network_senders = Some(network_senders);
self.libp2p_registry = libp2p_registry;
beacon_chain
.data_availability_checker
.set_network_globals(network_globals);

Ok(self)
}
Expand Down
10 changes: 10 additions & 0 deletions beacon_node/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ fn http_server_genesis_state() {

let node = build_node(&mut env);

let beacon_chain = node
.client
.beacon_chain()
.expect("client should have beacon chain");

beacon_chain
.data_availability_checker
.get_local_enr()
.expect("da checker should have access to network globals");

let remote_node = node.remote_node().expect("should produce remote node");

let api_state = env
Expand Down
Loading