fix reverse loop in write_stage, simplify banking_stage, add tooling to help find this (#1366)

This commit is contained in:
Rob Walker
2018-09-26 18:37:24 -07:00
committed by GitHub
parent 4e01fd5458
commit a23c230603
3 changed files with 22 additions and 11 deletions

View File

@ -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)?;
}

View File

@ -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);
}
}
}
}

View File

@ -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();
}