Skip to content

Commit f9f0646

Browse files
switch to cpiaccountsSmall
1 parent 31da74b commit f9f0646

File tree

17 files changed

+157
-129
lines changed

17 files changed

+157
-129
lines changed

sdk-libs/light-compressible-client/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl CompressibleInstruction {
203203
// Create system accounts internally (same pattern as decompress_accounts_idempotent)
204204
let mut remaining_accounts = PackedAccounts::default();
205205
let system_config = SystemAccountMetaConfig::new(*program_id);
206-
let _ = remaining_accounts.add_system_accounts(system_config);
206+
let _ = remaining_accounts.add_system_accounts_small(system_config);
207207

208208
// Pack tree infos into remaining accounts
209209
let packed_tree_infos =
@@ -301,7 +301,7 @@ impl CompressibleInstruction {
301301
// Setup remaining accounts to get tree infos
302302
let mut remaining_accounts = PackedAccounts::default();
303303
let system_config = SystemAccountMetaConfig::new(*program_id);
304-
let _ = remaining_accounts.add_system_accounts(system_config);
304+
let _ = remaining_accounts.add_system_accounts_small(system_config);
305305

306306
for pda in solana_accounts {
307307
remaining_accounts.add_pre_accounts_meta(AccountMeta::new(*pda, false));
@@ -381,6 +381,8 @@ impl CompressibleInstruction {
381381
data.extend_from_slice(discriminator);
382382
data.extend_from_slice(&serialized_data);
383383

384+
println!("client: all accounts len: {:?}", accounts.len());
385+
println!("client: all accounts: {:?}", accounts);
384386
Ok(Instruction {
385387
program_id: *program_id,
386388
accounts,

sdk-libs/macros/src/compressible.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@ pub(crate) fn add_compressible_instructions(
291291
return err!(ErrorCode::InvalidAccountCount);
292292
}
293293

294-
let cpi_accounts = light_sdk::cpi::CpiAccounts::new(
295-
&ctx.accounts.fee_payer,
296-
&ctx.remaining_accounts[system_accounts_offset as usize..],
297-
LIGHT_CPI_SIGNER,
298-
);
294+
let cpi_accounts = light_sdk::cpi::CpiAccountsSmall::new(
295+
&ctx.accounts.fee_payer,
296+
&ctx.remaining_accounts[system_accounts_offset as usize..],
297+
LIGHT_CPI_SIGNER,
298+
);
299299

300300
// Get address space from config checked.
301301
let config = light_sdk::compressible::CompressibleConfig::load_checked(&ctx.accounts.config, &super::ID)?;
@@ -346,7 +346,7 @@ pub(crate) fn add_compressible_instructions(
346346
msg!("No compressed accounts to decompress");
347347
} else {
348348
let cpi_inputs = light_sdk::cpi::CpiInputs::new(proof, all_compressed_infos);
349-
cpi_inputs.invoke_light_system_program(cpi_accounts)?;
349+
cpi_inputs.invoke_light_system_program_small(cpi_accounts)?;
350350
}
351351

352352
Ok(())
@@ -433,7 +433,7 @@ pub(crate) fn add_compressible_instructions(
433433
return err!(ErrorCode::InvalidRentRecipient);
434434
}
435435

436-
let cpi_accounts = light_sdk::cpi::CpiAccounts::new(
436+
let cpi_accounts = light_sdk::cpi::CpiAccountsSmall::new(
437437
&ctx.accounts.user,
438438
&ctx.remaining_accounts[..],
439439
LIGHT_CPI_SIGNER,

sdk-libs/sdk-types/src/instruction/tree_info.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use light_account_checks::AccountInfoTrait;
22
use light_compressed_account::instruction_data::data::NewAddressParamsPacked;
33

4-
use crate::{AnchorDeserialize, AnchorSerialize, CpiAccounts};
4+
use crate::{AnchorDeserialize, AnchorSerialize, CpiAccounts, CpiAccountsSmall};
55

66
#[derive(Debug, Clone, Copy, AnchorDeserialize, AnchorSerialize, PartialEq, Default)]
77
pub struct PackedStateTreeInfo {
@@ -37,4 +37,13 @@ impl PackedAddressTreeInfo {
3737
cpi_accounts.get_tree_account_info(self.address_merkle_tree_pubkey_index as usize)?;
3838
Ok(account.pubkey())
3939
}
40+
41+
pub fn get_tree_pubkey_small<T: AccountInfoTrait + Clone>(
42+
&self,
43+
cpi_accounts: &CpiAccountsSmall<'_, T>,
44+
) -> Result<T::Pubkey, crate::error::LightSdkTypesError> {
45+
let account =
46+
cpi_accounts.get_tree_account_info(self.address_merkle_tree_pubkey_index as usize)?;
47+
Ok(account.pubkey())
48+
}
4049
}

sdk-libs/sdk/src/compressible/compress_account.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::compressible::compression_info::CompressAs;
1212
use crate::{
1313
account::sha::LightAccount,
1414
compressible::{compress_account_on_init::close, compression_info::HasCompressionInfo},
15-
cpi::{CpiAccounts, CpiInputs},
15+
cpi::{CpiAccountsSmall, CpiInputs},
1616
error::LightSdkError,
1717
instruction::{account_meta::CompressedAccountMeta, ValidityProof},
1818
AnchorDeserialize, AnchorSerialize, LightDiscriminator,
@@ -47,7 +47,7 @@ pub fn compress_account<'info, A>(
4747
solana_account: &mut Account<'info, A>,
4848
compressed_account_meta: &CompressedAccountMeta,
4949
proof: ValidityProof,
50-
cpi_accounts: CpiAccounts<'_, 'info>,
50+
cpi_accounts: CpiAccountsSmall<'_, 'info>,
5151
rent_recipient: &AccountInfo<'info>,
5252
compression_delay: &u32,
5353
) -> Result<(), crate::ProgramError>
@@ -101,7 +101,7 @@ where
101101
let cpi_inputs = CpiInputs::new(proof, vec![compressed_account.to_account_info()?]);
102102

103103
// Invoke light system program to create the compressed account
104-
cpi_inputs.invoke_light_system_program(cpi_accounts)?;
104+
cpi_inputs.invoke_light_system_program_small(cpi_accounts)?;
105105

106106
// Close the PDA account using Anchor's close method
107107
solana_account.close(rent_recipient.clone())?;
@@ -136,7 +136,7 @@ pub fn compress_pda_native<'info, A>(
136136
pda_account_data: &mut A,
137137
compressed_account_meta: &CompressedAccountMeta,
138138
proof: ValidityProof,
139-
cpi_accounts: CpiAccounts<'_, 'info>,
139+
cpi_accounts: CpiAccountsSmall<'_, 'info>,
140140
rent_recipient: &AccountInfo<'info>,
141141
compression_delay: &u32,
142142
) -> Result<(), crate::ProgramError>
@@ -176,7 +176,7 @@ where
176176
let cpi_inputs = CpiInputs::new(proof, vec![compressed_account.to_account_info()?]);
177177

178178
// Invoke light system program to create the compressed account
179-
cpi_inputs.invoke_light_system_program(cpi_accounts)?;
179+
cpi_inputs.invoke_light_system_program_small(cpi_accounts)?;
180180
// Close PDA account manually
181181
close(pda_account_info, rent_recipient.clone())?;
182182
Ok(())

sdk-libs/sdk/src/compressible/compress_account_on_init.rs

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
account::sha::LightAccount,
1313
address::PackedNewAddressParams,
1414
compressible::HasCompressionInfo,
15-
cpi::{CpiAccounts, CpiInputs},
15+
cpi::{CpiAccountsSmall, CpiInputs},
1616
error::{LightSdkError, Result},
1717
instruction::ValidityProof,
1818
light_account_checks::AccountInfoTrait,
@@ -31,7 +31,7 @@ pub fn compress_account_on_init<'info, A>(
3131
address: &[u8; 32],
3232
new_address_param: &PackedNewAddressParams,
3333
output_state_tree_index: u8,
34-
cpi_accounts: CpiAccounts<'_, 'info>,
34+
cpi_accounts: CpiAccountsSmall<'_, 'info>,
3535
address_space: &[Pubkey],
3636
rent_recipient: &AccountInfo<'info>,
3737
proof: ValidityProof,
@@ -62,9 +62,18 @@ where
6262
rent_recipient,
6363
)?;
6464

65-
let cpi_inputs = CpiInputs::new_with_address(proof, compressed_infos, vec![*new_address_param]);
65+
let cpi_inputs = CpiInputs::new_with_assigned_address(
66+
proof,
67+
compressed_infos,
68+
vec![
69+
light_compressed_account::instruction_data::data::NewAddressParamsAssignedPacked::new(
70+
*new_address_param,
71+
None,
72+
),
73+
],
74+
);
6675

67-
cpi_inputs.invoke_light_system_program(cpi_accounts)?;
76+
cpi_inputs.invoke_light_system_program_small(cpi_accounts)?;
6877

6978
Ok(())
7079
}
@@ -97,7 +106,7 @@ pub fn prepare_accounts_for_compression_on_init<'info, A>(
97106
addresses: &[[u8; 32]],
98107
new_address_params: &[PackedNewAddressParams],
99108
output_state_tree_indices: &[u8],
100-
cpi_accounts: &CpiAccounts<'_, 'info>,
109+
cpi_accounts: &CpiAccountsSmall<'_, 'info>,
101110
address_space: &[Pubkey],
102111
rent_recipient: &AccountInfo<'info>,
103112
) -> Result<Vec<light_compressed_account::instruction_data::with_account_info::CompressedAccountInfo>>
@@ -203,7 +212,7 @@ pub fn compress_empty_account_on_init<'info, A>(
203212
address: &[u8; 32],
204213
new_address_param: &PackedNewAddressParams,
205214
output_state_tree_index: u8,
206-
cpi_accounts: CpiAccounts<'_, 'info>,
215+
cpi_accounts: CpiAccountsSmall<'_, 'info>,
207216
address_space: &[Pubkey],
208217
proof: ValidityProof,
209218
) -> Result<()>
@@ -232,9 +241,18 @@ where
232241
address_space,
233242
)?;
234243

235-
let cpi_inputs = CpiInputs::new_with_address(proof, compressed_infos, vec![*new_address_param]);
244+
let cpi_inputs = CpiInputs::new_with_assigned_address(
245+
proof,
246+
compressed_infos,
247+
vec![
248+
light_compressed_account::instruction_data::data::NewAddressParamsAssignedPacked::new(
249+
*new_address_param,
250+
None,
251+
),
252+
],
253+
);
236254

237-
cpi_inputs.invoke_light_system_program(cpi_accounts)?;
255+
cpi_inputs.invoke_light_system_program_small(cpi_accounts)?;
238256

239257
Ok(())
240258
}
@@ -268,7 +286,7 @@ pub fn prepare_empty_compressed_accounts_on_init<'info, A>(
268286
addresses: &[[u8; 32]],
269287
new_address_params: &[PackedNewAddressParams],
270288
output_state_tree_indices: &[u8],
271-
cpi_accounts: &CpiAccounts<'_, 'info>,
289+
cpi_accounts: &CpiAccountsSmall<'_, 'info>,
272290
address_space: &[Pubkey],
273291
) -> Result<Vec<light_compressed_account::instruction_data::with_account_info::CompressedAccountInfo>>
274292
where
@@ -395,7 +413,7 @@ pub fn compress_account_on_init_native<'info, A>(
395413
address: &[u8; 32],
396414
new_address_param: &PackedNewAddressParams,
397415
output_state_tree_index: u8,
398-
cpi_accounts: CpiAccounts<'_, 'info>,
416+
cpi_accounts: CpiAccountsSmall<'_, 'info>,
399417
address_space: &[Pubkey],
400418
rent_recipient: &AccountInfo<'info>,
401419
proof: ValidityProof,
@@ -427,9 +445,18 @@ where
427445
rent_recipient,
428446
)?;
429447

430-
let cpi_inputs = CpiInputs::new_with_address(proof, compressed_infos, vec![*new_address_param]);
448+
let cpi_inputs = CpiInputs::new_with_assigned_address(
449+
proof,
450+
compressed_infos,
451+
vec![
452+
light_compressed_account::instruction_data::data::NewAddressParamsAssignedPacked::new(
453+
*new_address_param,
454+
None,
455+
),
456+
],
457+
);
431458

432-
cpi_inputs.invoke_light_system_program(cpi_accounts)?;
459+
cpi_inputs.invoke_light_system_program_small(cpi_accounts)?;
433460

434461
Ok(())
435462
}
@@ -466,7 +493,7 @@ pub fn prepare_accounts_for_compression_on_init_native<'info, A>(
466493
addresses: &[[u8; 32]],
467494
new_address_params: &[PackedNewAddressParams],
468495
output_state_tree_indices: &[u8],
469-
cpi_accounts: &CpiAccounts<'_, 'info>,
496+
cpi_accounts: &CpiAccountsSmall<'_, 'info>,
470497
address_space: &[Pubkey],
471498
rent_recipient: &AccountInfo<'info>,
472499
) -> Result<Vec<light_compressed_account::instruction_data::with_account_info::CompressedAccountInfo>>
@@ -581,7 +608,7 @@ pub fn compress_empty_account_on_init_native<'info, A>(
581608
address: &[u8; 32],
582609
new_address_param: &PackedNewAddressParams,
583610
output_state_tree_index: u8,
584-
cpi_accounts: CpiAccounts<'_, 'info>,
611+
cpi_accounts: CpiAccountsSmall<'_, 'info>,
585612
address_space: &[Pubkey],
586613
proof: ValidityProof,
587614
) -> Result<()>
@@ -609,9 +636,18 @@ where
609636
address_space,
610637
)?;
611638

612-
let cpi_inputs = CpiInputs::new_with_address(proof, compressed_infos, vec![*new_address_param]);
639+
let cpi_inputs = CpiInputs::new_with_assigned_address(
640+
proof,
641+
compressed_infos,
642+
vec![
643+
light_compressed_account::instruction_data::data::NewAddressParamsAssignedPacked::new(
644+
*new_address_param,
645+
None,
646+
),
647+
],
648+
);
613649

614-
cpi_inputs.invoke_light_system_program(cpi_accounts)?;
650+
cpi_inputs.invoke_light_system_program_small(cpi_accounts)?;
615651

616652
Ok(())
617653
}
@@ -640,7 +676,7 @@ pub fn prepare_empty_compressed_accounts_on_init_native<'info, A>(
640676
addresses: &[[u8; 32]],
641677
new_address_params: &[PackedNewAddressParams],
642678
output_state_tree_indices: &[u8],
643-
cpi_accounts: &CpiAccounts<'_, 'info>,
679+
cpi_accounts: &CpiAccountsSmall<'_, 'info>,
644680
address_space: &[Pubkey],
645681
) -> Result<Vec<light_compressed_account::instruction_data::with_account_info::CompressedAccountInfo>>
646682
where

sdk-libs/sdk/src/compressible/decompress_idempotent.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use solana_sysvar::Sysvar;
1212

1313
use crate::{
1414
account::sha::LightAccount, compressible::compression_info::HasCompressionInfo,
15-
cpi::CpiAccounts, error::LightSdkError, AnchorDeserialize, AnchorSerialize, LightDiscriminator,
15+
cpi::CpiAccountsSmall, error::LightSdkError, AnchorDeserialize, AnchorSerialize,
16+
LightDiscriminator,
1617
};
1718

1819
/// Helper function to decompress multiple compressed accounts into PDAs
@@ -39,7 +40,7 @@ pub fn prepare_accounts_for_decompress_idempotent<'info, T>(
3940
solana_accounts: &[&AccountInfo<'info>],
4041
compressed_accounts: Vec<LightAccount<'_, T>>,
4142
solana_accounts_signer_seeds: &[&[&[u8]]],
42-
cpi_accounts: &CpiAccounts<'_, 'info>,
43+
cpi_accounts: &CpiAccountsSmall<'_, 'info>,
4344
rent_payer: &AccountInfo<'info>,
4445
address_space: Pubkey,
4546
) -> Result<Vec<CompressedAccountInfo>, LightSdkError>

sdk-libs/sdk/src/cpi/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
//! pub const LIGHT_CPI_SIGNER: CpiSigner =
99
//! derive_light_cpi_signer!("2tzfijPBGbrR5PboyFUFKzfEoLTwdDSHUjANCw929wyt");
1010
//!
11-
//! let light_cpi_accounts = CpiAccounts::new(
11+
//! let light_cpi_accounts = CpiAccountsSmall::new(
1212
//! ctx.accounts.fee_payer.as_ref(),
1313
//! ctx.remaining_accounts,
1414
//! crate::LIGHT_CPI_SIGNER,
15-
//! )
16-
//! .map_err(ProgramError::from)?;
15+
//! );
1716
//!
1817
//! let (address, address_seed) = derive_address(
1918
//! &[b"compressed", name.as_bytes()],
@@ -43,8 +42,7 @@
4342
//! );
4443
//!
4544
//! cpi_inputs
46-
//! .invoke_light_system_program(light_cpi_accounts)
47-
//! .map_err(ProgramError::from)?;
45+
//! .invoke_light_system_program_small(light_cpi_accounts)?;
4846
//! ```
4947
5048
mod accounts;

sdk-tests/anchor-compressible-derived/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use light_sdk::{
1111
compress_account_on_init, prepare_accounts_for_compression_on_init, CompressibleConfig,
1212
HasCompressionInfo,
1313
},
14-
cpi::{CpiAccounts, CpiInputs},
14+
cpi::{CpiAccountsSmall, CpiInputs},
1515
derive_light_cpi_signer,
1616
instruction::{PackedAddressTreeInfo, ValidityProof},
1717
};
@@ -53,8 +53,9 @@ pub mod anchor_compressible_derived {
5353
}
5454

5555
// 3. Create CPI accounts
56+
let user_account_info = ctx.accounts.user.to_account_info();
5657
let cpi_accounts =
57-
CpiAccounts::new(&ctx.accounts.user, ctx.remaining_accounts, LIGHT_CPI_SIGNER);
58+
CpiAccountsSmall::new(&user_account_info, ctx.remaining_accounts, LIGHT_CPI_SIGNER);
5859

5960
let new_address_params =
6061
address_tree_info.into_new_address_params_packed(user_record.key().to_bytes());
@@ -114,8 +115,9 @@ pub mod anchor_compressible_derived {
114115
game_session.score = 0;
115116

116117
// Create CPI accounts.
118+
let user_account_info = ctx.accounts.user.to_account_info();
117119
let cpi_accounts =
118-
CpiAccounts::new(&ctx.accounts.user, ctx.remaining_accounts, LIGHT_CPI_SIGNER);
120+
CpiAccountsSmall::new(&user_account_info, ctx.remaining_accounts, LIGHT_CPI_SIGNER);
119121

120122
// Prepare new address params. One per pda account.
121123
let user_new_address_params = compression_params
@@ -170,7 +172,7 @@ pub mod anchor_compressible_derived {
170172

171173
// Invoke light system program to create all compressed accounts in one
172174
// CPI. Call at the end of your init instruction.
173-
cpi_inputs.invoke_light_system_program(cpi_accounts)?;
175+
cpi_inputs.invoke_light_system_program_small(cpi_accounts)?;
174176

175177
Ok(())
176178
}

0 commit comments

Comments
 (0)