From a23c230603bee70fca0e5fa4c7613f85fe9354fe Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Wed, 26 Sep 2018 18:37:24 -0700 Subject: [PATCH] fix reverse loop in write_stage, simplify banking_stage, add tooling to help find this (#1366) --- src/banking_stage.rs | 9 ++------- src/bin/ledger-tool.rs | 21 +++++++++++++++++++-- src/write_stage.rs | 3 +-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/banking_stage.rs b/src/banking_stage.rs index 4b1ee0f64c0114..56c4711640ddea 100644 --- a/src/banking_stage.rs +++ b/src/banking_stage.rs @@ -7,7 +7,6 @@ use bincode::deserialize; use budget_transaction::BudgetTransaction; use counter::Counter; use entry::Entry; -use hash::Hasher; use log::Level; use packet::{Packets, SharedPackets}; use poh_recorder::PohRecorder; @@ -169,15 +168,11 @@ impl BankingStage { let results = bank.process_transactions(&transactions[chunk_start..chunk_end]); - let mut hasher = Hasher::default(); let processed_transactions: Vec<_> = transactions[chunk_start..chunk_end] .into_iter() .enumerate() .filter_map(|(i, x)| match results[i] { - Ok(_) => { - hasher.hash(&x.signature.as_ref()); - Some(x.clone()) - } + Ok(_) => Some(x.clone()), Err(ref e) => { debug!("process transaction failed {:?}", e); None @@ -185,7 +180,7 @@ impl BankingStage { }).collect(); if !processed_transactions.is_empty() { - let hash = hasher.result(); + let hash = Transaction::hash(&processed_transactions); debug!("processed ok: {} {}", processed_transactions.len(), hash); poh.record(hash, processed_transactions)?; } diff --git a/src/bin/ledger-tool.rs b/src/bin/ledger-tool.rs index ec47b403ca14ed..1af804ce47cd4b 100644 --- a/src/bin/ledger-tool.rs +++ b/src/bin/ledger-tool.rs @@ -37,6 +37,12 @@ fn main() { .long("precheck") .help("Use ledger_verify() to check internal ledger consistency before proceeding"), ) + .arg( + Arg::with_name("continue") + .short("c") + .long("continue") + .help("Continue verify even if verification fails"), + ) .subcommand(SubCommand::with_name("print").about("Print the ledger")) .subcommand(SubCommand::with_name("json").about("Print the ledger in JSON format")) .subcommand(SubCommand::with_name("verify").about("Verify the ledger's PoH")) @@ -50,6 +56,7 @@ fn main() { exit(1); } } + let entries = match read_ledger(ledger_path, true) { Ok(entries) => entries, Err(err) => { @@ -112,7 +119,9 @@ fn main() { if let Err(e) = bank.process_ledger(genesis) { eprintln!("verify failed at genesis err: {:?}", e); - exit(1); + if !matches.is_present("continue") { + exit(1); + } } } let entries = entries.map(|e| e.unwrap()); @@ -122,9 +131,17 @@ fn main() { if i >= head { break; } + if !entry.verify(&bank.last_id()) { + eprintln!("entry.verify() failed at entry[{}]", i + 2); + if !matches.is_present("continue") { + exit(1); + } + } if let Err(e) = bank.process_entry(&entry) { eprintln!("verify failed at entry[{}], err: {:?}", i + 2, e); - exit(1); + if !matches.is_present("continue") { + exit(1); + } } } } diff --git a/src/write_stage.rs b/src/write_stage.rs index c40c709b85cd4c..f8a9e4427223dd 100644 --- a/src/write_stage.rs +++ b/src/write_stage.rs @@ -131,8 +131,7 @@ impl WriteStage { let mut crdt_votes_total = 0; let start = Instant::now(); - for _ in 0..ventries.len() { - let entries = ventries.pop().unwrap(); + for entries in ventries { for e in &entries { num_txs += e.transactions.len(); }