Skip to content

Commit

Permalink
update tests for added feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-stones committed Jun 4, 2024
1 parent 4ce3d98 commit d57dfd0
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 62 deletions.
50 changes: 35 additions & 15 deletions compute-budget/src/compute_budget_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ mod tests {
},
};

impl Default for ComputeBudgetLimits {
fn default() -> Self {
ComputeBudgetLimits {
updated_heap_bytes: u32::try_from(MIN_HEAP_FRAME_BYTES).unwrap(),
compute_unit_limit: MAX_COMPUTE_UNIT_LIMIT,
compute_unit_price: 0,
loaded_accounts_bytes: DEFAULT_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
}
}
}

macro_rules! test {
( $instructions: expr, $expected_result: expr, $use_default_loaded_accounts_data_szie: expr) => {
let payer_keypair = Keypair::new();
Expand Down Expand Up @@ -468,9 +479,10 @@ mod tests {
for use_default_loaded_accounts_data_size in [true, false] {
let expected_result = Ok(ComputeBudgetLimits {
compute_unit_limit: DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT,
loaded_accounts_bytes: Self::get_default_loaded_accounts_data_size_bytes(
use_default_loaded_accounts_data_size,
),
loaded_accounts_bytes:
ComputeBudgetLimits::get_default_loaded_accounts_data_size_bytes(
use_default_loaded_accounts_data_size,
),
..ComputeBudgetLimits::default()
});

Expand Down Expand Up @@ -515,18 +527,26 @@ mod tests {
Hash::default(),
));

let result =
process_compute_budget_instructions(transaction.message().program_instructions_iter());
for use_default_loaded_accounts_data_size in [true, false] {
let result = process_compute_budget_instructions(
transaction.message().program_instructions_iter(),
use_default_loaded_accounts_data_size,
);

// assert process_instructions will be successful with default,
// and the default compute_unit_limit is 2 times default: one for bpf ix, one for
// builtin ix.
assert_eq!(
result,
Ok(ComputeBudgetLimits {
compute_unit_limit: 2 * DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT,
..ComputeBudgetLimits::default()
})
);
// assert process_instructions will be successful with default,
// and the default compute_unit_limit is 2 times default: one for bpf ix, one for
// builtin ix.
assert_eq!(
result,
Ok(ComputeBudgetLimits {
compute_unit_limit: 2 * DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT,
loaded_accounts_bytes:
ComputeBudgetLimits::get_default_loaded_accounts_data_size_bytes(
use_default_loaded_accounts_data_size
),
..ComputeBudgetLimits::default()
})
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ mod tests {
let transaction = Transaction::new_unsigned(Message::new(
&[
ComputeBudgetInstruction::set_compute_unit_price(priority),
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(64 * 1024 * 1024),
system_instruction::transfer(&from_account, write_to_account, 2),
],
Some(&from_account),
Expand Down
4 changes: 2 additions & 2 deletions cost-model/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ impl CostModel {
mod tests {
use {
super::*,
solana_compute_budget::compute_budget_processor::ComputeBudgetLimits,
solana_sdk::{
compute_budget::{self, ComputeBudgetInstruction},
fee::ACCOUNT_DATA_COST_PAGE_SIZE,
Expand Down Expand Up @@ -570,8 +571,7 @@ mod tests {
// default loaded_accounts_data_size_limit
const DEFAULT_PAGE_COST: u64 = 8;
let expected_loaded_accounts_data_size_cost =
solana_program_runtime::compute_budget_processor::DEFAULT_LOADED_ACCOUNTS_DATA_SIZE_BYTES
as u64
ComputeBudgetLimits::get_default_loaded_accounts_data_size_bytes(true) as u64
/ ACCOUNT_DATA_COST_PAGE_SIZE
* DEFAULT_PAGE_COST;

Expand Down
4 changes: 2 additions & 2 deletions cost-model/src/transaction_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ mod tests {
use {
super::*,
crate::cost_model::CostModel,
solana_compute_budget::compute_budget_processor::ComputeBudgetLimits,
solana_sdk::{
feature_set::FeatureSet,
fee::ACCOUNT_DATA_COST_PAGE_SIZE,
Expand Down Expand Up @@ -252,8 +253,7 @@ mod tests {
// expected non-vote tx cost would include default loaded accounts size cost additionally
const DEFAULT_PAGE_COST: u64 = 8;
let expected_loaded_accounts_data_size_cost =
solana_program_runtime::compute_budget_processor::DEFAULT_LOADED_ACCOUNTS_DATA_SIZE_BYTES
as u64
ComputeBudgetLimits::get_default_loaded_accounts_data_size_bytes(true) as u64
/ ACCOUNT_DATA_COST_PAGE_SIZE
* DEFAULT_PAGE_COST;
let min_none_vote_cost = SIMPLE_VOTE_USAGE_COST + expected_loaded_accounts_data_size_cost;
Expand Down
6 changes: 5 additions & 1 deletion programs/bpf-loader-tests/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use {
account::AccountSharedData,
account_utils::StateMut,
bpf_loader_upgradeable::{id, UpgradeableLoaderState},
compute_budget::ComputeBudgetInstruction,
instruction::{Instruction, InstructionError},
pubkey::Pubkey,
signature::{Keypair, Signer},
Expand Down Expand Up @@ -35,7 +36,10 @@ pub async fn assert_ix_error(
}

let transaction = Transaction::new_signed_with_payer(
&[ix],
&[
ix,
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(64 * 1024 * 1024),
],
Some(&fee_payer.pubkey()),
&signers,
recent_blockhash,
Expand Down
23 changes: 16 additions & 7 deletions programs/sbf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use {
},
solana_compute_budget::{
compute_budget::ComputeBudget,
compute_budget_processor::process_compute_budget_instructions,
compute_budget_processor::{process_compute_budget_instructions, ComputeBudgetLimits},
},
solana_ledger::token_balances::collect_token_balances,
solana_program_runtime::timings::ExecuteTimings,
Expand Down Expand Up @@ -3674,6 +3674,9 @@ fn test_program_fees() {
let fee_structure =
FeeStructure::new(0.000005, 0.0, vec![(200, 0.0000005), (1400000, 0.000005)]);
bank.set_fee_structure(&fee_structure);
let use_default_loaded_accounts_data_size = bank
.feature_set
.is_active(&feature_set::default_loaded_accounts_data_size_limit::id());
let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests();
let mut bank_client = BankClient::new_shared(bank);
let authority_keypair = Keypair::new();
Expand All @@ -3700,9 +3703,12 @@ fn test_program_fees() {
let expected_normal_fee = fee_structure.calculate_fee(
&sanitized_message,
congestion_multiplier,
&process_compute_budget_instructions(sanitized_message.program_instructions_iter())
.unwrap_or_default()
.into(),
&process_compute_budget_instructions(
sanitized_message.program_instructions_iter(),
use_default_loaded_accounts_data_size,
)
.unwrap_or_else(|_| ComputeBudgetLimits::new_with(use_default_loaded_accounts_data_size))
.into(),
false,
true,
);
Expand All @@ -3728,9 +3734,12 @@ fn test_program_fees() {
let expected_prioritized_fee = fee_structure.calculate_fee(
&sanitized_message,
congestion_multiplier,
&process_compute_budget_instructions(sanitized_message.program_instructions_iter())
.unwrap_or_default()
.into(),
&process_compute_budget_instructions(
sanitized_message.program_instructions_iter(),
use_default_loaded_accounts_data_size,
)
.unwrap_or_else(|_| ComputeBudgetLimits::new_with(use_default_loaded_accounts_data_size))
.into(),
false,
true,
);
Expand Down
16 changes: 12 additions & 4 deletions runtime-transaction/src/runtime_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ mod tests {
},
solana_sdk::{
compute_budget::ComputeBudgetInstruction,
feature_set::FeatureSet,
instruction::Instruction,
message::Message,
reserved_account_keys::ReservedAccountKeys,
Expand Down Expand Up @@ -221,10 +222,15 @@ mod tests {
svt: SanitizedVersionedTransaction,
is_simple_vote: Option<bool>,
) -> bool {
RuntimeTransaction::<SanitizedVersionedMessage>::try_from(svt, None, is_simple_vote)
.unwrap()
.meta
.is_simple_vote_tx
RuntimeTransaction::<SanitizedVersionedMessage>::try_from(
svt,
None,
is_simple_vote,
&FeatureSet::default(),
)
.unwrap()
.meta
.is_simple_vote_tx
}

assert!(!get_is_simple_vote(
Expand Down Expand Up @@ -257,6 +263,7 @@ mod tests {
non_vote_sanitized_versioned_transaction(),
Some(hash),
None,
&FeatureSet::default(),
)
.unwrap();

Expand Down Expand Up @@ -291,6 +298,7 @@ mod tests {
.to_sanitized_versioned_transaction(),
Some(hash),
None,
&FeatureSet::default(),
)
.unwrap();

Expand Down
5 changes: 3 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ use {
storable_accounts::StorableAccounts,
},
solana_bpf_loader_program::syscalls::create_program_runtime_environment_v1,
solana_compute_budget::compute_budget_processor::process_compute_budget_instructions,
solana_compute_budget::compute_budget_processor::{
process_compute_budget_instructions, ComputeBudgetLimits,
},
solana_cost_model::cost_tracker::CostTracker,
solana_loader_v4_program::create_program_runtime_environment_v2,
solana_measure::{measure, measure::Measure, measure_us},
solana_perf::perf_libs,
solana_program_runtime::{
compute_budget_processor::{process_compute_budget_instructions, ComputeBudgetLimits},
invoke_context::BuiltinFunctionWithContext,
loaded_programs::{
ProgramCache, ProgramCacheEntry, ProgramCacheEntryOwner, ProgramCacheEntryType,
Expand Down
17 changes: 13 additions & 4 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10098,9 +10098,15 @@ fn calculate_test_fee(
lamports_per_signature: u64,
fee_structure: &FeeStructure,
) -> u64 {
let budget_limits = process_compute_budget_instructions(message.program_instructions_iter())
.unwrap_or_default()
.into();
// feature gate `default_loaded_accounts_data_size_limit` status does not impact transaction
// fee. Safe to set it as activated for tests relate to fee
let use_default_loaded_accounts_data_size = true;
let budget_limits = process_compute_budget_instructions(
message.program_instructions_iter(),
use_default_loaded_accounts_data_size,
)
.unwrap_or_else(|_| ComputeBudgetLimits::new_with(use_default_loaded_accounts_data_size))
.into();

fee_structure.calculate_fee(message, lamports_per_signature, &budget_limits, false, true)
}
Expand Down Expand Up @@ -11175,7 +11181,10 @@ fn create_mock_realloc_tx(
account_metas,
);
Transaction::new_signed_with_payer(
&[instruction],
&[
instruction,
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(64 * 1024 * 1024),
],
Some(&payer.pubkey()),
&[payer],
recent_blockhash,
Expand Down
Loading

0 comments on commit d57dfd0

Please sign in to comment.