Skip to content

Commit 04b0790

Browse files
committed
Address review comments
1 parent 40985c2 commit 04b0790

File tree

13 files changed

+155
-46
lines changed

13 files changed

+155
-46
lines changed

chains/solana/contracts/Cargo.lock

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

chains/solana/contracts/programs/execution-buffer/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ default = []
1717

1818
[dependencies]
1919
solana-program = "1.17.25" # pin solana to 1.17
20-
anchor-lang = { version = "0.29.0", features = ["init-if-needed"] }
21-
anchor-spl = "0.29.0"
20+
anchor-lang = { version = "0.29.0" }
2221
bytemuck = "1.7"
23-
ethnum = "1.5"
2422
ccip_common = {path = "../ccip-common"}
2523
ccip_offramp = {path = "../ccip-offramp", features = ["cpi"]}

chains/solana/contracts/programs/execution-buffer/src/context.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
use crate::state::BufferedReport;
1+
use crate::state::{BufferId, BufferedReport};
22
use anchor_lang::prelude::*;
33
use ccip_common::seed;
44

55
pub const ANCHOR_DISCRIMINATOR: usize = 8; // size in bytes
66

77
#[derive(Accounts)]
8-
#[instruction(buffer_id: u64, data: Vec<u8>)]
8+
#[instruction(buffer_id: BufferId, data: Vec<u8>)]
99
pub struct AppendExecutionReportData<'info> {
1010
#[account(
1111
mut,
12-
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.to_le_bytes()],
12+
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.bytes],
1313
bump,
1414
realloc = ANCHOR_DISCRIMINATOR + BufferedReport::INIT_SPACE + buffered_report.raw_report_data.len() + data.len(),
1515
realloc::payer = authority,
@@ -23,11 +23,11 @@ pub struct AppendExecutionReportData<'info> {
2323
}
2424

2525
#[derive(Accounts)]
26-
#[instruction(buffer_id: u64)]
26+
#[instruction(buffer_id: BufferId)]
2727
pub struct InitializeExecutionReportBuffer<'info> {
2828
#[account(
2929
init,
30-
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.to_le_bytes()],
30+
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.bytes],
3131
bump,
3232
space = ANCHOR_DISCRIMINATOR + BufferedReport::INIT_SPACE,
3333
payer = authority,
@@ -40,11 +40,11 @@ pub struct InitializeExecutionReportBuffer<'info> {
4040
}
4141

4242
#[derive(Accounts)]
43-
#[instruction(buffer_id: u64)]
43+
#[instruction(buffer_id: BufferId)]
4444
pub struct CloseBuffer<'info> {
4545
#[account(
4646
mut,
47-
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.to_le_bytes()],
47+
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.bytes],
4848
bump,
4949
close = authority,
5050
)]
@@ -55,11 +55,11 @@ pub struct CloseBuffer<'info> {
5555
}
5656

5757
#[derive(Accounts)]
58-
#[instruction(buffer_id: u64, _token_indices: Vec<u8>)]
58+
#[instruction(buffer_id: BufferId, _token_indices: Vec<u8>)]
5959
pub struct ExecuteContext<'info> {
6060
#[account(
6161
mut,
62-
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.to_le_bytes()],
62+
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.bytes],
6363
bump,
6464
close = authority,
6565
)]

chains/solana/contracts/programs/execution-buffer/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ mod context;
44
use crate::context::*;
55

66
mod state;
7+
use crate::state::*;
78

89
declare_id!("buffGjr75PtEtV6D3pbKhaq59CR2qp4mwZDYGspggxZ");
910

1011
#[program]
1112
pub mod execution_buffer {
13+
1214
use super::*;
1315

1416
pub fn manually_execute_buffered<'info>(
1517
ctx: Context<'_, '_, 'info, 'info, ExecuteContext<'info>>,
16-
_buffer_id: u64,
18+
_buffer_id: BufferId,
1719
token_indexes: Vec<u8>,
1820
) -> Result<()> {
1921
let cpi_accounts = ccip_offramp::cpi::accounts::ExecuteReportContext {
@@ -42,7 +44,7 @@ pub mod execution_buffer {
4244

4345
pub fn append_execution_report_data<'info>(
4446
ctx: Context<'_, '_, 'info, 'info, AppendExecutionReportData>,
45-
_buffer_id: u64,
47+
_buffer_id: BufferId,
4648
data: Vec<u8>,
4749
) -> Result<()> {
4850
ctx.accounts
@@ -54,14 +56,14 @@ pub mod execution_buffer {
5456

5557
pub fn initialize_execution_report_buffer<'info>(
5658
_ctx: Context<'_, '_, 'info, 'info, InitializeExecutionReportBuffer>,
57-
_buffer_id: u64,
59+
_buffer_id: BufferId,
5860
) -> Result<()> {
5961
Ok(())
6062
}
6163

6264
pub fn close_buffer<'info>(
6365
_ctx: Context<'_, '_, 'info, 'info, CloseBuffer>,
64-
_buffer_id: u64,
66+
_buffer_id: BufferId,
6567
) -> Result<()> {
6668
Ok(())
6769
}

chains/solana/contracts/programs/execution-buffer/src/state.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
use anchor_lang::prelude::*;
22

3+
// Identifies a buffer. Has no specific meaning: it's only used
4+
// by the caller to track which buffer is which in case of uploading several.
5+
#[derive(Clone, Debug, AnchorDeserialize, AnchorSerialize, Eq, PartialEq)]
6+
pub struct BufferId {
7+
pub bytes: [u8; 32],
8+
}
9+
310
#[account]
411
#[derive(Debug, InitSpace)]
512
pub struct BufferedReport {

chains/solana/contracts/target/idl/execution_buffer.json

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@
7474
"args": [
7575
{
7676
"name": "bufferId",
77-
"type": "u64"
77+
"type": {
78+
"defined": "BufferId"
79+
}
7880
},
7981
{
8082
"name": "tokenIndexes",
@@ -104,7 +106,9 @@
104106
"args": [
105107
{
106108
"name": "bufferId",
107-
"type": "u64"
109+
"type": {
110+
"defined": "BufferId"
111+
}
108112
},
109113
{
110114
"name": "data",
@@ -134,7 +138,9 @@
134138
"args": [
135139
{
136140
"name": "bufferId",
137-
"type": "u64"
141+
"type": {
142+
"defined": "BufferId"
143+
}
138144
}
139145
]
140146
},
@@ -155,7 +161,9 @@
155161
"args": [
156162
{
157163
"name": "bufferId",
158-
"type": "u64"
164+
"type": {
165+
"defined": "BufferId"
166+
}
159167
}
160168
]
161169
}
@@ -173,5 +181,24 @@
173181
]
174182
}
175183
}
184+
],
185+
"types": [
186+
{
187+
"name": "BufferId",
188+
"type": {
189+
"kind": "struct",
190+
"fields": [
191+
{
192+
"name": "bytes",
193+
"type": {
194+
"array": [
195+
"u8",
196+
32
197+
]
198+
}
199+
}
200+
]
201+
}
202+
}
176203
]
177204
}

chains/solana/contracts/target/types/execution_buffer.ts

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export type ExecutionBuffer = {
7474
"args": [
7575
{
7676
"name": "bufferId",
77-
"type": "u64"
77+
"type": {
78+
"defined": "BufferId"
79+
}
7880
},
7981
{
8082
"name": "tokenIndexes",
@@ -104,7 +106,9 @@ export type ExecutionBuffer = {
104106
"args": [
105107
{
106108
"name": "bufferId",
107-
"type": "u64"
109+
"type": {
110+
"defined": "BufferId"
111+
}
108112
},
109113
{
110114
"name": "data",
@@ -134,7 +138,9 @@ export type ExecutionBuffer = {
134138
"args": [
135139
{
136140
"name": "bufferId",
137-
"type": "u64"
141+
"type": {
142+
"defined": "BufferId"
143+
}
138144
}
139145
]
140146
},
@@ -155,7 +161,9 @@ export type ExecutionBuffer = {
155161
"args": [
156162
{
157163
"name": "bufferId",
158-
"type": "u64"
164+
"type": {
165+
"defined": "BufferId"
166+
}
159167
}
160168
]
161169
}
@@ -173,6 +181,25 @@ export type ExecutionBuffer = {
173181
]
174182
}
175183
}
184+
],
185+
"types": [
186+
{
187+
"name": "BufferId",
188+
"type": {
189+
"kind": "struct",
190+
"fields": [
191+
{
192+
"name": "bytes",
193+
"type": {
194+
"array": [
195+
"u8",
196+
32
197+
]
198+
}
199+
}
200+
]
201+
}
202+
}
176203
]
177204
};
178205

@@ -252,7 +279,9 @@ export const IDL: ExecutionBuffer = {
252279
"args": [
253280
{
254281
"name": "bufferId",
255-
"type": "u64"
282+
"type": {
283+
"defined": "BufferId"
284+
}
256285
},
257286
{
258287
"name": "tokenIndexes",
@@ -282,7 +311,9 @@ export const IDL: ExecutionBuffer = {
282311
"args": [
283312
{
284313
"name": "bufferId",
285-
"type": "u64"
314+
"type": {
315+
"defined": "BufferId"
316+
}
286317
},
287318
{
288319
"name": "data",
@@ -312,7 +343,9 @@ export const IDL: ExecutionBuffer = {
312343
"args": [
313344
{
314345
"name": "bufferId",
315-
"type": "u64"
346+
"type": {
347+
"defined": "BufferId"
348+
}
316349
}
317350
]
318351
},
@@ -333,7 +366,9 @@ export const IDL: ExecutionBuffer = {
333366
"args": [
334367
{
335368
"name": "bufferId",
336-
"type": "u64"
369+
"type": {
370+
"defined": "BufferId"
371+
}
337372
}
338373
]
339374
}
@@ -351,5 +386,24 @@ export const IDL: ExecutionBuffer = {
351386
]
352387
}
353388
}
389+
],
390+
"types": [
391+
{
392+
"name": "BufferId",
393+
"type": {
394+
"kind": "struct",
395+
"fields": [
396+
{
397+
"name": "bytes",
398+
"type": {
399+
"array": [
400+
"u8",
401+
32
402+
]
403+
}
404+
}
405+
]
406+
}
407+
}
354408
]
355409
};

chains/solana/contracts/tests/ccip/ccip_router_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9520,11 +9520,10 @@ func TestCCIPRouter(t *testing.T) {
95209520
testutils.SendAndFailWithRPCError(ctx, t, solanaGoClient, []solana.Instruction{instruction}, transmitter, config.DefaultCommitment, []string{"VersionedTransaction too large"})
95219521
// We now build a buffer for the report and CPI to the executor instead.
95229522

9523-
// Arbitrary number decided by the caller, as long as it's not repeated between reports.
9524-
bufferID := uint64(0)
9523+
// Arbitrary ID decided by the caller, as long as it's not repeated between reports.
9524+
bufferID := execution_buffer.BufferId{Bytes: [32]uint8{1, 2, 3, 4, 5}}
95259525

9526-
bufferIDLittleEndian := common.Uint64ToLE(bufferID)
9527-
bufferPDA, _, _ := solana.FindProgramAddress([][]byte{[]byte("execution_buffer"), transmitter.PublicKey().Bytes(), bufferIDLittleEndian}, config.ExecutionBuffer)
9526+
bufferPDA, _, _ := solana.FindProgramAddress([][]byte{[]byte("execution_buffer"), transmitter.PublicKey().Bytes(), bufferID.Bytes[:]}, config.ExecutionBuffer)
95289527

95299528
bufferInitIx, err := execution_buffer.NewInitializeExecutionReportBufferInstruction(bufferID, bufferPDA, transmitter.PublicKey(), solana.SystemProgramID).ValidateAndBuild()
95309529
require.NoError(t, err)

chains/solana/gobindings/execution_buffer/AppendExecutionReportData.go

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

0 commit comments

Comments
 (0)