Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 35 additions & 0 deletions sdk/pinocchio/src/entrypoint/middleware.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Defines the middleware entrypoint, enabling a hot path to bypass
//! entrypoint deserialization, ejecting to the cold path on failure.
#[macro_export]
macro_rules! middleware_entrypoint {
($hot:expr, $cold:expr) => {
$crate::middleware_entrypoint!($hot, $cold, { $crate::MAX_TX_ACCOUNTS });
};
($hot:expr, $cold:expr, $maximum:expr ) => {

#[no_mangle]
pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
if $hot(input) == 0 {
return $crate::SUCCESS
}

const UNINIT: core::mem::MaybeUninit<$crate::account_info::AccountInfo> = core::mem::MaybeUninit::<$crate::account_info::AccountInfo>::uninit();
// Create an array of uninitialized account infos.
let mut accounts = [UNINIT; $maximum];

let (program_id, count, instruction_data) = unsafe {
$crate::entrypoint::deserialize::<$maximum>(input, &mut accounts) };

// Call the program's entrypoint passing `count` account infos; we know that
// they are initialized so we cast the pointer to a slice of `[AccountInfo]`.
match $cold(
&program_id,
unsafe { core::slice::from_raw_parts(accounts.as_ptr() as _, count) },
&instruction_data,
) {
Ok(()) => $crate::SUCCESS,
Err(error) => error.into(),
}
}
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

2 changes: 2 additions & 0 deletions sdk/pinocchio/src/entrypoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub mod lazy;

pub use lazy::{InstructionContext, MaybeAccount};

pub mod middleware;

#[cfg(not(feature = "std"))]
use core::alloc::{GlobalAlloc, Layout};

Expand Down
Loading