Gate nonce-overwrite change (#11081)
This commit is contained in:
		| @@ -650,6 +650,7 @@ impl Accounts { | |||||||
|         loaded: &mut [(Result<TransactionLoadResult>, Option<HashAgeKind>)], |         loaded: &mut [(Result<TransactionLoadResult>, Option<HashAgeKind>)], | ||||||
|         rent_collector: &RentCollector, |         rent_collector: &RentCollector, | ||||||
|         last_blockhash_with_fee_calculator: &(Hash, FeeCalculator), |         last_blockhash_with_fee_calculator: &(Hash, FeeCalculator), | ||||||
|  |         fix_recent_blockhashes_sysvar_delay: bool, | ||||||
|     ) { |     ) { | ||||||
|         let accounts_to_store = self.collect_accounts_to_store( |         let accounts_to_store = self.collect_accounts_to_store( | ||||||
|             txs, |             txs, | ||||||
| @@ -658,6 +659,7 @@ impl Accounts { | |||||||
|             loaded, |             loaded, | ||||||
|             rent_collector, |             rent_collector, | ||||||
|             last_blockhash_with_fee_calculator, |             last_blockhash_with_fee_calculator, | ||||||
|  |             fix_recent_blockhashes_sysvar_delay, | ||||||
|         ); |         ); | ||||||
|         self.accounts_db.store(slot, &accounts_to_store); |         self.accounts_db.store(slot, &accounts_to_store); | ||||||
|     } |     } | ||||||
| @@ -684,6 +686,7 @@ impl Accounts { | |||||||
|         loaded: &'a mut [(Result<TransactionLoadResult>, Option<HashAgeKind>)], |         loaded: &'a mut [(Result<TransactionLoadResult>, Option<HashAgeKind>)], | ||||||
|         rent_collector: &RentCollector, |         rent_collector: &RentCollector, | ||||||
|         last_blockhash_with_fee_calculator: &(Hash, FeeCalculator), |         last_blockhash_with_fee_calculator: &(Hash, FeeCalculator), | ||||||
|  |         fix_recent_blockhashes_sysvar_delay: bool, | ||||||
|     ) -> Vec<(&'a Pubkey, &'a Account)> { |     ) -> Vec<(&'a Pubkey, &'a Account)> { | ||||||
|         let mut accounts = Vec::with_capacity(loaded.len()); |         let mut accounts = Vec::with_capacity(loaded.len()); | ||||||
|         for (i, ((raccs, _hash_age_kind), tx)) in loaded |         for (i, ((raccs, _hash_age_kind), tx)) in loaded | ||||||
| @@ -720,6 +723,7 @@ impl Accounts { | |||||||
|                     res, |                     res, | ||||||
|                     maybe_nonce, |                     maybe_nonce, | ||||||
|                     last_blockhash_with_fee_calculator, |                     last_blockhash_with_fee_calculator, | ||||||
|  |                     fix_recent_blockhashes_sysvar_delay, | ||||||
|                 ); |                 ); | ||||||
|                 if message.is_writable(i) { |                 if message.is_writable(i) { | ||||||
|                     if account.rent_epoch == 0 { |                     if account.rent_epoch == 0 { | ||||||
| @@ -1675,6 +1679,7 @@ mod tests { | |||||||
|             &mut loaded, |             &mut loaded, | ||||||
|             &rent_collector, |             &rent_collector, | ||||||
|             &(Hash::default(), FeeCalculator::default()), |             &(Hash::default(), FeeCalculator::default()), | ||||||
|  |             true, | ||||||
|         ); |         ); | ||||||
|         assert_eq!(collected_accounts.len(), 2); |         assert_eq!(collected_accounts.len(), 2); | ||||||
|         assert!(collected_accounts |         assert!(collected_accounts | ||||||
|   | |||||||
| @@ -1776,6 +1776,7 @@ impl Bank { | |||||||
|             loaded_accounts, |             loaded_accounts, | ||||||
|             &self.rent_collector, |             &self.rent_collector, | ||||||
|             &self.last_blockhash_with_fee_calculator(), |             &self.last_blockhash_with_fee_calculator(), | ||||||
|  |             self.fix_recent_blockhashes_sysvar_delay(), | ||||||
|         ); |         ); | ||||||
|         self.collect_rent(executed, loaded_accounts); |         self.collect_rent(executed, loaded_accounts); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -52,13 +52,21 @@ pub fn prepare_if_nonce_account( | |||||||
|     tx_result: &transaction::Result<()>, |     tx_result: &transaction::Result<()>, | ||||||
|     maybe_nonce: Option<(&Pubkey, &Account)>, |     maybe_nonce: Option<(&Pubkey, &Account)>, | ||||||
|     last_blockhash_with_fee_calculator: &(Hash, FeeCalculator), |     last_blockhash_with_fee_calculator: &(Hash, FeeCalculator), | ||||||
|  |     fix_recent_blockhashes_sysvar_delay: bool, | ||||||
| ) { | ) { | ||||||
|     if let Some((nonce_key, nonce_acc)) = maybe_nonce { |     if let Some((nonce_key, nonce_acc)) = maybe_nonce { | ||||||
|         if account_pubkey == nonce_key { |         if account_pubkey == nonce_key { | ||||||
|  |             let overwrite = if tx_result.is_err() { | ||||||
|                 // Nonce TX failed with an InstructionError. Roll back |                 // Nonce TX failed with an InstructionError. Roll back | ||||||
|                 // its account state |                 // its account state | ||||||
|             if tx_result.is_err() { |  | ||||||
|                 *account = nonce_acc.clone(); |                 *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 |                 // Since hash_age_kind is DurableNonce, unwrap is safe here | ||||||
|                 let state = StateMut::<Versions>::state(nonce_acc) |                 let state = StateMut::<Versions>::state(nonce_acc) | ||||||
|                     .unwrap() |                     .unwrap() | ||||||
| @@ -294,6 +302,7 @@ mod tests { | |||||||
|             tx_result, |             tx_result, | ||||||
|             maybe_nonce, |             maybe_nonce, | ||||||
|             last_blockhash_with_fee_calculator, |             last_blockhash_with_fee_calculator, | ||||||
|  |             true, | ||||||
|         ); |         ); | ||||||
|         expect_account == account |         expect_account == account | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user