From 72800070c7f66c9e4d1a2facd876ca7a90104737 Mon Sep 17 00:00:00 2001 From: hana <81144685+2501babe@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:30:27 +0000 Subject: [PATCH] fix ledger tests --- ledger/src/blockstore_processor.rs | 76 +++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 6f0f35d8f4bb7a..c48af8f57e70f3 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -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, @@ -3672,8 +3673,11 @@ 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 { @@ -3681,7 +3685,11 @@ pub mod tests { 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(); @@ -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: @@ -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] @@ -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( @@ -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, @@ -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]