Skip to content

Commit

Permalink
use RuntimeTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Oct 7, 2024
1 parent a75c91d commit 7c93e54
Show file tree
Hide file tree
Showing 45 changed files with 537 additions and 360 deletions.
6 changes: 6 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 @@ -843,6 +843,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 @@ -869,9 +870,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
32 changes: 19 additions & 13 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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::{Slot, FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET, MAX_PROCESSING_AGE},
fee::FeeBudgetLimits,
Expand All @@ -41,6 +44,7 @@ use {
solana_svm_transaction::svm_message::SVMMessage,
solana_timings::ExecuteTimings,
std::{
ops::Deref,
sync::{atomic::Ordering, Arc},
time::Instant,
},
Expand Down Expand Up @@ -227,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 @@ -283,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 @@ -385,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 @@ -428,7 +432,7 @@ impl Consumer {
pub fn process_and_record_aged_transactions(
&self,
bank: &Arc<Bank>,
txs: &[SanitizedTransaction],
txs: &[RuntimeTransaction<SanitizedTransaction>],
max_slot_ages: &[Slot],
) -> ProcessTransactionBatchOutput {
let move_precompile_verification_to_svm = bank
Expand All @@ -446,7 +450,8 @@ impl Consumer {
// but whether it will pass sanitization needs to be checked.
let resanitized_tx =
bank.fully_verify_transaction(tx.to_versioned_transaction())?;
if resanitized_tx != *tx {
// Compare inner transaction types - ignore the meta.
if resanitized_tx.deref() != tx.deref() {
// Sanitization before/after epoch give different transaction data - do not execute.
return Err(TransactionError::ResanitizationNeeded);
}
Expand All @@ -471,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 @@ -802,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 @@ -886,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 @@ -2058,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 @@ -2130,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 @@ -2148,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
36 changes: 27 additions & 9 deletions core/src/banking_stage/immutable_deserialized_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use {
super::packet_filter::PacketFilterFailure,
solana_compute_budget::compute_budget_limits::ComputeBudgetLimits,
solana_perf::packet::Packet,
solana_runtime_transaction::instructions_processor::process_compute_budget_instructions,
solana_runtime_transaction::{
instructions_processor::process_compute_budget_instructions,
runtime_transaction::RuntimeTransaction,
},
solana_sanitize::SanitizeError,
solana_sdk::{
hash::Hash,
Expand Down Expand Up @@ -39,7 +42,7 @@ pub enum DeserializedPacketError {
FailedFilter(#[from] PacketFilterFailure),
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct ImmutableDeserializedPacket {
original_packet: Packet,
transaction: SanitizedVersionedTransaction,
Expand Down Expand Up @@ -116,22 +119,37 @@ impl ImmutableDeserializedPacket {
votes_only: bool,
address_loader: impl AddressLoader,
reserved_account_keys: &HashSet<Pubkey>,
) -> Option<SanitizedTransaction> {
) -> Option<RuntimeTransaction<SanitizedTransaction>> {
if votes_only && !self.is_simple_vote() {
return None;
}
let tx = SanitizedTransaction::try_new(
self.transaction().clone(),
*self.message_hash(),
self.is_simple_vote(),
address_loader,
reserved_account_keys,

let tx = RuntimeTransaction::<SanitizedVersionedTransaction>::try_from(
self.transaction.clone(),
Some(self.message_hash),
Some(self.is_simple_vote),
)
.and_then(|tx| {
RuntimeTransaction::<SanitizedTransaction>::try_from(
tx,
address_loader,
reserved_account_keys,
)
})
.ok()?;

Some(tx)
}
}

// Eq and PartialEq MUST be consistent with PartialOrd and Ord
impl Eq for ImmutableDeserializedPacket {}
impl PartialEq for ImmutableDeserializedPacket {
fn eq(&self, other: &Self) -> bool {
self.compute_unit_price() == other.compute_unit_price()
}
}

impl PartialOrd for ImmutableDeserializedPacket {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
Expand Down
Loading

0 comments on commit 7c93e54

Please sign in to comment.