Skip to content

Commit

Permalink
use RuntimeTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Oct 17, 2024
1 parent f4523e3 commit 33de7d8
Show file tree
Hide file tree
Showing 55 changed files with 671 additions and 492 deletions.
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
5 changes: 3 additions & 2 deletions 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,9 +179,9 @@ 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,
None, // message_hash
Some(false), // is_simple_vote_tx
bank,
bank.get_reserved_account_keys(),
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
10 changes: 8 additions & 2 deletions core/src/banking_stage/committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use {
solana_transaction_status::{
token_balances::TransactionTokenBalancesSet, TransactionTokenBalance,
},
std::{collections::HashMap, sync::Arc},
std::{collections::HashMap, ops::Deref, sync::Arc},
};

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -134,7 +134,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.deref().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
44 changes: 13 additions & 31 deletions core/src/banking_stage/consume_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,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 @@ -707,9 +708,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 @@ -720,9 +722,7 @@ mod tests {
signature::Keypair,
signer::Signer,
system_instruction, system_transaction,
transaction::{
MessageHash, SanitizedTransaction, TransactionError, VersionedTransaction,
},
transaction::VersionedTransaction,
},
solana_svm_transaction::svm_message::SVMMessage,
std::{
Expand Down Expand Up @@ -1075,7 +1075,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 All @@ -1092,7 +1092,7 @@ mod tests {
&[&payer],
)
.unwrap(),
MessageHash::Compute,
None,
None,
loader,
&HashSet::default(),
Expand All @@ -1108,7 +1108,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 @@ -1167,30 +1168,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
28 changes: 16 additions & 12 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::{
instructions_processor::process_compute_budget_instructions,
runtime_transaction::RuntimeTransaction,
},
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 @@ -804,7 +807,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 @@ -888,7 +891,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 Down Expand Up @@ -2060,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,
None,
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 @@ -2132,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 @@ -2150,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

0 comments on commit 33de7d8

Please sign in to comment.