Add error messages to ledger verify
This commit is contained in:
parent
8f046cb1f8
commit
6bd18e18ea
|
@ -389,6 +389,7 @@ impl Bank {
|
||||||
for block in &entries.into_iter().chunks(VERIFY_BLOCK_SIZE) {
|
for block in &entries.into_iter().chunks(VERIFY_BLOCK_SIZE) {
|
||||||
let block: Vec<_> = block.collect();
|
let block: Vec<_> = block.collect();
|
||||||
if !block.verify(&self.last_id()) {
|
if !block.verify(&self.last_id()) {
|
||||||
|
error!("Ledger proof of history failed at entry: {}", entry_count);
|
||||||
return Err(BankError::LedgerVerificationFailed);
|
return Err(BankError::LedgerVerificationFailed);
|
||||||
}
|
}
|
||||||
entry_count += self.process_entries_tail(block, tail, tail_idx)?;
|
entry_count += self.process_entries_tail(block, tail, tail_idx)?;
|
||||||
|
|
21
src/entry.rs
21
src/entry.rs
|
@ -115,8 +115,25 @@ impl Entry {
|
||||||
/// Verifies self.id is the result of hashing a `start_hash` `self.num_hashes` times.
|
/// 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.
|
/// If the transaction is not a Tick, then hash that as well.
|
||||||
pub fn verify(&self, start_hash: &Hash) -> bool {
|
pub fn verify(&self, start_hash: &Hash) -> bool {
|
||||||
self.transactions.par_iter().all(|tx| tx.verify_plan())
|
let tx_plans_verified = self.transactions.par_iter().all(|tx| {
|
||||||
&& self.id == next_hash(start_hash, self.num_hashes, &self.transactions)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,17 @@ impl Block for [Entry] {
|
||||||
fn verify(&self, start_hash: &Hash) -> bool {
|
fn verify(&self, start_hash: &Hash) -> bool {
|
||||||
let genesis = [Entry::new_tick(0, start_hash)];
|
let genesis = [Entry::new_tick(0, start_hash)];
|
||||||
let entry_pairs = genesis.par_iter().chain(self).zip(self);
|
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>) {
|
fn to_blobs(&self, blob_recycler: &packet::BlobRecycler, q: &mut VecDeque<SharedBlob>) {
|
||||||
|
|
Loading…
Reference in New Issue