Skip to content

Commit

Permalink
return precompile details not full signature details
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Sep 25, 2024
1 parent f1d0880 commit f834940
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
1 change: 1 addition & 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 runtime-transaction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
10 changes: 5 additions & 5 deletions runtime-transaction/benches/get_signature_details.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand All @@ -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);
});
});
}
Expand Down Expand Up @@ -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);
});
});
}
Expand Down Expand Up @@ -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);
});
});
}
Expand Down Expand Up @@ -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);
});
});
}
Expand Down
54 changes: 26 additions & 28 deletions runtime-transaction/src/signature_details.rs
Original file line number Diff line number Diff line change
@@ -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<Item = (&'a Pubkey, SVMInstruction<'a>)>,
) -> TransactionSignatureDetails {
) -> PrecompileSignatureDetails {
let mut filter = SignatureDetailsFilter::new();

// Wrapping arithmetic is safe below because the maximum number of signatures
Expand All @@ -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)]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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);
}
}

0 comments on commit f834940

Please sign in to comment.