make bank commit_credits non public (#4944)
* make bank commit_credits non pub * track down create() failure * move bank_client to process_transaction(), which commits credits
This commit is contained in:
parent
bb6bcd79c0
commit
eb4edd75e6
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -495,15 +495,23 @@ impl Bank {
|
|||
(validator_point_value, storage_point_value)
|
||||
}
|
||||
|
||||
fn set_hash(&self) -> bool {
|
||||
let mut hash = self.hash.write().unwrap();
|
||||
if *hash == Hash::default() {
|
||||
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() {
|
||||
// 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
|
||||
|
@ -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?
|
||||
|
|
|
@ -192,12 +192,7 @@ impl SyncClient for BankClient {
|
|||
impl BankClient {
|
||||
fn run(bank: &Bank, transaction_receiver: Receiver<Transaction>) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue