|
@@ -2,8 +2,11 @@
|
|
|
use qualifier_attr::{field_qualifiers, qualifiers};
|
|
use qualifier_attr::{field_qualifiers, qualifiers};
|
|
|
use {
|
|
use {
|
|
|
crate::{
|
|
crate::{
|
|
|
- account_overrides::AccountOverrides, nonce_info::NonceInfo,
|
|
|
|
|
- rollback_accounts::RollbackAccounts, transaction_error_metrics::TransactionErrorMetrics,
|
|
|
|
|
|
|
+ account_overrides::AccountOverrides,
|
|
|
|
|
+ nonce_info::NonceInfo,
|
|
|
|
|
+ rent_calculator::{check_rent_state_with_account, get_account_rent_state},
|
|
|
|
|
+ rollback_accounts::RollbackAccounts,
|
|
|
|
|
+ transaction_error_metrics::TransactionErrorMetrics,
|
|
|
transaction_execution_result::ExecutedTransaction,
|
|
transaction_execution_result::ExecutedTransaction,
|
|
|
},
|
|
},
|
|
|
ahash::{AHashMap, AHashSet},
|
|
ahash::{AHashMap, AHashSet},
|
|
@@ -21,7 +24,7 @@ use {
|
|
|
SVMTransactionExecutionAndFeeBudgetLimits, SVMTransactionExecutionBudget,
|
|
SVMTransactionExecutionAndFeeBudgetLimits, SVMTransactionExecutionBudget,
|
|
|
},
|
|
},
|
|
|
solana_pubkey::Pubkey,
|
|
solana_pubkey::Pubkey,
|
|
|
- solana_rent::RentDue,
|
|
|
|
|
|
|
+ solana_rent::Rent,
|
|
|
solana_rent_collector::RENT_EXEMPT_RENT_EPOCH,
|
|
solana_rent_collector::RENT_EXEMPT_RENT_EPOCH,
|
|
|
solana_sdk_ids::{
|
|
solana_sdk_ids::{
|
|
|
bpf_loader_upgradeable, native_loader,
|
|
bpf_loader_upgradeable, native_loader,
|
|
@@ -29,7 +32,6 @@ use {
|
|
|
},
|
|
},
|
|
|
solana_svm_callback::{AccountState, TransactionProcessingCallback},
|
|
solana_svm_callback::{AccountState, TransactionProcessingCallback},
|
|
|
solana_svm_feature_set::SVMFeatureSet,
|
|
solana_svm_feature_set::SVMFeatureSet,
|
|
|
- solana_svm_rent_collector::svm_rent_collector::SVMRentCollector,
|
|
|
|
|
solana_svm_transaction::svm_message::SVMMessage,
|
|
solana_svm_transaction::svm_message::SVMMessage,
|
|
|
solana_transaction_context::{IndexOfAccount, TransactionAccount},
|
|
solana_transaction_context::{IndexOfAccount, TransactionAccount},
|
|
|
solana_transaction_error::{TransactionError, TransactionResult as Result},
|
|
solana_transaction_error::{TransactionError, TransactionResult as Result},
|
|
@@ -339,21 +341,14 @@ impl<CB: TransactionProcessingCallback> solana_svm_callback::InvokeContextCallba
|
|
|
/// TODO: This function is used to update the rent epoch of an account. Once we
|
|
/// TODO: This function is used to update the rent epoch of an account. Once we
|
|
|
/// completely switched to lthash, where rent_epoch is ignored in accounts
|
|
/// completely switched to lthash, where rent_epoch is ignored in accounts
|
|
|
/// hashing, we can remove this function.
|
|
/// hashing, we can remove this function.
|
|
|
-pub fn update_rent_exempt_status_for_account(
|
|
|
|
|
- rent_collector: &dyn SVMRentCollector,
|
|
|
|
|
- account: &mut AccountSharedData,
|
|
|
|
|
-) {
|
|
|
|
|
|
|
+pub fn update_rent_exempt_status_for_account(rent: &Rent, account: &mut AccountSharedData) {
|
|
|
// Now that rent fee collection is disabled, we won't collect rent for any
|
|
// Now that rent fee collection is disabled, we won't collect rent for any
|
|
|
// account. If there are any rent paying accounts, their `rent_epoch` won't
|
|
// account. If there are any rent paying accounts, their `rent_epoch` won't
|
|
|
// change either. However, if the account itself is rent-exempted but its
|
|
// change either. However, if the account itself is rent-exempted but its
|
|
|
// `rent_epoch` is not u64::MAX, we will set its `rent_epoch` to u64::MAX.
|
|
// `rent_epoch` is not u64::MAX, we will set its `rent_epoch` to u64::MAX.
|
|
|
// In such case, the behavior stays the same as before.
|
|
// In such case, the behavior stays the same as before.
|
|
|
if account.rent_epoch() != RENT_EXEMPT_RENT_EPOCH
|
|
if account.rent_epoch() != RENT_EXEMPT_RENT_EPOCH
|
|
|
- && rent_collector.get_rent_due(
|
|
|
|
|
- account.lamports(),
|
|
|
|
|
- account.data().len(),
|
|
|
|
|
- account.rent_epoch(),
|
|
|
|
|
- ) == RentDue::Exempt
|
|
|
|
|
|
|
+ && rent.is_exempt(account.lamports(), account.data().len())
|
|
|
{
|
|
{
|
|
|
account.set_rent_epoch(RENT_EXEMPT_RENT_EPOCH);
|
|
account.set_rent_epoch(RENT_EXEMPT_RENT_EPOCH);
|
|
|
}
|
|
}
|
|
@@ -369,7 +364,7 @@ pub fn validate_fee_payer(
|
|
|
payer_account: &mut AccountSharedData,
|
|
payer_account: &mut AccountSharedData,
|
|
|
payer_index: IndexOfAccount,
|
|
payer_index: IndexOfAccount,
|
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
|
- rent_collector: &dyn SVMRentCollector,
|
|
|
|
|
|
|
+ rent: &Rent,
|
|
|
fee: u64,
|
|
fee: u64,
|
|
|
) -> Result<()> {
|
|
) -> Result<()> {
|
|
|
if payer_account.lamports() == 0 {
|
|
if payer_account.lamports() == 0 {
|
|
@@ -385,9 +380,7 @@ pub fn validate_fee_payer(
|
|
|
SystemAccountKind::Nonce => {
|
|
SystemAccountKind::Nonce => {
|
|
|
// Should we ever allow a fees charge to zero a nonce account's
|
|
// Should we ever allow a fees charge to zero a nonce account's
|
|
|
// balance. The state MUST be set to uninitialized in that case
|
|
// balance. The state MUST be set to uninitialized in that case
|
|
|
- rent_collector
|
|
|
|
|
- .get_rent()
|
|
|
|
|
- .minimum_balance(NonceState::size())
|
|
|
|
|
|
|
+ rent.minimum_balance(NonceState::size())
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -400,13 +393,13 @@ pub fn validate_fee_payer(
|
|
|
TransactionError::InsufficientFundsForFee
|
|
TransactionError::InsufficientFundsForFee
|
|
|
})?;
|
|
})?;
|
|
|
|
|
|
|
|
- let payer_pre_rent_state = rent_collector.get_account_rent_state(payer_account);
|
|
|
|
|
|
|
+ let payer_pre_rent_state = get_account_rent_state(rent, payer_account);
|
|
|
payer_account
|
|
payer_account
|
|
|
.checked_sub_lamports(fee)
|
|
.checked_sub_lamports(fee)
|
|
|
.map_err(|_| TransactionError::InsufficientFundsForFee)?;
|
|
.map_err(|_| TransactionError::InsufficientFundsForFee)?;
|
|
|
|
|
|
|
|
- let payer_post_rent_state = rent_collector.get_account_rent_state(payer_account);
|
|
|
|
|
- rent_collector.check_rent_state_with_account(
|
|
|
|
|
|
|
+ let payer_post_rent_state = get_account_rent_state(rent, payer_account);
|
|
|
|
|
+ check_rent_state_with_account(
|
|
|
&payer_pre_rent_state,
|
|
&payer_pre_rent_state,
|
|
|
&payer_post_rent_state,
|
|
&payer_post_rent_state,
|
|
|
payer_address,
|
|
payer_address,
|
|
@@ -420,7 +413,7 @@ pub(crate) fn load_transaction<CB: TransactionProcessingCallback>(
|
|
|
message: &impl SVMMessage,
|
|
message: &impl SVMMessage,
|
|
|
validation_result: TransactionValidationResult,
|
|
validation_result: TransactionValidationResult,
|
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
|
- rent_collector: &dyn SVMRentCollector,
|
|
|
|
|
|
|
+ rent: &Rent,
|
|
|
) -> TransactionLoadResult {
|
|
) -> TransactionLoadResult {
|
|
|
match validation_result {
|
|
match validation_result {
|
|
|
Err(e) => TransactionLoadResult::NotLoaded(e),
|
|
Err(e) => TransactionLoadResult::NotLoaded(e),
|
|
@@ -431,7 +424,7 @@ pub(crate) fn load_transaction<CB: TransactionProcessingCallback>(
|
|
|
tx_details.loaded_fee_payer_account,
|
|
tx_details.loaded_fee_payer_account,
|
|
|
tx_details.loaded_accounts_bytes_limit,
|
|
tx_details.loaded_accounts_bytes_limit,
|
|
|
error_metrics,
|
|
error_metrics,
|
|
|
- rent_collector,
|
|
|
|
|
|
|
+ rent,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
match load_result {
|
|
match load_result {
|
|
@@ -491,7 +484,7 @@ fn load_transaction_accounts<CB: TransactionProcessingCallback>(
|
|
|
loaded_fee_payer_account: LoadedTransactionAccount,
|
|
loaded_fee_payer_account: LoadedTransactionAccount,
|
|
|
loaded_accounts_bytes_limit: NonZeroU32,
|
|
loaded_accounts_bytes_limit: NonZeroU32,
|
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
|
- rent_collector: &dyn SVMRentCollector,
|
|
|
|
|
|
|
+ rent: &Rent,
|
|
|
) -> Result<LoadedTransactionAccounts> {
|
|
) -> Result<LoadedTransactionAccounts> {
|
|
|
if account_loader
|
|
if account_loader
|
|
|
.feature_set
|
|
.feature_set
|
|
@@ -503,7 +496,7 @@ fn load_transaction_accounts<CB: TransactionProcessingCallback>(
|
|
|
loaded_fee_payer_account,
|
|
loaded_fee_payer_account,
|
|
|
loaded_accounts_bytes_limit,
|
|
loaded_accounts_bytes_limit,
|
|
|
error_metrics,
|
|
error_metrics,
|
|
|
- rent_collector,
|
|
|
|
|
|
|
+ rent,
|
|
|
)
|
|
)
|
|
|
} else {
|
|
} else {
|
|
|
load_transaction_accounts_old(
|
|
load_transaction_accounts_old(
|
|
@@ -512,7 +505,7 @@ fn load_transaction_accounts<CB: TransactionProcessingCallback>(
|
|
|
loaded_fee_payer_account,
|
|
loaded_fee_payer_account,
|
|
|
loaded_accounts_bytes_limit,
|
|
loaded_accounts_bytes_limit,
|
|
|
error_metrics,
|
|
error_metrics,
|
|
|
- rent_collector,
|
|
|
|
|
|
|
+ rent,
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -523,7 +516,7 @@ fn load_transaction_accounts_simd186<CB: TransactionProcessingCallback>(
|
|
|
loaded_fee_payer_account: LoadedTransactionAccount,
|
|
loaded_fee_payer_account: LoadedTransactionAccount,
|
|
|
loaded_accounts_bytes_limit: NonZeroU32,
|
|
loaded_accounts_bytes_limit: NonZeroU32,
|
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
|
- rent_collector: &dyn SVMRentCollector,
|
|
|
|
|
|
|
+ rent: &Rent,
|
|
|
) -> Result<LoadedTransactionAccounts> {
|
|
) -> Result<LoadedTransactionAccounts> {
|
|
|
let account_keys = message.account_keys();
|
|
let account_keys = message.account_keys();
|
|
|
let mut additional_loaded_accounts: AHashSet<Pubkey> = AHashSet::new();
|
|
let mut additional_loaded_accounts: AHashSet<Pubkey> = AHashSet::new();
|
|
@@ -608,13 +601,8 @@ fn load_transaction_accounts_simd186<CB: TransactionProcessingCallback>(
|
|
|
|
|
|
|
|
// Attempt to load and collect remaining non-fee payer accounts.
|
|
// Attempt to load and collect remaining non-fee payer accounts.
|
|
|
for (account_index, account_key) in account_keys.iter().enumerate().skip(1) {
|
|
for (account_index, account_key) in account_keys.iter().enumerate().skip(1) {
|
|
|
- let loaded_account = load_transaction_account(
|
|
|
|
|
- account_loader,
|
|
|
|
|
- message,
|
|
|
|
|
- account_key,
|
|
|
|
|
- account_index,
|
|
|
|
|
- rent_collector,
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ let loaded_account =
|
|
|
|
|
+ load_transaction_account(account_loader, message, account_key, account_index, rent);
|
|
|
collect_loaded_account(account_loader, account_key, loaded_account)?;
|
|
collect_loaded_account(account_loader, account_key, loaded_account)?;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -653,7 +641,7 @@ fn load_transaction_accounts_old<CB: TransactionProcessingCallback>(
|
|
|
loaded_fee_payer_account: LoadedTransactionAccount,
|
|
loaded_fee_payer_account: LoadedTransactionAccount,
|
|
|
loaded_accounts_bytes_limit: NonZeroU32,
|
|
loaded_accounts_bytes_limit: NonZeroU32,
|
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
|
- rent_collector: &dyn SVMRentCollector,
|
|
|
|
|
|
|
+ rent: &Rent,
|
|
|
) -> Result<LoadedTransactionAccounts> {
|
|
) -> Result<LoadedTransactionAccounts> {
|
|
|
let account_keys = message.account_keys();
|
|
let account_keys = message.account_keys();
|
|
|
let mut accounts = Vec::with_capacity(account_keys.len());
|
|
let mut accounts = Vec::with_capacity(account_keys.len());
|
|
@@ -683,13 +671,8 @@ fn load_transaction_accounts_old<CB: TransactionProcessingCallback>(
|
|
|
|
|
|
|
|
// Attempt to load and collect remaining non-fee payer accounts
|
|
// Attempt to load and collect remaining non-fee payer accounts
|
|
|
for (account_index, account_key) in account_keys.iter().enumerate().skip(1) {
|
|
for (account_index, account_key) in account_keys.iter().enumerate().skip(1) {
|
|
|
- let loaded_account = load_transaction_account(
|
|
|
|
|
- account_loader,
|
|
|
|
|
- message,
|
|
|
|
|
- account_key,
|
|
|
|
|
- account_index,
|
|
|
|
|
- rent_collector,
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ let loaded_account =
|
|
|
|
|
+ load_transaction_account(account_loader, message, account_key, account_index, rent);
|
|
|
collect_loaded_account(account_key, loaded_account)?;
|
|
collect_loaded_account(account_key, loaded_account)?;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -762,7 +745,7 @@ fn load_transaction_account<CB: TransactionProcessingCallback>(
|
|
|
message: &impl SVMMessage,
|
|
message: &impl SVMMessage,
|
|
|
account_key: &Pubkey,
|
|
account_key: &Pubkey,
|
|
|
account_index: usize,
|
|
account_index: usize,
|
|
|
- rent_collector: &dyn SVMRentCollector,
|
|
|
|
|
|
|
+ rent: &Rent,
|
|
|
) -> LoadedTransactionAccount {
|
|
) -> LoadedTransactionAccount {
|
|
|
let is_writable = message.is_writable(account_index);
|
|
let is_writable = message.is_writable(account_index);
|
|
|
let loaded_account = if solana_sdk_ids::sysvar::instructions::check_id(account_key) {
|
|
let loaded_account = if solana_sdk_ids::sysvar::instructions::check_id(account_key) {
|
|
@@ -776,7 +759,7 @@ fn load_transaction_account<CB: TransactionProcessingCallback>(
|
|
|
account_loader.load_transaction_account(account_key, is_writable)
|
|
account_loader.load_transaction_account(account_key, is_writable)
|
|
|
{
|
|
{
|
|
|
if is_writable {
|
|
if is_writable {
|
|
|
- update_rent_exempt_status_for_account(rent_collector, &mut loaded_account.account);
|
|
|
|
|
|
|
+ update_rent_exempt_status_for_account(rent, &mut loaded_account.account);
|
|
|
}
|
|
}
|
|
|
loaded_account
|
|
loaded_account
|
|
|
} else {
|
|
} else {
|
|
@@ -853,7 +836,6 @@ mod tests {
|
|
|
agave_reserved_account_keys::ReservedAccountKeys,
|
|
agave_reserved_account_keys::ReservedAccountKeys,
|
|
|
rand0_7::prelude::*,
|
|
rand0_7::prelude::*,
|
|
|
solana_account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
|
|
solana_account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
|
|
|
- solana_epoch_schedule::EpochSchedule,
|
|
|
|
|
solana_hash::Hash,
|
|
solana_hash::Hash,
|
|
|
solana_instruction::{AccountMeta, Instruction},
|
|
solana_instruction::{AccountMeta, Instruction},
|
|
|
solana_keypair::Keypair,
|
|
solana_keypair::Keypair,
|
|
@@ -870,7 +852,7 @@ mod tests {
|
|
|
},
|
|
},
|
|
|
solana_pubkey::Pubkey,
|
|
solana_pubkey::Pubkey,
|
|
|
solana_rent::Rent,
|
|
solana_rent::Rent,
|
|
|
- solana_rent_collector::{RentCollector, RENT_EXEMPT_RENT_EPOCH},
|
|
|
|
|
|
|
+ solana_rent_collector::RENT_EXEMPT_RENT_EPOCH,
|
|
|
solana_sdk_ids::{
|
|
solana_sdk_ids::{
|
|
|
bpf_loader, bpf_loader_upgradeable, native_loader, system_program, sysvar,
|
|
bpf_loader, bpf_loader_upgradeable, native_loader, system_program, sysvar,
|
|
|
},
|
|
},
|
|
@@ -947,7 +929,7 @@ mod tests {
|
|
|
fn load_accounts_with_features_and_rent(
|
|
fn load_accounts_with_features_and_rent(
|
|
|
tx: Transaction,
|
|
tx: Transaction,
|
|
|
accounts: &[TransactionAccount],
|
|
accounts: &[TransactionAccount],
|
|
|
- rent_collector: &RentCollector,
|
|
|
|
|
|
|
+ rent: &Rent,
|
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
error_metrics: &mut TransactionErrorMetrics,
|
|
|
feature_set: SVMFeatureSet,
|
|
feature_set: SVMFeatureSet,
|
|
|
) -> TransactionLoadResult {
|
|
) -> TransactionLoadResult {
|
|
@@ -974,7 +956,7 @@ mod tests {
|
|
|
..ValidatedTransactionDetails::default()
|
|
..ValidatedTransactionDetails::default()
|
|
|
}),
|
|
}),
|
|
|
error_metrics,
|
|
error_metrics,
|
|
|
- rent_collector,
|
|
|
|
|
|
|
+ rent,
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1016,7 +998,7 @@ mod tests {
|
|
|
let load_results = load_accounts_with_features_and_rent(
|
|
let load_results = load_accounts_with_features_and_rent(
|
|
|
tx,
|
|
tx,
|
|
|
&accounts,
|
|
&accounts,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
feature_set,
|
|
feature_set,
|
|
|
);
|
|
);
|
|
@@ -1064,7 +1046,7 @@ mod tests {
|
|
|
let loaded_accounts = load_accounts_with_features_and_rent(
|
|
let loaded_accounts = load_accounts_with_features_and_rent(
|
|
|
tx,
|
|
tx,
|
|
|
&accounts,
|
|
&accounts,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
feature_set,
|
|
feature_set,
|
|
|
);
|
|
);
|
|
@@ -1124,7 +1106,7 @@ mod tests {
|
|
|
let load_results = load_accounts_with_features_and_rent(
|
|
let load_results = load_accounts_with_features_and_rent(
|
|
|
tx,
|
|
tx,
|
|
|
&accounts,
|
|
&accounts,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
feature_set,
|
|
feature_set,
|
|
|
);
|
|
);
|
|
@@ -1182,7 +1164,7 @@ mod tests {
|
|
|
let load_results = load_accounts_with_features_and_rent(
|
|
let load_results = load_accounts_with_features_and_rent(
|
|
|
tx,
|
|
tx,
|
|
|
&accounts,
|
|
&accounts,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
feature_set,
|
|
feature_set,
|
|
|
);
|
|
);
|
|
@@ -1242,7 +1224,7 @@ mod tests {
|
|
|
let loaded_accounts = load_accounts_with_features_and_rent(
|
|
let loaded_accounts = load_accounts_with_features_and_rent(
|
|
|
tx,
|
|
tx,
|
|
|
&accounts,
|
|
&accounts,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
feature_set,
|
|
feature_set,
|
|
|
);
|
|
);
|
|
@@ -1289,7 +1271,7 @@ mod tests {
|
|
|
&tx,
|
|
&tx,
|
|
|
Ok(ValidatedTransactionDetails::default()),
|
|
Ok(ValidatedTransactionDetails::default()),
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1398,10 +1380,7 @@ mod tests {
|
|
|
expected_result: Result<()>,
|
|
expected_result: Result<()>,
|
|
|
payer_post_balance: u64,
|
|
payer_post_balance: u64,
|
|
|
}
|
|
}
|
|
|
- fn validate_fee_payer_account(
|
|
|
|
|
- test_parameter: ValidateFeePayerTestParameter,
|
|
|
|
|
- rent_collector: &RentCollector,
|
|
|
|
|
- ) {
|
|
|
|
|
|
|
+ fn validate_fee_payer_account(test_parameter: ValidateFeePayerTestParameter, rent: &Rent) {
|
|
|
let payer_account_keys = Keypair::new();
|
|
let payer_account_keys = Keypair::new();
|
|
|
let mut account = if test_parameter.is_nonce {
|
|
let mut account = if test_parameter.is_nonce {
|
|
|
AccountSharedData::new_data(
|
|
AccountSharedData::new_data(
|
|
@@ -1418,7 +1397,7 @@ mod tests {
|
|
|
&mut account,
|
|
&mut account,
|
|
|
0,
|
|
0,
|
|
|
&mut TransactionErrorMetrics::default(),
|
|
&mut TransactionErrorMetrics::default(),
|
|
|
- rent_collector,
|
|
|
|
|
|
|
+ rent,
|
|
|
test_parameter.fee,
|
|
test_parameter.fee,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -1428,16 +1407,11 @@ mod tests {
|
|
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
|
fn test_validate_fee_payer() {
|
|
fn test_validate_fee_payer() {
|
|
|
- let rent_collector = RentCollector::new(
|
|
|
|
|
- 0,
|
|
|
|
|
- EpochSchedule::default(),
|
|
|
|
|
- 500_000.0,
|
|
|
|
|
- Rent {
|
|
|
|
|
- lamports_per_byte_year: 1,
|
|
|
|
|
- ..Rent::default()
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- let min_balance = rent_collector.rent.minimum_balance(NonceState::size());
|
|
|
|
|
|
|
+ let rent = Rent {
|
|
|
|
|
+ lamports_per_byte_year: 1,
|
|
|
|
|
+ ..Rent::default()
|
|
|
|
|
+ };
|
|
|
|
|
+ let min_balance = rent.minimum_balance(NonceState::size());
|
|
|
let fee = 5_000;
|
|
let fee = 5_000;
|
|
|
|
|
|
|
|
// If payer account has sufficient balance, expect successful fee deduction,
|
|
// If payer account has sufficient balance, expect successful fee deduction,
|
|
@@ -1452,7 +1426,7 @@ mod tests {
|
|
|
expected_result: Ok(()),
|
|
expected_result: Ok(()),
|
|
|
payer_post_balance: min_balance,
|
|
payer_post_balance: min_balance,
|
|
|
},
|
|
},
|
|
|
- &rent_collector,
|
|
|
|
|
|
|
+ &rent,
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1469,7 +1443,7 @@ mod tests {
|
|
|
expected_result: Err(TransactionError::AccountNotFound),
|
|
expected_result: Err(TransactionError::AccountNotFound),
|
|
|
payer_post_balance: 0,
|
|
payer_post_balance: 0,
|
|
|
},
|
|
},
|
|
|
- &rent_collector,
|
|
|
|
|
|
|
+ &rent,
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1486,7 +1460,7 @@ mod tests {
|
|
|
expected_result: Err(TransactionError::InsufficientFundsForFee),
|
|
expected_result: Err(TransactionError::InsufficientFundsForFee),
|
|
|
payer_post_balance: min_balance + fee - 1,
|
|
payer_post_balance: min_balance + fee - 1,
|
|
|
},
|
|
},
|
|
|
- &rent_collector,
|
|
|
|
|
|
|
+ &rent,
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1502,22 +1476,17 @@ mod tests {
|
|
|
expected_result: Ok(()),
|
|
expected_result: Ok(()),
|
|
|
payer_post_balance: 0,
|
|
payer_post_balance: 0,
|
|
|
},
|
|
},
|
|
|
- &rent_collector,
|
|
|
|
|
|
|
+ &rent,
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
|
fn test_validate_nonce_fee_payer_with_checked_arithmetic() {
|
|
fn test_validate_nonce_fee_payer_with_checked_arithmetic() {
|
|
|
- let rent_collector = RentCollector::new(
|
|
|
|
|
- 0,
|
|
|
|
|
- EpochSchedule::default(),
|
|
|
|
|
- 500_000.0,
|
|
|
|
|
- Rent {
|
|
|
|
|
- lamports_per_byte_year: 1,
|
|
|
|
|
- ..Rent::default()
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ let rent = Rent {
|
|
|
|
|
+ lamports_per_byte_year: 1,
|
|
|
|
|
+ ..Rent::default()
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
// nonce payer account has balance of u64::MAX, so does fee; due to nonce account
|
|
// nonce payer account has balance of u64::MAX, so does fee; due to nonce account
|
|
|
// requires additional min_balance, expect InsufficientFundsForFee error if feature gate is
|
|
// requires additional min_balance, expect InsufficientFundsForFee error if feature gate is
|
|
@@ -1530,7 +1499,7 @@ mod tests {
|
|
|
expected_result: Err(TransactionError::InsufficientFundsForFee),
|
|
expected_result: Err(TransactionError::InsufficientFundsForFee),
|
|
|
payer_post_balance: u64::MAX,
|
|
payer_post_balance: u64::MAX,
|
|
|
},
|
|
},
|
|
|
- &rent_collector,
|
|
|
|
|
|
|
+ &rent,
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1588,7 +1557,7 @@ mod tests {
|
|
|
},
|
|
},
|
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
assert_eq!(
|
|
assert_eq!(
|
|
|
result.unwrap(),
|
|
result.unwrap(),
|
|
@@ -1652,7 +1621,7 @@ mod tests {
|
|
|
},
|
|
},
|
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
if formalize_loaded_transaction_data_size {
|
|
if formalize_loaded_transaction_data_size {
|
|
@@ -1715,7 +1684,7 @@ mod tests {
|
|
|
LoadedTransactionAccount::default(),
|
|
LoadedTransactionAccount::default(),
|
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(result.err(), Some(TransactionError::ProgramAccountNotFound));
|
|
assert_eq!(result.err(), Some(TransactionError::ProgramAccountNotFound));
|
|
@@ -1757,7 +1726,7 @@ mod tests {
|
|
|
LoadedTransactionAccount::default(),
|
|
LoadedTransactionAccount::default(),
|
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
assert_eq!(
|
|
@@ -1825,7 +1794,7 @@ mod tests {
|
|
|
},
|
|
},
|
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
let loaded_accounts_data_size = base_account_size as u32 * 2;
|
|
let loaded_accounts_data_size = base_account_size as u32 * 2;
|
|
@@ -1886,7 +1855,7 @@ mod tests {
|
|
|
LoadedTransactionAccount::default(),
|
|
LoadedTransactionAccount::default(),
|
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(result.err(), Some(TransactionError::ProgramAccountNotFound));
|
|
assert_eq!(result.err(), Some(TransactionError::ProgramAccountNotFound));
|
|
@@ -1938,7 +1907,7 @@ mod tests {
|
|
|
LoadedTransactionAccount::default(),
|
|
LoadedTransactionAccount::default(),
|
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
assert_eq!(
|
|
@@ -2014,7 +1983,7 @@ mod tests {
|
|
|
},
|
|
},
|
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
let loaded_accounts_data_size = base_account_size as u32 * 2;
|
|
let loaded_accounts_data_size = base_account_size as u32 * 2;
|
|
@@ -2110,7 +2079,7 @@ mod tests {
|
|
|
},
|
|
},
|
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
let loaded_accounts_data_size = base_account_size as u32 * 2;
|
|
let loaded_accounts_data_size = base_account_size as u32 * 2;
|
|
@@ -2169,7 +2138,7 @@ mod tests {
|
|
|
&sanitized_tx.clone(),
|
|
&sanitized_tx.clone(),
|
|
|
Ok(ValidatedTransactionDetails::default()),
|
|
Ok(ValidatedTransactionDetails::default()),
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
let TransactionLoadResult::Loaded(loaded_transaction) = load_result else {
|
|
let TransactionLoadResult::Loaded(loaded_transaction) = load_result else {
|
|
@@ -2180,21 +2149,17 @@ mod tests {
|
|
|
compute_unit_limit: u64::from(DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT),
|
|
compute_unit_limit: u64::from(DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT),
|
|
|
..SVMTransactionExecutionBudget::default()
|
|
..SVMTransactionExecutionBudget::default()
|
|
|
};
|
|
};
|
|
|
- let rent_collector = RentCollector::default();
|
|
|
|
|
|
|
+ let rent = Rent::default();
|
|
|
let transaction_context = TransactionContext::new(
|
|
let transaction_context = TransactionContext::new(
|
|
|
loaded_transaction.accounts,
|
|
loaded_transaction.accounts,
|
|
|
- rent_collector.get_rent().clone(),
|
|
|
|
|
|
|
+ rent.clone(),
|
|
|
compute_budget.max_instruction_stack_depth,
|
|
compute_budget.max_instruction_stack_depth,
|
|
|
compute_budget.max_instruction_trace_length,
|
|
compute_budget.max_instruction_trace_length,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
assert_eq!(
|
|
|
- TransactionAccountStateInfo::new(
|
|
|
|
|
- &transaction_context,
|
|
|
|
|
- sanitized_tx.message(),
|
|
|
|
|
- &rent_collector,
|
|
|
|
|
- )
|
|
|
|
|
- .len(),
|
|
|
|
|
|
|
+ TransactionAccountStateInfo::new(&transaction_context, sanitized_tx.message(), &rent,)
|
|
|
|
|
+ .len(),
|
|
|
num_accounts,
|
|
num_accounts,
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
@@ -2276,7 +2241,7 @@ mod tests {
|
|
|
&sanitized_transaction,
|
|
&sanitized_transaction,
|
|
|
validation_result,
|
|
validation_result,
|
|
|
&mut error_metrics,
|
|
&mut error_metrics,
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
let loaded_accounts_data_size = base_account_size as u32 * 2;
|
|
let loaded_accounts_data_size = base_account_size as u32 * 2;
|
|
@@ -2314,7 +2279,7 @@ mod tests {
|
|
|
fn test_load_accounts_error() {
|
|
fn test_load_accounts_error() {
|
|
|
let mock_bank = TestCallbacks::default();
|
|
let mock_bank = TestCallbacks::default();
|
|
|
let mut account_loader = (&mock_bank).into();
|
|
let mut account_loader = (&mock_bank).into();
|
|
|
- let rent_collector = RentCollector::default();
|
|
|
|
|
|
|
+ let rent = Rent::default();
|
|
|
|
|
|
|
|
let message = Message {
|
|
let message = Message {
|
|
|
account_keys: vec![Pubkey::new_from_array([0; 32])],
|
|
account_keys: vec![Pubkey::new_from_array([0; 32])],
|
|
@@ -2340,7 +2305,7 @@ mod tests {
|
|
|
&sanitized_transaction,
|
|
&sanitized_transaction,
|
|
|
validation_result.clone(),
|
|
validation_result.clone(),
|
|
|
&mut TransactionErrorMetrics::default(),
|
|
&mut TransactionErrorMetrics::default(),
|
|
|
- &rent_collector,
|
|
|
|
|
|
|
+ &rent,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
assert!(matches!(
|
|
assert!(matches!(
|
|
@@ -2358,7 +2323,7 @@ mod tests {
|
|
|
&sanitized_transaction,
|
|
&sanitized_transaction,
|
|
|
validation_result,
|
|
validation_result,
|
|
|
&mut TransactionErrorMetrics::default(),
|
|
&mut TransactionErrorMetrics::default(),
|
|
|
- &rent_collector,
|
|
|
|
|
|
|
+ &rent,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
assert!(matches!(
|
|
assert!(matches!(
|
|
@@ -2369,34 +2334,28 @@ mod tests {
|
|
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
|
fn test_update_rent_exempt_status_for_account() {
|
|
fn test_update_rent_exempt_status_for_account() {
|
|
|
- let rent_collector = RentCollector {
|
|
|
|
|
- epoch: 1,
|
|
|
|
|
- ..RentCollector::default()
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ let rent = Rent::default();
|
|
|
|
|
|
|
|
- let min_exempt_balance = rent_collector.rent.minimum_balance(0);
|
|
|
|
|
|
|
+ let min_exempt_balance = rent.minimum_balance(0);
|
|
|
let mut account = AccountSharedData::from(Account {
|
|
let mut account = AccountSharedData::from(Account {
|
|
|
lamports: min_exempt_balance,
|
|
lamports: min_exempt_balance,
|
|
|
..Account::default()
|
|
..Account::default()
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- update_rent_exempt_status_for_account(&rent_collector, &mut account);
|
|
|
|
|
|
|
+ update_rent_exempt_status_for_account(&rent, &mut account);
|
|
|
assert_eq!(account.rent_epoch(), RENT_EXEMPT_RENT_EPOCH);
|
|
assert_eq!(account.rent_epoch(), RENT_EXEMPT_RENT_EPOCH);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
|
fn test_update_rent_exempt_status_for_rent_paying_account() {
|
|
fn test_update_rent_exempt_status_for_rent_paying_account() {
|
|
|
- let rent_collector = RentCollector {
|
|
|
|
|
- epoch: 1,
|
|
|
|
|
- ..RentCollector::default()
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ let rent = Rent::default();
|
|
|
|
|
|
|
|
let mut account = AccountSharedData::from(Account {
|
|
let mut account = AccountSharedData::from(Account {
|
|
|
lamports: 1,
|
|
lamports: 1,
|
|
|
..Account::default()
|
|
..Account::default()
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- update_rent_exempt_status_for_account(&rent_collector, &mut account);
|
|
|
|
|
|
|
+ update_rent_exempt_status_for_account(&rent, &mut account);
|
|
|
assert_eq!(account.rent_epoch(), 0);
|
|
assert_eq!(account.rent_epoch(), 0);
|
|
|
assert_eq!(account.lamports(), 1);
|
|
assert_eq!(account.lamports(), 1);
|
|
|
}
|
|
}
|
|
@@ -2469,7 +2428,7 @@ mod tests {
|
|
|
&sanitized_transaction,
|
|
&sanitized_transaction,
|
|
|
validation_result,
|
|
validation_result,
|
|
|
&mut TransactionErrorMetrics::default(),
|
|
&mut TransactionErrorMetrics::default(),
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// ensure the loaded accounts are inspected
|
|
// ensure the loaded accounts are inspected
|
|
@@ -2594,7 +2553,7 @@ mod tests {
|
|
|
},
|
|
},
|
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
|
&mut TransactionErrorMetrics::default(),
|
|
&mut TransactionErrorMetrics::default(),
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
)
|
|
)
|
|
|
.unwrap();
|
|
.unwrap();
|
|
|
|
|
|
|
@@ -3026,7 +2985,7 @@ mod tests {
|
|
|
},
|
|
},
|
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
|
|
|
&mut TransactionErrorMetrics::default(),
|
|
&mut TransactionErrorMetrics::default(),
|
|
|
- &RentCollector::default(),
|
|
|
|
|
|
|
+ &Rent::default(),
|
|
|
)
|
|
)
|
|
|
.unwrap();
|
|
.unwrap();
|
|
|
|
|
|