Skip to content

Commit

Permalink
feat: solana changes according to centralized
Browse files Browse the repository at this point in the history
  • Loading branch information
gcranju committed Dec 11, 2024
1 parent 7d1dba3 commit 1a1cab6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
7 changes: 4 additions & 3 deletions contracts/solana/programs/cluster-connection/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ pub fn call_xcall_handle_message_with_signatures<'info>(
ctx: Context<'_, '_, '_, 'info, ReceiveMessageWithSignatures<'info>>,
from_nid: String,
message: Vec<u8>,
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);
Expand All @@ -104,6 +104,7 @@ pub fn call_xcall_handle_message_with_signatures<'info>(
from_nid,
message,
sequence_no,
conn_sn,
};
args.serialize(&mut data)?;

Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
Expand Down Expand Up @@ -35,8 +35,8 @@ pub fn query_send_message_accounts<'info>(
})
}

pub fn query_recv_message_accounts(
ctx: Context<QueryAccountsCtx>,
pub fn query_recv_message_accounts<'info>(
ctx: Context<'_, '_, '_, 'info, QueryAccountsCtx<'info>>,
src_network: String,
conn_sn: u128,
msg: Vec<u8>,
Expand Down Expand Up @@ -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 {
Expand All @@ -78,15 +78,19 @@ 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,
accounts: xcall_account_metas,
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;
Expand Down Expand Up @@ -171,12 +175,14 @@ pub fn get_handle_message_ix_data(
from_nid: String,
message: Vec<u8>,
sequence_no: u128,
conn_sn: u128,
) -> Result<Vec<u8>> {
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)?;

Expand Down
2 changes: 1 addition & 1 deletion contracts/solana/programs/cluster-connection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1a1cab6

Please sign in to comment.