ledger-tool can now load a ledger snapshot (#6730)

This commit is contained in:
Michael Vines
2019-11-04 22:54:56 -07:00
committed by GitHub
parent 787096f503
commit 1f4222092a
8 changed files with 122 additions and 56 deletions

View File

@@ -1,28 +1,31 @@
use crate::bank_forks::BankForks;
use crate::blocktree::Blocktree;
use crate::blocktree_meta::SlotMeta;
use crate::entry::{create_ticks, Entry, EntrySlice};
use crate::leader_schedule_cache::LeaderScheduleCache;
use crate::{
bank_forks::BankForks,
blocktree::Blocktree,
blocktree_meta::SlotMeta,
entry::{create_ticks, Entry, EntrySlice},
leader_schedule_cache::LeaderScheduleCache,
};
use itertools::Itertools;
use log::*;
use rand::seq::SliceRandom;
use rand::thread_rng;
use rayon::prelude::*;
use rayon::ThreadPool;
use rand::{seq::SliceRandom, thread_rng};
use rayon::{prelude::*, ThreadPool};
use solana_metrics::{datapoint, datapoint_error, inc_new_counter_debug};
use solana_runtime::bank::Bank;
use solana_runtime::transaction_batch::TransactionBatch;
use solana_sdk::clock::{Slot, MAX_RECENT_BLOCKHASHES};
use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::hash::Hash;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::timing::duration_as_ms;
use solana_sdk::transaction::Result;
use std::result;
use std::sync::Arc;
use std::time::{Duration, Instant};
use solana_rayon_threadlimit::get_thread_count;
use std::cell::RefCell;
use solana_runtime::{bank::Bank, transaction_batch::TransactionBatch};
use solana_sdk::{
clock::{Slot, MAX_RECENT_BLOCKHASHES},
genesis_block::GenesisBlock,
hash::Hash,
signature::{Keypair, KeypairUtil},
timing::duration_as_ms,
transaction::Result,
};
use std::{
cell::RefCell,
result,
sync::Arc,
time::{Duration, Instant},
};
thread_local!(static PAR_THREAD_POOL: RefCell<ThreadPool> = RefCell::new(rayon::ThreadPoolBuilder::new()
.num_threads(get_thread_count())
@@ -183,7 +186,7 @@ pub type ProcessCallback = Arc<dyn Fn(&Bank) -> () + Sync + Send>;
#[derive(Default)]
pub struct ProcessOptions {
pub verify_ledger: bool,
pub poh_verify: bool,
pub full_leader_cache: bool,
pub dev_halt_at_slot: Option<Slot>,
pub entry_callback: Option<ProcessCallback>,
@@ -269,9 +272,14 @@ pub fn process_blocktree_from_root(
};
info!(
"processing ledger...complete in {}ms, forks={}...",
"ledger processed in {}ms. {} fork{} at {}",
duration_as_ms(&now.elapsed()),
bank_forks_info.len(),
if bank_forks_info.len() > 1 { "s" } else { "" },
bank_forks_info
.iter()
.map(|bfi| bfi.bank_slot.to_string())
.join(", ")
);
Ok((bank_forks, bank_forks_info, leader_schedule_cache))
@@ -285,7 +293,7 @@ fn verify_and_process_entries(
) -> result::Result<Hash, BlocktreeProcessorError> {
assert!(!entries.is_empty());
if opts.verify_ledger && !entries.verify(&last_entry_hash) {
if opts.poh_verify && !entries.verify(&last_entry_hash) {
warn!("Ledger proof of history failed at slot: {}", bank.slot());
return Err(BlocktreeProcessorError::LedgerVerificationFailed);
}
@@ -558,7 +566,7 @@ pub mod tests {
fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 2, 1, blockhash);
let opts = ProcessOptions {
verify_ledger: true,
poh_verify: true,
..ProcessOptions::default()
};
let (mut _bank_forks, bank_forks_info, _) =
@@ -620,7 +628,7 @@ pub mod tests {
blocktree.set_roots(&[0, 1, 4]).unwrap();
let opts = ProcessOptions {
verify_ledger: true,
poh_verify: true,
..ProcessOptions::default()
};
let (bank_forks, bank_forks_info, _) =
@@ -694,7 +702,7 @@ pub mod tests {
blocktree.set_roots(&[0, 1]).unwrap();
let opts = ProcessOptions {
verify_ledger: true,
poh_verify: true,
..ProcessOptions::default()
};
let (bank_forks, bank_forks_info, _) =
@@ -774,7 +782,7 @@ pub mod tests {
// Check that we can properly restart the ledger / leader scheduler doesn't fail
let opts = ProcessOptions {
verify_ledger: true,
poh_verify: true,
..ProcessOptions::default()
};
let (bank_forks, bank_forks_info, _) =
@@ -912,7 +920,7 @@ pub mod tests {
)
.unwrap();
let opts = ProcessOptions {
verify_ledger: true,
poh_verify: true,
..ProcessOptions::default()
};
let (bank_forks, bank_forks_info, _) =
@@ -941,7 +949,7 @@ pub mod tests {
let blocktree = Blocktree::open(&ledger_path).unwrap();
let opts = ProcessOptions {
verify_ledger: true,
poh_verify: true,
..ProcessOptions::default()
};
let (bank_forks, bank_forks_info, _) =
@@ -1676,7 +1684,7 @@ pub mod tests {
// Set up bank1
let bank0 = Arc::new(Bank::new(&genesis_block));
let opts = ProcessOptions {
verify_ledger: true,
poh_verify: true,
..ProcessOptions::default()
};
process_bank_0(&bank0, &blocktree, &opts).unwrap();