Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,9 @@ mod tests {

let (bank, _bank_forks) = Bank::new_no_wallclock_throttle_for_tests(&genesis_config);
for entry in entries {
bank.process_entry_transactions(entry.transactions)
.iter()
.for_each(|x| assert_eq!(*x, Ok(())));
let _ = bank
.try_process_entry_transactions(entry.transactions)
.expect("All transactions should be processed");
Comment thread
steviez marked this conversation as resolved.
}

// Assert the user doesn't hold three lamports. If the stage only outputs one
Expand Down
7 changes: 2 additions & 5 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4676,10 +4676,7 @@ impl Bank {
/// Process a Transaction. This is used for unit tests and simply calls the vector
/// Bank::process_transactions method.
pub fn process_transaction(&self, tx: &Transaction) -> Result<()> {
self.try_process_transactions(std::iter::once(tx))?[0].clone()?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR, but given the "This is used for unit tests and ..." comment, this should seemingly be DCOU

tx.signatures
.first()
.map_or(Ok(()), |sig| self.get_signature_status(sig).unwrap())
self.try_process_transactions(std::iter::once(tx))?[0].clone()
Comment thread
steviez marked this conversation as resolved.
}

/// Process a Transaction and store metadata. This is used for tests and the banks services. It
Expand Down Expand Up @@ -4743,7 +4740,7 @@ impl Bank {
)
.0
.into_iter()
.map(|commit_result| commit_result.map(|_| ()))
.map(|commit_result| commit_result.and_then(|committed_tx| committed_tx.status))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this revealed a few tests that were processing transactions unsuccessfully. I think it makes sense to always bubble up the execution status.

.collect()
}

Expand Down
55 changes: 37 additions & 18 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ use {
},
solana_transaction_context::TransactionAccount,
solana_transaction_error::{TransactionError, TransactionResult as Result},
solana_vote_interface::state::TowerSync,
solana_vote_program::{
vote_instruction,
vote_state::{
self, create_account_with_authorized, BlockTimestamp, Vote, VoteInit, VoteState,
self, create_account_with_authorized, BlockTimestamp, VoteInit, VoteState,
VoteStateVersions, MAX_LOCKOUT_HISTORY,
},
},
Expand Down Expand Up @@ -503,14 +504,15 @@ fn test_credit_debit_rent_no_side_effect_on_hash() {

assert_eq!(bank.last_blockhash(), genesis_config.hash());

let plenty_of_lamports = 264;
let min_balance = genesis_config.rent.minimum_balance(0);
let plenty_of_lamports = min_balance + 1;
let too_few_lamports = 10;
// Initialize credit-debit and credit only accounts
let accounts = [
AccountSharedData::new(plenty_of_lamports, 0, &Pubkey::default()),
AccountSharedData::new(plenty_of_lamports, 1, &Pubkey::default()),
AccountSharedData::new(plenty_of_lamports, 0, &Pubkey::default()),
AccountSharedData::new(plenty_of_lamports, 1, &Pubkey::default()),
AccountSharedData::new(plenty_of_lamports, 0, &Pubkey::default()),
AccountSharedData::new(plenty_of_lamports, 0, &Pubkey::default()),
// Transaction between these two accounts will fail
AccountSharedData::new(too_few_lamports, 0, &Pubkey::default()),
AccountSharedData::new(too_few_lamports, 1, &Pubkey::default()),
Expand Down Expand Up @@ -3087,6 +3089,9 @@ fn test_readonly_accounts(relax_intrabatch_account_locks: bool) {
if !relax_intrabatch_account_locks {
bank.deactivate_feature(&feature_set::relax_intrabatch_account_locks::id());
}

let next_slot = bank.slot() + 1;
let bank = Bank::new_from_parent(Arc::new(bank), &Pubkey::default(), next_slot);
let (bank, _bank_forks) = bank.wrap_with_bank_forks_for_tests();

let vote_pubkey0 = solana_pubkey::new_rand();
Expand All @@ -3097,12 +3102,27 @@ fn test_readonly_accounts(relax_intrabatch_account_locks: bool) {
let payer1 = Keypair::new();

// Create vote accounts
let vote_account0 =
vote_state::create_account(&vote_pubkey0, &authorized_voter.pubkey(), 0, 100);
let vote_account1 =
vote_state::create_account(&vote_pubkey1, &authorized_voter.pubkey(), 0, 100);
let vote_account2 =
vote_state::create_account(&vote_pubkey2, &authorized_voter.pubkey(), 0, 100);
let vote_account0 = vote_state::create_account_with_authorized(
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't technically require all of the vote transactions to succeed, but I thought it was worth cleaning up all the issues causing them to fail. One issue with this test was that vote_state::create_account sets the authorized voter as the vote account itself. So I updated to create_account_with_authorized to set the authorized voter to authorized_voter as I assume was intended by the original author.

&vote_pubkey0,
&authorized_voter.pubkey(),
&authorized_voter.pubkey(),
0,
100,
);
let vote_account1 = vote_state::create_account_with_authorized(
&vote_pubkey1,
&authorized_voter.pubkey(),
&authorized_voter.pubkey(),
0,
100,
);
let vote_account2 = vote_state::create_account_with_authorized(
&vote_pubkey2,
&authorized_voter.pubkey(),
&authorized_voter.pubkey(),
0,
100,
);
bank.store_account(&vote_pubkey0, &vote_account0);
bank.store_account(&vote_pubkey1, &vote_account1);
bank.store_account(&vote_pubkey2, &vote_account2);
Expand All @@ -3113,15 +3133,15 @@ fn test_readonly_accounts(relax_intrabatch_account_locks: bool) {
bank.transfer(1, &mint_keypair, &authorized_voter.pubkey())
.unwrap();

let vote = Vote::new(vec![1], Hash::default());
let ix0 = vote_instruction::vote(&vote_pubkey0, &authorized_voter.pubkey(), vote.clone());
let vote = TowerSync::new_from_slot(bank.parent_slot, bank.parent_hash);
Comment thread
steviez marked this conversation as resolved.
let ix0 = vote_instruction::tower_sync(&vote_pubkey0, &authorized_voter.pubkey(), vote.clone());
let tx0 = Transaction::new_signed_with_payer(
&[ix0],
Some(&payer0.pubkey()),
&[&payer0, &authorized_voter],
bank.last_blockhash(),
);
let ix1 = vote_instruction::vote(&vote_pubkey1, &authorized_voter.pubkey(), vote.clone());
let ix1 = vote_instruction::tower_sync(&vote_pubkey1, &authorized_voter.pubkey(), vote.clone());
let tx1 = Transaction::new_signed_with_payer(
&[ix1],
Some(&payer1.pubkey()),
Expand All @@ -3136,7 +3156,7 @@ fn test_readonly_accounts(relax_intrabatch_account_locks: bool) {
assert_eq!(results[0], Ok(()));
assert_eq!(results[1], Ok(()));

let ix0 = vote_instruction::vote(&vote_pubkey2, &authorized_voter.pubkey(), vote);
let ix0 = vote_instruction::tower_sync(&vote_pubkey2, &authorized_voter.pubkey(), vote);
let tx0 = Transaction::new_signed_with_payer(
&[ix0],
Some(&payer0.pubkey()),
Expand Down Expand Up @@ -10153,6 +10173,7 @@ fn test_failed_compute_request_instruction() {
bank.transfer(10, &mint_keypair, &payer1_keypair.pubkey())
.unwrap();

const TEST_COMPUTE_UNIT_LIMIT: u32 = 500u32;
declare_process_instruction!(MockBuiltin, 1, |invoke_context| {
let compute_budget = ComputeBudget::from_budget_and_cost(
invoke_context.get_compute_budget(),
Expand All @@ -10161,9 +10182,7 @@ fn test_failed_compute_request_instruction() {
assert_eq!(
compute_budget,
ComputeBudget {
compute_unit_limit: u64::from(
execution_budget::DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT
),
compute_unit_limit: u64::from(TEST_COMPUTE_UNIT_LIMIT),
heap_size: 48 * 1024,
..ComputeBudget::default()
}
Expand All @@ -10182,7 +10201,7 @@ fn test_failed_compute_request_instruction() {
// This message will be processed successfully
let message1 = Message::new(
&[
ComputeBudgetInstruction::set_compute_unit_limit(1),
ComputeBudgetInstruction::set_compute_unit_limit(TEST_COMPUTE_UNIT_LIMIT),
ComputeBudgetInstruction::request_heap_frame(48 * 1024),
Instruction::new_with_bincode(program_id, &0, vec![]),
],
Expand Down
Loading