Skip to content

Commit

Permalink
fix ledger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Jan 14, 2025
1 parent aee66c2 commit 7280007
Showing 1 changed file with 55 additions and 21 deletions.
76 changes: 55 additions & 21 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2396,6 +2396,7 @@ pub mod tests {
solana_sdk::{
account::{AccountSharedData, WritableAccount},
epoch_schedule::EpochSchedule,
feature_set,
hash::Hash,
instruction::{Instruction, InstructionError},
native_token::LAMPORTS_PER_SOL,
Expand Down Expand Up @@ -3672,16 +3673,23 @@ pub mod tests {
});
}

#[test]
fn test_process_entries_2nd_entry_collision_with_self_and_error() {
#[test_case(false; "old")]
#[test_case(true; "simd83")]
fn test_process_entries_2nd_entry_collision_with_self_and_error(
relax_intrabatch_account_locks: bool,
) {
solana_logger::setup();

let GenesisConfigInfo {
genesis_config,
mint_keypair,
..
} = create_genesis_config(1000);
let (bank, _bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config);
let mut bank = Bank::new_for_tests(&genesis_config);
if !relax_intrabatch_account_locks {
bank.deactivate_feature(&feature_set::relax_intrabatch_account_locks::id());
}
let (bank, _bank_forks) = bank.wrap_with_bank_forks_for_tests();
let keypair1 = Keypair::new();
let keypair2 = Keypair::new();
let keypair3 = Keypair::new();
Expand Down Expand Up @@ -3721,7 +3729,7 @@ pub mod tests {
&mint_keypair.pubkey(),
2,
bank.last_blockhash(),
), // will collide with predecessor
), // will collide with preceding entry
],
);
// should now be:
Expand All @@ -3744,28 +3752,37 @@ pub mod tests {
&keypair2.pubkey(),
1,
bank.last_blockhash(),
), // should be fine
), // will collide with preceding transaction
],
);
// would now be:
// if successful, becomes:
// keypair1=0
// keypair2=3
// keypair3=3

assert!(process_entries_for_tests_without_scheduler(
// succeeds following simd83 locking, fails otherwise
let result = process_entries_for_tests_without_scheduler(
&bank,
vec![
entry_1_to_mint,
entry_2_to_3_and_1_to_mint,
entry_conflict_itself,
],
)
.is_err());
);

// last entry should have been aborted before par_execute_entries
assert_eq!(bank.get_balance(&keypair1.pubkey()), 2);
assert_eq!(bank.get_balance(&keypair2.pubkey()), 2);
assert_eq!(bank.get_balance(&keypair3.pubkey()), 2);
let balances = [
bank.get_balance(&keypair1.pubkey()),
bank.get_balance(&keypair2.pubkey()),
bank.get_balance(&keypair3.pubkey()),
];

if relax_intrabatch_account_locks {
assert!(result.is_ok());
assert_eq!(balances, [0, 3, 3]);
} else {
assert!(result.is_err());
assert_eq!(balances, [2, 2, 2]);
}
}

#[test]
Expand Down Expand Up @@ -4075,14 +4092,19 @@ pub mod tests {
);
}

#[test]
fn test_update_transaction_statuses_fail() {
#[test_case(false; "old")]
#[test_case(true; "simd83")]
fn test_update_transaction_statuses_fail(relax_intrabatch_account_locks: bool) {
let GenesisConfigInfo {
genesis_config,
mint_keypair,
..
} = create_genesis_config(11_000);
let (bank, _bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config);
let mut bank = Bank::new_for_tests(&genesis_config);
if !relax_intrabatch_account_locks {
bank.deactivate_feature(&feature_set::relax_intrabatch_account_locks::id());
}
let (bank, _bank_forks) = bank.wrap_with_bank_forks_for_tests();
let keypair1 = Keypair::new();
let keypair2 = Keypair::new();
let success_tx = system_transaction::transfer(
Expand All @@ -4091,7 +4113,7 @@ pub mod tests {
1,
bank.last_blockhash(),
);
let fail_tx = system_transaction::transfer(
let test_tx = system_transaction::transfer(
&mint_keypair,
&keypair2.pubkey(),
2,
Expand All @@ -4103,17 +4125,29 @@ pub mod tests {
1,
vec![
success_tx,
fail_tx.clone(), // will collide
test_tx.clone(), // will collide
],
);

// succeeds with simd83, fails because of account locking conflict otherwise
assert_eq!(
process_entries_for_tests_without_scheduler(&bank, vec![entry_1_to_mint]),
Err(TransactionError::AccountInUse)
if relax_intrabatch_account_locks {
Ok(())
} else {
Err(TransactionError::AccountInUse)
}
);

// Should not see duplicate signature error
assert_eq!(bank.process_transaction(&fail_tx), Ok(()));
// fails with simd83 as already processed, succeeds otherwise
assert_eq!(
bank.process_transaction(&test_tx),
if relax_intrabatch_account_locks {
Err(TransactionError::AlreadyProcessed)
} else {
Ok(())
}
);
}

#[test]
Expand Down

0 comments on commit 7280007

Please sign in to comment.