Skip to content

Commit a941941

Browse files
authored
[solana] Reuse accounts (#1216)
* Reuse accounts * add comment
1 parent 0ce4c4c commit a941941

File tree

1 file changed

+6
-2
lines changed
  • target_chains/solana/programs/pyth-solana-receiver/src

1 file changed

+6
-2
lines changed

target_chains/solana/programs/pyth-solana-receiver/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ pub struct PostUpdates<'info> {
269269
/// CHECK: This is just a PDA controlled by the program. There is currently no way to withdraw funds from it.
270270
#[account(mut)]
271271
pub treasury: AccountInfo<'info>,
272-
#[account(init, payer =payer, space = PriceUpdateV1::LEN)]
272+
/// The contraint is such that either the price_update_account is uninitialized or the payer is the write_authority.
273+
/// Pubkey::default() is the SystemProgram on Solana and it can't sign so it's impossible that price_update_account.write_authority == Pubkey::default() once the account is initialized
274+
#[account(init_if_needed, constraint = price_update_account.write_authority == Pubkey::default() || price_update_account.write_authority == payer.key(), payer =payer, space = PriceUpdateV1::LEN)]
273275
pub price_update_account: Account<'info, PriceUpdateV1>,
274276
pub system_program: Program<'info, System>,
275277
}
@@ -288,7 +290,9 @@ pub struct PostUpdatesAtomic<'info> {
288290
#[account(mut, seeds = [TREASURY_SEED.as_ref()], bump)]
289291
/// CHECK: This is just a PDA controlled by the program. There is currently no way to withdraw funds from it.
290292
pub treasury: AccountInfo<'info>,
291-
#[account(init, payer = payer, space = PriceUpdateV1::LEN)]
293+
/// The contraint is such that either the price_update_account is uninitialized or the payer is the write_authority.
294+
/// Pubkey::default() is the SystemProgram on Solana and it can't sign so it's impossible that price_update_account.write_authority == Pubkey::default() once the account is initialized
295+
#[account(init_if_needed, constraint = price_update_account.write_authority == Pubkey::default() || price_update_account.write_authority == payer.key(), payer = payer, space = PriceUpdateV1::LEN)]
292296
pub price_update_account: Account<'info, PriceUpdateV1>,
293297
pub system_program: Program<'info, System>,
294298
}

0 commit comments

Comments
 (0)