2019-11-13 20:10:38 -08:00
|
|
|
use clap::{crate_description, crate_name, App, Arg};
|
2019-08-30 15:33:30 -07:00
|
|
|
use console::style;
|
2020-01-16 08:29:36 -08:00
|
|
|
use solana_archiver_lib::archiver::Archiver;
|
2019-11-23 08:55:43 -08:00
|
|
|
use solana_clap_utils::{
|
|
|
|
input_validators::is_keypair,
|
|
|
|
keypair::{
|
|
|
|
self, keypair_input, KeypairWithSource, ASK_SEED_PHRASE_ARG,
|
|
|
|
SKIP_SEED_PHRASE_VALIDATION_ARG,
|
|
|
|
},
|
|
|
|
};
|
2019-11-06 13:15:00 -08:00
|
|
|
use solana_core::{
|
|
|
|
cluster_info::{Node, VALIDATOR_PORT_RANGE},
|
|
|
|
contact_info::ContactInfo,
|
|
|
|
};
|
2019-11-23 08:55:43 -08:00
|
|
|
use solana_sdk::{commitment_config::CommitmentConfig, signature::KeypairUtil};
|
2019-11-06 13:15:00 -08:00
|
|
|
use std::{net::SocketAddr, path::PathBuf, process::exit, sync::Arc};
|
2018-09-21 15:32:15 -07:00
|
|
|
|
|
|
|
fn main() {
|
2018-12-14 12:36:50 -08:00
|
|
|
solana_logger::setup();
|
2018-09-27 10:48:40 -07:00
|
|
|
|
2019-05-03 11:01:35 -07:00
|
|
|
let matches = App::new(crate_name!())
|
|
|
|
.about(crate_description!())
|
2019-11-13 20:10:38 -08:00
|
|
|
.version(solana_clap_utils::version!())
|
2018-09-21 15:32:15 -07:00
|
|
|
.arg(
|
2019-11-23 08:55:43 -08:00
|
|
|
Arg::with_name("identity_keypair")
|
2018-09-21 15:32:15 -07:00
|
|
|
.short("i")
|
2019-11-23 08:55:43 -08:00
|
|
|
.long("identity-keypair")
|
2018-09-21 15:32:15 -07:00
|
|
|
.value_name("PATH")
|
|
|
|
.takes_value(true)
|
2019-08-30 09:27:35 -07:00
|
|
|
.validator(is_keypair)
|
2019-03-04 14:27:06 -08:00
|
|
|
.help("File containing an identity (keypair)"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.arg(
|
2019-05-03 15:00:19 -07:00
|
|
|
Arg::with_name("entrypoint")
|
2018-09-21 15:32:15 -07:00
|
|
|
.short("n")
|
2019-05-03 15:00:19 -07:00
|
|
|
.long("entrypoint")
|
2018-09-21 15:32:15 -07:00
|
|
|
.value_name("HOST:PORT")
|
|
|
|
.takes_value(true)
|
2019-01-02 11:02:15 -08:00
|
|
|
.required(true)
|
2019-11-12 12:37:13 -08:00
|
|
|
.validator(solana_net_utils::is_host_port)
|
2019-05-03 15:00:19 -07:00
|
|
|
.help("Rendezvous with the cluster at this entry point"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.arg(
|
2018-09-21 15:32:15 -07:00
|
|
|
Arg::with_name("ledger")
|
|
|
|
.short("l")
|
|
|
|
.long("ledger")
|
|
|
|
.value_name("DIR")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.help("use DIR as persistent ledger location"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
2019-05-09 13:43:39 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("storage_keypair")
|
|
|
|
.short("s")
|
2019-05-15 15:19:29 -07:00
|
|
|
.long("storage-keypair")
|
|
|
|
.value_name("PATH")
|
2019-05-09 13:43:39 -07:00
|
|
|
.takes_value(true)
|
2019-08-30 09:27:35 -07:00
|
|
|
.validator(is_keypair)
|
2019-05-09 13:43:39 -07:00
|
|
|
.help("File containing the storage account keypair"),
|
|
|
|
)
|
2019-11-23 08:55:43 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name(ASK_SEED_PHRASE_ARG.name)
|
|
|
|
.long(ASK_SEED_PHRASE_ARG.long)
|
|
|
|
.value_name("KEYPAIR NAME")
|
|
|
|
.multiple(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.possible_values(&["identity-keypair", "storage-keypair"])
|
|
|
|
.help(ASK_SEED_PHRASE_ARG.help),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name(SKIP_SEED_PHRASE_VALIDATION_ARG.name)
|
|
|
|
.long(SKIP_SEED_PHRASE_VALIDATION_ARG.long)
|
|
|
|
.requires(ASK_SEED_PHRASE_ARG.name)
|
|
|
|
.help(SKIP_SEED_PHRASE_VALIDATION_ARG.help),
|
|
|
|
)
|
2018-12-07 19:01:28 -08:00
|
|
|
.get_matches();
|
2018-09-21 15:32:15 -07:00
|
|
|
|
2019-07-30 15:53:41 -07:00
|
|
|
let ledger_path = PathBuf::from(matches.value_of("ledger").unwrap());
|
2018-09-21 15:32:15 -07:00
|
|
|
|
2019-11-23 08:55:43 -08:00
|
|
|
let identity_keypair = keypair_input(&matches, "identity_keypair")
|
|
|
|
.unwrap_or_else(|err| {
|
|
|
|
eprintln!("Identity keypair input failed: {}", err);
|
2019-05-09 13:43:39 -07:00
|
|
|
exit(1);
|
|
|
|
})
|
2019-11-23 08:55:43 -08:00
|
|
|
.keypair;
|
|
|
|
let KeypairWithSource {
|
|
|
|
keypair: storage_keypair,
|
|
|
|
source: storage_keypair_source,
|
|
|
|
} = keypair_input(&matches, "storage_keypair").unwrap_or_else(|err| {
|
|
|
|
eprintln!("Storage keypair input failed: {}", err);
|
|
|
|
exit(1);
|
|
|
|
});
|
|
|
|
if storage_keypair_source == keypair::Source::Generated {
|
|
|
|
clap::Error::with_description(
|
|
|
|
"The `storage-keypair` argument was not found",
|
|
|
|
clap::ErrorKind::ArgumentNotFound,
|
|
|
|
)
|
|
|
|
.exit();
|
|
|
|
}
|
2018-09-21 15:32:15 -07:00
|
|
|
|
2019-05-03 15:00:19 -07:00
|
|
|
let entrypoint_addr = matches
|
|
|
|
.value_of("entrypoint")
|
|
|
|
.map(|entrypoint| {
|
2019-11-12 12:37:13 -08:00
|
|
|
solana_net_utils::parse_host_port(entrypoint)
|
|
|
|
.expect("failed to parse entrypoint address")
|
2019-05-03 11:01:35 -07:00
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
|
2019-03-04 14:27:06 -08:00
|
|
|
let gossip_addr = {
|
2019-11-12 12:37:13 -08:00
|
|
|
let ip = solana_net_utils::get_public_ip_addr(&entrypoint_addr).unwrap();
|
2019-06-13 17:53:54 -07:00
|
|
|
let mut addr = SocketAddr::new(ip, 0);
|
2019-11-12 12:37:13 -08:00
|
|
|
addr.set_ip(solana_net_utils::get_public_ip_addr(&entrypoint_addr).unwrap());
|
2019-03-04 14:27:06 -08:00
|
|
|
addr
|
|
|
|
};
|
2019-11-23 08:55:43 -08:00
|
|
|
let node = Node::new_archiver_with_external_ip(
|
|
|
|
&identity_keypair.pubkey(),
|
|
|
|
&gossip_addr,
|
|
|
|
VALIDATOR_PORT_RANGE,
|
|
|
|
);
|
2018-09-21 15:32:15 -07:00
|
|
|
|
2019-08-30 15:33:30 -07:00
|
|
|
println!(
|
|
|
|
"{} version {} (branch={}, commit={})",
|
|
|
|
style(crate_name!()).bold(),
|
2019-11-13 20:10:38 -08:00
|
|
|
solana_clap_utils::version!(),
|
2019-08-30 15:33:30 -07:00
|
|
|
option_env!("CI_BRANCH").unwrap_or("unknown"),
|
|
|
|
option_env!("CI_COMMIT").unwrap_or("unknown")
|
|
|
|
);
|
2019-11-23 08:55:43 -08:00
|
|
|
solana_metrics::set_host_id(identity_keypair.pubkey().to_string());
|
2018-09-21 15:32:15 -07:00
|
|
|
println!(
|
2019-11-23 08:55:43 -08:00
|
|
|
"replicating the data with identity_keypair={:?} gossip_addr={:?}",
|
|
|
|
identity_keypair.pubkey(),
|
2019-03-04 14:27:06 -08:00
|
|
|
gossip_addr
|
2018-09-21 15:32:15 -07:00
|
|
|
);
|
|
|
|
|
2019-05-03 15:00:19 -07:00
|
|
|
let entrypoint_info = ContactInfo::new_gossip_entry_point(&entrypoint_addr);
|
2019-10-21 10:29:37 -07:00
|
|
|
let archiver = Archiver::new(
|
2019-07-30 15:53:41 -07:00
|
|
|
&ledger_path,
|
2019-03-27 15:54:09 -07:00
|
|
|
node,
|
2019-05-03 15:00:19 -07:00
|
|
|
entrypoint_info,
|
2019-11-23 08:55:43 -08:00
|
|
|
Arc::new(identity_keypair),
|
2019-05-09 13:43:39 -07:00
|
|
|
Arc::new(storage_keypair),
|
2019-11-06 13:15:00 -08:00
|
|
|
CommitmentConfig::recent(),
|
2019-03-27 15:54:09 -07:00
|
|
|
)
|
|
|
|
.unwrap();
|
2018-10-02 11:47:51 -07:00
|
|
|
|
2019-10-21 10:29:37 -07:00
|
|
|
archiver.join();
|
2018-09-21 15:32:15 -07:00
|
|
|
}
|