From f5e225eb21af530fd35932f6ab0e3cc11b672e96 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Thu, 7 Nov 2024 14:08:00 -0600 Subject: [PATCH] RuntimeTransaction --- .../src/runtime_transaction.rs | 1 + .../runtime_transaction/transaction_view.rs | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 runtime-transaction/src/runtime_transaction/transaction_view.rs diff --git a/runtime-transaction/src/runtime_transaction.rs b/runtime-transaction/src/runtime_transaction.rs index 4c94b1b3dce2df..07ed60f234e0a5 100644 --- a/runtime-transaction/src/runtime_transaction.rs +++ b/runtime-transaction/src/runtime_transaction.rs @@ -31,6 +31,7 @@ use { }; mod sdk_transactions; +mod transaction_view; #[cfg_attr(feature = "dev-context-only-utils", derive(Clone))] #[derive(Debug)] diff --git a/runtime-transaction/src/runtime_transaction/transaction_view.rs b/runtime-transaction/src/runtime_transaction/transaction_view.rs new file mode 100644 index 00000000000000..2931d638295c3f --- /dev/null +++ b/runtime-transaction/src/runtime_transaction/transaction_view.rs @@ -0,0 +1,62 @@ +use { + super::{ComputeBudgetInstructionDetails, RuntimeTransaction}, + crate::{ + signature_details::get_precompile_signature_details, transaction_meta::TransactionMeta, + }, + agave_transaction_view::{ + transaction_data::TransactionData, transaction_version::TransactionVersion, + transaction_view::SanitizedTransactionView, + }, + solana_sdk::{ + message::{TransactionSignatureDetails, VersionedMessage}, + simple_vote_transaction_checker::is_simple_vote_transaction_impl, + transaction::{MessageHash, Result}, + }, +}; + +fn is_simple_vote_transaction( + transaction: &SanitizedTransactionView, +) -> bool { + let signatures = transaction.signatures(); + let is_legacy_message = matches!(transaction.version(), TransactionVersion::Legacy); + let instruction_programs = transaction + .program_instructions_iter() + .map(|(program_id, _ix)| program_id); + + is_simple_vote_transaction_impl(signatures, is_legacy_message, instruction_programs) +} + +impl RuntimeTransaction> { + pub fn try_from( + transaction: SanitizedTransactionView, + message_hash: MessageHash, + is_simple_vote_tx: Option, + ) -> Result { + let message_hash = match message_hash { + MessageHash::Precomputed(hash) => hash, + MessageHash::Compute => VersionedMessage::hash_raw_message(transaction.message_data()), + }; + let is_simple_vote_tx = + is_simple_vote_tx.unwrap_or_else(|| is_simple_vote_transaction(&transaction)); + + let precompile_signature_details = + get_precompile_signature_details(transaction.program_instructions_iter()); + let signature_details = TransactionSignatureDetails::new( + u64::from(transaction.num_required_signatures()), + precompile_signature_details.num_secp256k1_instruction_signatures, + precompile_signature_details.num_ed25519_instruction_signatures, + ); + let compute_budget_instruction_details = + ComputeBudgetInstructionDetails::try_from(transaction.program_instructions_iter())?; + + Ok(Self { + transaction, + meta: TransactionMeta { + message_hash, + is_simple_vote_transaction: is_simple_vote_tx, + signature_details, + compute_budget_instruction_details, + }, + }) + } +}