From 1991320917fe0a75403151ec6f56fb91484307e4 Mon Sep 17 00:00:00 2001 From: John Saigle Date: Thu, 29 Feb 2024 12:32:23 -0500 Subject: [PATCH] solana: Add comments and lint directives for governance entrypoint Add function documentation and some clarifying notes about how the governance program works Add linting directives for cargo dylint to ignore ownership checks in a particular case --- .../src/instructions/governance.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/solana/programs/wormhole-governance/src/instructions/governance.rs b/solana/programs/wormhole-governance/src/instructions/governance.rs index 1b5b849c6..8b9385a15 100644 --- a/solana/programs/wormhole-governance/src/instructions/governance.rs +++ b/solana/programs/wormhole-governance/src/instructions/governance.rs @@ -9,7 +9,7 @@ //! instruction is able to invoke the program's admin instructions. //! //! The instruction needs to be encoded in the VAA payload, with all the -//! accounts. These accounts may be in any order, with two placeholder accounts: +//! accounts. These accounts may be in any order and must include two additional placeholder accounts: //! - [`OWNER`]: the program will replace this account with the governance PDA //! - [`PAYER`]: the program will replace this account with the payer account use anchor_lang::prelude::*; @@ -124,12 +124,21 @@ impl From for Acc { } } +/// Processes a VAA [wormhole_anchor_sdk::wormhole::PostedVaa] sent to this program via a Guardian set. +/// The VAA's payload contains an instruction and relevant Accounts that it requires. This program +/// performs verification of the VAA's contents and then performs a Cross Program Invocation if all +/// verification succeeds. +/// NOTE: `missing_owner_check` is disabled here: The VAA instruction is expected to contain +/// placeholder accounts with Pubkeys set to hard-coded values [OWNER] and [PAYER]. These keys are +/// overwritten. Because they are placeholders, the `owner` field is not important. +#[allow(unknown_lints)] +#[allow(missing_owner_check)] pub fn governance<'info>(ctx: Context<'_, '_, '_, 'info, Governance<'info>>) -> Result<()> { let vaa_data = ctx.accounts.vaa.data(); let mut instruction: Instruction = vaa_data.clone().into(); - // Iterate over a copy of all accounts provided in the VAA payload. + // Iterate over a copy of all accounts provided in the VAA payload. // If the Pubkey for an account is equal to the hard-coded OWNER constant, overwrite with the // governance program's Pubkey. // If the Pubkey for an account is equal to the hard-coded PAYER constant, overwrite with the @@ -137,8 +146,10 @@ pub fn governance<'info>(ctx: Context<'_, '_, '_, 'info, Governance<'info>>) -> // Governance account.) instruction.accounts.iter_mut().for_each(|acc| { if acc.pubkey == OWNER { + // Missing ownership check is OK here acc.pubkey = ctx.accounts.governance.key(); } else if acc.pubkey == PAYER { + // Missing ownership check is OK here acc.pubkey = ctx.accounts.payer.key(); } });