If the node was loaded from a snapshot, advertise it in gossip (#8364)
automerge
This commit is contained in:
parent
2d665da3e1
commit
18fd52367e
|
@ -38,7 +38,6 @@ use solana_sdk::{
|
|||
clock::{Slot, DEFAULT_SLOTS_PER_TURN},
|
||||
genesis_config::GenesisConfig,
|
||||
hash::Hash,
|
||||
poh_config::PohConfig,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
timing::timestamp,
|
||||
|
@ -159,14 +158,14 @@ impl Validator {
|
|||
|
||||
info!("creating bank...");
|
||||
let (
|
||||
genesis_hash,
|
||||
genesis_config,
|
||||
bank_forks,
|
||||
bank_forks_info,
|
||||
blockstore,
|
||||
ledger_signal_receiver,
|
||||
completed_slots_receiver,
|
||||
leader_schedule_cache,
|
||||
poh_config,
|
||||
snapshot_hash,
|
||||
) = new_banks_from_blockstore(
|
||||
config.expected_genesis_hash,
|
||||
ledger_path,
|
||||
|
@ -196,8 +195,10 @@ impl Validator {
|
|||
let validator_exit = Arc::new(RwLock::new(Some(validator_exit)));
|
||||
|
||||
node.info.wallclock = timestamp();
|
||||
node.info.shred_version =
|
||||
compute_shred_version(&genesis_hash, Some(&bank.hard_forks().read().unwrap()));
|
||||
node.info.shred_version = compute_shred_version(
|
||||
&genesis_config.hash(),
|
||||
Some(&bank.hard_forks().read().unwrap()),
|
||||
);
|
||||
Self::print_node_info(&node);
|
||||
|
||||
if let Some(expected_shred_version) = config.expected_shred_version {
|
||||
|
@ -241,7 +242,7 @@ impl Validator {
|
|||
block_commitment_cache.clone(),
|
||||
blockstore.clone(),
|
||||
cluster_info.clone(),
|
||||
genesis_hash,
|
||||
genesis_config.hash(),
|
||||
ledger_path,
|
||||
storage_state.clone(),
|
||||
validator_exit.clone(),
|
||||
|
@ -299,7 +300,7 @@ impl Validator {
|
|||
std::thread::park();
|
||||
}
|
||||
|
||||
let poh_config = Arc::new(poh_config);
|
||||
let poh_config = Arc::new(genesis_config.poh_config);
|
||||
let (mut poh_recorder, entry_receiver) = PohRecorder::new_with_clear_signal(
|
||||
bank.tick_height(),
|
||||
bank.last_blockhash(),
|
||||
|
@ -343,6 +344,14 @@ impl Validator {
|
|||
.set_entrypoint(entrypoint_info.clone());
|
||||
}
|
||||
|
||||
// If the node was loaded from a snapshot, advertise it in gossip
|
||||
if let Some(snapshot_hash) = snapshot_hash {
|
||||
cluster_info
|
||||
.write()
|
||||
.unwrap()
|
||||
.push_snapshot_hashes(vec![snapshot_hash]);
|
||||
}
|
||||
|
||||
wait_for_supermajority(config, &bank, &cluster_info);
|
||||
|
||||
let voting_keypair = if config.voting_disabled {
|
||||
|
@ -505,20 +514,21 @@ impl Validator {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn new_banks_from_blockstore(
|
||||
expected_genesis_hash: Option<Hash>,
|
||||
blockstore_path: &Path,
|
||||
poh_verify: bool,
|
||||
config: &ValidatorConfig,
|
||||
) -> (
|
||||
Hash,
|
||||
GenesisConfig,
|
||||
BankForks,
|
||||
Vec<BankForksInfo>,
|
||||
Blockstore,
|
||||
Receiver<bool>,
|
||||
CompletedSlotsReceiver,
|
||||
LeaderScheduleCache,
|
||||
PohConfig,
|
||||
Option<(Slot, Hash)>,
|
||||
) {
|
||||
let genesis_config = GenesisConfig::load(blockstore_path).unwrap_or_else(|err| {
|
||||
error!("Failed to load genesis from {:?}: {}", blockstore_path, err);
|
||||
|
@ -548,7 +558,8 @@ fn new_banks_from_blockstore(
|
|||
..blockstore_processor::ProcessOptions::default()
|
||||
};
|
||||
|
||||
let (mut bank_forks, bank_forks_info, mut leader_schedule_cache) = bank_forks_utils::load(
|
||||
let (mut bank_forks, bank_forks_info, mut leader_schedule_cache, snapshot_hash) =
|
||||
bank_forks_utils::load(
|
||||
&genesis_config,
|
||||
&blockstore,
|
||||
config.account_paths.clone(),
|
||||
|
@ -565,14 +576,14 @@ fn new_banks_from_blockstore(
|
|||
bank_forks.set_snapshot_config(config.snapshot_config.clone());
|
||||
|
||||
(
|
||||
genesis_hash,
|
||||
genesis_config,
|
||||
bank_forks,
|
||||
bank_forks_info,
|
||||
blockstore,
|
||||
ledger_signal_receiver,
|
||||
completed_slots_receiver,
|
||||
leader_schedule_cache,
|
||||
genesis_config.poh_config,
|
||||
snapshot_hash,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use solana_ledger::{
|
|||
bank_forks_utils,
|
||||
blockstore::Blockstore,
|
||||
blockstore_db::{self, Column, Database},
|
||||
blockstore_processor::{BankForksInfo, BlockstoreProcessorResult, ProcessOptions},
|
||||
blockstore_processor::{BankForksInfo, ProcessOptions},
|
||||
rooted_slot_iterator::RootedSlotIterator,
|
||||
shred_version::compute_shred_version,
|
||||
snapshot_utils,
|
||||
|
@ -529,7 +529,7 @@ fn load_bank_forks(
|
|||
ledger_path: &PathBuf,
|
||||
genesis_config: &GenesisConfig,
|
||||
process_options: ProcessOptions,
|
||||
) -> BlockstoreProcessorResult {
|
||||
) -> bank_forks_utils::LoadResult {
|
||||
let snapshot_config = if arg_matches.is_present("no_snapshot") {
|
||||
None
|
||||
} else {
|
||||
|
@ -775,7 +775,7 @@ fn main() {
|
|||
};
|
||||
let genesis_config = open_genesis_config(&ledger_path);
|
||||
match load_bank_forks(arg_matches, &ledger_path, &genesis_config, process_options) {
|
||||
Ok((bank_forks, bank_forks_info, _leader_schedule_cache)) => {
|
||||
Ok((bank_forks, bank_forks_info, _leader_schedule_cache, _snapshot_hash)) => {
|
||||
let bank_info = &bank_forks_info[0];
|
||||
let bank = bank_forks[bank_info.bank_slot].clone();
|
||||
|
||||
|
@ -849,7 +849,7 @@ fn main() {
|
|||
&open_genesis_config(&ledger_path),
|
||||
process_options,
|
||||
) {
|
||||
Ok((bank_forks, bank_forks_info, _leader_schedule_cache)) => {
|
||||
Ok((bank_forks, bank_forks_info, _leader_schedule_cache, _snapshot_hash)) => {
|
||||
let dot = graph_forks(
|
||||
&bank_forks,
|
||||
&bank_forks_info,
|
||||
|
@ -889,7 +889,7 @@ fn main() {
|
|||
};
|
||||
let genesis_config = open_genesis_config(&ledger_path);
|
||||
match load_bank_forks(arg_matches, &ledger_path, &genesis_config, process_options) {
|
||||
Ok((bank_forks, _bank_forks_info, _leader_schedule_cache)) => {
|
||||
Ok((bank_forks, _bank_forks_info, _leader_schedule_cache, _snapshot_hash)) => {
|
||||
let bank = bank_forks.get(snapshot_slot).unwrap_or_else(|| {
|
||||
eprintln!("Error: Slot {} is not available", snapshot_slot);
|
||||
exit(1);
|
||||
|
@ -950,7 +950,7 @@ fn main() {
|
|||
};
|
||||
let genesis_config = open_genesis_config(&ledger_path);
|
||||
match load_bank_forks(arg_matches, &ledger_path, &genesis_config, process_options) {
|
||||
Ok((bank_forks, bank_forks_info, _leader_schedule_cache)) => {
|
||||
Ok((bank_forks, bank_forks_info, _leader_schedule_cache, _snapshot_hash)) => {
|
||||
let slot = dev_halt_at_slot.unwrap_or_else(|| {
|
||||
if bank_forks_info.len() > 1 {
|
||||
eprintln!("Error: multiple forks present");
|
||||
|
|
|
@ -1,13 +1,40 @@
|
|||
use crate::{
|
||||
bank_forks::SnapshotConfig,
|
||||
bank_forks::{BankForks, SnapshotConfig},
|
||||
blockstore::Blockstore,
|
||||
blockstore_processor::{self, BlockstoreProcessorResult, ProcessOptions},
|
||||
blockstore_processor::{
|
||||
self, BankForksInfo, BlockstoreProcessorError, BlockstoreProcessorResult, ProcessOptions,
|
||||
},
|
||||
entry::VerifyRecyclers,
|
||||
leader_schedule_cache::LeaderScheduleCache,
|
||||
snapshot_utils,
|
||||
};
|
||||
use log::*;
|
||||
use solana_sdk::genesis_config::GenesisConfig;
|
||||
use std::{fs, path::PathBuf, sync::Arc};
|
||||
use solana_sdk::{clock::Slot, genesis_config::GenesisConfig, hash::Hash};
|
||||
use std::{fs, path::PathBuf, result, sync::Arc};
|
||||
|
||||
pub type LoadResult = result::Result<
|
||||
(
|
||||
BankForks,
|
||||
Vec<BankForksInfo>,
|
||||
LeaderScheduleCache,
|
||||
Option<(Slot, Hash)>,
|
||||
),
|
||||
BlockstoreProcessorError,
|
||||
>;
|
||||
|
||||
fn to_loadresult(
|
||||
brp: BlockstoreProcessorResult,
|
||||
snapshot_hash: Option<(Slot, Hash)>,
|
||||
) -> LoadResult {
|
||||
brp.map(|(bank_forks, bank_forks_info, leader_schedule_cache)| {
|
||||
(
|
||||
bank_forks,
|
||||
bank_forks_info,
|
||||
leader_schedule_cache,
|
||||
snapshot_hash,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn load(
|
||||
genesis_config: &GenesisConfig,
|
||||
|
@ -15,7 +42,7 @@ pub fn load(
|
|||
account_paths: Vec<PathBuf>,
|
||||
snapshot_config: Option<&SnapshotConfig>,
|
||||
process_options: ProcessOptions,
|
||||
) -> BlockstoreProcessorResult {
|
||||
) -> LoadResult {
|
||||
if let Some(snapshot_config) = snapshot_config.as_ref() {
|
||||
info!(
|
||||
"Initializing snapshot path: {:?}",
|
||||
|
@ -43,12 +70,16 @@ pub fn load(
|
|||
)
|
||||
.expect("Load from snapshot failed");
|
||||
|
||||
return blockstore_processor::process_blockstore_from_root(
|
||||
let snapshot_hash = (deserialized_bank.slot(), deserialized_bank.hash());
|
||||
return to_loadresult(
|
||||
blockstore_processor::process_blockstore_from_root(
|
||||
genesis_config,
|
||||
blockstore,
|
||||
Arc::new(deserialized_bank),
|
||||
&process_options,
|
||||
&VerifyRecyclers::default(),
|
||||
),
|
||||
Some(snapshot_hash),
|
||||
);
|
||||
} else {
|
||||
info!("Snapshot package does not exist: {:?}", tar);
|
||||
|
@ -58,10 +89,13 @@ pub fn load(
|
|||
}
|
||||
|
||||
info!("Processing ledger from genesis");
|
||||
to_loadresult(
|
||||
blockstore_processor::process_blockstore(
|
||||
&genesis_config,
|
||||
&blockstore,
|
||||
account_paths,
|
||||
process_options,
|
||||
),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue