From 1a1cab644f5eb09aade7502b96f0484636637f62 Mon Sep 17 00:00:00 2001 From: gcranju Date: Wed, 11 Dec 2024 13:11:08 +0545 Subject: [PATCH] feat: solana changes according to centralized --- .../programs/cluster-connection/src/helper.rs | 7 ++++--- .../src/instructions/query_accounts.rs | 20 ++++++++++++------- .../programs/cluster-connection/src/lib.rs | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/contracts/solana/programs/cluster-connection/src/helper.rs b/contracts/solana/programs/cluster-connection/src/helper.rs index 99f1c9ad7..4dc9dfce0 100644 --- a/contracts/solana/programs/cluster-connection/src/helper.rs +++ b/contracts/solana/programs/cluster-connection/src/helper.rs @@ -81,13 +81,13 @@ pub fn call_xcall_handle_message_with_signatures<'info>( ctx: Context<'_, '_, '_, 'info, ReceiveMessageWithSignatures<'info>>, from_nid: String, message: Vec, - connection_sn: u128, + conn_sn: u128, sequence_no: u128, signatures: Vec<[u8; 65]>, ) -> Result<()> { let mut data = vec![]; let dst_nid = get_nid(&ctx.remaining_accounts[1], &ctx.accounts.config); - let message_hash = get_message_hash(&from_nid, &connection_sn, &message, &dst_nid); + let message_hash = get_message_hash(&from_nid, &conn_sn, &message, &dst_nid); let mut unique_validators = Vec::new(); for sig in signatures { let pubkey = recover_pubkey(message_hash, sig); @@ -104,6 +104,7 @@ pub fn call_xcall_handle_message_with_signatures<'info>( from_nid, message, sequence_no, + conn_sn, }; args.serialize(&mut data)?; @@ -181,9 +182,9 @@ pub fn invoke_instruction<'info>( } + #[test] fn test_recover_pubkey() { - // let message = b"message"; let from_nid = "0x2.icon"; let connection_sn = 128; let message = b"hello"; diff --git a/contracts/solana/programs/cluster-connection/src/instructions/query_accounts.rs b/contracts/solana/programs/cluster-connection/src/instructions/query_accounts.rs index 7f1496235..9f21112fc 100644 --- a/contracts/solana/programs/cluster-connection/src/instructions/query_accounts.rs +++ b/contracts/solana/programs/cluster-connection/src/instructions/query_accounts.rs @@ -2,7 +2,7 @@ use anchor_lang::{ prelude::*, solana_program::{ instruction::Instruction, - program::{get_return_data, invoke}, + program::{get_return_data, invoke, invoke_signed}, system_program, }, }; @@ -35,8 +35,8 @@ pub fn query_send_message_accounts<'info>( }) } -pub fn query_recv_message_accounts( - ctx: Context, +pub fn query_recv_message_accounts<'info>( + ctx: Context<'_, '_, '_, 'info, QueryAccountsCtx<'info>>, src_network: String, conn_sn: u128, msg: Vec, @@ -65,8 +65,8 @@ pub fn query_recv_message_accounts( AccountMetadata::new(authority, false), ]; - let mut xcall_account_metas = vec![]; - let mut xcall_account_infos = vec![]; + let mut xcall_account_metas = vec![AccountMeta::new_readonly(config.key(), true)]; + let mut xcall_account_infos = vec![config.to_account_info()]; for (_, account) in ctx.remaining_accounts.iter().enumerate() { if account.is_writable { @@ -78,7 +78,7 @@ pub fn query_recv_message_accounts( xcall_account_infos.push(account.to_account_info()) } - let ix_data = get_handle_message_ix_data(src_network, msg, sequence_no)?; + let ix_data = get_handle_message_ix_data(src_network, msg, sequence_no, conn_sn)?; let ix = Instruction { program_id: config.xcall, @@ -86,7 +86,11 @@ pub fn query_recv_message_accounts( data: ix_data, }; - invoke(&ix, &xcall_account_infos)?; + invoke_signed( + &ix, + &xcall_account_infos, + &[&[Config::SEED_PREFIX.as_bytes(), &[config.bump]]], + )?; let (_, data) = get_return_data().unwrap(); let mut data_slice: &[u8] = &data; @@ -171,12 +175,14 @@ pub fn get_handle_message_ix_data( from_nid: String, message: Vec, sequence_no: u128, + conn_sn: u128, ) -> Result> { let mut ix_args_data = vec![]; let ix_args = xcall_type::HandleMessageArgs { from_nid, message, sequence_no, + conn_sn, }; ix_args.serialize(&mut ix_args_data)?; diff --git a/contracts/solana/programs/cluster-connection/src/lib.rs b/contracts/solana/programs/cluster-connection/src/lib.rs index 60558cc36..43b4aa971 100644 --- a/contracts/solana/programs/cluster-connection/src/lib.rs +++ b/contracts/solana/programs/cluster-connection/src/lib.rs @@ -66,7 +66,7 @@ pub mod centralized_connection { #[allow(unused_variables)] - pub fn receive_message<'info>( + pub fn recv_message<'info>( ctx: Context<'_, '_, '_, 'info, ReceiveMessageWithSignatures<'info>>, src_network: String, conn_sn: u128,