mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-29 20:27:14 +00:00
Improve single-node testnet support and Arc NetworkConfig/ChainSpec (#6396)
* Arc ChainSpec and NetworkConfig * Fix release tests * Fix lint * Merge remote-tracking branch 'origin/unstable' into single-node-testnet
This commit is contained in:
@@ -21,7 +21,7 @@ use lighthouse_network::{
|
||||
discv5::enr::{self, CombinedKey},
|
||||
rpc::methods::{MetaData, MetaDataV2},
|
||||
types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield},
|
||||
Client, MessageId, NetworkGlobals, PeerId, Response,
|
||||
Client, MessageId, NetworkConfig, NetworkGlobals, PeerId, Response,
|
||||
};
|
||||
use slot_clock::SlotClock;
|
||||
use std::iter::Iterator;
|
||||
@@ -91,6 +91,7 @@ impl TestRig {
|
||||
// This allows for testing voluntary exits without building out a massive chain.
|
||||
let mut spec = test_spec::<E>();
|
||||
spec.shard_committee_period = 2;
|
||||
let spec = Arc::new(spec);
|
||||
|
||||
let harness = BeaconChainHarness::builder(MainnetEthSpec)
|
||||
.spec(spec.clone())
|
||||
@@ -204,12 +205,14 @@ impl TestRig {
|
||||
});
|
||||
let enr_key = CombinedKey::generate_secp256k1();
|
||||
let enr = enr::Enr::builder().build(&enr_key).unwrap();
|
||||
let network_config = Arc::new(NetworkConfig::default());
|
||||
let network_globals = Arc::new(NetworkGlobals::new(
|
||||
enr,
|
||||
meta_data,
|
||||
vec![],
|
||||
false,
|
||||
&log,
|
||||
network_config,
|
||||
spec,
|
||||
));
|
||||
|
||||
|
||||
@@ -81,7 +81,8 @@ mod tests {
|
||||
MinimalEthSpec,
|
||||
MemoryStore<MinimalEthSpec>,
|
||||
MemoryStore<MinimalEthSpec>,
|
||||
> = HotColdDB::open_ephemeral(StoreConfig::default(), ChainSpec::minimal(), log).unwrap();
|
||||
> = HotColdDB::open_ephemeral(StoreConfig::default(), ChainSpec::minimal().into(), log)
|
||||
.unwrap();
|
||||
let enrs = vec![Enr::from_str("enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOonrkTfj499SZuOh8R33Ls8RRcy5wBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA8yWM0xOIN1ZHCCdl8").unwrap()];
|
||||
store
|
||||
.put_item(&DHT_DB_KEY, &PersistedDht { enrs: enrs.clone() })
|
||||
|
||||
@@ -205,7 +205,7 @@ pub struct NetworkService<T: BeaconChainTypes> {
|
||||
impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
async fn build(
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
config: &NetworkConfig,
|
||||
config: Arc<NetworkConfig>,
|
||||
executor: task_executor::TaskExecutor,
|
||||
libp2p_registry: Option<&'_ mut Registry>,
|
||||
beacon_processor_send: BeaconProcessorSend<T::EthSpec>,
|
||||
@@ -271,10 +271,10 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
|
||||
// construct the libp2p service context
|
||||
let service_context = Context {
|
||||
config,
|
||||
config: config.clone(),
|
||||
enr_fork_id,
|
||||
fork_context: fork_context.clone(),
|
||||
chain_spec: &beacon_chain.spec,
|
||||
chain_spec: beacon_chain.spec.clone(),
|
||||
libp2p_registry,
|
||||
};
|
||||
|
||||
@@ -318,12 +318,12 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
let attestation_service = AttestationService::new(
|
||||
beacon_chain.clone(),
|
||||
network_globals.local_enr().node_id(),
|
||||
config,
|
||||
&config,
|
||||
&network_log,
|
||||
);
|
||||
// sync committee subnet service
|
||||
let sync_committee_service =
|
||||
SyncCommitteeService::new(beacon_chain.clone(), config, &network_log);
|
||||
SyncCommitteeService::new(beacon_chain.clone(), &config, &network_log);
|
||||
|
||||
// create a timer for updating network metrics
|
||||
let metrics_update = tokio::time::interval(Duration::from_secs(METRIC_UPDATE_INTERVAL));
|
||||
@@ -368,7 +368,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub async fn start(
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
config: &NetworkConfig,
|
||||
config: Arc<NetworkConfig>,
|
||||
executor: task_executor::TaskExecutor,
|
||||
libp2p_registry: Option<&'_ mut Registry>,
|
||||
beacon_processor_send: BeaconProcessorSend<T::EthSpec>,
|
||||
|
||||
@@ -73,6 +73,7 @@ mod tests {
|
||||
config.discv5_config.table_filter = |_| true; // Do not ignore local IPs
|
||||
config.upnp_enabled = false;
|
||||
config.boot_nodes_enr = enrs.clone();
|
||||
let config = Arc::new(config);
|
||||
runtime.block_on(async move {
|
||||
// Create a new network service which implicitly gets dropped at the
|
||||
// end of the block.
|
||||
@@ -86,7 +87,7 @@ mod tests {
|
||||
|
||||
let _network_service = NetworkService::start(
|
||||
beacon_chain.clone(),
|
||||
&config,
|
||||
config,
|
||||
executor,
|
||||
None,
|
||||
beacon_processor_tx,
|
||||
@@ -125,7 +126,7 @@ mod tests {
|
||||
|
||||
// Build beacon chain.
|
||||
let beacon_chain = BeaconChainHarness::builder(MinimalEthSpec)
|
||||
.spec(spec.clone())
|
||||
.spec(spec.clone().into())
|
||||
.deterministic_keypairs(8)
|
||||
.fresh_ephemeral_store()
|
||||
.mock_execution_layer()
|
||||
@@ -149,12 +150,13 @@ mod tests {
|
||||
config.set_ipv4_listening_address(std::net::Ipv4Addr::UNSPECIFIED, 21214, 21214, 21215);
|
||||
config.discv5_config.table_filter = |_| true; // Do not ignore local IPs
|
||||
config.upnp_enabled = false;
|
||||
let config = Arc::new(config);
|
||||
|
||||
let beacon_processor_channels =
|
||||
BeaconProcessorChannels::new(&BeaconProcessorConfig::default());
|
||||
NetworkService::build(
|
||||
beacon_chain.clone(),
|
||||
&config,
|
||||
config,
|
||||
executor.clone(),
|
||||
None,
|
||||
beacon_processor_channels.beacon_processor_tx,
|
||||
|
||||
@@ -38,7 +38,7 @@ pub struct TestBeaconChain {
|
||||
|
||||
impl TestBeaconChain {
|
||||
pub fn new_with_system_clock() -> Self {
|
||||
let spec = MainnetEthSpec::default_spec();
|
||||
let spec = Arc::new(MainnetEthSpec::default_spec());
|
||||
|
||||
let keypairs = generate_deterministic_keypairs(1);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ use lighthouse_network::service::api_types::{
|
||||
SyncRequestId,
|
||||
};
|
||||
use lighthouse_network::types::SyncState;
|
||||
use lighthouse_network::{NetworkGlobals, Request};
|
||||
use lighthouse_network::{NetworkConfig, NetworkGlobals, Request};
|
||||
use slog::info;
|
||||
use slot_clock::{ManualSlotClock, SlotClock, TestingSlotClock};
|
||||
use store::MemoryStore;
|
||||
@@ -116,7 +116,7 @@ impl TestRig {
|
||||
|
||||
// Initialise a new beacon chain
|
||||
let harness = BeaconChainHarness::<EphemeralHarnessType<E>>::builder(E)
|
||||
.spec(spec)
|
||||
.spec(Arc::new(spec))
|
||||
.logger(log.clone())
|
||||
.deterministic_keypairs(1)
|
||||
.fresh_ephemeral_store()
|
||||
@@ -132,9 +132,11 @@ impl TestRig {
|
||||
let (network_tx, network_rx) = mpsc::unbounded_channel();
|
||||
// TODO(das): make the generation of the ENR use the deterministic rng to have consistent
|
||||
// column assignments
|
||||
let network_config = Arc::new(NetworkConfig::default());
|
||||
let globals = Arc::new(NetworkGlobals::new_test_globals(
|
||||
Vec::new(),
|
||||
&log,
|
||||
network_config,
|
||||
chain.spec.clone(),
|
||||
));
|
||||
let (beacon_processor, beacon_processor_rx) = NetworkBeaconProcessor::null_for_testing(
|
||||
|
||||
@@ -51,8 +51,7 @@ use beacon_chain::block_verification_types::RpcBlock;
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use lighthouse_network::rpc::GoodbyeReason;
|
||||
use lighthouse_network::service::api_types::Id;
|
||||
use lighthouse_network::PeerId;
|
||||
use lighthouse_network::SyncInfo;
|
||||
use lighthouse_network::{PeerId, SyncInfo};
|
||||
use lru_cache::LRUTimeCache;
|
||||
use slog::{crit, debug, trace, warn};
|
||||
use std::collections::HashMap;
|
||||
@@ -399,7 +398,7 @@ mod tests {
|
||||
use beacon_processor::WorkEvent as BeaconWorkEvent;
|
||||
use lighthouse_network::service::api_types::SyncRequestId;
|
||||
use lighthouse_network::{
|
||||
rpc::StatusMessage, service::api_types::AppRequestId, NetworkGlobals,
|
||||
rpc::StatusMessage, service::api_types::AppRequestId, NetworkConfig, NetworkGlobals,
|
||||
};
|
||||
use slog::{o, Drain};
|
||||
use slot_clock::TestingSlotClock;
|
||||
@@ -692,9 +691,11 @@ mod tests {
|
||||
log.new(o!("component" => "range")),
|
||||
);
|
||||
let (network_tx, network_rx) = mpsc::unbounded_channel();
|
||||
let network_config = Arc::new(NetworkConfig::default());
|
||||
let globals = Arc::new(NetworkGlobals::new_test_globals(
|
||||
Vec::new(),
|
||||
&log,
|
||||
network_config,
|
||||
chain.spec.clone(),
|
||||
));
|
||||
let (network_beacon_processor, beacon_processor_rx) =
|
||||
|
||||
Reference in New Issue
Block a user