Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod tests {
.get(&deserialized_bank.slot())
.unwrap()
.clone();
assert!(*bank == deserialized_bank);
assert_eq!(*bank, deserialized_bank);

let slot_snapshot_paths = snapshot_utils::get_snapshot_paths(&snapshot_path);

Expand Down
10 changes: 9 additions & 1 deletion programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use solana_sdk::{
program_utils::limited_deserialize,
pubkey::Pubkey,
};
use std::{cell::RefCell, rc::Rc, sync::Arc};
use std::{cell::RefCell, fmt::Debug, rc::Rc, sync::Arc};
use thiserror::Error;

solana_sdk::declare_builtin!(
Expand Down Expand Up @@ -214,6 +214,14 @@ impl InstructionMeter for ThisInstructionMeter {
pub struct BPFExecutor {
executable: Box<dyn Executable<BPFError>>,
}

// Well, implement Debug for solana_rbpf::vm::Executable in solana-rbpf...
impl Debug for BPFExecutor {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "BPFExecutor({:p})", self)
}
}

impl Executor for BPFExecutor {
fn execute(
&self,
Expand Down
75 changes: 67 additions & 8 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use crate::{
instruction_recorder::InstructionRecorder,
log_collector::LogCollector,
message_processor::{Executors, MessageProcessor},
process_instruction::{Executor, ProcessInstruction, ProcessInstructionWithContext},
process_instruction::{
ErasedProcessInstruction, ErasedProcessInstructionWithContext, Executor,
ProcessInstruction, ProcessInstructionWithContext,
},
rent_collector::RentCollector,
stakes::Stakes,
status_cache::{SlotDelta, StatusCache},
Expand Down Expand Up @@ -139,7 +142,31 @@ pub enum Entrypoint {
Loader(ProcessInstructionWithContext),
}

#[derive(Clone)]
impl fmt::Debug for Entrypoint {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[derive(Debug)]
enum EntrypointForDebug {
Program(String),
Loader(String),
}
// rustc doesn't compile due to bug without this work around
// https://github.com/rust-lang/rust/issues/50280
// https://users.rust-lang.org/t/display-function-pointer/17073/2
let entrypoint = match self {
Entrypoint::Program(instruction) => EntrypointForDebug::Program(format!(
"{:p}",
*instruction as ErasedProcessInstruction
)),
Entrypoint::Loader(instruction) => EntrypointForDebug::Loader(format!(
"{:p}",
*instruction as ErasedProcessInstructionWithContext
)),
};
write!(f, "{:?}", entrypoint)
}
}

#[derive(Clone, Debug)]
pub struct Builtin {
pub name: String,
pub id: Pubkey,
Expand All @@ -156,7 +183,7 @@ impl Builtin {
}

/// Copy-on-write holder of CachedExecutors
#[derive(AbiExample, Default)]
#[derive(AbiExample, Debug, Default)]
struct CowCachedExecutors {
shared: bool,
executors: Arc<RwLock<CachedExecutors>>,
Expand Down Expand Up @@ -200,7 +227,7 @@ impl AbiExample for Builtin {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Builtins {
/// Builtin programs that are always available
pub genesis_builtins: Vec<Builtin>,
Expand All @@ -212,6 +239,7 @@ pub struct Builtins {
const MAX_CACHED_EXECUTORS: usize = 100; // 10 MB assuming programs are around 100k

/// LFU Cache of executors
#[derive(Debug)]
struct CachedExecutors {
max: usize,
executors: HashMap<Pubkey, (AtomicU64, Arc<dyn Executor>)>,
Expand Down Expand Up @@ -289,7 +317,7 @@ impl CachedExecutors {
}
}

#[derive(Default)]
#[derive(Default, Debug)]
pub struct BankRc {
/// where all the Accounts are stored
pub accounts: Arc<Accounts>,
Expand Down Expand Up @@ -330,7 +358,7 @@ impl BankRc {
}
}

#[derive(Default, AbiExample)]
#[derive(Default, Debug, AbiExample)]
pub struct StatusCacheRc {
/// where all the Accounts are stored
/// A cache of signature statuses
Expand Down Expand Up @@ -411,7 +439,7 @@ impl HashAgeKind {
// Bank's common fields shared by all supported snapshot versions for deserialization.
// Sync fields with BankFieldsToSerialize! This is paired with it.
// All members are made public to remain Bank's members private and to make versioned deserializer workable on this
#[derive(Clone, Default)]
#[derive(Clone, Debug, Default)]
pub(crate) struct BankFieldsToDeserialize {
pub(crate) blockhash_queue: BlockhashQueue,
pub(crate) ancestors: Ancestors,
Expand Down Expand Up @@ -558,7 +586,7 @@ pub struct RewardInfo {
/// Manager for the state of all accounts and programs after processing its entries.
/// AbiExample is needed even without Serialize/Deserialize; actual (de-)serialization
/// are implemented elsewhere for versioning
#[derive(AbiExample, Default)]
#[derive(AbiExample, Debug, Default)]
pub struct Bank {
/// References to accounts, parent and signature status
pub rc: BankRc,
Expand Down Expand Up @@ -9319,6 +9347,7 @@ mod tests {
}
}

#[derive(Debug)]
struct TestExecutor {}
impl Executor for TestExecutor {
fn execute(
Expand Down Expand Up @@ -9972,4 +10001,34 @@ mod tests {
))
);
}

#[test]
fn test_debug_bank() {
let (genesis_config, _mint_keypair) = create_genesis_config(50000);
let mut bank = Bank::new(&genesis_config);
bank.finish_init(&genesis_config, None);
let debug = format!("{:#?}", bank);
assert!(!debug.is_empty());
}

#[test]
fn test_debug_entrypoint() {
fn mock_process_instruction(
_program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
_data: &[u8],
) -> std::result::Result<(), InstructionError> {
Ok(())
}
fn mock_ix_processor(
_pubkey: &Pubkey,
_ka: &[KeyedAccount],
_data: &[u8],
_context: &mut dyn InvokeContext,
) -> std::result::Result<(), InstructionError> {
Ok(())
}
assert!(!format!("{:?}", Entrypoint::Program(mock_process_instruction)).is_empty());
assert!(!format!("{:?}", Entrypoint::Loader(mock_ix_processor)).is_empty());
}
}
2 changes: 1 addition & 1 deletion runtime/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ lazy_static! {
}

/// `FeatureSet` holds the set of currently active/inactive runtime features
#[derive(AbiExample, Clone)]
#[derive(AbiExample, Debug, Clone)]
pub struct FeatureSet {
pub active: HashSet<Pubkey>,
pub inactive: HashSet<Pubkey>,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ mod tests {
_ka: &[KeyedAccount],
_data: &[u8],
_context: &mut dyn InvokeContext,
) -> std::result::Result<(), InstructionError> {
) -> Result<(), InstructionError> {
Ok(())
}
let program_id = Pubkey::new_rand();
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/process_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use solana_sdk::{
message::Message,
pubkey::Pubkey,
};
use std::{cell::RefCell, rc::Rc, sync::Arc};
use std::{cell::RefCell, fmt::Debug, rc::Rc, sync::Arc};

// Prototype of a native loader entry point
///
Expand Down Expand Up @@ -174,7 +174,7 @@ pub trait Logger {
}

/// Program executor
pub trait Executor: Send + Sync {
pub trait Executor: Debug + Send + Sync {
/// Execute the program
fn execute(
&self,
Expand Down