From feb197cb6e1cbfd196eefa99ec126b64932fb76b Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Mon, 28 Feb 2022 23:56:34 -0700 Subject: [PATCH] Allow sub-rent-exempt-minimum transfers to `1nc1nerator` (#23382) * Add failing test * Allow small burns to incinerator * Use check_id method (cherry picked from commit 19448ba078379846213fd3d5691feefb2b2f4810) # Conflicts: # runtime/src/account_rent_state.rs --- runtime/src/account_rent_state.rs | 34 +++++++++++++++++++++++++++++++ runtime/src/bank.rs | 22 ++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/runtime/src/account_rent_state.rs b/runtime/src/account_rent_state.rs index 976390275594d3..2e07796ef1e88e 100644 --- a/runtime/src/account_rent_state.rs +++ b/runtime/src/account_rent_state.rs @@ -55,11 +55,45 @@ pub(crate) fn check_rent_state( account: &AccountSharedData, ) -> Result<()> { if let Some((pre_rent_state, post_rent_state)) = pre_rent_state.zip(post_rent_state) { +<<<<<<< HEAD submit_rent_state_metrics(pre_rent_state, post_rent_state); if !post_rent_state.transition_allowed_from(pre_rent_state) { debug!("Account {:?} not rent exempt, state {:?}", address, account); return Err(TransactionError::InvalidRentPayingAccount); } +======= + let expect_msg = "account must exist at TransactionContext index if rent-states are Some"; + check_rent_state_with_account( + pre_rent_state, + post_rent_state, + transaction_context + .get_key_of_account_at_index(index) + .expect(expect_msg), + &transaction_context + .get_account_at_index(index) + .expect(expect_msg) + .borrow(), + )?; + } + Ok(()) +} + +pub(crate) fn check_rent_state_with_account( + pre_rent_state: &RentState, + post_rent_state: &RentState, + address: &Pubkey, + account_state: &AccountSharedData, +) -> Result<()> { + submit_rent_state_metrics(pre_rent_state, post_rent_state); + if !solana_sdk::incinerator::check_id(address) + && !post_rent_state.transition_allowed_from(pre_rent_state) + { + debug!( + "Account {} not rent exempt, state {:?}", + address, account_state, + ); + return Err(TransactionError::InvalidRentPayingAccount); +>>>>>>> 19448ba07 (Allow sub-rent-exempt-minimum transfers to `1nc1nerator` (#23382)) } Ok(()) } diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 38494d401bcf21..572edefbe204b6 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -17030,6 +17030,28 @@ pub(crate) mod tests { )); } + // Ensure System transfers of any size can be made to the incinerator + #[test] + fn test_rent_state_incinerator() { + let GenesisConfigInfo { + mut genesis_config, + mint_keypair, + .. + } = create_genesis_config_with_leader(sol_to_lamports(100.), &Pubkey::new_unique(), 42); + genesis_config.rent = Rent::default(); + let rent_exempt_minimum = genesis_config.rent.minimum_balance(0); + + // Activate features, including require_rent_exempt_accounts + activate_all_features(&mut genesis_config); + + let bank = Bank::new_for_tests(&genesis_config); + + for amount in [rent_exempt_minimum - 1, rent_exempt_minimum] { + bank.transfer(amount, &mint_keypair, &solana_sdk::incinerator::id()) + .unwrap(); + } + } + #[test] fn test_rent_state_list_len() { let GenesisConfigInfo {