Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TransactionBatch - hold RuntimeTransaction #3041

Merged
Merged
Show file tree
Hide file tree
Changes from 7 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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions banks-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ solana-banks-interface = { workspace = true }
solana-client = { workspace = true }
solana-feature-set = { workspace = true }
solana-runtime = { workspace = true }
solana-runtime-transaction = { workspace = true }
solana-sdk = { workspace = true }
solana-send-transaction-service = { workspace = true }
solana-svm = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use {
commitment::BlockCommitmentCache,
verify_precompiles::verify_precompiles,
},
solana_runtime_transaction::runtime_transaction::RuntimeTransaction,
solana_sdk::{
account::Account,
clock::Slot,
Expand Down Expand Up @@ -178,7 +179,7 @@ fn simulate_transaction(
bank: &Bank,
transaction: VersionedTransaction,
) -> BanksTransactionResultWithSimulation {
let sanitized_transaction = match SanitizedTransaction::try_create(
let sanitized_transaction = match RuntimeTransaction::try_create(
transaction,
MessageHash::Compute,
Some(false), // is_simple_vote_tx
Expand Down
5 changes: 3 additions & 2 deletions core/benches/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use {
poh_service::PohService,
},
solana_runtime::{bank::Bank, bank_forks::BankForks},
solana_runtime_transaction::runtime_transaction::RuntimeTransaction,
solana_sdk::{
account::{Account, ReadableAccount},
signature::Keypair,
Expand Down Expand Up @@ -66,7 +67,7 @@ fn create_funded_accounts(bank: &Bank, num: usize) -> Vec<Keypair> {
accounts
}

fn create_transactions(bank: &Bank, num: usize) -> Vec<SanitizedTransaction> {
fn create_transactions(bank: &Bank, num: usize) -> Vec<RuntimeTransaction<SanitizedTransaction>> {
let funded_accounts = create_funded_accounts(bank, 2 * num);
funded_accounts
.into_par_iter()
Expand All @@ -76,7 +77,7 @@ fn create_transactions(bank: &Bank, num: usize) -> Vec<SanitizedTransaction> {
let to = &chunk[1];
system_transaction::transfer(from, &to.pubkey(), 1, bank.last_blockhash())
})
.map(SanitizedTransaction::from_transaction_for_tests)
.map(RuntimeTransaction::from_transaction_for_tests)
.collect()
}

Expand Down
7 changes: 5 additions & 2 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ mod tests {
poh_service::PohService,
},
solana_runtime::{bank::Bank, genesis_utils::bootstrap_validator_stake_lamports},
solana_runtime_transaction::runtime_transaction::RuntimeTransaction,
solana_sdk::{
hash::Hash,
poh_config::PohConfig,
Expand All @@ -867,9 +868,11 @@ mod tests {
(node, cluster_info)
}

pub(crate) fn sanitize_transactions(txs: Vec<Transaction>) -> Vec<SanitizedTransaction> {
pub(crate) fn sanitize_transactions(
txs: Vec<Transaction>,
) -> Vec<RuntimeTransaction<SanitizedTransaction>> {
txs.into_iter()
.map(SanitizedTransaction::from_transaction_for_tests)
.map(RuntimeTransaction::from_transaction_for_tests)
.collect()
}

Expand Down
11 changes: 9 additions & 2 deletions core/src/banking_stage/committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use {
transaction_batch::TransactionBatch,
vote_sender_types::ReplayVoteSender,
},
solana_runtime_transaction::svm_transaction_adapter::SVMTransactionAdapter,
solana_sdk::{pubkey::Pubkey, saturating_add_assign, transaction::SanitizedTransaction},
solana_svm::{
transaction_commit_result::{TransactionCommitResult, TransactionCommitResultExtensions},
Expand All @@ -22,7 +23,7 @@ use {
solana_transaction_status::{
token_balances::TransactionTokenBalancesSet, TransactionTokenBalance,
},
std::{collections::HashMap, sync::Arc},
std::{borrow::Borrow, collections::HashMap, sync::Arc},
};

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -134,7 +135,13 @@ impl Committer {
starting_transaction_index: Option<usize>,
) {
if let Some(transaction_status_sender) = &self.transaction_status_sender {
let txs = batch.sanitized_transactions().to_vec();
// Clone `SanitizedTransaction` out of `RuntimeTransaction`, this is
// done to send over the status sender.
let txs = batch
.sanitized_transactions()
.iter()
.map(|tx| tx.as_sanitized_transaction().borrow().clone())
.collect_vec();
let post_balances = bank.collect_balances(batch);
let post_token_balances =
collect_token_balances(bank, batch, &mut pre_balance_info.mint_decimals);
Expand Down
42 changes: 12 additions & 30 deletions core/src/banking_stage/consume_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ mod tests {
tests::{create_slow_genesis_config, sanitize_transactions, simulate_poh},
},
crossbeam_channel::unbounded,
itertools::Itertools,
solana_ledger::{
blockstore::Blockstore, genesis_utils::GenesisConfigInfo,
get_tmp_ledger_path_auto_delete, leader_schedule_cache::LeaderScheduleCache,
Expand All @@ -733,9 +734,10 @@ mod tests {
bank_forks::BankForks, prioritization_fee_cache::PrioritizationFeeCache,
vote_sender_types::ReplayVoteReceiver,
},
solana_runtime_transaction::runtime_transaction::RuntimeTransaction,
solana_sdk::{
address_lookup_table::AddressLookupTableAccount,
clock::{Slot, MAX_PROCESSING_AGE},
clock::Slot,
genesis_config::GenesisConfig,
message::{
v0::{self, LoadedAddresses},
Expand All @@ -746,9 +748,7 @@ mod tests {
signature::Keypair,
signer::Signer,
system_instruction, system_transaction,
transaction::{
MessageHash, SanitizedTransaction, TransactionError, VersionedTransaction,
},
transaction::{MessageHash, VersionedTransaction},
},
solana_svm_transaction::svm_message::SVMMessage,
std::{
Expand Down Expand Up @@ -1101,7 +1101,7 @@ mod tests {
readonly: vec![],
};
let loader = SimpleAddressLoader::Enabled(loaded_addresses);
SanitizedTransaction::try_create(
RuntimeTransaction::try_create(
VersionedTransaction::try_new(
VersionedMessage::V0(
v0::Message::try_compile(
Expand Down Expand Up @@ -1134,7 +1134,8 @@ mod tests {
txs.push(simple_v0_transfer());
txs.push(simple_v0_transfer());
txs.push(simple_v0_transfer());
let sanitized_txs = txs.clone();

let signatures = txs.iter().map(|tx| *tx.signature()).collect::<Vec<_>>();

// Fund the keypairs.
for tx in &txs {
Expand Down Expand Up @@ -1193,30 +1194,11 @@ mod tests {
// all but one succeed. 6 for initial funding
assert_eq!(bank.transaction_count(), 6 + 5);

let already_processed_results = bank
.check_transactions(
&sanitized_txs,
&vec![Ok(()); sanitized_txs.len()],
MAX_PROCESSING_AGE,
&mut TransactionErrorMetrics::default(),
)
.into_iter()
.map(|r| match r {
Ok(_) => Ok(()),
Err(err) => Err(err),
})
.collect::<Vec<_>>();
assert_eq!(
already_processed_results,
vec![
Err(TransactionError::AlreadyProcessed),
Err(TransactionError::AlreadyProcessed),
Err(TransactionError::AlreadyProcessed),
Ok(()), // <--- this transaction was not processed
Err(TransactionError::AlreadyProcessed),
Err(TransactionError::AlreadyProcessed)
]
);
let is_processed = signatures
.iter()
.map(|signature| bank.get_signature_status(signature).is_some())
.collect_vec();
assert_eq!(is_processed, [true, true, true, false, true, true]);

drop(test_frame);
let _ = worker_thread.join().unwrap();
Expand Down
27 changes: 16 additions & 11 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use {
transaction_batch::TransactionBatch,
verify_precompiles::verify_precompiles,
},
solana_runtime_transaction::instructions_processor::process_compute_budget_instructions,
solana_runtime_transaction::{
Copy link

Choose a reason for hiding this comment

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

Is there a reason that execute_and_commit_transactions_locked is recomputing the compute budget details still rather than using them from runtime tx?

instructions_processor::process_compute_budget_instructions,
runtime_transaction::RuntimeTransaction,
Copy link

Choose a reason for hiding this comment

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

Also how come check_fee_payer_unlocked isn't using runtime tx now?

},
solana_sdk::{
clock::{FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET, MAX_PROCESSING_AGE},
fee::FeeBudgetLimits,
Expand Down Expand Up @@ -228,7 +231,7 @@ impl Consumer {
&self,
bank: &Arc<Bank>,
bank_creation_time: &Instant,
sanitized_transactions: &[SanitizedTransaction],
sanitized_transactions: &[RuntimeTransaction<SanitizedTransaction>],
banking_stage_stats: &BankingStageStats,
slot_metrics_tracker: &mut LeaderSlotMetricsTracker,
) -> ProcessTransactionsSummary {
Expand Down Expand Up @@ -284,7 +287,7 @@ impl Consumer {
&self,
bank: &Arc<Bank>,
bank_creation_time: &Instant,
transactions: &[SanitizedTransaction],
transactions: &[RuntimeTransaction<SanitizedTransaction>],
) -> ProcessTransactionsSummary {
let mut chunk_start = 0;
let mut all_retryable_tx_indexes = vec![];
Expand Down Expand Up @@ -386,7 +389,7 @@ impl Consumer {
pub fn process_and_record_transactions(
&self,
bank: &Arc<Bank>,
txs: &[SanitizedTransaction],
txs: &[RuntimeTransaction<SanitizedTransaction>],
chunk_offset: usize,
) -> ProcessTransactionBatchOutput {
let mut error_counters = TransactionErrorMetrics::default();
Expand Down Expand Up @@ -429,7 +432,7 @@ impl Consumer {
pub fn process_and_record_aged_transactions(
&self,
bank: &Arc<Bank>,
txs: &[SanitizedTransaction],
txs: &[RuntimeTransaction<SanitizedTransaction>],
max_ages: &[MaxAge],
) -> ProcessTransactionBatchOutput {
let move_precompile_verification_to_svm = bank
Expand Down Expand Up @@ -473,7 +476,7 @@ impl Consumer {
fn process_and_record_transactions_with_pre_results(
&self,
bank: &Arc<Bank>,
txs: &[SanitizedTransaction],
txs: &[RuntimeTransaction<SanitizedTransaction>],
chunk_offset: usize,
pre_results: impl Iterator<Item = Result<(), TransactionError>>,
) -> ProcessTransactionBatchOutput {
Expand Down Expand Up @@ -803,7 +806,7 @@ impl Consumer {
/// * `pending_indexes` - identifies which indexes in the `transactions` list are still pending
fn filter_pending_packets_from_pending_txs(
bank: &Bank,
transactions: &[SanitizedTransaction],
transactions: &[RuntimeTransaction<SanitizedTransaction>],
pending_indexes: &[usize],
) -> Vec<usize> {
let filter =
Expand Down Expand Up @@ -887,7 +890,7 @@ mod tests {
signature::Keypair,
signer::Signer,
system_instruction, system_program, system_transaction,
transaction::{MessageHash, Transaction, VersionedTransaction},
transaction::{Transaction, VersionedTransaction},
},
solana_svm::account_loader::CheckedTransactionDetails,
solana_timings::ProgramTiming,
Expand All @@ -902,6 +905,7 @@ mod tests {
thread::{Builder, JoinHandle},
time::Duration,
},
transaction::MessageHash,
};

fn execute_transactions_with_dummy_poh_service(
Expand Down Expand Up @@ -2059,14 +2063,15 @@ mod tests {
});

let tx = VersionedTransaction::try_new(message, &[&keypair]).unwrap();
let sanitized_tx = SanitizedTransaction::try_create(
let sanitized_tx = RuntimeTransaction::try_create(
tx.clone(),
MessageHash::Compute,
Some(false),
bank.as_ref(),
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();
let loaded_addresses = sanitized_tx.get_loaded_addresses();

let entry = next_versioned_entry(&genesis_config.hash(), 1, vec![tx]);
let entries = vec![entry];
Expand Down Expand Up @@ -2131,7 +2136,7 @@ mod tests {
);
let consumer = Consumer::new(committer, recorder, QosService::new(1), None);

let _ = consumer.process_and_record_transactions(&bank, &[sanitized_tx.clone()], 0);
let _ = consumer.process_and_record_transactions(&bank, &[sanitized_tx], 0);

drop(consumer); // drop/disconnect transaction_status_sender
transaction_status_service.join().unwrap();
Expand All @@ -2149,7 +2154,7 @@ mod tests {
pre_token_balances: Some(vec![]),
post_token_balances: Some(vec![]),
rewards: Some(vec![]),
loaded_addresses: sanitized_tx.get_loaded_addresses(),
loaded_addresses,
compute_units_consumed: Some(0),
..TransactionStatusMeta::default()
}
Expand Down
Loading
Loading