No longer flood log with emtpy entries

This commit is contained in:
Greg Fitzgerald 2018-06-14 17:32:39 -06:00
parent 87946eafd5
commit 9b202c6e1e
1 changed files with 24 additions and 2 deletions

View File

@ -315,9 +315,11 @@ impl Bank {
I: IntoIterator<Item = Entry>, I: IntoIterator<Item = Entry>,
{ {
for entry in entries { for entry in entries {
if !entry.transactions.is_empty() {
for result in self.process_transactions(entry.transactions) { for result in self.process_transactions(entry.transactions) {
result?; result?;
} }
}
self.register_entry_id(&entry.id); self.register_entry_id(&entry.id);
} }
Ok(()) Ok(())
@ -440,6 +442,7 @@ impl Bank {
mod tests { mod tests {
use super::*; use super::*;
use bincode::serialize; use bincode::serialize;
use entry::next_entry;
use hash::hash; use hash::hash;
use signature::KeyPairUtil; use signature::KeyPairUtil;
@ -651,6 +654,25 @@ mod tests {
// Assert bad transactions aren't counted. // Assert bad transactions aren't counted.
assert_eq!(bank.transaction_count(), 1); assert_eq!(bank.transaction_count(), 1);
} }
#[test]
fn test_process_empty_entry_is_registered() {
let mint = Mint::new(1);
let bank = Bank::new(&mint);
let keypair = KeyPair::new();
let entry = next_entry(&mint.last_id(), 1, vec![]);
let tx = Transaction::new(&mint.keypair(), keypair.pubkey(), 1, entry.id);
// First, ensure the TX is rejected because of the unregistered last ID
assert_eq!(
bank.process_transaction(&tx),
Err(BankError::LastIdNotFound(entry.id))
);
// Now ensure the TX is accepted despite pointing to the ID of an empty entry.
bank.process_entries(vec![entry]).unwrap();
assert!(bank.process_transaction(&tx).is_ok());
}
} }
#[cfg(all(feature = "unstable", test))] #[cfg(all(feature = "unstable", test))]