diff --git a/Cargo.lock b/Cargo.lock index 6cba387a9e551d..ba5a049cec13ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7722,6 +7722,7 @@ dependencies = [ "solana-builtins-default-costs", "solana-compute-budget", "solana-program", + "solana-pubkey", "solana-sdk", "solana-svm-transaction", "thiserror", diff --git a/runtime-transaction/Cargo.toml b/runtime-transaction/Cargo.toml index 00118b43794f06..9ccb325593da89 100644 --- a/runtime-transaction/Cargo.toml +++ b/runtime-transaction/Cargo.toml @@ -14,6 +14,7 @@ agave-transaction-view = { workspace = true } log = { workspace = true } solana-builtins-default-costs = { workspace = true } solana-compute-budget = { workspace = true } +solana-pubkey = { workspace = true } solana-sdk = { workspace = true } solana-svm-transaction = { workspace = true } thiserror = { workspace = true } diff --git a/runtime-transaction/benches/get_signature_details.rs b/runtime-transaction/benches/get_signature_details.rs index 8fb6f23d982225..3a576574909a08 100644 --- a/runtime-transaction/benches/get_signature_details.rs +++ b/runtime-transaction/benches/get_signature_details.rs @@ -1,6 +1,6 @@ use { criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}, - solana_runtime_transaction::signature_details::get_signature_details, + solana_runtime_transaction::signature_details::get_precompile_signature_details, solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey}, solana_svm_transaction::instruction::SVMInstruction, }; @@ -13,7 +13,7 @@ fn bench_get_signature_details_empty(c: &mut Criterion) { .bench_function("0 instructions", |bencher| { bencher.iter(|| { let instructions = black_box(instructions.clone()); - let _ = get_signature_details(0, instructions); + let _ = get_precompile_signature_details(instructions); }); }); } @@ -43,7 +43,7 @@ fn bench_get_signature_details_no_sigs_unique(c: &mut Criterion) { black_box(instructions.iter().map(|(program_id, instruction)| { (*program_id, SVMInstruction::from(instruction)) })); - let _ = get_signature_details(0, instructions); + let _ = get_precompile_signature_details(instructions); }); }); } @@ -78,7 +78,7 @@ fn bench_get_signature_details_packed_sigs(c: &mut Criterion) { black_box(instructions.iter().map(|(program_id, instruction)| { (*program_id, SVMInstruction::from(instruction)) })); - let _ = get_signature_details(0, instructions); + let _ = get_precompile_signature_details(instructions); }); }); } @@ -116,7 +116,7 @@ fn bench_get_signature_details_mixed_sigs(c: &mut Criterion) { black_box(instructions.iter().map(|(program_id, instruction)| { (*program_id, SVMInstruction::from(instruction)) })); - let _ = get_signature_details(0, instructions); + let _ = get_precompile_signature_details(instructions); }); }); } diff --git a/runtime-transaction/src/signature_details.rs b/runtime-transaction/src/signature_details.rs index 8daabbf52b79cc..8972873116a236 100644 --- a/runtime-transaction/src/signature_details.rs +++ b/runtime-transaction/src/signature_details.rs @@ -1,15 +1,18 @@ // static account keys has max use { agave_transaction_view::static_account_keys_frame::MAX_STATIC_ACCOUNTS_PER_PACKET as FILTER_SIZE, - solana_sdk::{message::TransactionSignatureDetails, pubkey::Pubkey}, - solana_svm_transaction::instruction::SVMInstruction, + solana_pubkey::Pubkey, solana_svm_transaction::instruction::SVMInstruction, }; +pub struct PrecompileSignatureDetails { + pub num_secp256k1_instruction_signatures: u64, + pub num_ed25519_instruction_signatures: u64, +} + /// Get transaction signature details. -pub fn get_signature_details<'a>( - num_transaction_signatures: u64, +pub fn get_precompile_signature_details<'a>( instructions: impl Iterator)>, -) -> TransactionSignatureDetails { +) -> PrecompileSignatureDetails { let mut filter = SignatureDetailsFilter::new(); // Wrapping arithmetic is safe below because the maximum number of signatures @@ -23,25 +26,24 @@ pub fn get_signature_details<'a>( ProgramIdStatus::NotSignature => {} ProgramIdStatus::Secp256k1 => { num_secp256k1_instruction_signatures = num_secp256k1_instruction_signatures - .wrapping_add(u64::from(get_num_signatures_in_instruction(&instruction))); + .wrapping_add(get_num_signatures_in_instruction(&instruction)); } ProgramIdStatus::Ed25519 => { num_ed25519_instruction_signatures = num_ed25519_instruction_signatures - .wrapping_add(u64::from(get_num_signatures_in_instruction(&instruction))); + .wrapping_add(get_num_signatures_in_instruction(&instruction)); } } } - TransactionSignatureDetails::new( - num_transaction_signatures, + PrecompileSignatureDetails { num_secp256k1_instruction_signatures, num_ed25519_instruction_signatures, - ) + } } #[inline] -fn get_num_signatures_in_instruction(instruction: &SVMInstruction) -> u8 { - instruction.data.first().copied().unwrap_or(0) +fn get_num_signatures_in_instruction(instruction: &SVMInstruction) -> u64 { + u64::from(instruction.data.first().copied().unwrap_or(0)) } #[derive(Copy, Clone)] @@ -113,11 +115,10 @@ mod tests { #[test] fn test_get_signature_details_no_instructions() { let instructions = std::iter::empty(); - let signature_details = get_signature_details(2, instructions); + let signature_details = get_precompile_signature_details(instructions); - assert_eq!(signature_details.num_transaction_signatures(), 2); - assert_eq!(signature_details.num_secp256k1_instruction_signatures(), 0); - assert_eq!(signature_details.num_ed25519_instruction_signatures(), 0); + assert_eq!(signature_details.num_secp256k1_instruction_signatures, 0); + assert_eq!(signature_details.num_ed25519_instruction_signatures, 0); } #[test] @@ -128,10 +129,9 @@ mod tests { make_instruction(&program_ids, 1, &[]), ]; - let signature_details = get_signature_details(2, instructions.into_iter()); - assert_eq!(signature_details.num_transaction_signatures(), 2); - assert_eq!(signature_details.num_secp256k1_instruction_signatures(), 0); - assert_eq!(signature_details.num_ed25519_instruction_signatures(), 0); + let signature_details = get_precompile_signature_details(instructions.into_iter()); + assert_eq!(signature_details.num_secp256k1_instruction_signatures, 0); + assert_eq!(signature_details.num_ed25519_instruction_signatures, 0); } #[test] @@ -150,10 +150,9 @@ mod tests { make_instruction(&program_ids, 0, &[]), ]; - let signature_details = get_signature_details(2, instructions.into_iter()); - assert_eq!(signature_details.num_transaction_signatures(), 2); - assert_eq!(signature_details.num_secp256k1_instruction_signatures(), 6); - assert_eq!(signature_details.num_ed25519_instruction_signatures(), 5); + let signature_details = get_precompile_signature_details(instructions.into_iter()); + assert_eq!(signature_details.num_secp256k1_instruction_signatures, 6); + assert_eq!(signature_details.num_ed25519_instruction_signatures, 5); } #[test] @@ -167,9 +166,8 @@ mod tests { make_instruction(&program_ids, 1, &[]), ]; - let signature_details = get_signature_details(2, instructions.into_iter()); - assert_eq!(signature_details.num_transaction_signatures(), 2); - assert_eq!(signature_details.num_secp256k1_instruction_signatures(), 0); - assert_eq!(signature_details.num_ed25519_instruction_signatures(), 0); + let signature_details = get_precompile_signature_details(instructions.into_iter()); + assert_eq!(signature_details.num_secp256k1_instruction_signatures, 0); + assert_eq!(signature_details.num_ed25519_instruction_signatures, 0); } }