Add further CLI progress
This commit is contained in:
parent
453c8e2255
commit
cdf3ade63f
@ -46,8 +46,12 @@ impl Bootstrapper {
|
|||||||
/// For example, the server `http://192.168.0.1` might end up with a `best_effort_multiaddr` of
|
/// For example, the server `http://192.168.0.1` might end up with a `best_effort_multiaddr` of
|
||||||
/// `/ipv4/192.168.0.1/tcp/9000` if the server advertises a listening address of
|
/// `/ipv4/192.168.0.1/tcp/9000` if the server advertises a listening address of
|
||||||
/// `/ipv4/172.0.0.1/tcp/9000`.
|
/// `/ipv4/172.0.0.1/tcp/9000`.
|
||||||
pub fn best_effort_multiaddr(&self) -> Option<Multiaddr> {
|
pub fn best_effort_multiaddr(&self, port: Option<u16>) -> Option<Multiaddr> {
|
||||||
let tcp_port = self.listen_port().ok()?;
|
let tcp_port = if let Some(port) = port {
|
||||||
|
port
|
||||||
|
} else {
|
||||||
|
self.listen_port().ok()?
|
||||||
|
};
|
||||||
|
|
||||||
let mut multiaddr = Multiaddr::with_capacity(2);
|
let mut multiaddr = Multiaddr::with_capacity(2);
|
||||||
|
|
||||||
|
@ -21,14 +21,42 @@ pub struct Config {
|
|||||||
db_name: String,
|
db_name: String,
|
||||||
pub log_file: PathBuf,
|
pub log_file: PathBuf,
|
||||||
pub spec_constants: String,
|
pub spec_constants: String,
|
||||||
pub genesis_state: GenesisState,
|
#[serde(skip)]
|
||||||
|
pub boot_method: BootMethod,
|
||||||
pub network: network::NetworkConfig,
|
pub network: network::NetworkConfig,
|
||||||
pub rpc: rpc::RPCConfig,
|
pub rpc: rpc::RPCConfig,
|
||||||
pub rest_api: rest_api::ApiConfig,
|
pub rest_api: rest_api::ApiConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone)]
|
||||||
#[serde(tag = "type")]
|
pub enum BootMethod {
|
||||||
|
/// Resume from an existing database.
|
||||||
|
Resume,
|
||||||
|
/// Generate a state with `validator_count` validators, all with well-known secret keys.
|
||||||
|
///
|
||||||
|
/// Set the genesis time to be the start of the previous 30-minute window.
|
||||||
|
RecentGenesis { validator_count: usize },
|
||||||
|
/// Generate a state with `genesis_time` and `validator_count` validators, all with well-known
|
||||||
|
/// secret keys.
|
||||||
|
Generated {
|
||||||
|
validator_count: usize,
|
||||||
|
genesis_time: u64,
|
||||||
|
},
|
||||||
|
/// Load a YAML-encoded genesis state from a file.
|
||||||
|
Yaml { file: PathBuf },
|
||||||
|
/// Use a HTTP server (running our REST-API) to load genesis and finalized states and blocks.
|
||||||
|
HttpBootstrap {
|
||||||
|
server: String,
|
||||||
|
port: Option<String>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for BootMethod {
|
||||||
|
fn default() -> Self {
|
||||||
|
BootMethod::Resume
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub enum GenesisState {
|
pub enum GenesisState {
|
||||||
/// Use the mainnet genesis state.
|
/// Use the mainnet genesis state.
|
||||||
///
|
///
|
||||||
@ -61,9 +89,7 @@ impl Default for Config {
|
|||||||
rpc: rpc::RPCConfig::default(),
|
rpc: rpc::RPCConfig::default(),
|
||||||
rest_api: rest_api::ApiConfig::default(),
|
rest_api: rest_api::ApiConfig::default(),
|
||||||
spec_constants: TESTNET_SPEC_CONSTANTS.into(),
|
spec_constants: TESTNET_SPEC_CONSTANTS.into(),
|
||||||
genesis_state: GenesisState::RecentGenesis {
|
boot_method: BootMethod::default(),
|
||||||
validator_count: TESTNET_VALIDATOR_COUNT,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,40 +166,6 @@ impl Config {
|
|||||||
self.update_logger(log)?;
|
self.update_logger(log)?;
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the `--bootstrap` flag is provided, overwrite the default configuration.
|
|
||||||
if let Some(server) = args.value_of("bootstrap") {
|
|
||||||
do_bootstrapping(self, server.to_string(), &log)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform the HTTP bootstrapping procedure, reading an ENR and multiaddr from the HTTP server and
|
|
||||||
/// adding them to the `config`.
|
|
||||||
fn do_bootstrapping(config: &mut Config, server: String, log: &slog::Logger) -> Result<(), String> {
|
|
||||||
// Set the genesis state source.
|
|
||||||
config.genesis_state = GenesisState::HttpBootstrap {
|
|
||||||
server: server.to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let bootstrapper = Bootstrapper::from_server_string(server.to_string())?;
|
|
||||||
|
|
||||||
config.network.boot_nodes.push(bootstrapper.enr()?);
|
|
||||||
|
|
||||||
if let Some(server_multiaddr) = bootstrapper.best_effort_multiaddr() {
|
|
||||||
info!(
|
|
||||||
log,
|
|
||||||
"Estimated bootstrapper libp2p address";
|
|
||||||
"multiaddr" => format!("{:?}", server_multiaddr)
|
|
||||||
);
|
|
||||||
config.network.libp2p_nodes.push(server_multiaddr);
|
|
||||||
} else {
|
|
||||||
warn!(
|
|
||||||
log,
|
|
||||||
"Unable to estimate a bootstrapper libp2p address, this node may not find any peers."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use client::{ClientConfig, Eth2Config};
|
use client::{Bootstrapper, ClientConfig, Eth2Config};
|
||||||
use eth2_config::{read_from_file, write_to_file};
|
use eth2_config::{read_from_file, write_to_file};
|
||||||
use rand::{distributions::Alphanumeric, Rng};
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
use slog::{crit, info, Logger};
|
use slog::{crit, info, Logger};
|
||||||
@ -30,6 +30,41 @@ pub fn get_configs(matches: &ArgMatches, log: &Logger) -> Result<Config> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
builder.update_spec_from_subcommand(&sub_matches)?;
|
builder.update_spec_from_subcommand(&sub_matches)?;
|
||||||
|
|
||||||
|
match sub_matches.subcommand() {
|
||||||
|
// The bootstrap testnet method requires inserting a libp2p address into the
|
||||||
|
// network config.
|
||||||
|
("bootstrap", Some(sub_matches)) => {
|
||||||
|
let server = sub_matches
|
||||||
|
.value_of("server")
|
||||||
|
.ok_or_else(|| "No bootstrap server specified".into())?;
|
||||||
|
|
||||||
|
let bootstrapper = Bootstrapper::from_server_string(server.to_string())?;
|
||||||
|
|
||||||
|
if let Some(server_multiaddr) =
|
||||||
|
bootstrapper.best_effort_multiaddr(sub_matches.value_of("libp2p_port"))
|
||||||
|
{
|
||||||
|
info!(
|
||||||
|
log,
|
||||||
|
"Estimated bootstrapper libp2p address";
|
||||||
|
"multiaddr" => format!("{:?}", server_multiaddr)
|
||||||
|
);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.client_config
|
||||||
|
.network
|
||||||
|
.libp2p_nodes
|
||||||
|
.push(server_multiaddr);
|
||||||
|
} else {
|
||||||
|
warn!(
|
||||||
|
log,
|
||||||
|
"Unable to estimate a bootstrapper libp2p address, this node may not find any peers."
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
|
||||||
builder.write_configs_to_new_datadir()?;
|
builder.write_configs_to_new_datadir()?;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -53,8 +88,8 @@ struct ConfigBuilder<'a> {
|
|||||||
matches: &'a ArgMatches<'a>,
|
matches: &'a ArgMatches<'a>,
|
||||||
log: &'a Logger,
|
log: &'a Logger,
|
||||||
pub data_dir: PathBuf,
|
pub data_dir: PathBuf,
|
||||||
eth2_config: Eth2Config,
|
pub eth2_config: Eth2Config,
|
||||||
client_config: ClientConfig,
|
pub client_config: ClientConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ConfigBuilder<'a> {
|
impl<'a> ConfigBuilder<'a> {
|
||||||
|
Loading…
Reference in New Issue
Block a user