-
Notifications
You must be signed in to change notification settings - Fork 10
[Solana] Execution buffer contract for large TX #897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PabloMansanet
wants to merge
4
commits into
main
Choose a base branch
from
execution-buffer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
chains/solana/contracts/programs/execution-buffer/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "execution_buffer" | ||
version = "0.1.0-dev" | ||
description = "Created with Anchor" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] | ||
name = "execution_buffer" | ||
|
||
[features] | ||
no-entrypoint = [] | ||
no-idl = [] | ||
no-log-ix-name = [] | ||
cpi = ["no-entrypoint"] | ||
default = [] | ||
|
||
[dependencies] | ||
solana-program = "1.17.25" # pin solana to 1.17 | ||
anchor-lang = { version = "0.29.0" } | ||
bytemuck = "1.7" | ||
ccip_common = {path = "../ccip-common"} | ||
ccip_offramp = {path = "../ccip-offramp", features = ["cpi"]} |
113 changes: 113 additions & 0 deletions
113
chains/solana/contracts/programs/execution-buffer/src/context.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use crate::state::{BufferId, BufferedReport}; | ||
use anchor_lang::prelude::*; | ||
use ccip_common::seed; | ||
|
||
pub const ANCHOR_DISCRIMINATOR: usize = 8; // size in bytes | ||
|
||
#[derive(Accounts)] | ||
#[instruction(buffer_id: BufferId, data: Vec<u8>)] | ||
pub struct AppendExecutionReportData<'info> { | ||
#[account( | ||
mut, | ||
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.bytes], | ||
bump, | ||
realloc = ANCHOR_DISCRIMINATOR + BufferedReport::INIT_SPACE + buffered_report.raw_report_data.len() + data.len(), | ||
realloc::payer = authority, | ||
realloc::zero = false | ||
)] | ||
pub buffered_report: Account<'info, BufferedReport>, | ||
|
||
#[account(mut)] | ||
pub authority: Signer<'info>, | ||
pub system_program: Program<'info, System>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
#[instruction(buffer_id: BufferId)] | ||
pub struct InitializeExecutionReportBuffer<'info> { | ||
#[account( | ||
init, | ||
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.bytes], | ||
bump, | ||
space = ANCHOR_DISCRIMINATOR + BufferedReport::INIT_SPACE, | ||
payer = authority, | ||
)] | ||
pub buffered_report: Account<'info, BufferedReport>, | ||
|
||
#[account(mut)] | ||
pub authority: Signer<'info>, | ||
pub system_program: Program<'info, System>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
#[instruction(buffer_id: BufferId)] | ||
pub struct CloseBuffer<'info> { | ||
#[account( | ||
mut, | ||
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.bytes], | ||
bump, | ||
close = authority, | ||
)] | ||
pub buffered_report: Account<'info, BufferedReport>, | ||
|
||
#[account(mut)] | ||
pub authority: Signer<'info>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
#[instruction(buffer_id: BufferId, _token_indices: Vec<u8>)] | ||
pub struct ExecuteContext<'info> { | ||
#[account( | ||
mut, | ||
seeds = [seed::EXECUTION_BUFFER, authority.key().as_ref(), &buffer_id.bytes], | ||
bump, | ||
close = authority, | ||
)] | ||
pub buffered_report: Account<'info, BufferedReport>, | ||
// ------------------------ | ||
// Accounts for offramp CPI: All validations are done by the offramp | ||
/// CHECK: validated during CPI | ||
pub config: UncheckedAccount<'info>, | ||
/// CHECK: validated during CPI | ||
pub reference_addresses: UncheckedAccount<'info>, | ||
/// CHECK: validated during CPI | ||
pub source_chain: UncheckedAccount<'info>, | ||
/// CHECK: validated during CPI | ||
#[account(mut)] | ||
pub commit_report: UncheckedAccount<'info>, | ||
/// CHECK: validated during CPI | ||
pub offramp: UncheckedAccount<'info>, | ||
/// CHECK: validated during CPI | ||
pub allowed_offramp: UncheckedAccount<'info>, | ||
/// CHECK: validated during CPI | ||
pub rmn_remote: UncheckedAccount<'info>, | ||
/// CHECK: validated during CPI | ||
pub rmn_remote_curses: UncheckedAccount<'info>, | ||
/// CHECK: validated during CPI | ||
pub rmn_remote_config: UncheckedAccount<'info>, | ||
/// CHECK: validated during CPI | ||
pub sysvar_instructions: UncheckedAccount<'info>, | ||
|
||
#[account(mut)] | ||
pub authority: Signer<'info>, | ||
pub system_program: Program<'info, System>, | ||
// remaining accounts | ||
// [receiver_program, external_execution_signer, receiver_account, ...user specified accounts from message data for arbitrary messaging] | ||
// + | ||
// [ | ||
// ccip_offramp_pools_signer - derivable PDA [seed::EXTERNAL_TOKEN_POOL, pool_program], seeds::program=offramp (not in lookup table) | ||
// user/sender token account (must be associated token account - derivable PDA [wallet_addr, token_program, mint]) | ||
// per chain per token config (ccip: billing, ccip admin controlled - derivable PDA [chain_selector, mint]) | ||
// pool chain config (pool: custom configs that may include rate limits & remote chain configs, pool admin controlled - derivable [chain_selector, mint]) | ||
// token pool lookup table | ||
// token registry PDA | ||
// pool program | ||
// pool config | ||
// pool token account (must be associated token account - derivable PDA [wallet_addr, token_program, mint]) | ||
// pool signer | ||
// token program | ||
// token mint | ||
// ccip_router_pools_signer - derivable PDA [seed::EXTERNAL_TOKEN_POOL, pool_program], seeds::program=router (present in lookup table) | ||
// ...additional accounts for pool config | ||
// ] x N tokens | ||
} |
70 changes: 70 additions & 0 deletions
70
chains/solana/contracts/programs/execution-buffer/src/lib.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
mod context; | ||
use crate::context::*; | ||
|
||
mod state; | ||
use crate::state::*; | ||
|
||
declare_id!("Buff7ufrtmskFnHtGd9LXaWSAjX6wAMQ2q2s2WSWoSGS"); | ||
|
||
#[program] | ||
pub mod execution_buffer { | ||
|
||
use super::*; | ||
|
||
pub fn manually_execute_buffered<'info>( | ||
ctx: Context<'_, '_, 'info, 'info, ExecuteContext<'info>>, | ||
_buffer_id: BufferId, | ||
token_indexes: Vec<u8>, | ||
) -> Result<()> { | ||
let cpi_accounts = ccip_offramp::cpi::accounts::ExecuteReportContext { | ||
config: ctx.accounts.config.to_account_info(), | ||
reference_addresses: ctx.accounts.reference_addresses.to_account_info(), | ||
source_chain: ctx.accounts.source_chain.to_account_info(), | ||
commit_report: ctx.accounts.commit_report.to_account_info(), | ||
offramp: ctx.accounts.offramp.to_account_info(), | ||
allowed_offramp: ctx.accounts.allowed_offramp.to_account_info(), | ||
authority: ctx.accounts.authority.to_account_info(), | ||
system_program: ctx.accounts.system_program.to_account_info(), | ||
sysvar_instructions: ctx.accounts.sysvar_instructions.to_account_info(), | ||
rmn_remote: ctx.accounts.rmn_remote.to_account_info(), | ||
rmn_remote_curses: ctx.accounts.rmn_remote_curses.to_account_info(), | ||
rmn_remote_config: ctx.accounts.rmn_remote_config.to_account_info(), | ||
}; | ||
let cpi_remaining_accounts = ctx.remaining_accounts.to_vec(); | ||
let cpi_context = CpiContext::new(ctx.accounts.offramp.to_account_info(), cpi_accounts) | ||
.with_remaining_accounts(cpi_remaining_accounts); | ||
ccip_offramp::cpi::manually_execute( | ||
cpi_context, | ||
ctx.accounts.buffered_report.raw_report_data.clone(), | ||
token_indexes, | ||
) | ||
} | ||
|
||
pub fn append_execution_report_data<'info>( | ||
ctx: Context<'_, '_, 'info, 'info, AppendExecutionReportData>, | ||
_buffer_id: BufferId, | ||
data: Vec<u8>, | ||
) -> Result<()> { | ||
ctx.accounts | ||
.buffered_report | ||
.raw_report_data | ||
.extend_from_slice(&data); | ||
Ok(()) | ||
} | ||
|
||
pub fn initialize_execution_report_buffer<'info>( | ||
_ctx: Context<'_, '_, 'info, 'info, InitializeExecutionReportBuffer>, | ||
_buffer_id: BufferId, | ||
) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
pub fn close_buffer<'info>( | ||
_ctx: Context<'_, '_, 'info, 'info, CloseBuffer>, | ||
_buffer_id: BufferId, | ||
) -> Result<()> { | ||
Ok(()) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
chains/solana/contracts/programs/execution-buffer/src/state.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
// Identifies a buffer. Has no specific meaning: it's only used | ||
// by the caller to track which buffer is which in case of uploading several. | ||
#[derive(Clone, Debug, AnchorDeserialize, AnchorSerialize, Eq, PartialEq)] | ||
pub struct BufferId { | ||
pub bytes: [u8; 32], | ||
} | ||
|
||
#[account] | ||
#[derive(Debug, InitSpace)] | ||
pub struct BufferedReport { | ||
#[max_len(0)] | ||
pub raw_report_data: Vec<u8>, | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good overall, but I'm curious if we need to implement a hard cap for the report data size on-chain? While the CPI limits would eventually act as a constraint, I'm just asking out of curiosity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, not sure myself, what's the worst case scenario here? Even if we promise "infinite size TX", I would imagine that users experienced with Solana will expect something to break.