Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
fix reverse loop in write_stage, simplify banking_stage, add tooling …
Browse files Browse the repository at this point in the history
…to help find this (#1366)
  • Loading branch information
rob-solana authored Sep 27, 2018
1 parent 4e01fd5 commit a23c230
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
9 changes: 2 additions & 7 deletions src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -169,23 +168,19 @@ 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
}
}).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)?;
}
Expand Down
21 changes: 19 additions & 2 deletions src/bin/ledger-tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -50,6 +56,7 @@ fn main() {
exit(1);
}
}

let entries = match read_ledger(ledger_path, true) {
Ok(entries) => entries,
Err(err) => {
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/write_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit a23c230

Please sign in to comment.