removes feature gate code preventing crediting accounts that end rent paying (#28818)
This commit is contained in:
parent
d798e751a0
commit
28956d7653
|
@ -36,11 +36,7 @@ impl RentState {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn transition_allowed_from(
|
||||
&self,
|
||||
pre_rent_state: &RentState,
|
||||
prevent_crediting_accounts_that_end_rent_paying: bool,
|
||||
) -> bool {
|
||||
pub(crate) fn transition_allowed_from(&self, pre_rent_state: &RentState) -> bool {
|
||||
match self {
|
||||
Self::Uninitialized | Self::RentExempt => true,
|
||||
Self::RentPaying {
|
||||
|
@ -53,15 +49,8 @@ impl RentState {
|
|||
data_size: pre_data_size,
|
||||
lamports: pre_lamports,
|
||||
} => {
|
||||
// Cannot remain RentPaying if resized
|
||||
if post_data_size != pre_data_size {
|
||||
false
|
||||
} else if prevent_crediting_accounts_that_end_rent_paying {
|
||||
// Cannot remain RentPaying if credited
|
||||
post_lamports <= pre_lamports
|
||||
} else {
|
||||
true
|
||||
}
|
||||
// Cannot remain RentPaying if resized or credited.
|
||||
post_data_size == pre_data_size && post_lamports <= pre_lamports
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +79,6 @@ pub(crate) fn check_rent_state(
|
|||
transaction_context: &TransactionContext,
|
||||
index: IndexOfAccount,
|
||||
include_account_index_in_err: bool,
|
||||
prevent_crediting_accounts_that_end_rent_paying: bool,
|
||||
) -> Result<()> {
|
||||
if let Some((pre_rent_state, post_rent_state)) = pre_rent_state.zip(post_rent_state) {
|
||||
let expect_msg = "account must exist at TransactionContext index if rent-states are Some";
|
||||
|
@ -105,7 +93,6 @@ pub(crate) fn check_rent_state(
|
|||
.expect(expect_msg)
|
||||
.borrow(),
|
||||
include_account_index_in_err.then_some(index),
|
||||
prevent_crediting_accounts_that_end_rent_paying,
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
|
@ -117,14 +104,10 @@ pub(crate) fn check_rent_state_with_account(
|
|||
address: &Pubkey,
|
||||
account_state: &AccountSharedData,
|
||||
account_index: Option<IndexOfAccount>,
|
||||
prevent_crediting_accounts_that_end_rent_paying: bool,
|
||||
) -> 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,
|
||||
prevent_crediting_accounts_that_end_rent_paying,
|
||||
)
|
||||
&& !post_rent_state.transition_allowed_from(pre_rent_state)
|
||||
{
|
||||
debug!(
|
||||
"Account {} not rent exempt, state {:?}",
|
||||
|
@ -196,103 +179,66 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_transition_allowed_from() {
|
||||
check_transition_allowed_from(
|
||||
/*prevent_crediting_accounts_that_end_rent_paying:*/ false,
|
||||
);
|
||||
check_transition_allowed_from(
|
||||
/*prevent_crediting_accounts_that_end_rent_paying:*/ true,
|
||||
);
|
||||
}
|
||||
|
||||
fn check_transition_allowed_from(prevent_crediting_accounts_that_end_rent_paying: bool) {
|
||||
let post_rent_state = RentState::Uninitialized;
|
||||
assert!(post_rent_state.transition_allowed_from(
|
||||
&RentState::Uninitialized,
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
assert!(post_rent_state.transition_allowed_from(
|
||||
&RentState::RentExempt,
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
assert!(post_rent_state.transition_allowed_from(
|
||||
&RentState::RentPaying {
|
||||
assert!(post_rent_state.transition_allowed_from(&RentState::Uninitialized));
|
||||
assert!(post_rent_state.transition_allowed_from(&RentState::RentExempt));
|
||||
assert!(
|
||||
post_rent_state.transition_allowed_from(&RentState::RentPaying {
|
||||
data_size: 0,
|
||||
lamports: 1,
|
||||
},
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
})
|
||||
);
|
||||
|
||||
let post_rent_state = RentState::RentExempt;
|
||||
assert!(post_rent_state.transition_allowed_from(
|
||||
&RentState::Uninitialized,
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
assert!(post_rent_state.transition_allowed_from(
|
||||
&RentState::RentExempt,
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
assert!(post_rent_state.transition_allowed_from(
|
||||
&RentState::RentPaying {
|
||||
assert!(post_rent_state.transition_allowed_from(&RentState::Uninitialized));
|
||||
assert!(post_rent_state.transition_allowed_from(&RentState::RentExempt));
|
||||
assert!(
|
||||
post_rent_state.transition_allowed_from(&RentState::RentPaying {
|
||||
data_size: 0,
|
||||
lamports: 1,
|
||||
},
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
})
|
||||
);
|
||||
let post_rent_state = RentState::RentPaying {
|
||||
data_size: 2,
|
||||
lamports: 5,
|
||||
};
|
||||
assert!(!post_rent_state.transition_allowed_from(
|
||||
&RentState::Uninitialized,
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
assert!(!post_rent_state.transition_allowed_from(
|
||||
&RentState::RentExempt,
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
assert!(!post_rent_state.transition_allowed_from(
|
||||
&RentState::RentPaying {
|
||||
assert!(!post_rent_state.transition_allowed_from(&RentState::Uninitialized));
|
||||
assert!(!post_rent_state.transition_allowed_from(&RentState::RentExempt));
|
||||
assert!(
|
||||
!post_rent_state.transition_allowed_from(&RentState::RentPaying {
|
||||
data_size: 3,
|
||||
lamports: 5
|
||||
},
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
assert!(!post_rent_state.transition_allowed_from(
|
||||
&RentState::RentPaying {
|
||||
})
|
||||
);
|
||||
assert!(
|
||||
!post_rent_state.transition_allowed_from(&RentState::RentPaying {
|
||||
data_size: 1,
|
||||
lamports: 5
|
||||
},
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
})
|
||||
);
|
||||
// Transition is always allowed if there is no account data resize or
|
||||
// change in account's lamports.
|
||||
assert!(post_rent_state.transition_allowed_from(
|
||||
&RentState::RentPaying {
|
||||
assert!(
|
||||
post_rent_state.transition_allowed_from(&RentState::RentPaying {
|
||||
data_size: 2,
|
||||
lamports: 5
|
||||
},
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
})
|
||||
);
|
||||
// Transition is always allowed if there is no account data resize and
|
||||
// account's lamports is reduced.
|
||||
assert!(post_rent_state.transition_allowed_from(
|
||||
&RentState::RentPaying {
|
||||
assert!(
|
||||
post_rent_state.transition_allowed_from(&RentState::RentPaying {
|
||||
data_size: 2,
|
||||
lamports: 7
|
||||
},
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
));
|
||||
// Once the feature is activated, transition is not allowed if the
|
||||
// account is credited with more lamports and remains rent-paying.
|
||||
assert_eq!(
|
||||
post_rent_state.transition_allowed_from(
|
||||
&RentState::RentPaying {
|
||||
data_size: 2,
|
||||
lamports: 3
|
||||
},
|
||||
prevent_crediting_accounts_that_end_rent_paying
|
||||
),
|
||||
!prevent_crediting_accounts_that_end_rent_paying
|
||||
})
|
||||
);
|
||||
// Transition is not allowed if the account is credited with more
|
||||
// lamports and remains rent-paying.
|
||||
assert!(
|
||||
!post_rent_state.transition_allowed_from(&RentState::RentPaying {
|
||||
data_size: 2,
|
||||
lamports: 3
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -492,8 +492,6 @@ impl Accounts {
|
|||
feature_set
|
||||
.is_active(&feature_set::include_account_index_in_rent_error::ID)
|
||||
.then_some(payer_index),
|
||||
feature_set
|
||||
.is_active(&feature_set::prevent_crediting_accounts_that_end_rent_paying::id()),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -13957,9 +13957,9 @@ pub(crate) mod tests {
|
|||
let pubkey0 = solana_sdk::pubkey::new_rand();
|
||||
let pubkey1 = solana_sdk::pubkey::new_rand();
|
||||
let pubkey2 = solana_sdk::pubkey::new_rand();
|
||||
let keypair0_account = AccountSharedData::new(8_000, 0, &Pubkey::default());
|
||||
let keypair1_account = AccountSharedData::new(9_000, 0, &Pubkey::default());
|
||||
let account0 = AccountSharedData::new(11_000, 0, &Pubkey::default());
|
||||
let keypair0_account = AccountSharedData::new(908_000, 0, &Pubkey::default());
|
||||
let keypair1_account = AccountSharedData::new(909_000, 0, &Pubkey::default());
|
||||
let account0 = AccountSharedData::new(911_000, 0, &Pubkey::default());
|
||||
bank0.store_account(&keypair0.pubkey(), &keypair0_account);
|
||||
bank0.store_account(&keypair1.pubkey(), &keypair1_account);
|
||||
bank0.store_account(&pubkey0, &account0);
|
||||
|
@ -13968,7 +13968,7 @@ pub(crate) mod tests {
|
|||
|
||||
let tx0 = system_transaction::transfer(&keypair0, &pubkey0, 2_000, blockhash);
|
||||
let tx1 = system_transaction::transfer(&Keypair::new(), &pubkey1, 2_000, blockhash);
|
||||
let tx2 = system_transaction::transfer(&keypair1, &pubkey2, 12_000, blockhash);
|
||||
let tx2 = system_transaction::transfer(&keypair1, &pubkey2, 912_000, blockhash);
|
||||
let txs = vec![tx0, tx1, tx2];
|
||||
|
||||
let lock_result = bank0.prepare_batch_for_tests(txs);
|
||||
|
@ -13990,11 +13990,11 @@ pub(crate) mod tests {
|
|||
assert!(transaction_results.execution_results[0].was_executed_successfully());
|
||||
assert_eq!(
|
||||
transaction_balances_set.pre_balances[0],
|
||||
vec![8_000, 11_000, 1]
|
||||
vec![908_000, 911_000, 1]
|
||||
);
|
||||
assert_eq!(
|
||||
transaction_balances_set.post_balances[0],
|
||||
vec![1_000, 13_000, 1]
|
||||
vec![901_000, 913_000, 1]
|
||||
);
|
||||
|
||||
// Failed transactions still produce balance sets
|
||||
|
@ -14021,8 +14021,14 @@ pub(crate) mod tests {
|
|||
..
|
||||
},
|
||||
));
|
||||
assert_eq!(transaction_balances_set.pre_balances[2], vec![9_000, 0, 1]);
|
||||
assert_eq!(transaction_balances_set.post_balances[2], vec![4_000, 0, 1]);
|
||||
assert_eq!(
|
||||
transaction_balances_set.pre_balances[2],
|
||||
vec![909_000, 0, 1]
|
||||
);
|
||||
assert_eq!(
|
||||
transaction_balances_set.post_balances[2],
|
||||
vec![904_000, 0, 1]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -64,9 +64,6 @@ impl Bank {
|
|||
let include_account_index_in_err = self
|
||||
.feature_set
|
||||
.is_active(&feature_set::include_account_index_in_rent_error::id());
|
||||
let prevent_crediting_accounts_that_end_rent_paying = self
|
||||
.feature_set
|
||||
.is_active(&feature_set::prevent_crediting_accounts_that_end_rent_paying::id());
|
||||
for (i, (pre_state_info, post_state_info)) in
|
||||
pre_state_infos.iter().zip(post_state_infos).enumerate()
|
||||
{
|
||||
|
@ -76,7 +73,6 @@ impl Bank {
|
|||
transaction_context,
|
||||
i as IndexOfAccount,
|
||||
include_account_index_in_err,
|
||||
prevent_crediting_accounts_that_end_rent_paying,
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue