Skip to content

Commit

Permalink
Add error messages to ledger verify
Browse files Browse the repository at this point in the history
  • Loading branch information
sakridge committed Jul 25, 2018
1 parent 8f046cb commit 6bd18e1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ impl Bank {
for block in &entries.into_iter().chunks(VERIFY_BLOCK_SIZE) {
let block: Vec<_> = block.collect();
if !block.verify(&self.last_id()) {
error!("Ledger proof of history failed at entry: {}", entry_count);
return Err(BankError::LedgerVerificationFailed);
}
entry_count += self.process_entries_tail(block, tail, tail_idx)?;
Expand Down
21 changes: 19 additions & 2 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,25 @@ impl Entry {
/// Verifies self.id is the result of hashing a `start_hash` `self.num_hashes` times.
/// If the transaction is not a Tick, then hash that as well.
pub fn verify(&self, start_hash: &Hash) -> bool {
self.transactions.par_iter().all(|tx| tx.verify_plan())
&& self.id == next_hash(start_hash, self.num_hashes, &self.transactions)
let tx_plans_verified = self.transactions.par_iter().all(|tx| {
let r = tx.verify_plan();
if !r {
error!("tx plan invalid: {:?}", tx);
}
r
});
if !tx_plans_verified {
return false;
}
let ref_hash = next_hash(start_hash, self.num_hashes, &self.transactions);
if self.id != ref_hash {
error!(
"next_hash is invalid expected: {:?} actual: {:?}",
self.id, ref_hash
);
return false;
}
true
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ impl Block for [Entry] {
fn verify(&self, start_hash: &Hash) -> bool {
let genesis = [Entry::new_tick(0, start_hash)];
let entry_pairs = genesis.par_iter().chain(self).zip(self);
entry_pairs.all(|(x0, x1)| x1.verify(&x0.id))
entry_pairs.all(|(x0, x1)| {
let r = x1.verify(&x0.id);
if !r {
error!(
"entry invalid!: {:?} num txs: {}",
x1.id,
x1.transactions.len()
);
}
r
})
}

fn to_blobs(&self, blob_recycler: &packet::BlobRecycler, q: &mut VecDeque<SharedBlob>) {
Expand Down

0 comments on commit 6bd18e1

Please sign in to comment.