Skip to content
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

fix(svm): use free function in handling cctp #718

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions programs/svm-spoke/src/instructions/handle_receive_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ pub struct HandleReceiveMessageParams {
pub authority_bump: u8,
}

// TODO: consider refactoring this to be consistent with using free functions.
impl<'info> HandleReceiveMessage<'info> {
pub fn handle_receive_message(&self, params: &HandleReceiveMessageParams) -> Result<Vec<u8>> {
// Return instruction data for the self invoked CPI based on the received message body.
translate_message(&params.message_body)
}
pub fn handle_receive_message<'info>(
ctx: Context<'_, '_, '_, 'info, HandleReceiveMessage<'info>>,
params: HandleReceiveMessageParams,
) -> Result<()> {
let self_ix_data = translate_message(&params.message_body)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this order of operators is easier to understand


invoke_self(&ctx, &self_ix_data)
}

// TODO: ensure that CCTP blocks re-played messages sent over the bridge. i.e one pauseDeposit Call cant be replayed.
fn translate_message(data: &Vec<u8>) -> Result<Vec<u8>> {
match utils::get_solidity_selector(data)? {
Expand Down Expand Up @@ -99,7 +101,7 @@ fn translate_message(data: &Vec<u8>) -> Result<Vec<u8>> {
// Invokes self CPI for remote domain invoked message calls. We use low level invoke_signed with seeds corresponding to
// the self_authority account and passing all remaining accounts from the context. Instruction data is obtained within
// handle_receive_message by translating the received message body into a valid instruction data for the invoked CPI.
pub fn invoke_self<'info>(ctx: &Context<'_, '_, '_, 'info, HandleReceiveMessage<'info>>, data: &Vec<u8>) -> Result<()> {
fn invoke_self<'info>(ctx: &Context<'_, '_, '_, 'info, HandleReceiveMessage<'info>>, data: &Vec<u8>) -> Result<()> {
let self_authority_seeds: &[&[&[u8]]] = &[&[b"self_authority", &[ctx.bumps.self_authority]]];

let mut accounts = Vec::with_capacity(1 + ctx.remaining_accounts.len());
Expand Down
7 changes: 1 addition & 6 deletions programs/svm-spoke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,11 @@ pub mod svm_spoke {
}

// CCTP methods.
// TODO: consider refactoring this to be consistent with using free functions.
pub fn handle_receive_message<'info>(
ctx: Context<'_, '_, '_, 'info, HandleReceiveMessage<'info>>,
params: HandleReceiveMessageParams,
) -> Result<()> {
let self_ix_data = ctx.accounts.handle_receive_message(&params)?;

invoke_self(&ctx, &self_ix_data)?;

Ok(())
instructions::handle_receive_message(ctx, params)
}

// Slow fill methods.
Expand Down
Loading