fix reverse loop in write_stage, simplify banking_stage, add tooling to help find this (#1366)
This commit is contained in:
@ -7,7 +7,6 @@ use bincode::deserialize;
|
|||||||
use budget_transaction::BudgetTransaction;
|
use budget_transaction::BudgetTransaction;
|
||||||
use counter::Counter;
|
use counter::Counter;
|
||||||
use entry::Entry;
|
use entry::Entry;
|
||||||
use hash::Hasher;
|
|
||||||
use log::Level;
|
use log::Level;
|
||||||
use packet::{Packets, SharedPackets};
|
use packet::{Packets, SharedPackets};
|
||||||
use poh_recorder::PohRecorder;
|
use poh_recorder::PohRecorder;
|
||||||
@ -169,15 +168,11 @@ impl BankingStage {
|
|||||||
|
|
||||||
let results = bank.process_transactions(&transactions[chunk_start..chunk_end]);
|
let results = bank.process_transactions(&transactions[chunk_start..chunk_end]);
|
||||||
|
|
||||||
let mut hasher = Hasher::default();
|
|
||||||
let processed_transactions: Vec<_> = transactions[chunk_start..chunk_end]
|
let processed_transactions: Vec<_> = transactions[chunk_start..chunk_end]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(i, x)| match results[i] {
|
.filter_map(|(i, x)| match results[i] {
|
||||||
Ok(_) => {
|
Ok(_) => Some(x.clone()),
|
||||||
hasher.hash(&x.signature.as_ref());
|
|
||||||
Some(x.clone())
|
|
||||||
}
|
|
||||||
Err(ref e) => {
|
Err(ref e) => {
|
||||||
debug!("process transaction failed {:?}", e);
|
debug!("process transaction failed {:?}", e);
|
||||||
None
|
None
|
||||||
@ -185,7 +180,7 @@ impl BankingStage {
|
|||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
if !processed_transactions.is_empty() {
|
if !processed_transactions.is_empty() {
|
||||||
let hash = hasher.result();
|
let hash = Transaction::hash(&processed_transactions);
|
||||||
debug!("processed ok: {} {}", processed_transactions.len(), hash);
|
debug!("processed ok: {} {}", processed_transactions.len(), hash);
|
||||||
poh.record(hash, processed_transactions)?;
|
poh.record(hash, processed_transactions)?;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,12 @@ fn main() {
|
|||||||
.long("precheck")
|
.long("precheck")
|
||||||
.help("Use ledger_verify() to check internal ledger consistency before proceeding"),
|
.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("print").about("Print the ledger"))
|
||||||
.subcommand(SubCommand::with_name("json").about("Print the ledger in JSON format"))
|
.subcommand(SubCommand::with_name("json").about("Print the ledger in JSON format"))
|
||||||
.subcommand(SubCommand::with_name("verify").about("Verify the ledger's PoH"))
|
.subcommand(SubCommand::with_name("verify").about("Verify the ledger's PoH"))
|
||||||
@ -50,6 +56,7 @@ fn main() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let entries = match read_ledger(ledger_path, true) {
|
let entries = match read_ledger(ledger_path, true) {
|
||||||
Ok(entries) => entries,
|
Ok(entries) => entries,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -112,9 +119,11 @@ fn main() {
|
|||||||
|
|
||||||
if let Err(e) = bank.process_ledger(genesis) {
|
if let Err(e) = bank.process_ledger(genesis) {
|
||||||
eprintln!("verify failed at genesis err: {:?}", e);
|
eprintln!("verify failed at genesis err: {:?}", e);
|
||||||
|
if !matches.is_present("continue") {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let entries = entries.map(|e| e.unwrap());
|
let entries = entries.map(|e| e.unwrap());
|
||||||
|
|
||||||
let head = head - 2;
|
let head = head - 2;
|
||||||
@ -122,12 +131,20 @@ fn main() {
|
|||||||
if i >= head {
|
if i >= head {
|
||||||
break;
|
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) {
|
if let Err(e) = bank.process_entry(&entry) {
|
||||||
eprintln!("verify failed at entry[{}], err: {:?}", i + 2, e);
|
eprintln!("verify failed at entry[{}], err: {:?}", i + 2, e);
|
||||||
|
if !matches.is_present("continue") {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
("", _) => {
|
("", _) => {
|
||||||
eprintln!("{}", matches.usage());
|
eprintln!("{}", matches.usage());
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -131,8 +131,7 @@ impl WriteStage {
|
|||||||
let mut crdt_votes_total = 0;
|
let mut crdt_votes_total = 0;
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
for _ in 0..ventries.len() {
|
for entries in ventries {
|
||||||
let entries = ventries.pop().unwrap();
|
|
||||||
for e in &entries {
|
for e in &entries {
|
||||||
num_txs += e.transactions.len();
|
num_txs += e.transactions.len();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user