Add beacon_chain_sim

This commit is contained in:
Paul Hauner
2019-11-19 13:29:29 +11:00
parent c5071afdbc
commit 90d63a46c7
6 changed files with 113 additions and 15 deletions

View File

@@ -1,13 +1,12 @@
use beacon_node::{
beacon_chain::BeaconChainTypes, Client, ClientConfig, ClientGenesis, ProductionBeaconNode,
ProductionClient,
};
use beacon_node::{beacon_chain::BeaconChainTypes, Client, ClientGenesis, ProductionBeaconNode};
use environment::RuntimeContext;
use futures::Future;
use remote_beacon_node::RemoteBeaconNode;
use std::path::PathBuf;
use tempdir::TempDir;
use types::EthSpec;
pub use beacon_node::{ClientConfig, ProductionClient};
pub use environment;
/// Provides a beacon node that is running in the current process. Useful for testing purposes.
@@ -18,8 +17,13 @@ pub struct LocalBeaconNode<T> {
impl<E: EthSpec> LocalBeaconNode<ProductionClient<E>> {
/// Starts a new, production beacon node.
pub fn production(context: RuntimeContext<E>) -> Self {
let (client_config, datadir) = testing_client_config();
pub fn production(context: RuntimeContext<E>, mut client_config: ClientConfig) -> Self {
// Creates a temporary directory that will be deleted once this `TempDir` is dropped.
let datadir = TempDir::new("lighthouse_node_test_rig")
.expect("should create temp directory for client datadir");
client_config.data_dir = datadir.path().into();
client_config.network.network_dir = PathBuf::from(datadir.path()).join("network");
let client = ProductionBeaconNode::new(context, client_config)
.wait()
@@ -42,15 +46,9 @@ impl<T: BeaconChainTypes> LocalBeaconNode<Client<T>> {
}
}
fn testing_client_config() -> (ClientConfig, TempDir) {
// Creates a temporary directory that will be deleted once this `TempDir` is dropped.
let tempdir = TempDir::new("lighthouse_node_test_rig")
.expect("should create temp directory for client datadir");
pub fn testing_client_config() -> ClientConfig {
let mut client_config = ClientConfig::default();
client_config.data_dir = tempdir.path().into();
// Setting ports to `0` means that the OS will choose some available port.
client_config.network.libp2p_port = 0;
client_config.network.discovery_port = 0;
@@ -63,5 +61,5 @@ fn testing_client_config() -> (ClientConfig, TempDir) {
genesis_time: 13_371_337,
};
(client_config, tempdir)
client_config
}