diff --git a/program-tests/create-address-test-program/Cargo.toml b/program-tests/create-address-test-program/Cargo.toml index f25726d3be..42c5f8a00b 100644 --- a/program-tests/create-address-test-program/Cargo.toml +++ b/program-tests/create-address-test-program/Cargo.toml @@ -24,5 +24,5 @@ anchor-lang = { workspace = true } light-system-program-anchor = { workspace = true, features = ["cpi"] } account-compression = { workspace = true, features = ["cpi"] } light-compressed-account = { workspace = true, features = ["anchor"] } -light-sdk = { workspace = true, features = ["anchor", "v2", "small_ix"] } +light-sdk = { workspace = true, features = ["anchor", "v2", "v2_ix"] } light-sdk-types = { workspace = true } diff --git a/program-tests/create-address-test-program/src/lib.rs b/program-tests/create-address-test-program/src/lib.rs index b0ad818d44..0da6b37a5d 100644 --- a/program-tests/create-address-test-program/src/lib.rs +++ b/program-tests/create-address-test-program/src/lib.rs @@ -18,7 +18,7 @@ use light_compressed_account::instruction_data::{ use light_sdk::{ constants::LIGHT_SYSTEM_PROGRAM_ID, cpi::{ - get_account_metas_from_config, invoke_light_system_program, to_account_metas_small, + get_account_metas_from_config, invoke_light_system_program, to_account_metas_v2, CpiAccountsConfig, CpiInstructionConfig, }, }; @@ -58,23 +58,23 @@ pub mod system_cpi_test { pub fn invoke_with_read_only<'info>( ctx: Context<'_, '_, '_, 'info, InvokeCpiReadOnly<'info>>, config: CpiAccountsConfig, - small_ix: bool, + v2_ix: bool, inputs: Vec, ) -> Result<()> { let fee_payer = ctx.accounts.signer.to_account_info(); - let (account_infos, account_metas) = if small_ix { - use light_sdk::cpi::CpiAccountsSmall; + let (account_infos, account_metas) = if v2_ix { + use light_sdk::cpi::CpiAccountsV2; let cpi_accounts = - CpiAccountsSmall::new_with_config(&fee_payer, ctx.remaining_accounts, config); + CpiAccountsV2::new_with_config(&fee_payer, ctx.remaining_accounts, config); let account_infos = cpi_accounts .to_account_infos() .into_iter() .cloned() .collect::>(); - let account_metas = to_account_metas_small(cpi_accounts) - .map_err(|_| ErrorCode::AccountNotEnoughKeys)?; + let account_metas = + to_account_metas_v2(cpi_accounts).map_err(|_| ErrorCode::AccountNotEnoughKeys)?; (account_infos, account_metas) } else { use light_sdk::cpi::CpiAccounts; @@ -218,11 +218,11 @@ pub fn create_invoke_read_only_account_info_instruction( signer: Pubkey, inputs: Vec, config: CpiAccountsConfig, - small: bool, + v2_ix: bool, remaining_accounts: Vec, ) -> Instruction { let ix_data = crate::instruction::InvokeWithReadOnly { - small_ix: small, + v2_ix, inputs, config, } diff --git a/program-tests/system-cpi-v2-test/tests/invoke_cpi_with_read_only.rs b/program-tests/system-cpi-v2-test/tests/invoke_cpi_with_read_only.rs index 1acfd13797..0865b1d8bd 100644 --- a/program-tests/system-cpi-v2-test/tests/invoke_cpi_with_read_only.rs +++ b/program-tests/system-cpi-v2-test/tests/invoke_cpi_with_read_only.rs @@ -48,7 +48,7 @@ use solana_sdk::pubkey::Pubkey; #[tokio::test] async fn functional_read_only() { spawn_prover(ProverConfig::default()).await; - for (batched, is_small_ix) in [(true, false), (true, true), (false, false), (false, true)] { + for (batched, is_v2_ix) in [(true, false), (true, true), (false, false), (false, true)] { let config = if batched { let mut config = ProgramTestConfig::default_with_batched_trees(false); config.with_prover = false; @@ -114,7 +114,7 @@ async fn functional_read_only() { None, None, None, - is_small_ix, + is_v2_ix, true, Vec::new(), Vec::new(), @@ -314,7 +314,7 @@ async fn functional_read_only() { proof_res.proof.0, None, Some(account_infos), - is_small_ix, + is_v2_ix, true, read_only_accounts, readonly_addresses, @@ -347,7 +347,7 @@ async fn functional_read_only() { #[tokio::test] async fn functional_account_infos() { spawn_prover(ProverConfig::default()).await; - for (batched, is_small_ix) in + for (batched, is_v2_ix) in [(true, false), (true, true), (false, false), (false, true)].into_iter() { let config = if batched { @@ -411,7 +411,7 @@ async fn functional_account_infos() { None, None, None, - is_small_ix, + is_v2_ix, true, Vec::new(), Vec::new(), @@ -619,7 +619,7 @@ async fn functional_account_infos() { proof_res.value.proof.0, None, Some(account_infos), - is_small_ix, + is_v2_ix, true, read_only_accounts, readonly_addresses, @@ -662,7 +662,7 @@ async fn functional_account_infos() { async fn create_addresses_with_account_info() { spawn_prover(ProverConfig::default()).await; let with_transaction_hash = true; - for (batched, is_small_ix) in + for (batched, is_v2_ix) in [(true, false), (true, true), (false, false), (false, true)].into_iter() { let config = if batched { @@ -788,7 +788,7 @@ async fn create_addresses_with_account_info() { rpc_result.value.proof.0, None, Some(vec![account_info.clone()]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -815,7 +815,7 @@ async fn create_addresses_with_account_info() { rpc_result.value.proof.0, None, Some(vec![]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -850,7 +850,7 @@ async fn create_addresses_with_account_info() { rpc_result.value.proof.0, None, Some(vec![account_info]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -877,7 +877,7 @@ async fn create_addresses_with_account_info() { rpc_result.value.proof.0, None, Some(vec![account_info1.clone()]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -906,7 +906,7 @@ async fn create_addresses_with_account_info() { rpc_result.value.proof.0, None, Some(vec![account_info.clone()]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -933,7 +933,7 @@ async fn create_addresses_with_account_info() { rpc_result.value.proof.0, None, Some(vec![account_info.clone(), account_info1.clone()]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1012,7 +1012,7 @@ async fn create_addresses_with_account_info() { rpc_result.value.proof.0, None, Some(vec![]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1068,7 +1068,7 @@ async fn create_addresses_with_account_info() { rpc_result.value.proof.0, None, Some(vec![]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1156,7 +1156,7 @@ async fn create_addresses_with_account_info() { rpc_result.value.proof.0, None, Some(vec![account_info]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1222,7 +1222,7 @@ async fn create_addresses_with_account_info() { rpc_result.value.proof.0, None, Some(vec![account_info]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1262,10 +1262,10 @@ async fn create_addresses_with_account_info() { async fn create_addresses_with_read_only() { spawn_prover(ProverConfig::default()).await; let with_transaction_hash = true; - for (batched, is_small_ix) in + for (batched, is_v2_ix) in [(true, false), (true, true), (false, false), (false, true)].into_iter() { - println!("batched {}, small ix {}", batched, is_small_ix); + println!("batched {}, v2 ix {}", batched, is_v2_ix); let config = if batched { let mut config = ProgramTestConfig::default_with_batched_trees(false); config.with_prover = false; @@ -1380,7 +1380,7 @@ async fn create_addresses_with_read_only() { rpc_result.value.proof.0, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1408,7 +1408,7 @@ async fn create_addresses_with_read_only() { rpc_result.value.proof.0, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1444,7 +1444,7 @@ async fn create_addresses_with_read_only() { rpc_result.value.proof.0, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1472,7 +1472,7 @@ async fn create_addresses_with_read_only() { rpc_result.value.proof.0, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1502,7 +1502,7 @@ async fn create_addresses_with_read_only() { rpc_result.value.proof.0, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1530,7 +1530,7 @@ async fn create_addresses_with_read_only() { rpc_result.value.proof.0, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1610,7 +1610,7 @@ async fn create_addresses_with_read_only() { rpc_result.value.proof.0, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1667,7 +1667,7 @@ async fn create_addresses_with_read_only() { rpc_result.value.proof.0, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1752,7 +1752,7 @@ async fn create_addresses_with_read_only() { rpc_result.value.proof.0, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1815,7 +1815,7 @@ async fn create_addresses_with_read_only() { rpc_result.value.proof.0, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1837,7 +1837,7 @@ async fn create_addresses_with_read_only() { async fn compress_sol_with_account_info() { let with_transaction_hash = false; let batched = true; - for is_small_ix in [true, false].into_iter() { + for is_v2_ix in [true, false].into_iter() { let config = { let mut config = ProgramTestConfig::default_with_batched_trees(false); config.with_prover = false; @@ -1891,7 +1891,7 @@ async fn compress_sol_with_account_info() { None, None, Some(vec![account_info.clone()]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1918,7 +1918,7 @@ async fn compress_sol_with_account_info() { None, None, Some(vec![account_info.clone()]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1969,7 +1969,7 @@ async fn compress_sol_with_account_info() { None, Some(recipient), Some(vec![account_info.clone()]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -1996,7 +1996,7 @@ async fn compress_sol_with_account_info() { None, Some(recipient), Some(vec![account_info.clone()]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -2023,7 +2023,7 @@ async fn cpi_context_with_read_only() { spawn_prover(ProverConfig::default()).await; let with_transaction_hash = false; let batched = true; - for is_small_ix in [true, false].into_iter() { + for is_v2_ix in [true, false].into_iter() { let config = { let mut config = ProgramTestConfig::default_with_batched_trees(false); config.with_prover = false; @@ -2091,7 +2091,7 @@ async fn cpi_context_with_read_only() { None, None, None, - is_small_ix, + is_v2_ix, true, Vec::new(), Vec::new(), @@ -2181,7 +2181,7 @@ async fn cpi_context_with_read_only() { None, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -2224,7 +2224,7 @@ async fn cpi_context_with_read_only() { None, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -2267,7 +2267,7 @@ async fn cpi_context_with_read_only() { rpc_result.value.proof.0, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -2313,7 +2313,7 @@ async fn cpi_context_with_account_info() { spawn_prover(ProverConfig::default()).await; let with_transaction_hash = false; let batched = true; - for is_small_ix in [true, false].into_iter() { + for is_v2_ix in [true, false].into_iter() { let config = if batched { let mut config = ProgramTestConfig::default_with_batched_trees(false); config.with_prover = false; @@ -2387,7 +2387,7 @@ async fn cpi_context_with_account_info() { None, None, None, - is_small_ix, + is_v2_ix, true, Vec::new(), Vec::new(), @@ -2477,7 +2477,7 @@ async fn cpi_context_with_account_info() { None, None, Some(vec![account_info]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -2534,7 +2534,7 @@ async fn cpi_context_with_account_info() { None, None, Some(vec![account_info1, account_info2]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -2585,7 +2585,7 @@ async fn cpi_context_with_account_info() { rpc_result.value.proof.0, None, Some(vec![account_info1, account_info2]), - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -2631,7 +2631,7 @@ async fn cpi_context_with_account_info() { async fn compress_sol_with_read_only() { let with_transaction_hash = false; let batched = true; - for is_small_ix in [true, false].into_iter() { + for is_v2_ix in [true, false].into_iter() { let config = if batched { let mut config = ProgramTestConfig::default_with_batched_trees(false); config.with_prover = false; @@ -2684,7 +2684,7 @@ async fn compress_sol_with_read_only() { None, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -2711,7 +2711,7 @@ async fn compress_sol_with_read_only() { None, None, None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -2759,7 +2759,7 @@ async fn compress_sol_with_read_only() { None, Some(recipient), None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -2786,7 +2786,7 @@ async fn compress_sol_with_read_only() { None, Some(recipient), None, - is_small_ix, + is_v2_ix, with_transaction_hash, Vec::new(), Vec::new(), @@ -2907,7 +2907,7 @@ async fn test_duplicate_account_in_inputs_and_read_only() { rpc_result.value.proof.0, // proof None, // sol_compression_recipient None, // account_infos - false, // small_ix + false, // v2_ix false, // with_transaction_hash vec![read_only_account], // read_only_accounts Vec::new(), // read_only_addresses @@ -2995,7 +2995,7 @@ pub mod local_sdk { proof: Option, sol_compression_recipient: Option, account_infos: Option>, - small_ix: bool, + v2_ix: bool, with_transaction_hash: bool, read_only_accounts: Vec, read_only_addresses: Vec, @@ -3048,7 +3048,7 @@ pub mod local_sdk { let ix_data = if account_infos.is_none() { InstructionDataInvokeCpiWithReadOnly { - mode: if small_ix { 1 } else { 0 }, + mode: if v2_ix { 1 } else { 0 }, bump: 255, invoking_program_id: create_address_test_program::ID.into(), proof, @@ -3078,7 +3078,7 @@ pub mod local_sdk { .unwrap() } else if let Some(account_infos) = account_infos.as_ref() { InstructionDataInvokeCpiWithAccountInfo { - mode: if small_ix { 1 } else { 0 }, + mode: if v2_ix { 1 } else { 0 }, bump: 255, invoking_program_id: create_address_test_program::ID.into(), proof, @@ -3117,7 +3117,7 @@ pub mod local_sdk { None }, sol_compression_recipient, - small_ix, + v2_ix, }; let instruction_discriminator = if account_infos.is_none() { @@ -3139,7 +3139,7 @@ pub mod local_sdk { payer.pubkey(), [instruction_discriminator.to_vec(), ix_data].concat(), onchain_config, - small_ix, + v2_ix, remaining_accounts, ); let res = rpc @@ -3167,7 +3167,7 @@ pub mod local_sdk { pub cpi_context: Option, pub sol_compression_recipient: Option, pub sol_pool_pda: Option, - pub small_ix: bool, + pub v2_ix: bool, } impl SystemAccountMetaConfig { @@ -3177,7 +3177,7 @@ pub mod local_sdk { cpi_context: None, sol_compression_recipient: None, sol_pool_pda: None, - small_ix: false, + v2_ix: false, } } pub fn new_with_account_options(self_program: Pubkey) -> Self { @@ -3186,7 +3186,7 @@ pub mod local_sdk { cpi_context: None, sol_compression_recipient: None, sol_pool_pda: None, - small_ix: true, + v2_ix: true, } } @@ -3196,7 +3196,7 @@ pub mod local_sdk { cpi_context: Some(cpi_context), sol_compression_recipient: None, sol_pool_pda: None, - small_ix: false, + v2_ix: false, } } } @@ -3326,7 +3326,7 @@ pub mod local_sdk { let cpi_signer = Pubkey::new_from_array(LIGHT_CPI_SIGNER.cpi_signer); println!("cpi signer {:?}", cpi_signer); let default_pubkeys = SystemAccountPubkeys::default(); - let mut vec = if config.small_ix { + let mut vec = if config.v2_ix { // Accounts without noop and self program. let vec = vec![ AccountMeta::new_readonly(default_pubkeys.light_sytem_program, false), @@ -3365,7 +3365,7 @@ pub mod local_sdk { is_writable: true, }); } - if !config.small_ix { + if !config.v2_ix { vec.push(AccountMeta::new_readonly( default_pubkeys.system_program, false, diff --git a/programs/system/src/accounts/mode.rs b/programs/system/src/accounts/mode.rs index 9ecb73c8f0..048b7e2525 100644 --- a/programs/system/src/accounts/mode.rs +++ b/programs/system/src/accounts/mode.rs @@ -7,7 +7,7 @@ pub enum AccountMode { Anchor, /// Do not send optional accounts if not required. /// Use instruction data to signal whether an optional account is expected. - Small, + V2, } impl TryFrom for AccountMode { @@ -16,7 +16,7 @@ impl TryFrom for AccountMode { fn try_from(value: u8) -> std::result::Result { match value { 0 => Ok(AccountMode::Anchor), - 1 => Ok(AccountMode::Small), + 1 => Ok(AccountMode::V2), _ => Err(SystemProgramError::InvalidAccountMode), } } @@ -26,7 +26,7 @@ impl From for u8 { fn from(value: AccountMode) -> Self { match value { AccountMode::Anchor => 0u8, - AccountMode::Small => 1u8, + AccountMode::V2 => 1u8, } } } diff --git a/programs/system/src/invoke_cpi/instruction_small.rs b/programs/system/src/invoke_cpi/instruction_v2.rs similarity index 92% rename from programs/system/src/invoke_cpi/instruction_small.rs rename to programs/system/src/invoke_cpi/instruction_v2.rs index 3a13d6bbc2..9c62c6aa4d 100644 --- a/programs/system/src/invoke_cpi/instruction_small.rs +++ b/programs/system/src/invoke_cpi/instruction_v2.rs @@ -14,7 +14,7 @@ use crate::{ }; #[derive(PartialEq, Eq)] -pub struct InvokeCpiInstructionSmall<'info> { +pub struct InvokeCpiInstructionV2<'info> { /// Fee payer needs to be mutable to pay rollover and protocol fees. pub fee_payer: &'info AccountInfo, pub authority: &'info AccountInfo, @@ -28,7 +28,7 @@ pub struct InvokeCpiInstructionSmall<'info> { pub cpi_context_account: Option<&'info AccountInfo>, } -impl<'info> InvokeCpiInstructionSmall<'info> { +impl<'info> InvokeCpiInstructionV2<'info> { pub fn from_account_infos( account_infos: &'info [AccountInfo], account_options: AccountOptions, @@ -69,7 +69,7 @@ impl<'info> InvokeCpiInstructionSmall<'info> { } } -impl<'info> SignerAccounts<'info> for InvokeCpiInstructionSmall<'info> { +impl<'info> SignerAccounts<'info> for InvokeCpiInstructionV2<'info> { fn get_fee_payer(&self) -> &'info AccountInfo { self.fee_payer } @@ -79,12 +79,12 @@ impl<'info> SignerAccounts<'info> for InvokeCpiInstructionSmall<'info> { } } -impl<'info> CpiContextAccountTrait<'info> for InvokeCpiInstructionSmall<'info> { +impl<'info> CpiContextAccountTrait<'info> for InvokeCpiInstructionV2<'info> { fn get_cpi_context_account(&self) -> Option<&'info AccountInfo> { self.cpi_context_account } } -impl<'info> InvokeAccounts<'info> for InvokeCpiInstructionSmall<'info> { +impl<'info> InvokeAccounts<'info> for InvokeCpiInstructionV2<'info> { fn get_registered_program_pda(&self) -> &'info AccountInfo { self.registered_program_pda } diff --git a/programs/system/src/invoke_cpi/mod.rs b/programs/system/src/invoke_cpi/mod.rs index 790921f2c8..d9dee72792 100644 --- a/programs/system/src/invoke_cpi/mod.rs +++ b/programs/system/src/invoke_cpi/mod.rs @@ -1,7 +1,7 @@ pub mod account; pub mod instruction; -pub mod instruction_small; +pub mod instruction_v2; pub mod process_cpi_context; pub mod processor; pub mod verify_signer; diff --git a/programs/system/src/lib.rs b/programs/system/src/lib.rs index 483b2fd31a..d954c5eadc 100644 --- a/programs/system/src/lib.rs +++ b/programs/system/src/lib.rs @@ -12,7 +12,7 @@ use accounts::{init_context_account::init_cpi_context_account, mode::AccountMode pub use constants::*; use invoke::instruction::InvokeInstruction; use invoke_cpi::{ - instruction::InvokeCpiInstruction, instruction_small::InvokeCpiInstructionSmall, + instruction::InvokeCpiInstruction, instruction_v2::InvokeCpiInstructionV2, processor::process_invoke_cpi, }; use light_compressed_account::instruction_data::{ @@ -180,12 +180,12 @@ fn shared_invoke_cpi<'a, 'info, T: InstructionData<'a>>( remaining_accounts, ) } - AccountMode::Small => { - let (ctx, remaining_accounts) = InvokeCpiInstructionSmall::from_account_infos( + AccountMode::V2 => { + let (ctx, remaining_accounts) = InvokeCpiInstructionV2::from_account_infos( accounts, inputs.account_option_config(), )?; - process_invoke_cpi::( + process_invoke_cpi::( invoking_program, ctx, inputs, diff --git a/programs/system/tests/invoke_cpi_instruction_small.rs b/programs/system/tests/invoke_cpi_instruction_v2.rs similarity index 79% rename from programs/system/tests/invoke_cpi_instruction_small.rs rename to programs/system/tests/invoke_cpi_instruction_v2.rs index c42941b79b..27f08580b6 100644 --- a/programs/system/tests/invoke_cpi_instruction_small.rs +++ b/programs/system/tests/invoke_cpi_instruction_v2.rs @@ -7,7 +7,7 @@ use light_account_checks::{ }; use light_compressed_account::instruction_data::traits::AccountOptions; use light_system_program_pinocchio::invoke_cpi::{ - account::CpiContextAccount, instruction_small::InvokeCpiInstructionSmall, + account::CpiContextAccount, instruction_v2::InvokeCpiInstructionV2, }; // We'll avoid direct PDA validation as it's difficult in unit tests use pinocchio::account_info::AccountInfo; @@ -54,7 +54,7 @@ fn get_decompression_recipient_account_info() -> AccountInfo { } #[test] -fn functional_from_account_infos_small() { +fn functional_from_account_infos_v2() { let fee_payer = get_fee_payer_account_info(); let authority = get_authority_account_info(); let registered_program_pda = get_registered_program_pda_account_info(); @@ -74,36 +74,28 @@ fn functional_from_account_infos_small() { registered_program_pda.clone(), account_compression_authority.clone(), ]; - let result = InvokeCpiInstructionSmall::from_account_infos( + let result = InvokeCpiInstructionV2::from_account_infos( account_info_array.as_slice(), options_config, ); // Verify result is Ok and contains the expected accounts - let (invoke_cpi_instruction_small, _) = result.unwrap(); + let (invoke_cpi_instruction_v2, _) = result.unwrap(); + assert_eq!(invoke_cpi_instruction_v2.fee_payer.key(), fee_payer.key()); + assert_eq!(invoke_cpi_instruction_v2.authority.key(), authority.key()); assert_eq!( - invoke_cpi_instruction_small.fee_payer.key(), - fee_payer.key() - ); - assert_eq!( - invoke_cpi_instruction_small.authority.key(), - authority.key() - ); - assert_eq!( - invoke_cpi_instruction_small.registered_program_pda.key(), + invoke_cpi_instruction_v2.registered_program_pda.key(), registered_program_pda.key() ); assert_eq!( - invoke_cpi_instruction_small + invoke_cpi_instruction_v2 .account_compression_authority .key(), account_compression_authority.key() ); - assert!(invoke_cpi_instruction_small.sol_pool_pda.is_none()); - assert!(invoke_cpi_instruction_small - .decompression_recipient - .is_none()); - assert!(invoke_cpi_instruction_small.cpi_context_account.is_none()); + assert!(invoke_cpi_instruction_v2.sol_pool_pda.is_none()); + assert!(invoke_cpi_instruction_v2.decompression_recipient.is_none()); + assert!(invoke_cpi_instruction_v2.cpi_context_account.is_none()); } // 1. With decompression recipient @@ -123,29 +115,23 @@ fn functional_from_account_infos_small() { decompression_recipient.clone(), ]; - let result = InvokeCpiInstructionSmall::from_account_infos( + let result = InvokeCpiInstructionV2::from_account_infos( account_info_array.as_slice(), options_config, ); - let (invoke_cpi_instruction_small, _) = result.unwrap(); - assert_eq!( - invoke_cpi_instruction_small.fee_payer.key(), - fee_payer.key() - ); - assert_eq!( - invoke_cpi_instruction_small.authority.key(), - authority.key() - ); - assert!(invoke_cpi_instruction_small.sol_pool_pda.is_none()); + let (invoke_cpi_instruction_v2, _) = result.unwrap(); + assert_eq!(invoke_cpi_instruction_v2.fee_payer.key(), fee_payer.key()); + assert_eq!(invoke_cpi_instruction_v2.authority.key(), authority.key()); + assert!(invoke_cpi_instruction_v2.sol_pool_pda.is_none()); assert_eq!( - invoke_cpi_instruction_small + invoke_cpi_instruction_v2 .decompression_recipient .unwrap() .key(), decompression_recipient.key() ); - assert!(invoke_cpi_instruction_small.cpi_context_account.is_none()); + assert!(invoke_cpi_instruction_v2.cpi_context_account.is_none()); } // With cpi_context_account { @@ -170,30 +156,19 @@ fn functional_from_account_infos_small() { ]; // This should pass with valid discriminator - let result = InvokeCpiInstructionSmall::from_account_infos( + let result = InvokeCpiInstructionV2::from_account_infos( account_info_array.as_slice(), options_config, ); // Verify result is Ok and contains the expected accounts - let (invoke_cpi_instruction_small, _) = result.unwrap(); + let (invoke_cpi_instruction_v2, _) = result.unwrap(); + assert_eq!(invoke_cpi_instruction_v2.fee_payer.key(), fee_payer.key()); + assert_eq!(invoke_cpi_instruction_v2.authority.key(), authority.key()); + assert!(invoke_cpi_instruction_v2.sol_pool_pda.is_none()); + assert!(invoke_cpi_instruction_v2.decompression_recipient.is_none()); assert_eq!( - invoke_cpi_instruction_small.fee_payer.key(), - fee_payer.key() - ); - assert_eq!( - invoke_cpi_instruction_small.authority.key(), - authority.key() - ); - assert!(invoke_cpi_instruction_small.sol_pool_pda.is_none()); - assert!(invoke_cpi_instruction_small - .decompression_recipient - .is_none()); - assert_eq!( - invoke_cpi_instruction_small - .cpi_context_account - .unwrap() - .key(), + invoke_cpi_instruction_v2.cpi_context_account.unwrap().key(), cpi_context_account.key() ); } @@ -222,7 +197,7 @@ fn test_cpi_context_account_error_handling() { invalid_cpi_context_account.clone(), ]; - let result = InvokeCpiInstructionSmall::from_account_infos( + let result = InvokeCpiInstructionV2::from_account_infos( account_info_array.as_slice(), options_config, ); @@ -241,7 +216,7 @@ fn test_cpi_context_account_error_handling() { invalid_cpi_context_account.clone(), ]; - let result = InvokeCpiInstructionSmall::from_account_infos( + let result = InvokeCpiInstructionV2::from_account_infos( account_info_array.as_slice(), options_config, ); @@ -276,40 +251,29 @@ fn test_decompression_recipient_and_cpi_context_validation() { ]; // This should pass with valid discriminator - let result = InvokeCpiInstructionSmall::from_account_infos( - account_info_array.as_slice(), - options_config, - ); + let result = + InvokeCpiInstructionV2::from_account_infos(account_info_array.as_slice(), options_config); // Verify result is Ok and contains the expected accounts - let (invoke_cpi_instruction_small, _) = result.unwrap(); + let (invoke_cpi_instruction_v2, _) = result.unwrap(); + assert_eq!(invoke_cpi_instruction_v2.fee_payer.key(), fee_payer.key()); + assert_eq!(invoke_cpi_instruction_v2.authority.key(), authority.key()); + assert!(invoke_cpi_instruction_v2.sol_pool_pda.is_none()); assert_eq!( - invoke_cpi_instruction_small.fee_payer.key(), - fee_payer.key() - ); - assert_eq!( - invoke_cpi_instruction_small.authority.key(), - authority.key() - ); - assert!(invoke_cpi_instruction_small.sol_pool_pda.is_none()); - assert_eq!( - invoke_cpi_instruction_small + invoke_cpi_instruction_v2 .decompression_recipient .unwrap() .key(), decompression_recipient.key() ); assert_eq!( - invoke_cpi_instruction_small - .cpi_context_account - .unwrap() - .key(), + invoke_cpi_instruction_v2.cpi_context_account.unwrap().key(), cpi_context_account.key() ); } #[test] -fn failing_from_account_infos_small() { +fn failing_from_account_infos_v2() { let fee_payer = get_fee_payer_account_info(); let authority = get_authority_account_info(); let registered_program_pda = get_registered_program_pda_account_info(); @@ -331,7 +295,7 @@ fn failing_from_account_infos_small() { cpi_context_account: false, }; - let result = InvokeCpiInstructionSmall::from_account_infos( + let result = InvokeCpiInstructionV2::from_account_infos( account_info_array.as_slice(), options_config, ); @@ -349,7 +313,7 @@ fn failing_from_account_infos_small() { let mut account_info_array_clone = account_info_array.clone(); account_info_array_clone[1] = get_fee_payer_account_info(); // Use a mutable account - let result = InvokeCpiInstructionSmall::from_account_infos( + let result = InvokeCpiInstructionV2::from_account_infos( account_info_array_clone.as_slice(), options_config, ); @@ -371,7 +335,7 @@ fn failing_from_account_infos_small() { let mut account_info_array_clone = account_info_array.clone(); account_info_array_clone[2] = get_mut_account_info(); - let result = InvokeCpiInstructionSmall::from_account_infos( + let result = InvokeCpiInstructionV2::from_account_infos( account_info_array_clone.as_slice(), options_config, ); @@ -393,7 +357,7 @@ fn failing_from_account_infos_small() { let mut account_info_array_clone = account_info_array.clone(); account_info_array_clone[3] = get_mut_account_info(); - let result = InvokeCpiInstructionSmall::from_account_infos( + let result = InvokeCpiInstructionV2::from_account_infos( account_info_array_clone.as_slice(), options_config, ); @@ -422,7 +386,7 @@ fn failing_from_account_infos_small() { // This will panic with index out of bounds let result = catch_unwind(|| { - InvokeCpiInstructionSmall::from_account_infos( + InvokeCpiInstructionV2::from_account_infos( insufficient_array.as_slice(), options_config, ) @@ -448,7 +412,7 @@ fn failing_from_account_infos_small() { decompression_recipient.clone(), ]; - let result = InvokeCpiInstructionSmall::from_account_infos( + let result = InvokeCpiInstructionV2::from_account_infos( account_array_with_decompression.as_slice(), options_with_decompression, ); diff --git a/scripts/devenv.sh b/scripts/devenv.sh index eaaab82235..3584f8652c 100755 --- a/scripts/devenv.sh +++ b/scripts/devenv.sh @@ -92,8 +92,8 @@ export SBF_OUT_DIR=target/deploy # Set Redis URL if not already set export REDIS_URL="${REDIS_URL:-redis://localhost:6379}" -# Enable small_ix feature by default in devenv -export CARGO_FEATURES="${CARGO_FEATURES:-small_ix}" +# Enable v2_ix feature by default in devenv +export CARGO_FEATURES="${CARGO_FEATURES:-v2_ix}" # macOS-specific settings if [[ "$(uname)" == "Darwin" ]]; then diff --git a/sdk-libs/sdk-pinocchio/Cargo.toml b/sdk-libs/sdk-pinocchio/Cargo.toml index 90264c3d5a..da096a5088 100644 --- a/sdk-libs/sdk-pinocchio/Cargo.toml +++ b/sdk-libs/sdk-pinocchio/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" [features] default = [] v2 = ["light-sdk-types/v2"] -small_ix = ["light-sdk-types/small_ix"] +v2_ix = ["light-sdk-types/v2_ix"] [dependencies] pinocchio = { workspace = true } diff --git a/sdk-libs/sdk-pinocchio/src/cpi/accounts_small.rs b/sdk-libs/sdk-pinocchio/src/cpi/accounts_v2.rs similarity index 83% rename from sdk-libs/sdk-pinocchio/src/cpi/accounts_small.rs rename to sdk-libs/sdk-pinocchio/src/cpi/accounts_v2.rs index 6f59d524b0..89e124cb8b 100644 --- a/sdk-libs/sdk-pinocchio/src/cpi/accounts_small.rs +++ b/sdk-libs/sdk-pinocchio/src/cpi/accounts_v2.rs @@ -1,16 +1,13 @@ use light_sdk_types::{ - CompressionCpiAccountIndexSmall, CpiAccountsSmall as GenericCpiAccountsSmall, - PROGRAM_ACCOUNTS_LEN, + CompressionCpiAccountIndexV2, CpiAccountsV2 as GenericCpiAccountsV2, PROGRAM_ACCOUNTS_LEN, }; use pinocchio::{account_info::AccountInfo, instruction::AccountMeta}; use crate::error::Result; -pub type CpiAccountsSmall<'a> = GenericCpiAccountsSmall<'a, AccountInfo>; +pub type CpiAccountsV2<'a> = GenericCpiAccountsV2<'a, AccountInfo>; -pub fn to_account_metas_small<'a>( - cpi_accounts: &CpiAccountsSmall<'a>, -) -> Result>> { +pub fn to_account_metas_v2<'a>(cpi_accounts: &CpiAccountsV2<'a>) -> Result>> { let mut account_metas = Vec::with_capacity(1 + cpi_accounts.account_infos().len() - PROGRAM_ACCOUNTS_LEN); @@ -27,7 +24,7 @@ pub fn to_account_metas_small<'a>( )); let accounts = cpi_accounts.account_infos(); - let mut index = CompressionCpiAccountIndexSmall::SolPoolPda as usize; + let mut index = CompressionCpiAccountIndexV2::SolPoolPda as usize; if cpi_accounts.config().sol_pool_pda { let account = cpi_accounts.get_account_info(index)?; diff --git a/sdk-libs/sdk-pinocchio/src/cpi/mod.rs b/sdk-libs/sdk-pinocchio/src/cpi/mod.rs index d255f3dc19..d1825509d2 100644 --- a/sdk-libs/sdk-pinocchio/src/cpi/mod.rs +++ b/sdk-libs/sdk-pinocchio/src/cpi/mod.rs @@ -1,9 +1,9 @@ pub mod accounts; -#[cfg(feature = "small_ix")] -pub mod accounts_small; +#[cfg(feature = "v2_ix")] +pub mod accounts_v2; pub mod invoke; pub use accounts::*; -#[cfg(feature = "small_ix")] -pub use accounts_small::*; +#[cfg(feature = "v2_ix")] +pub use accounts_v2::*; pub use invoke::*; diff --git a/sdk-libs/sdk-types/Cargo.toml b/sdk-libs/sdk-types/Cargo.toml index 18b3589b66..a4a2d34eba 100644 --- a/sdk-libs/sdk-types/Cargo.toml +++ b/sdk-libs/sdk-types/Cargo.toml @@ -9,7 +9,7 @@ description = "Core types for Light Protocol SDK" [features] anchor = ["anchor-lang", "light-compressed-account/anchor"] v2 = [] -small_ix = [] +v2_ix = [] [dependencies] anchor-lang = { workspace = true, optional = true } diff --git a/sdk-libs/sdk-types/src/cpi_accounts_small.rs b/sdk-libs/sdk-types/src/cpi_accounts_v2.rs similarity index 85% rename from sdk-libs/sdk-types/src/cpi_accounts_small.rs rename to sdk-libs/sdk-types/src/cpi_accounts_v2.rs index 517b84a4a6..314f8c17ac 100644 --- a/sdk-libs/sdk-types/src/cpi_accounts_small.rs +++ b/sdk-libs/sdk-types/src/cpi_accounts_v2.rs @@ -6,7 +6,7 @@ use crate::{ }; #[repr(usize)] -pub enum CompressionCpiAccountIndexSmall { +pub enum CompressionCpiAccountIndexV2 { LightSystemProgram, // Only exposed to outer instruction AccountCompressionProgram, // Only exposed to outer instruction SystemProgram, // Only exposed to outer instruction @@ -20,15 +20,15 @@ pub enum CompressionCpiAccountIndexSmall { pub const PROGRAM_ACCOUNTS_LEN: usize = 3; // 6 + 3 program ids, fee payer is extra. -pub const SMALL_SYSTEM_ACCOUNTS_LEN: usize = 9; +pub const V2_SYSTEM_ACCOUNTS_LEN: usize = 9; -pub struct CpiAccountsSmall<'a, T: AccountInfoTrait> { +pub struct CpiAccountsV2<'a, T: AccountInfoTrait> { fee_payer: &'a T, accounts: &'a [T], config: CpiAccountsConfig, } -impl<'a, T: AccountInfoTrait> CpiAccountsSmall<'a, T> { +impl<'a, T: AccountInfoTrait> CpiAccountsV2<'a, T> { pub fn new(fee_payer: &'a T, accounts: &'a [T], cpi_signer: CpiSigner) -> Self { Self { fee_payer, @@ -50,42 +50,42 @@ impl<'a, T: AccountInfoTrait> CpiAccountsSmall<'a, T> { } pub fn authority(&self) -> Result<&'a T> { - let index = CompressionCpiAccountIndexSmall::Authority as usize; + let index = CompressionCpiAccountIndexV2::Authority as usize; self.accounts .get(index) .ok_or(LightSdkTypesError::CpiAccountsIndexOutOfBounds(index)) } pub fn registered_program_pda(&self) -> Result<&'a T> { - let index = CompressionCpiAccountIndexSmall::RegisteredProgramPda as usize; + let index = CompressionCpiAccountIndexV2::RegisteredProgramPda as usize; self.accounts .get(index) .ok_or(LightSdkTypesError::CpiAccountsIndexOutOfBounds(index)) } pub fn account_compression_authority(&self) -> Result<&'a T> { - let index = CompressionCpiAccountIndexSmall::AccountCompressionAuthority as usize; + let index = CompressionCpiAccountIndexV2::AccountCompressionAuthority as usize; self.accounts .get(index) .ok_or(LightSdkTypesError::CpiAccountsIndexOutOfBounds(index)) } pub fn sol_pool_pda(&self) -> Result<&'a T> { - let index = CompressionCpiAccountIndexSmall::SolPoolPda as usize; + let index = CompressionCpiAccountIndexV2::SolPoolPda as usize; self.accounts .get(index) .ok_or(LightSdkTypesError::CpiAccountsIndexOutOfBounds(index)) } pub fn decompression_recipient(&self) -> Result<&'a T> { - let index = CompressionCpiAccountIndexSmall::DecompressionRecipient as usize; + let index = CompressionCpiAccountIndexV2::DecompressionRecipient as usize; self.accounts .get(index) .ok_or(LightSdkTypesError::CpiAccountsIndexOutOfBounds(index)) } pub fn cpi_context(&self) -> Result<&'a T> { - let index = CompressionCpiAccountIndexSmall::CpiContext as usize; + let index = CompressionCpiAccountIndexV2::CpiContext as usize; self.accounts .get(index) .ok_or(LightSdkTypesError::CpiAccountsIndexOutOfBounds(index)) @@ -100,7 +100,7 @@ impl<'a, T: AccountInfoTrait> CpiAccountsSmall<'a, T> { } pub fn system_accounts_end_offset(&self) -> usize { - let mut len = SMALL_SYSTEM_ACCOUNTS_LEN; + let mut len = V2_SYSTEM_ACCOUNTS_LEN; if !self.config.sol_pool_pda { len -= 1; } diff --git a/sdk-libs/sdk-types/src/lib.rs b/sdk-libs/sdk-types/src/lib.rs index 015c8a8e6c..36341f5d02 100644 --- a/sdk-libs/sdk-types/src/lib.rs +++ b/sdk-libs/sdk-types/src/lib.rs @@ -1,8 +1,8 @@ pub mod address; pub mod constants; pub mod cpi_accounts; -#[cfg(feature = "small_ix")] -pub mod cpi_accounts_small; +#[cfg(feature = "v2_ix")] +pub mod cpi_accounts_v2; pub mod error; pub mod instruction; @@ -13,10 +13,9 @@ use anchor_lang::{AnchorDeserialize, AnchorSerialize}; use borsh::{BorshDeserialize as AnchorDeserialize, BorshSerialize as AnchorSerialize}; pub use constants::*; pub use cpi_accounts::*; -#[cfg(feature = "small_ix")] -pub use cpi_accounts_small::{ - CompressionCpiAccountIndexSmall, CpiAccountsSmall, PROGRAM_ACCOUNTS_LEN, - SMALL_SYSTEM_ACCOUNTS_LEN, +#[cfg(feature = "v2_ix")] +pub use cpi_accounts_v2::{ + CompressionCpiAccountIndexV2, CpiAccountsV2, PROGRAM_ACCOUNTS_LEN, V2_SYSTEM_ACCOUNTS_LEN, }; /// Configuration struct containing program ID, CPI signer, and bump for Light Protocol diff --git a/sdk-libs/sdk/Cargo.toml b/sdk-libs/sdk/Cargo.toml index 9afeb4af92..ace487331c 100644 --- a/sdk-libs/sdk/Cargo.toml +++ b/sdk-libs/sdk/Cargo.toml @@ -19,7 +19,7 @@ anchor = [ "light-sdk-types/anchor", ] v2 = ["light-sdk-types/v2"] -small_ix = ["light-sdk-types/small_ix"] +v2_ix = ["light-sdk-types/v2_ix"] [dependencies] solana-pubkey = { workspace = true, features = ["borsh", "sha2", "curve25519"] } diff --git a/sdk-libs/sdk/src/cpi/accounts_small_ix.rs b/sdk-libs/sdk/src/cpi/accounts_v2_ix.rs similarity index 85% rename from sdk-libs/sdk/src/cpi/accounts_small_ix.rs rename to sdk-libs/sdk/src/cpi/accounts_v2_ix.rs index c4e4f7c144..9efc0d2930 100644 --- a/sdk-libs/sdk/src/cpi/accounts_small_ix.rs +++ b/sdk-libs/sdk/src/cpi/accounts_v2_ix.rs @@ -1,13 +1,12 @@ use light_sdk_types::{ - CompressionCpiAccountIndexSmall, CpiAccountsSmall as GenericCpiAccountsSmall, - PROGRAM_ACCOUNTS_LEN, + CompressionCpiAccountIndexV2, CpiAccountsV2 as GenericCpiAccountsV2, PROGRAM_ACCOUNTS_LEN, }; use crate::{error::Result, AccountInfo, AccountMeta}; -pub type CpiAccountsSmall<'c, 'info> = GenericCpiAccountsSmall<'c, AccountInfo<'info>>; +pub type CpiAccountsV2<'c, 'info> = GenericCpiAccountsV2<'c, AccountInfo<'info>>; -pub fn to_account_metas_small(cpi_accounts: CpiAccountsSmall<'_, '_>) -> Result> { +pub fn to_account_metas_v2(cpi_accounts: CpiAccountsV2<'_, '_>) -> Result> { // TODO: do a version with a const array instead of vector. let mut account_metas = Vec::with_capacity(1 + cpi_accounts.account_infos().len() - PROGRAM_ACCOUNTS_LEN); @@ -35,7 +34,7 @@ pub fn to_account_metas_small(cpi_accounts: CpiAccountsSmall<'_, '_>) -> Result< }); let accounts = cpi_accounts.account_infos(); - let mut index = CompressionCpiAccountIndexSmall::SolPoolPda as usize; + let mut index = CompressionCpiAccountIndexV2::SolPoolPda as usize; if cpi_accounts.config().sol_pool_pda { let account = cpi_accounts.get_account_info(index)?; diff --git a/sdk-libs/sdk/src/cpi/mod.rs b/sdk-libs/sdk/src/cpi/mod.rs index e1329328df..c96da72c8b 100644 --- a/sdk-libs/sdk/src/cpi/mod.rs +++ b/sdk-libs/sdk/src/cpi/mod.rs @@ -48,13 +48,13 @@ //! ``` mod accounts; -#[cfg(feature = "small_ix")] -mod accounts_small_ix; +#[cfg(feature = "v2_ix")] +mod accounts_v2_ix; mod invoke; pub use accounts::*; -#[cfg(feature = "small_ix")] -pub use accounts_small_ix::*; +#[cfg(feature = "v2_ix")] +pub use accounts_v2_ix::*; pub use invoke::*; /// Derives cpi signer and bump to invoke the light system program at compile time. pub use light_sdk_macros::derive_light_cpi_signer; diff --git a/sdk-libs/sdk/src/instruction/system_accounts.rs b/sdk-libs/sdk/src/instruction/system_accounts.rs index 8859068603..2e5538e0ce 100644 --- a/sdk-libs/sdk/src/instruction/system_accounts.rs +++ b/sdk-libs/sdk/src/instruction/system_accounts.rs @@ -120,7 +120,7 @@ pub fn get_light_system_account_metas(config: SystemAccountMetaConfig) -> Vec Vec { +pub fn get_light_system_account_metas_v2(config: SystemAccountMetaConfig) -> Vec { let cpi_signer = find_cpi_signer_macro!(&config.self_program).0; let default_pubkeys = SystemAccountPubkeys::default();