Skip to content

Commit

Permalink
Fix constant import
Browse files Browse the repository at this point in the history
  • Loading branch information
febo committed Oct 26, 2024
1 parent b44d79a commit e018eb3
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions sdk/pinocchio/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ pub const SUCCESS: u64 = super::SUCCESS;
#[macro_export]
macro_rules! entrypoint {
( $process_instruction:ident ) => {
entrypoint!($process_instruction, {
$crate::entrypoint::MAX_TX_ACCOUNTS
});
entrypoint!($process_instruction, { $crate::MAX_TX_ACCOUNTS });
};
( $process_instruction:ident, $maximum:expr ) => {
/// Program entrypoint.
Expand Down Expand Up @@ -143,34 +141,37 @@ pub unsafe fn deserialize<'a, const MAX_ACCOUNTS: usize>(
let processed = core::cmp::min(total_accounts, MAX_ACCOUNTS);

for i in 0..processed {
let duplicate = *(input.add(offset) as *const u8);
if duplicate == NON_DUP_MARKER {
let account_info: *mut Account = input.add(offset) as *mut _;
let account_info: *mut Account = input.add(offset) as *mut _;

if (*account_info).borrow_state == NON_DUP_MARKER {
// repurpose the borrow state to track borrows
(*account_info).borrow_state = 0b_0000_0000;

offset += core::mem::size_of::<Account>();
offset += (*account_info).data_len as usize;
offset += MAX_PERMITTED_DATA_INCREASE;
offset += (offset as *const u8).align_offset(BPF_ALIGN_OF_U128);
offset += core::mem::size_of::<u64>();

(*account_info).borrow_state = 0b_0000_0000;

accounts[i].write(AccountInfo { raw: account_info });
} else {
offset += core::mem::size_of::<u64>();
// duplicate account, clone the original pointer
accounts[i].write(accounts[duplicate as usize].assume_init_ref().clone());
accounts[i].write(
accounts[(*account_info).borrow_state as usize]
.assume_init_ref()
.clone(),
);
}
}

// process any remaining accounts to move the offset to the instruction
// data (there is a duplication of logic but we avoid testing whether we
// have space for the account or not)
for _ in processed..total_accounts {
let duplicate_info = *(input.add(offset) as *const u8);
let account_info: *mut Account = input.add(offset) as *mut _;

if duplicate_info == NON_DUP_MARKER {
let account_info: *mut Account = input.add(offset) as *mut _;
if (*account_info).borrow_state == NON_DUP_MARKER {
offset += core::mem::size_of::<Account>();
offset += (*account_info).data_len as usize;
offset += MAX_PERMITTED_DATA_INCREASE;
Expand Down

0 comments on commit e018eb3

Please sign in to comment.