From bc2fd56516911e700c4477c305af8ed9edf40ed0 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 15 Jul 2020 18:22:33 -0600 Subject: [PATCH] Gate nonce-overwrite change (#11081) (#11086) (cherry picked from commit 1da9f9f05a67ae8190236c698b40c7c1538ab578) Co-authored-by: Tyera Eulberg --- runtime/src/accounts.rs | 5 +++++ runtime/src/bank.rs | 1 + runtime/src/nonce_utils.rs | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 574036a101..25f0f55333 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -680,6 +680,7 @@ impl Accounts { loaded: &mut [(Result, Option)], rent_collector: &RentCollector, last_blockhash_with_fee_calculator: &(Hash, FeeCalculator), + fix_recent_blockhashes_sysvar_delay: bool, ) { let accounts_to_store = self.collect_accounts_to_store( txs, @@ -688,6 +689,7 @@ impl Accounts { loaded, rent_collector, last_blockhash_with_fee_calculator, + fix_recent_blockhashes_sysvar_delay, ); self.accounts_db.store(slot, &accounts_to_store); } @@ -714,6 +716,7 @@ impl Accounts { loaded: &'a mut [(Result, Option)], rent_collector: &RentCollector, last_blockhash_with_fee_calculator: &(Hash, FeeCalculator), + fix_recent_blockhashes_sysvar_delay: bool, ) -> Vec<(&'a Pubkey, &'a Account)> { let mut accounts = Vec::with_capacity(loaded.len()); for (i, ((raccs, _hash_age_kind), tx)) in loaded @@ -750,6 +753,7 @@ impl Accounts { res, maybe_nonce, last_blockhash_with_fee_calculator, + fix_recent_blockhashes_sysvar_delay, ); if message.is_writable(i) { if account.rent_epoch == 0 { @@ -1772,6 +1776,7 @@ mod tests { &mut loaded, &rent_collector, &(Hash::default(), FeeCalculator::default()), + true, ); assert_eq!(collected_accounts.len(), 2); assert!(collected_accounts diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 3f6143beb7..06cddb7cce 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -1636,6 +1636,7 @@ impl Bank { loaded_accounts, &self.rent_collector, &self.last_blockhash_with_fee_calculator(), + self.fix_recent_blockhashes_sysvar_delay(), ); self.collect_rent(executed, loaded_accounts); diff --git a/runtime/src/nonce_utils.rs b/runtime/src/nonce_utils.rs index 48c7d8b120..ecf299510b 100644 --- a/runtime/src/nonce_utils.rs +++ b/runtime/src/nonce_utils.rs @@ -52,13 +52,21 @@ pub fn prepare_if_nonce_account( tx_result: &transaction::Result<()>, maybe_nonce: Option<(&Pubkey, &Account)>, last_blockhash_with_fee_calculator: &(Hash, FeeCalculator), + fix_recent_blockhashes_sysvar_delay: bool, ) { if let Some((nonce_key, nonce_acc)) = maybe_nonce { if account_pubkey == nonce_key { - // Nonce TX failed with an InstructionError. Roll back - // its account state - if tx_result.is_err() { + let overwrite = if tx_result.is_err() { + // Nonce TX failed with an InstructionError. Roll back + // its account state *account = nonce_acc.clone(); + true + } else { + // Retain overwrite on successful transactions until + // recent_blockhashes_sysvar_delay fix is activated + !fix_recent_blockhashes_sysvar_delay + }; + if overwrite { // Since hash_age_kind is DurableNonce, unwrap is safe here let state = StateMut::::state(nonce_acc) .unwrap() @@ -301,6 +309,7 @@ mod tests { tx_result, maybe_nonce, last_blockhash_with_fee_calculator, + true, ); expect_account == account }