Adds TX signature to `TransactionContext` in debug mode (#29597)

Adds TX signature to TransactionContext in debug mode.
This commit is contained in:
Alexander Meißner 2023-01-10 00:54:26 +01:00 committed by GitHub
parent dda34b208c
commit db277d320b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -4227,6 +4227,8 @@ impl Bank {
{ {
transaction_context.enable_cap_accounts_data_allocations_per_transaction(); transaction_context.enable_cap_accounts_data_allocations_per_transaction();
} }
#[cfg(debug_assertions)]
transaction_context.set_signature(tx.signature());
let pre_account_state_info = let pre_account_state_info =
self.get_transaction_account_state_info(&transaction_context, tx.message()); self.get_transaction_account_state_info(&transaction_context, tx.message());

View File

@ -1,6 +1,8 @@
//! Data shared between program runtime and built-in programs as well as SBF programs. //! Data shared between program runtime and built-in programs as well as SBF programs.
#![deny(clippy::indexing_slicing)] #![deny(clippy::indexing_slicing)]
#[cfg(all(not(target_os = "solana"), debug_assertions))]
use crate::signature::Signature;
#[cfg(not(target_os = "solana"))] #[cfg(not(target_os = "solana"))]
use crate::{ use crate::{
account::WritableAccount, account::WritableAccount,
@ -68,6 +70,9 @@ pub struct TransactionContext {
rent: Option<Rent>, rent: Option<Rent>,
#[cfg(not(target_os = "solana"))] #[cfg(not(target_os = "solana"))]
is_cap_accounts_data_allocations_per_transaction_enabled: bool, is_cap_accounts_data_allocations_per_transaction_enabled: bool,
/// Useful for debugging to filter by or to look it up on the explorer
#[cfg(all(not(target_os = "solana"), debug_assertions))]
signature: Signature,
} }
impl TransactionContext { impl TransactionContext {
@ -97,6 +102,8 @@ impl TransactionContext {
accounts_resize_delta: RefCell::new(0), accounts_resize_delta: RefCell::new(0),
rent, rent,
is_cap_accounts_data_allocations_per_transaction_enabled: false, is_cap_accounts_data_allocations_per_transaction_enabled: false,
#[cfg(all(not(target_os = "solana"), debug_assertions))]
signature: Signature::default(),
} }
} }
@ -118,6 +125,18 @@ impl TransactionContext {
self.rent.is_some() self.rent.is_some()
} }
/// Stores the signature of the current transaction
#[cfg(all(not(target_os = "solana"), debug_assertions))]
pub fn set_signature(&mut self, signature: &Signature) {
self.signature = *signature;
}
/// Returns the signature of the current transaction
#[cfg(all(not(target_os = "solana"), debug_assertions))]
pub fn get_signature(&self) -> &Signature {
&self.signature
}
/// Returns the total number of accounts loaded in this Transaction /// Returns the total number of accounts loaded in this Transaction
pub fn get_number_of_accounts(&self) -> IndexOfAccount { pub fn get_number_of_accounts(&self) -> IndexOfAccount {
self.accounts.len() as IndexOfAccount self.accounts.len() as IndexOfAccount