Decouple genesis fetch and snapshot fetch (#10931)
This commit is contained in:
parent
58a475b789
commit
960f6f6f07
|
@ -370,12 +370,29 @@ fn check_genesis_hash(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn load_local_genesis(
|
||||||
|
ledger_path: &std::path::Path,
|
||||||
|
expected_genesis_hash: Option<Hash>,
|
||||||
|
) -> Result<GenesisConfig, String> {
|
||||||
|
let existing_genesis = GenesisConfig::load(&ledger_path)
|
||||||
|
.map_err(|err| format!("Failed to load genesis config: {}", err))?;
|
||||||
|
check_genesis_hash(&existing_genesis, expected_genesis_hash)?;
|
||||||
|
|
||||||
|
Ok(existing_genesis)
|
||||||
|
}
|
||||||
|
|
||||||
fn download_then_check_genesis_hash(
|
fn download_then_check_genesis_hash(
|
||||||
rpc_addr: &SocketAddr,
|
rpc_addr: &SocketAddr,
|
||||||
ledger_path: &std::path::Path,
|
ledger_path: &std::path::Path,
|
||||||
expected_genesis_hash: Option<Hash>,
|
expected_genesis_hash: Option<Hash>,
|
||||||
max_genesis_archive_unpacked_size: u64,
|
max_genesis_archive_unpacked_size: u64,
|
||||||
|
no_genesis_fetch: bool,
|
||||||
) -> Result<Hash, String> {
|
) -> Result<Hash, String> {
|
||||||
|
if no_genesis_fetch {
|
||||||
|
let genesis_config = load_local_genesis(ledger_path, expected_genesis_hash)?;
|
||||||
|
return Ok(genesis_config.hash());
|
||||||
|
}
|
||||||
|
|
||||||
let genesis_package = ledger_path.join("genesis.tar.bz2");
|
let genesis_package = ledger_path.join("genesis.tar.bz2");
|
||||||
let genesis_config =
|
let genesis_config =
|
||||||
if let Ok(tmp_genesis_package) = download_genesis_if_missing(rpc_addr, &genesis_package) {
|
if let Ok(tmp_genesis_package) = download_genesis_if_missing(rpc_addr, &genesis_package) {
|
||||||
|
@ -395,11 +412,7 @@ fn download_then_check_genesis_hash(
|
||||||
|
|
||||||
downloaded_genesis
|
downloaded_genesis
|
||||||
} else {
|
} else {
|
||||||
let existing_genesis = GenesisConfig::load(&ledger_path)
|
load_local_genesis(ledger_path, expected_genesis_hash)?
|
||||||
.map_err(|err| format!("Failed to load genesis config: {}", err))?;
|
|
||||||
check_genesis_hash(&existing_genesis, expected_genesis_hash)?;
|
|
||||||
|
|
||||||
existing_genesis
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(genesis_config.hash())
|
Ok(genesis_config.hash())
|
||||||
|
@ -549,7 +562,6 @@ pub fn main() {
|
||||||
Arg::with_name("no_snapshot_fetch")
|
Arg::with_name("no_snapshot_fetch")
|
||||||
.long("no-snapshot-fetch")
|
.long("no-snapshot-fetch")
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.requires("entrypoint")
|
|
||||||
.help("Do not attempt to fetch a snapshot from the cluster, \
|
.help("Do not attempt to fetch a snapshot from the cluster, \
|
||||||
start from a local snapshot if present"),
|
start from a local snapshot if present"),
|
||||||
)
|
)
|
||||||
|
@ -557,7 +569,6 @@ pub fn main() {
|
||||||
Arg::with_name("no_genesis_fetch")
|
Arg::with_name("no_genesis_fetch")
|
||||||
.long("no-genesis-fetch")
|
.long("no-genesis-fetch")
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.requires("entrypoint")
|
|
||||||
.help("Do not fetch genesis from the cluster"),
|
.help("Do not fetch genesis from the cluster"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -1204,7 +1215,7 @@ pub fn main() {
|
||||||
) {
|
) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if !no_genesis_fetch {
|
if !no_genesis_fetch || !no_snapshot_fetch {
|
||||||
let (cluster_info, gossip_exit_flag, gossip_service) = start_gossip_node(
|
let (cluster_info, gossip_exit_flag, gossip_service) = start_gossip_node(
|
||||||
&identity_keypair,
|
&identity_keypair,
|
||||||
&cluster_entrypoint.gossip,
|
&cluster_entrypoint.gossip,
|
||||||
|
@ -1241,6 +1252,7 @@ pub fn main() {
|
||||||
&ledger_path,
|
&ledger_path,
|
||||||
validator_config.expected_genesis_hash,
|
validator_config.expected_genesis_hash,
|
||||||
max_genesis_archive_unpacked_size,
|
max_genesis_archive_unpacked_size,
|
||||||
|
no_genesis_fetch,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Ok(genesis_hash) = genesis_hash {
|
if let Ok(genesis_hash) = genesis_hash {
|
||||||
|
|
Loading…
Reference in New Issue