Skip to content

Commit ce75369

Browse files
committed
small fixes
1 parent 8b366be commit ce75369

File tree

23 files changed

+121
-145
lines changed

23 files changed

+121
-145
lines changed

program-libs/compressed-account/src/instruction_data/traits.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::{compressed_account::CompressedAccountData, pubkey::Pubkey, Compresse
1212
pub trait InstructionData<'a> {
1313
fn owner(&self) -> Pubkey;
1414
fn new_addresses(&self) -> &[impl NewAddress<'a>];
15-
fn new_address_owner(&self) -> Vec<Option<Pubkey>>;
1615
fn input_accounts(&self) -> &[impl InputAccount<'a>];
1716
fn output_accounts(&self) -> &[impl OutputAccount<'a>];
1817
fn read_only_accounts(&self) -> Option<&[ZPackedReadOnlyCompressedAccount]>;
@@ -35,6 +34,9 @@ where
3534
fn address_merkle_tree_account_index(&self) -> u8;
3635
fn address_merkle_tree_root_index(&self) -> u16;
3736
fn assigned_compressed_account_index(&self) -> Option<usize>;
37+
fn owner(&self) -> Option<&[u8; 32]> {
38+
None
39+
}
3840
}
3941

4042
pub trait InputAccount<'a>

program-libs/compressed-account/src/instruction_data/with_account_info.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,6 @@ impl<'a> InstructionData<'a> for ZInstructionDataInvokeCpiWithAccountInfo<'a> {
347347
self.new_address_params.as_slice()
348348
}
349349

350-
fn new_address_owner(&self) -> Vec<Option<Pubkey>> {
351-
vec![Some(self.invoking_program_id); self.new_address_params.len()]
352-
}
353-
354350
fn proof(&self) -> Option<Ref<&'a [u8], CompressedProof>> {
355351
self.proof
356352
}

program-libs/compressed-account/src/instruction_data/with_readonly.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,6 @@ impl<'a> InstructionData<'a> for ZInstructionDataInvokeCpiWithReadOnly<'a> {
305305
self.new_address_params.as_slice()
306306
}
307307

308-
fn new_address_owner(&self) -> Vec<Option<Pubkey>> {
309-
// Return one owner per address
310-
(0..self.new_address_params.len())
311-
.map(|_| Some(self.invoking_program_id))
312-
.collect()
313-
}
314308
fn proof(&self) -> Option<Ref<&'a [u8], CompressedProof>> {
315309
self.proof
316310
}

program-libs/compressed-account/src/instruction_data/zero_copy.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,6 @@ impl<'a> InstructionData<'a> for ZInstructionDataInvoke<'a> {
475475
self.new_address_params.as_slice()
476476
}
477477

478-
fn new_address_owner(&self) -> Vec<Option<Pubkey>> {
479-
vec![None; self.new_address_params.len()]
480-
}
481-
482478
fn input_accounts(&self) -> &[impl InputAccount<'a>] {
483479
self.input_compressed_accounts_with_merkle_context
484480
.as_slice()
@@ -608,10 +604,6 @@ impl<'a> InstructionData<'a> for ZInstructionDataInvokeCpi<'a> {
608604
self.new_address_params.as_slice()
609605
}
610606

611-
fn new_address_owner(&self) -> Vec<Option<Pubkey>> {
612-
vec![None; self.new_address_params.len()]
613-
}
614-
615607
fn output_accounts(&self) -> &[impl OutputAccount<'a>] {
616608
self.output_compressed_accounts.as_slice()
617609
}

program-libs/compressed-account/src/instruction_data/zero_copy_set.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ impl ZInstructionDataInvokeCpiWithReadOnlyMut<'_> {
144144
if self.proof.is_none() && input_proof.is_some() {
145145
return Err(CompressedAccountError::ZeroCopyExpectedProof);
146146
}
147+
// self.cpi_context is constant, always allocated
148+
// -> no reverse ok_or check necessary
147149
if let Some(cpi_context) = cpi_context {
148150
self.with_cpi_context = 1;
149151
self.cpi_context.cpi_context_account_index = 0;

program-tests/system-test/tests/test_re_init_cpi_account.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use light_program_test::{
88
ProgramTestConfig,
99
};
1010
use light_sdk::constants::{
11-
CPI_CONTEXT_ACCOUNT_2_DISCRIMINATOR, CPI_CONTEXT_ACCOUNT_DISCRIMINATOR,
11+
CPI_CONTEXT_ACCOUNT_1_DISCRIMINATOR, CPI_CONTEXT_ACCOUNT_2_DISCRIMINATOR,
1212
};
1313
use light_system_program_pinocchio::cpi_context::state::deserialize_cpi_context_account;
1414
use light_test_utils::{legacy_cpi_context_account::get_legacy_cpi_context_account, Rpc};
@@ -63,7 +63,7 @@ async fn test_re_init_cpi_account() {
6363
.unwrap();
6464
assert_eq!(
6565
&pre_account.data[0..8],
66-
&CPI_CONTEXT_ACCOUNT_2_DISCRIMINATOR,
66+
&CPI_CONTEXT_ACCOUNT_1_DISCRIMINATOR,
6767
"Account should have legacy discriminator"
6868
);
6969
assert_eq!(
@@ -89,7 +89,7 @@ async fn test_re_init_cpi_account() {
8989
.unwrap();
9090
assert_eq!(
9191
&post_account.data[0..8],
92-
&CPI_CONTEXT_ACCOUNT_DISCRIMINATOR,
92+
&CPI_CONTEXT_ACCOUNT_2_DISCRIMINATOR,
9393
"Account should have new discriminator after reinit"
9494
);
9595

programs/compressed-token/src/process_transfer.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,17 @@ pub fn cpi_execute_compressed_transaction_transfer<
502502
is_signer: false,
503503
is_writable: false,
504504
});
505-
let mut remaining_accounts_index = 4;
505+
account_metas.push(AccountMeta {
506+
pubkey: account_infos[4].key(),
507+
is_signer: false,
508+
is_writable: false,
509+
});
510+
account_metas.push(AccountMeta {
511+
pubkey: account_infos[5].key(),
512+
is_signer: false,
513+
is_writable: false,
514+
});
515+
let mut remaining_accounts_index = 6;
506516

507517
if let Some(account_info) = cpi_context_account {
508518
account_infos.push(account_info);

programs/system/src/accounts/init_context_account.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn init_cpi_context_account(accounts: &[AccountInfo]) -> Result<()> {
6060
let ctx = InitializeCpiContextAccount::from_account_infos(accounts)?;
6161
let params: CpiContextAccountInitParams =
6262
CpiContextAccountInitParams::new(*ctx.associated_merkle_tree.key());
63-
cpi_context_account_new::<false>(ctx.cpi_context_account, params).map(|_| ())?;
63+
cpi_context_account_new::<false>(ctx.cpi_context_account, params)?;
6464

6565
Ok(())
6666
}
@@ -79,7 +79,7 @@ pub fn reinit_cpi_context_account(accounts: &[AccountInfo]) -> Result<()> {
7979
};
8080
let params: CpiContextAccountInitParams =
8181
CpiContextAccountInitParams::new(associated_merkle_tree);
82-
cpi_context_account_new::<true>(cpi_context_account, params).map(|_| ())?;
82+
cpi_context_account_new::<true>(cpi_context_account, params)?;
8383

8484
Ok(())
8585
}

programs/system/src/constants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub const INVOKE_INSTRUCTION: [u8; 8] = [26, 16, 169, 7, 21, 202, 242, 25];
1111
pub const INVOKE_CPI_INSTRUCTION: [u8; 8] = [49, 212, 191, 129, 39, 194, 43, 196];
1212
pub const INVOKE_CPI_WITH_READ_ONLY_INSTRUCTION: [u8; 8] = [86, 47, 163, 166, 21, 223, 92, 8];
1313
// discriminator of CpiContextAccount2
14-
pub const CPI_CONTEXT_ACCOUNT_DISCRIMINATOR: [u8; 8] = [34, 184, 183, 14, 100, 80, 183, 124];
15-
pub const CPI_CONTEXT_ACCOUNT_2_DISCRIMINATOR: [u8; 8] = [22, 20, 149, 218, 74, 204, 128, 166];
14+
pub const CPI_CONTEXT_ACCOUNT_2_DISCRIMINATOR: [u8; 8] = [34, 184, 183, 14, 100, 80, 183, 124];
15+
pub const CPI_CONTEXT_ACCOUNT_1_DISCRIMINATOR: [u8; 8] = [22, 20, 149, 218, 74, 204, 128, 166];
1616
pub const INVOKE_CPI_WITH_ACCOUNT_INFO_INSTRUCTION: [u8; 8] = [228, 34, 128, 84, 47, 139, 86, 240];
1717
pub const RE_INIT_CPI_CONTEXT_ACCOUNT_INSTRUCTION: [u8; 8] =
1818
[187, 147, 22, 142, 104, 180, 136, 190];

programs/system/src/context.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use light_compressed_account::{
88
};
99
use light_program_profiler::profile;
1010
use pinocchio::{account_info::AccountInfo, instruction::AccountMeta, pubkey::Pubkey};
11+
use solana_msg::msg;
1112

1213
use crate::{
1314
cpi_context::state::ZCpiContextAccount2, errors::SystemProgramError,
@@ -87,23 +88,30 @@ impl<'info> SystemContext<'info> {
8788
&mut self,
8889
ix_data_index: u8,
8990
remaining_accounts: &'info [AccountInfo],
90-
) -> u8 {
91+
name: &str,
92+
) -> std::result::Result<u8, SystemProgramError> {
9193
let queue_index = self
9294
.account_indices
9395
.iter()
9496
.position(|a| *a == ix_data_index);
9597
match queue_index {
96-
Some(index) => index as u8,
98+
Some(index) => Ok(index as u8),
9799
None => {
98100
self.account_indices.push(ix_data_index);
99-
let account_info = &remaining_accounts[ix_data_index as usize];
101+
let account_info =
102+
&remaining_accounts
103+
.get(ix_data_index as usize)
104+
.ok_or_else(|| {
105+
msg!("Index: {}, account name: {}", ix_data_index, name);
106+
SystemProgramError::PackedAccountIndexOutOfBounds
107+
})?;
100108
self.accounts.push(AccountMeta {
101109
pubkey: account_info.key(),
102110
is_signer: false,
103111
is_writable: true,
104112
});
105113
self.account_infos.push(account_info);
106-
self.account_indices.len() as u8 - 1
114+
Ok(self.account_indices.len() as u8 - 1)
107115
}
108116
}
109117
}
@@ -308,18 +316,6 @@ impl<'a, T: InstructionData<'a>> WrappedInstructionData<'a, T> {
308316
}
309317
}
310318

311-
pub fn new_addresses_owners(&self) -> Vec<Option<light_compressed_account::Pubkey>> {
312-
if let Some(cpi_context) = &self.cpi_context {
313-
[
314-
cpi_context.new_address_owner(),
315-
self.instruction_data.new_address_owner(),
316-
]
317-
.concat()
318-
} else {
319-
self.instruction_data.new_address_owner()
320-
}
321-
}
322-
323319
pub fn output_accounts<'b>(&'b self) -> impl Iterator<Item = &'b dyn OutputAccount<'a>> {
324320
if let Some(cpi_context) = &self.cpi_context {
325321
chain_outputs(

0 commit comments

Comments
 (0)