Skip to content

Commit d3d3c95

Browse files
committed
documentation and typo fixes
1 parent 57a94b0 commit d3d3c95

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,48 @@ pub fn process_instruction(
172172
> ⚠️ **Note:**
173173
> The `no_allocator!` macro can also be used in combination with the `lazy_program_entrypoint!`.
174174
175+
📌 [`middleware_program_entrypoint!`](https://docs.rs/pinocchio/latest/pinocchio/macro.middleware_program_entrypoint.html)
176+
177+
The `middleware_program_entrypoint!` macro defines a dual entrypoint implementation consisting of a `hot` path which bypasses entrypoint deserialization, and a `cold` path with behaves like a regular pinocchio entrypoint that has undergone `program_entrypoint!` deserialization. This gives the user flexibility to implement extreme CU optimizations against the most critical paths in their proggram with the convenience of being able to fallback to a regular pinocchio program to manage the fail case and other instructions that do not require such optimizations.
178+
179+
To use the `middleware_program_entrypoint!` macro, use the following in your entrypoint definition:
180+
181+
```rust
182+
#![cfg_attr(target_os = "solana", no_std)]
183+
use pinocchio::{
184+
ProgramResult,
185+
account_info::AccountInfo,
186+
middleware_program_entrypoint,
187+
msg,
188+
no_allocator,
189+
nostd_panic_handler,
190+
pubkey::Pubkey
191+
};
192+
193+
nostd_panic_handler!();
194+
no_allocator!();
195+
196+
middleware_program_entrypoint!(hot,cold);
197+
198+
// This uses 4 CUs
199+
#[inline(always)]
200+
pub fn hot(input: *mut u8) -> u64 {
201+
unsafe { *input as u64 }
202+
}
203+
204+
// This uses 113 CUs
205+
#[cold]
206+
#[inline(always)]
207+
pub fn cold(
208+
_program_id: &Pubkey,
209+
_accounts: &[AccountInfo],
210+
_instruction_data: &[u8],
211+
) -> ProgramResult {
212+
msg!("Hello from Pinocchio!");
213+
Ok(())
214+
}
215+
```
216+
175217
## Crate feature: `std`
176218

177219
By default, `pinocchio` is a `no_std` crate. This means that it does not use any code from the standard (`std`) library. While this does not affect how `pinocchio` is used, there is one particular apparent difference. In a `no_std` environment, the `msg!` macro does not provide any formatting options since the `format!` macro requires the `std` library. In order to use `msg!` with formatting, the `std` feature should be enabled when adding `pinocchio` as a dependency:

sdk/pinocchio/src/entrypoint/middleware.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
/// Declare the middleware program entrypoint.
55
///
6-
/// The macro expect a `hot` and `cold` path expressions. The `hot` is a function with
6+
/// The macro expects a `hot` and `cold` path expressions. The `hot` is a function with
77
/// the following type signature:
88
///
99
/// ```ignore
@@ -29,7 +29,7 @@
2929
/// use pinocchio::{
3030
/// ProgramResult,
3131
/// account_info::AccountInfo,
32-
/// middleware_entrypoint,
32+
/// middleware_program_entrypoint,
3333
/// msg,
3434
/// no_allocator,
3535
/// nostd_panic_handler,
@@ -39,7 +39,7 @@
3939
/// nostd_panic_handler!();
4040
/// no_allocator!();
4141
///
42-
/// middleware_entrypoint!(hot,cold);
42+
/// middleware_program_entrypoint!(hot,cold);
4343
///
4444
/// // This uses 4 CUs
4545
/// #[inline(always)]
@@ -55,14 +55,14 @@
5555
/// _accounts: &[AccountInfo],
5656
/// _instruction_data: &[u8],
5757
/// ) -> ProgramResult {
58-
/// msg!("Hello from my Pinocchio!");
58+
/// msg!("Hello from Pinocchio!");
5959
/// Ok(())
6060
/// }
6161
/// ```
6262
#[macro_export]
6363
macro_rules! middleware_program_entrypoint {
6464
($hot:expr, $cold:expr) => {
65-
$crate::middleware_entrypoint!($hot, $cold, { $crate::MAX_TX_ACCOUNTS });
65+
$crate::middleware_program_entrypoint!($hot, $cold, { $crate::MAX_TX_ACCOUNTS });
6666
};
6767
($hot:expr, $cold:expr, $maximum:expr ) => {
6868

0 commit comments

Comments
 (0)