Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
update test for both feature gate status (#31708)
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-stones authored May 18, 2023
1 parent 039991e commit e84613b
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ mod tests {
solana_poh::poh_recorder::{PohRecorder, WorkingBankEntry},
solana_program_runtime::timings::ProgramTiming,
solana_rpc::transaction_status_service::TransactionStatusService,
solana_runtime::prioritization_fee_cache::PrioritizationFeeCache,
solana_runtime::{cost_model::CostModel, prioritization_fee_cache::PrioritizationFeeCache},
solana_sdk::{
account::AccountSharedData,
instruction::InstructionError,
Expand Down Expand Up @@ -1076,14 +1076,26 @@ mod tests {

#[test]
fn test_bank_process_and_record_transactions_cost_tracker() {
for apply_cost_tracker_during_replay_enabled in [true, false] {
bank_process_and_record_transactions_cost_tracker(
apply_cost_tracker_during_replay_enabled,
);
}
}

fn bank_process_and_record_transactions_cost_tracker(
apply_cost_tracker_during_replay_enabled: bool,
) {
solana_logger::setup();
let GenesisConfigInfo {
genesis_config,
mint_keypair,
..
} = create_slow_genesis_config(10_000);
let mut bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
bank.deactivate_feature(&feature_set::apply_cost_tracker_during_replay::id());
if !apply_cost_tracker_during_replay_enabled {
bank.deactivate_feature(&feature_set::apply_cost_tracker_during_replay::id());
}
let bank = Arc::new(bank);
let pubkey = solana_sdk::pubkey::new_rand();

Expand Down Expand Up @@ -1150,10 +1162,13 @@ mod tests {

//
// TEST: When a tx in a batch can't be executed (here because of account
// locks), then its cost does not affect the cost tracker.
// locks), then its cost does not affect the cost tracker only if qos
// adjusts it with actual execution cost (when apply_cost_tracker_during_replay
// is not enabled).
//

let allocate_keypair = Keypair::new();

let transactions = sanitize_transactions(vec![
system_transaction::transfer(&mint_keypair, &pubkey, 2, genesis_config.hash()),
// intentionally use a tx that has a different cost
Expand All @@ -1164,6 +1179,13 @@ mod tests {
1,
),
]);
let mut expected_block_cost = 2 * single_transfer_cost;
let mut expected_tracked_tx_count = 2;
if apply_cost_tracker_during_replay_enabled {
expected_block_cost +=
CostModel::calculate_cost(&transactions[1], &bank.feature_set).sum();
expected_tracked_tx_count += 1;
}

let process_transactions_batch_output =
consumer.process_and_record_transactions(&bank, &transactions, 0);
Expand All @@ -1178,8 +1200,8 @@ mod tests {
assert!(commit_transactions_result.is_ok());
assert_eq!(retryable_transaction_indexes, vec![1]);

assert_eq!(get_block_cost(), 2 * single_transfer_cost);
assert_eq!(get_tx_count(), 2);
assert_eq!(get_block_cost(), expected_block_cost);
assert_eq!(get_tx_count(), expected_tracked_tx_count);

poh_recorder
.read()
Expand Down

0 comments on commit e84613b

Please sign in to comment.