Skip to content

Commit 55ee3cd

Browse files
chore: remove vec length bytes from new instructions (#1802)
* chore: remove vec length bytes from new instructions * fix: cpi test, fix ctoken system program cpi small * fix: system-cpi-v2-test * fix: ts tests * chore: fix create_invoke_cpi_instruction * fix lint * fix: lint * chore: update photon * update cargo lock * update photon commit * Update program-libs/compressed-account/src/indexer_event/parse.rs Co-authored-by: Swen Schäferjohann <42959314+SwenSchaeferjohann@users.noreply.github.com> * Update program-libs/compressed-account/src/indexer_event/parse.rs --------- Co-authored-by: Swen Schäferjohann <42959314+SwenSchaeferjohann@users.noreply.github.com>
1 parent da6459d commit 55ee3cd

File tree

15 files changed

+351
-212
lines changed

15 files changed

+351
-212
lines changed

Cargo.lock

Lines changed: 243 additions & 134 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

anchor-programs/system/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ pub mod instructions;
77
pub mod utils;
88
pub use instructions::*;
99
pub mod cpi_context_account;
10-
use light_compressed_account::instruction_data::with_account_info::InstructionDataInvokeCpiWithAccountInfo;
10+
use light_compressed_account::instruction_data::{
11+
with_account_info::InstructionDataInvokeCpiWithAccountInfo,
12+
with_readonly::InstructionDataInvokeCpiWithReadOnly,
13+
};
14+
1115
declare_id!("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7");
1216

1317
#[program]
@@ -30,12 +34,10 @@ pub mod light_system_program {
3034

3135
pub fn invoke_cpi_with_read_only(
3236
ctx: Context<InvokeCpiInstruction>,
33-
// TODO: revert once parse_batched_event_functional is migrated to manual cpi
34-
inputs: Vec<u8>, // inputs: InstructionDataInvokeCpiWithReadOnly,
37+
inputs: InstructionDataInvokeCpiWithReadOnly,
3538
) -> Result<()> {
3639
unimplemented!("anchor wrapper not implemented")
3740
}
38-
3941
pub fn invoke_cpi_with_account_info(
4042
ctx: Context<InvokeCpiInstruction>,
4143
inputs: InstructionDataInvokeCpiWithAccountInfo,

forester/tests/address_v2_test.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{collections::HashMap, sync::Arc, time::Duration};
22

3+
use anchor_lang::Discriminator;
34
use borsh::BorshSerialize;
45
use create_address_test_program::create_invoke_cpi_instruction;
56
use forester::{config::GeneralConfig, epoch_manager::WorkReport, run_pipeline, ForesterConfig};
@@ -395,7 +396,11 @@ async fn create_v2_addresses<R: Rpc + MerkleTreeExt + Indexer>(
395396

396397
let instruction = create_invoke_cpi_instruction(
397398
payer.pubkey(),
398-
ix_data.try_to_vec()?,
399+
[
400+
light_system_program::instruction::InvokeCpiWithReadOnly::DISCRIMINATOR.to_vec(),
401+
ix_data.try_to_vec()?,
402+
]
403+
.concat(),
399404
remaining_accounts,
400405
None,
401406
);

js/stateless.js/src/programs/system/layout.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import { LightSystemProgram } from '.';
2424
import {
2525
INVOKE_CPI_DISCRIMINATOR,
26+
INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR,
2627
INVOKE_DISCRIMINATOR,
2728
} from '../../constants';
2829

@@ -232,7 +233,7 @@ export const InstructionDataInvokeCpiWithReadOnlyLayout = struct([
232233

233234
export function decodeInstructionDataInvokeCpiWithReadOnly(buffer: Buffer) {
234235
return InstructionDataInvokeCpiWithReadOnlyLayout.decode(
235-
buffer.slice(INVOKE_DISCRIMINATOR.length + 4),
236+
buffer.slice(INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR.length),
236237
);
237238
}
238239

js/stateless.js/tests/unit/utils/conversion.test.ts

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -81,48 +81,48 @@ describe('deserialize apc cpi', () => {
8181

8282
describe('deserialize InstructionDataInvokeCpiWithReadOnly', () => {
8383
it('should deserialize the complete InstructionDataInvokeCpiWithReadOnly structure', () => {
84-
// first 12 bytes are skipped.
84+
// first 8 bytes are skipped.
8585
const data = [
86-
1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 148, 0, 0, 0, 0, 0, 0, 0, 1,
87-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88-
0, 90, 70, 83, 164, 216, 39, 10, 106, 0, 0, 1, 0, 1, 83, 0, 3, 0, 0,
89-
0, 91, 97, 69, 180, 246, 54, 236, 250, 62, 116, 95, 226, 176, 250,
90-
172, 150, 38, 157, 38, 110, 3, 110, 130, 133, 102, 14, 42, 118, 151,
91-
177, 74, 49, 180, 127, 245, 54, 1, 13, 208, 197, 129, 101, 36, 193,
92-
85, 161, 48, 175, 182, 23, 26, 150, 52, 204, 60, 96, 233, 248, 140,
93-
33, 212, 16, 175, 111, 218, 54, 195, 97, 239, 148, 66, 48, 24, 183,
94-
0, 254, 113, 31, 157, 136, 188, 202, 183, 37, 203, 248, 36, 216,
95-
177, 227, 159, 93, 238, 171, 167, 173, 224, 196, 144, 193, 203, 88,
96-
88, 133, 174, 71, 142, 254, 17, 121, 254, 208, 0, 153, 1, 0, 0, 0,
97-
237, 83, 2, 61, 227, 140, 40, 48, 68, 54, 55, 57, 228, 108, 104, 1,
98-
19, 138, 156, 96, 249, 111, 250, 212, 130, 57, 47, 54, 4, 5, 48,
99-
192, 174, 157, 141, 112, 18, 255, 0, 64, 136, 164, 130, 37, 210, 47,
100-
0, 253, 75, 4, 203, 167, 187, 45, 253, 192, 154, 0, 4, 0, 0, 0, 0,
101-
0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102-
0, 0, 0, 0, 0, 0, 0, 0, 201, 78, 254, 108, 214, 2, 223, 68, 0, 0,
103-
43, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 78, 17, 123, 28, 100, 171, 124,
105-
219, 0, 0, 253, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0,
106-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 126, 220, 103, 34, 32,
107-
110, 222, 30, 0, 0, 197, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0,
108-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 196, 198, 75,
109-
26, 237, 186, 126, 74, 0, 1, 19, 61, 250, 254, 150, 6, 163, 86, 0,
110-
0, 0, 0, 156, 9, 53, 70, 77, 194, 172, 226, 190, 160, 23, 141, 31,
111-
196, 236, 120, 84, 107, 116, 110, 205, 212, 164, 48, 143, 224, 119,
112-
115, 144, 225, 207, 228, 49, 3, 0, 0, 0, 39, 168, 127, 189, 18, 209,
113-
50, 130, 61, 249, 224, 77, 91, 119, 75, 140, 171, 218, 60, 106, 84,
114-
193, 224, 111, 159, 45, 25, 182, 255, 151, 70, 104, 70, 51, 175, 83,
115-
83, 120, 178, 62, 215, 154, 181, 237, 76, 231, 56, 133, 102, 223,
116-
246, 189, 104, 18, 195, 42, 151, 220, 240, 78, 245, 64, 112, 90,
117-
139, 200, 70, 9, 144, 245, 142, 205, 162, 130, 217, 110, 191, 231,
118-
184, 36, 71, 173, 105, 78, 104, 199, 27, 1, 160, 6, 177, 68, 34, 22,
119-
224, 174, 159, 50, 42, 53, 143, 251, 61, 65, 82, 2, 0, 0, 0, 139,
120-
161, 56, 237, 157, 233, 116, 185, 12, 196, 217, 30, 184, 96, 146,
121-
164, 150, 251, 140, 3, 158, 71, 77, 130, 169, 233, 128, 60, 221,
122-
108, 98, 247, 124, 28, 145, 30, 204, 146, 1, 14, 104, 21, 236, 252,
123-
114, 187, 150, 4, 37, 93, 254, 107, 46, 123, 96, 206, 209, 39, 91,
124-
61, 214, 71, 4, 118, 24, 221, 216, 152, 135, 71, 93, 155, 81, 50,
125-
14, 128, 30, 108, 170, 1, 235, 59,
86+
1, 0, 0, 0, 1, 0, 0, 0, 0, 148, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
87+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 70,
88+
83, 164, 216, 39, 10, 106, 0, 0, 1, 0, 1, 83, 0, 3, 0, 0, 0, 91, 97,
89+
69, 180, 246, 54, 236, 250, 62, 116, 95, 226, 176, 250, 172, 150,
90+
38, 157, 38, 110, 3, 110, 130, 133, 102, 14, 42, 118, 151, 177, 74,
91+
49, 180, 127, 245, 54, 1, 13, 208, 197, 129, 101, 36, 193, 85, 161,
92+
48, 175, 182, 23, 26, 150, 52, 204, 60, 96, 233, 248, 140, 33, 212,
93+
16, 175, 111, 218, 54, 195, 97, 239, 148, 66, 48, 24, 183, 0, 254,
94+
113, 31, 157, 136, 188, 202, 183, 37, 203, 248, 36, 216, 177, 227,
95+
159, 93, 238, 171, 167, 173, 224, 196, 144, 193, 203, 88, 88, 133,
96+
174, 71, 142, 254, 17, 121, 254, 208, 0, 153, 1, 0, 0, 0, 237, 83,
97+
2, 61, 227, 140, 40, 48, 68, 54, 55, 57, 228, 108, 104, 1, 19, 138,
98+
156, 96, 249, 111, 250, 212, 130, 57, 47, 54, 4, 5, 48, 192, 174,
99+
157, 141, 112, 18, 255, 0, 64, 136, 164, 130, 37, 210, 47, 0, 253,
100+
75, 4, 203, 167, 187, 45, 253, 192, 154, 0, 4, 0, 0, 0, 0, 0, 0, 0,
101+
0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102+
0, 0, 0, 0, 0, 201, 78, 254, 108, 214, 2, 223, 68, 0, 0, 43, 0, 0,
103+
0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104+
0, 0, 0, 0, 0, 0, 0, 78, 17, 123, 28, 100, 171, 124, 219, 0, 0, 253,
105+
0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
106+
0, 0, 0, 0, 0, 0, 0, 0, 0, 126, 220, 103, 34, 32, 110, 222, 30, 0,
107+
0, 197, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 196, 198, 75, 26, 237, 186, 126,
109+
74, 0, 1, 19, 61, 250, 254, 150, 6, 163, 86, 0, 0, 0, 0, 156, 9, 53,
110+
70, 77, 194, 172, 226, 190, 160, 23, 141, 31, 196, 236, 120, 84,
111+
107, 116, 110, 205, 212, 164, 48, 143, 224, 119, 115, 144, 225, 207,
112+
228, 49, 3, 0, 0, 0, 39, 168, 127, 189, 18, 209, 50, 130, 61, 249,
113+
224, 77, 91, 119, 75, 140, 171, 218, 60, 106, 84, 193, 224, 111,
114+
159, 45, 25, 182, 255, 151, 70, 104, 70, 51, 175, 83, 83, 120, 178,
115+
62, 215, 154, 181, 237, 76, 231, 56, 133, 102, 223, 246, 189, 104,
116+
18, 195, 42, 151, 220, 240, 78, 245, 64, 112, 90, 139, 200, 70, 9,
117+
144, 245, 142, 205, 162, 130, 217, 110, 191, 231, 184, 36, 71, 173,
118+
105, 78, 104, 199, 27, 1, 160, 6, 177, 68, 34, 22, 224, 174, 159,
119+
50, 42, 53, 143, 251, 61, 65, 82, 2, 0, 0, 0, 139, 161, 56, 237,
120+
157, 233, 116, 185, 12, 196, 217, 30, 184, 96, 146, 164, 150, 251,
121+
140, 3, 158, 71, 77, 130, 169, 233, 128, 60, 221, 108, 98, 247, 124,
122+
28, 145, 30, 204, 146, 1, 14, 104, 21, 236, 252, 114, 187, 150, 4,
123+
37, 93, 254, 107, 46, 123, 96, 206, 209, 39, 91, 61, 214, 71, 4,
124+
118, 24, 221, 216, 152, 135, 71, 93, 155, 81, 50, 14, 128, 30, 108,
125+
170, 1, 235, 59,
126126
];
127127

128128
const buffer = Buffer.from(data);

program-libs/compressed-account/src/indexer_event/parse.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,16 @@ fn deserialize_instruction<'a>(
286286
));
287287
}
288288
let instruction_discriminator = instruction[0..8].try_into().unwrap();
289-
let instruction = instruction.split_at(12).1;
289+
let instruction = instruction.split_at(8).1;
290290
match instruction_discriminator {
291291
// Cannot be exucted with cpi context -> executing tx
292292
DISCRIMINATOR_INVOKE => {
293293
if accounts.len() < 9 {
294294
return Err(ParseIndexerEventError::DeserializeSystemInstructionError);
295295
}
296296
let accounts = accounts.split_at(9).1;
297-
let data = InstructionDataInvoke::deserialize(&mut &instruction[..])?;
297+
// Skips vec size bytes
298+
let data = InstructionDataInvoke::deserialize(&mut &instruction[4..])?;
298299
Ok(ExecutingSystemInstruction {
299300
output_compressed_accounts: data.output_compressed_accounts,
300301
input_compressed_accounts: data.input_compressed_accounts_with_merkle_context,
@@ -311,7 +312,7 @@ fn deserialize_instruction<'a>(
311312
}
312313
let accounts = accounts.split_at(11).1;
313314
let data = crate::instruction_data::invoke_cpi::InstructionDataInvokeCpi::deserialize(
314-
&mut &instruction[..],
315+
&mut &instruction[4..],
315316
)?;
316317
Ok(ExecutingSystemInstruction {
317318
output_compressed_accounts: data.output_compressed_accounts,

program-tests/create-address-test-program/src/lib.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,34 @@ pub fn process_invoke_cpi<'info>(
134134
};
135135
let seeds: [&[u8]; 2] = [CPI_AUTHORITY_PDA_SEED, &[bump]];
136136
let signer_seeds: [&[&[u8]]; 1] = [&seeds[..]];
137+
let mut account_infos = cpi_accounts.to_account_infos();
138+
139+
// Add remaining accounts
140+
account_infos.extend_from_slice(ctx.remaining_accounts);
141+
142+
// Create instruction
143+
let mut account_metas = cpi_accounts.to_account_metas(None);
144+
ctx.remaining_accounts.iter().for_each(|account| {
145+
account_metas.push(AccountMeta {
146+
pubkey: *account.key,
147+
is_signer: account.is_signer,
148+
is_writable: account.is_writable,
149+
});
150+
});
151+
let instruction = Instruction {
152+
program_id: ctx.accounts.light_system_program.key(),
153+
accounts: account_metas,
154+
data: inputs,
155+
};
137156

138-
let mut cpi_ctx = CpiContext::new_with_signer(
139-
ctx.accounts.light_system_program.to_account_info(),
140-
cpi_accounts,
141-
&signer_seeds,
142-
);
143-
144-
cpi_ctx.remaining_accounts = ctx.remaining_accounts.to_vec();
145157
anchor_lang::solana_program::log::sol_log_compute_units();
146-
light_system_program::cpi::invoke_cpi_with_read_only(cpi_ctx, inputs)?;
158+
159+
// Invoke the instruction with signer seeds
160+
anchor_lang::solana_program::program::invoke_signed(
161+
&instruction,
162+
&account_infos,
163+
&signer_seeds,
164+
)?;
147165
Ok(())
148166
}
149167

program-tests/sdk-pinocchio-test/tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #![cfg(feature = "test-sbf")]
1+
#![cfg(feature = "test-sbf")]
22

33
use borsh::BorshSerialize;
44
use light_compressed_account::{

program-tests/system-cpi-test/src/create_pda.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,7 @@ fn cpi_compressed_pda_transfer_as_program<'info>(
438438

439439
cpi_ctx.remaining_accounts = remaining_accounts;
440440

441-
light_system_program::cpi::invoke_cpi_with_read_only(
442-
cpi_ctx,
443-
inputs_struct.try_to_vec().unwrap(),
444-
)?;
441+
light_system_program::cpi::invoke_cpi_with_read_only(cpi_ctx, inputs_struct)?;
445442
} else {
446443
let cpi_accounts = light_system_program::cpi::accounts::InvokeCpiInstruction {
447444
fee_payer: ctx.accounts.signer.to_account_info(),

program-tests/system-cpi-v2-test/tests/event.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::collections::HashMap;
44

5-
use anchor_lang::prelude::borsh::BorshSerialize;
5+
use anchor_lang::{prelude::borsh::BorshSerialize, Discriminator};
66
use create_address_test_program::create_invoke_cpi_instruction;
77
use light_client::{
88
indexer::{AddressWithTree, Indexer},
@@ -722,7 +722,11 @@ pub async fn perform_test_transaction<R: Rpc>(
722722
let remaining_accounts = to_account_metas(remaining_accounts);
723723
let instruction = create_invoke_cpi_instruction(
724724
payer.pubkey(),
725-
ix_data.try_to_vec().unwrap(),
725+
[
726+
light_system_program::instruction::InvokeCpiWithReadOnly::DISCRIMINATOR.to_vec(),
727+
ix_data.try_to_vec().unwrap(),
728+
]
729+
.concat(),
726730
remaining_accounts,
727731
num_cpis,
728732
);

0 commit comments

Comments
 (0)