Skip to content

Commit

Permalink
runtime transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Oct 1, 2024
1 parent 590c2e2 commit fb11a17
Show file tree
Hide file tree
Showing 41 changed files with 314 additions and 219 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: 4 additions & 1 deletion banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use {
bank_forks::BankForks,
commitment::BlockCommitmentCache,
},
solana_runtime_transaction::runtime_transaction::RuntimeTransaction,
solana_sdk::{
account::Account,
clock::Slot,
Expand Down Expand Up @@ -183,7 +184,9 @@ fn simulate_transaction(
Some(false), // is_simple_vote_tx
bank,
bank.get_reserved_account_keys(),
) {
)
.and_then(RuntimeTransaction::try_from_sanitized_transaction)
{
Err(err) => {
return BanksTransactionResultWithSimulation {
result: Some(Err(err)),
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 @@ -847,6 +847,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 @@ -873,9 +874,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
21 changes: 13 additions & 8 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ use {
bank::{Bank, LoadAndExecuteTransactionsOutput},
transaction_batch::TransactionBatch,
},
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 @@ -40,6 +43,7 @@ use {
solana_svm_transaction::svm_message::SVMMessage,
solana_timings::ExecuteTimings,
std::{
ops::Deref,
sync::{atomic::Ordering, Arc},
time::Instant,
},
Expand Down Expand Up @@ -226,7 +230,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 @@ -282,7 +286,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 @@ -384,7 +388,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 @@ -427,7 +431,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 @@ -445,7 +449,7 @@ 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 {
if &resanitized_tx != tx.deref() {
// Sanitization before/after epoch give different transaction data - do not execute.
return Err(TransactionError::ResanitizationNeeded);
}
Expand All @@ -470,7 +474,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 @@ -801,7 +805,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 @@ -2064,6 +2068,7 @@ mod tests {
bank.as_ref(),
&ReservedAccountKeys::empty_key_set(),
)
.and_then(RuntimeTransaction::try_from_sanitized_transaction)
.unwrap();

let entry = next_versioned_entry(&genesis_config.hash(), 1, vec![tx]);
Expand Down
8 changes: 6 additions & 2 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 @@ -116,7 +119,7 @@ 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;
}
Expand All @@ -127,6 +130,7 @@ impl ImmutableDeserializedPacket {
address_loader,
reserved_account_keys,
)
.and_then(RuntimeTransaction::try_from_sanitized_transaction)
.ok()?;
Some(tx)
}
Expand Down
34 changes: 14 additions & 20 deletions core/src/banking_stage/qos_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use {
solana_feature_set::FeatureSet,
solana_measure::measure::Measure,
solana_runtime::bank::Bank,
solana_runtime_transaction::runtime_transaction::RuntimeTransaction,
solana_sdk::{
clock::Slot,
saturating_add_assign,
Expand Down Expand Up @@ -42,7 +43,7 @@ impl QosService {
pub fn select_and_accumulate_transaction_costs(
&self,
bank: &Bank,
transactions: &[SanitizedTransaction],
transactions: &[RuntimeTransaction<SanitizedTransaction>],
pre_results: impl Iterator<Item = transaction::Result<()>>,
) -> (Vec<transaction::Result<TransactionCost>>, u64) {
let transaction_costs =
Expand All @@ -69,7 +70,7 @@ impl QosService {
fn compute_transaction_costs<'a>(
&self,
feature_set: &FeatureSet,
transactions: impl Iterator<Item = &'a SanitizedTransaction>,
transactions: impl Iterator<Item = &'a RuntimeTransaction<SanitizedTransaction>>,
pre_results: impl Iterator<Item = transaction::Result<()>>,
) -> Vec<transaction::Result<TransactionCost>> {
let mut compute_cost_time = Measure::start("compute_cost_time");
Expand All @@ -94,7 +95,7 @@ impl QosService {
/// and a count of the number of transactions that would fit in the block
fn select_transactions_per_cost<'a>(
&self,
transactions: impl Iterator<Item = &'a SanitizedTransaction>,
transactions: impl Iterator<Item = &'a RuntimeTransaction<SanitizedTransaction>>,
transactions_costs: impl Iterator<Item = transaction::Result<TransactionCost>>,
bank: &Bank,
) -> (Vec<transaction::Result<TransactionCost>>, usize) {
Expand Down Expand Up @@ -626,10 +627,10 @@ mod tests {

// make a vec of txs
let keypair = Keypair::new();
let transfer_tx = SanitizedTransaction::from_transaction_for_tests(
let transfer_tx = RuntimeTransaction::from_transaction_for_tests(
system_transaction::transfer(&keypair, &keypair.pubkey(), 1, Hash::default()),
);
let vote_tx = SanitizedTransaction::from_transaction_for_tests(
let vote_tx = RuntimeTransaction::from_transaction_for_tests(
vote_transaction::new_tower_sync_transaction(
TowerSync::from(vec![(42, 1)]),
Hash::default(),
Expand Down Expand Up @@ -669,10 +670,10 @@ mod tests {
let bank = Arc::new(Bank::new_for_tests(&genesis_config));

let keypair = Keypair::new();
let transfer_tx = SanitizedTransaction::from_transaction_for_tests(
let transfer_tx = RuntimeTransaction::from_transaction_for_tests(
system_transaction::transfer(&keypair, &keypair.pubkey(), 1, Hash::default()),
);
let vote_tx = SanitizedTransaction::from_transaction_for_tests(
let vote_tx = RuntimeTransaction::from_transaction_for_tests(
vote_transaction::new_tower_sync_transaction(
TowerSync::from(vec![(42, 1)]),
Hash::default(),
Expand All @@ -688,7 +689,6 @@ mod tests {

// make a vec of txs
let txs = vec![transfer_tx.clone(), vote_tx.clone(), transfer_tx, vote_tx];

let qos_service = QosService::new(1);
let txs_costs = qos_service.compute_transaction_costs(
&FeatureSet::all_enabled(),
Expand Down Expand Up @@ -731,10 +731,8 @@ mod tests {
],
Some(&keypair.pubkey()),
));
let transfer_tx = SanitizedTransaction::from_transaction_for_tests(transaction.clone());
let txs: Vec<SanitizedTransaction> = (0..transaction_count)
.map(|_| transfer_tx.clone())
.collect();
let transfer_tx = RuntimeTransaction::from_transaction_for_tests(transaction.clone());
let txs = vec![transfer_tx; transaction_count as usize];
let execute_units_adjustment: u64 = 10;
let loaded_accounts_data_size_adjustment: u32 = 32000;
let loaded_accounts_data_size_cost_adjustment =
Expand Down Expand Up @@ -801,12 +799,10 @@ mod tests {
// calculate their costs, apply to cost_tracker
let transaction_count = 5;
let keypair = Keypair::new();
let transfer_tx = SanitizedTransaction::from_transaction_for_tests(
let transfer_tx = RuntimeTransaction::from_transaction_for_tests(
system_transaction::transfer(&keypair, &keypair.pubkey(), 1, Hash::default()),
);
let txs: Vec<SanitizedTransaction> = (0..transaction_count)
.map(|_| transfer_tx.clone())
.collect();
let txs = vec![transfer_tx; transaction_count];

// assert all tx_costs should be removed from cost_tracker if all execution_results are all Not Committed
{
Expand Down Expand Up @@ -851,10 +847,8 @@ mod tests {
],
Some(&keypair.pubkey()),
));
let transfer_tx = SanitizedTransaction::from_transaction_for_tests(transaction.clone());
let txs: Vec<SanitizedTransaction> = (0..transaction_count)
.map(|_| transfer_tx.clone())
.collect();
let transfer_tx = RuntimeTransaction::from_transaction_for_tests(transaction.clone());
let txs = vec![transfer_tx; transaction_count];
let execute_units_adjustment: u64 = 10;
let loaded_accounts_data_size_adjustment: u32 = 32000;
let loaded_accounts_data_size_cost_adjustment =
Expand Down
3 changes: 2 additions & 1 deletion core/src/banking_stage/scheduler_messages.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
super::immutable_deserialized_packet::ImmutableDeserializedPacket,
solana_runtime_transaction::runtime_transaction::RuntimeTransaction,
solana_sdk::{clock::Slot, transaction::SanitizedTransaction},
std::{fmt::Display, sync::Arc},
};
Expand Down Expand Up @@ -41,7 +42,7 @@ impl Display for TransactionId {
pub struct ConsumeWork {
pub batch_id: TransactionBatchId,
pub ids: Vec<TransactionId>,
pub transactions: Vec<SanitizedTransaction>,
pub transactions: Vec<RuntimeTransaction<SanitizedTransaction>>,
pub max_age_slots: Vec<Slot>,
}

Expand Down
Loading

0 comments on commit fb11a17

Please sign in to comment.