Skip to content

Commit

Permalink
chore:sync code (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
KenYuan1987 authored Jun 27, 2024
1 parent 0e24165 commit 7aebbd7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::*;

#[derive(Accounts)]
#[instruction(params: CloseVerifyParams)]
pub struct CloseVerify<'info> {
pub dvn: Signer<'info>,
#[account(mut)]
pub receiver: AccountInfo<'info>,
#[account(
mut,
seeds = [
CONFIRMATIONS_SEED,
&params.packet_header_hash[..],
&params.payload_hash[..],
dvn.key.as_ref()
],
bump = confirmations.bump,
close = receiver
)]
pub confirmations: Account<'info, Confirmations>,
}

impl CloseVerify<'_> {
pub fn apply() -> Result<()> {
Ok(())
}
}

#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
pub struct CloseVerifyParams {
pub packet_header_hash: [u8; 32],
pub payload_hash: [u8; 32],
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::*;
use anchor_lang::{solana_program::keccak::hash as keccak256, system_program};
use anchor_lang::solana_program::keccak::hash as keccak256;
use messagelib_helper::{
endpoint_verify,
packet_v1_codec::{self, PACKET_HEADER_SIZE},
Expand All @@ -23,8 +23,7 @@ pub struct CommitVerification<'info> {
bump = default_receive_config.bump,
)]
pub default_receive_config: Account<'info, ReceiveConfig>,
/// This account is mutable for receiving the reclaimed lamports
#[account(mut, seeds = [ULN_SEED], bump = uln.bump)]
#[account(seeds = [ULN_SEED], bump = uln.bump)]
pub uln: Account<'info, UlnSettings>,
}

Expand Down Expand Up @@ -66,11 +65,7 @@ impl CommitVerification<'_> {
params.payload_hash,
&[ULN_SEED, &[ctx.accounts.uln.bump]],
&ctx.remaining_accounts[dvns_size..],
)?;

// need to reclaim storage after verification, otherwise the lamports of uln account will be changed
// and endpoint_verify::verify() will fail
reclaim_storage(confirmation_accounts, ctx.accounts.uln.as_ref())
)
}
}

Expand All @@ -82,28 +77,6 @@ fn get_receive_config(
UlnConfig::get_config(&default_config.uln, &custom_config.uln)
}

fn reclaim_storage(confirmation_accounts: &[AccountInfo], sol_dest: &AccountInfo) -> Result<()> {
// close accounts
for acc in confirmation_accounts {
// skip if account already closed
if *acc.owner == system_program::ID {
continue;
}

// check if the account is writable to reclaim storage
require!(acc.is_writable, UlnError::InvalidConfirmation);

let lamports = acc.lamports();
sol_dest.add_lamports(lamports)?;
acc.sub_lamports(lamports)?;

acc.assign(&system_program::ID);
acc.realloc(0, false)?;
}

Ok(())
}

pub fn check_verifiable(
config: &UlnConfig,
accounts: &[AccountInfo],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
pub mod close_verify;
pub mod commit_verification;
pub mod init_verify;
pub mod verify;

pub use close_verify::*;
pub use commit_verification::*;
pub use init_verify::*;
pub use verify::*;
4 changes: 4 additions & 0 deletions packages/layerzero-v2/solana/programs/programs/uln/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ pub mod uln {
Verify::apply(&mut ctx, &params)
}

pub fn close_verify(_ctx: Context<CloseVerify>, _params: CloseVerifyParams) -> Result<()> {
CloseVerify::apply()
}

pub fn commit_verification(
mut ctx: Context<CommitVerification>,
params: CommitVerificationParams,
Expand Down

0 comments on commit 7aebbd7

Please sign in to comment.