diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 4904c38f09..3a033bcc26 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -616,7 +616,6 @@ impl ReplayStage { slot_full_sender: &Sender<(u64, Pubkey)>, ) { bank.freeze(); - bank.commit_credits(); info!("bank frozen {}", bank.slot()); if let Err(e) = slot_full_sender.send((bank.slot(), *bank.collector_id())) { trace!("{} slot_full alert failed: {:?}", my_pubkey, e); diff --git a/runtime/src/append_vec.rs b/runtime/src/append_vec.rs index b5c393a74b..80812e5c22 100644 --- a/runtime/src/append_vec.rs +++ b/runtime/src/append_vec.rs @@ -92,7 +92,15 @@ impl AppendVec { .write(true) .create(create) .open(file) - .expect("Unable to open data file"); + .map_err(|e| { + panic!( + "Unable to {} data file {}, err {:?}", + if create { "create" } else { "open" }, + file.display(), + e + ); + }) + .unwrap(); data.seek(SeekFrom::Start((size - 1) as u64)).unwrap(); data.write_all(&[0]).unwrap(); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 6e15b63a11..18b152c6ea 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -495,16 +495,24 @@ impl Bank { (validator_point_value, storage_point_value) } + fn collect_fees(&self) { + let collector_fees = self.collector_fees.load(Ordering::Relaxed) as u64; + + if collector_fees != 0 { + // burn a portion of fees + self.deposit(&self.collector_id, self.fee_calculator.burn(collector_fees)); + } + } + fn set_hash(&self) -> bool { let mut hash = self.hash.write().unwrap(); - if *hash == Hash::default() { - let collector_fees = self.collector_fees.load(Ordering::Relaxed) as u64; - if collector_fees != 0 { - // burn a portion of fees - self.deposit(&self.collector_id, self.fee_calculator.burn(collector_fees)); - } - // freeze is a one-way trip, idempotent + if *hash == Hash::default() { + // finish up any deferred changes to account state + self.commit_credits(); + self.collect_fees(); + + // freeze is a one-way trip, idempotent *hash = self.hash_internal_state(); true } else { @@ -1404,7 +1412,7 @@ impl Bank { ); } - pub fn commit_credits(&self) { + fn commit_credits(&self) { self.rc .accounts .commit_credits(&self.ancestors, self.slot()); @@ -1578,6 +1586,7 @@ mod tests { let t2 = system_transaction::transfer(&mint_keypair, &key2, 1, genesis_block.hash()); let res = bank.process_transactions(&vec![t1.clone(), t2.clone()]); bank.commit_credits(); + assert_eq!(res.len(), 2); assert_eq!(res[0], Ok(())); assert_eq!(res[1], Err(TransactionError::AccountInUse)); @@ -1987,7 +1996,6 @@ mod tests { let txs = vec![tx0, tx1]; let results = bank.process_transactions(&txs); bank.commit_credits(); - // However, an account may not be locked as credit-only and credit-debit at the same time. assert_eq!(results[0], Ok(())); assert_eq!(results[1], Err(TransactionError::AccountInUse)); @@ -2129,8 +2137,8 @@ mod tests { bank.transfer(1, &mint_keypair, &key1.pubkey()).unwrap(); assert_eq!(bank.get_balance(&key1.pubkey()), 1); let tx = system_transaction::transfer(&key1, &key1.pubkey(), 1, genesis_block.hash()); - let res = bank.process_transactions(&vec![tx.clone()]); - assert_eq!(res.len(), 1); + let _res = bank.process_transaction(&tx); + assert_eq!(bank.get_balance(&key1.pubkey()), 1); // TODO: Why do we convert errors to Oks? diff --git a/runtime/src/bank_client.rs b/runtime/src/bank_client.rs index 95400e74e7..40b60191a6 100644 --- a/runtime/src/bank_client.rs +++ b/runtime/src/bank_client.rs @@ -192,12 +192,7 @@ impl SyncClient for BankClient { impl BankClient { fn run(bank: &Bank, transaction_receiver: Receiver) { while let Ok(tx) = transaction_receiver.recv() { - let mut transactions = vec![tx]; - while let Ok(tx) = transaction_receiver.try_recv() { - transactions.push(tx); - } - let _ = bank.process_transactions(&transactions); - bank.commit_credits(); + let _ = bank.process_transaction(&tx); } }