mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 11:52:42 +00:00
Merge branch 'deposit-flow' into kill-grpc
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
use beacon_node::{
|
||||
beacon_chain::BeaconChainTypes, Client, ClientConfig, ClientGenesis, ProductionBeaconNode,
|
||||
ProductionClient,
|
||||
};
|
||||
use beacon_node::{beacon_chain::BeaconChainTypes, Client, ProductionBeaconNode};
|
||||
use environment::RuntimeContext;
|
||||
use futures::Future;
|
||||
use remote_beacon_node::RemoteBeaconNode;
|
||||
use std::path::PathBuf;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use tempdir::TempDir;
|
||||
use types::EthSpec;
|
||||
use validator_client::{validator_directory::ValidatorDirectoryBuilder, ProductionValidatorClient};
|
||||
|
||||
pub use beacon_node::{ClientConfig, ClientGenesis, ProductionClient};
|
||||
pub use environment;
|
||||
pub use validator_client::Config as ValidatorConfig;
|
||||
|
||||
/// Provides a beacon node that is running in the current process. Useful for testing purposes.
|
||||
/// Provides a beacon node that is running in the current process (i.e., local). Useful for testing
|
||||
/// purposes.
|
||||
pub struct LocalBeaconNode<T> {
|
||||
pub client: T,
|
||||
pub datadir: TempDir,
|
||||
@@ -18,8 +21,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,28 +50,84 @@ 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;
|
||||
client_config.rpc.port = 0;
|
||||
client_config.rest_api.port = 0;
|
||||
client_config.websocket_server.port = 0;
|
||||
|
||||
client_config.dummy_eth1_backend = true;
|
||||
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.expect("should get system time")
|
||||
.as_secs();
|
||||
|
||||
client_config.genesis = ClientGenesis::Interop {
|
||||
validator_count: 8,
|
||||
genesis_time: 13_371_337,
|
||||
genesis_time: now,
|
||||
};
|
||||
|
||||
client_config.dummy_eth1_backend = true;
|
||||
|
||||
(client_config, tempdir)
|
||||
client_config
|
||||
}
|
||||
|
||||
pub struct LocalValidatorClient<T: EthSpec> {
|
||||
pub client: ProductionValidatorClient<T>,
|
||||
pub datadir: TempDir,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> LocalValidatorClient<E> {
|
||||
pub fn production_with_insecure_keypairs(
|
||||
context: RuntimeContext<E>,
|
||||
config: ValidatorConfig,
|
||||
keypair_indices: &[usize],
|
||||
) -> Self {
|
||||
// Creates a temporary directory that will be deleted once this `TempDir` is dropped.
|
||||
let datadir = TempDir::new("lighthouse-beacon-node")
|
||||
.expect("should create temp directory for client datadir");
|
||||
|
||||
keypair_indices.iter().for_each(|i| {
|
||||
ValidatorDirectoryBuilder::default()
|
||||
.spec(context.eth2_config.spec.clone())
|
||||
.full_deposit_amount()
|
||||
.expect("should set full deposit amount")
|
||||
.insecure_keypairs(*i)
|
||||
.create_directory(PathBuf::from(datadir.path()))
|
||||
.expect("should create directory")
|
||||
.write_keypair_files()
|
||||
.expect("should write keypair files")
|
||||
.write_eth1_data_file()
|
||||
.expect("should write eth1 data file")
|
||||
.build()
|
||||
.expect("should build dir");
|
||||
});
|
||||
|
||||
Self::new(context, config, datadir)
|
||||
}
|
||||
|
||||
pub fn production(context: RuntimeContext<E>, config: ValidatorConfig) -> Self {
|
||||
// Creates a temporary directory that will be deleted once this `TempDir` is dropped.
|
||||
let datadir = TempDir::new("lighthouse-validator")
|
||||
.expect("should create temp directory for client datadir");
|
||||
|
||||
Self::new(context, config, datadir)
|
||||
}
|
||||
|
||||
fn new(context: RuntimeContext<E>, mut config: ValidatorConfig, datadir: TempDir) -> Self {
|
||||
config.data_dir = datadir.path().into();
|
||||
|
||||
let client =
|
||||
ProductionValidatorClient::new(context, config).expect("should start validator client");
|
||||
|
||||
client
|
||||
.start_service()
|
||||
.expect("should start validator client");
|
||||
|
||||
Self { client, datadir }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user