From de794ad120402d429b6689f252e7e116506c7e4e Mon Sep 17 00:00:00 2001 From: Alessandro Manfredi Date: Wed, 18 Dec 2024 08:10:30 +0100 Subject: [PATCH] refactor(solana): adds missing comments to wormhole_reporter --- .../src/contexts/dispatch_root.rs | 144 +++++++++++++++- .../src/contexts/initialize.rs | 163 +++++++++++++++++- .../wormhole-reporter/src/state/config.rs | 72 ++++++-- .../src/state/wormhole_emitter.rs | 18 +- 4 files changed, 366 insertions(+), 31 deletions(-) diff --git a/packages/solana/programs/wormhole-reporter/src/contexts/dispatch_root.rs b/packages/solana/programs/wormhole-reporter/src/contexts/dispatch_root.rs index 4422c76a..46b2d143 100644 --- a/packages/solana/programs/wormhole-reporter/src/contexts/dispatch_root.rs +++ b/packages/solana/programs/wormhole-reporter/src/contexts/dispatch_root.rs @@ -11,10 +11,36 @@ const SEED_PREFIX_SENT: &[u8; 4] = b"sent"; #[derive(Accounts)] pub struct DispatchRoot<'info> { + /// The `payer` is responsible for paying the Wormhole fee to post a message. + /// + /// - **Type**: `Signer<'info>` + /// - **Attributes**: + /// - **`mut`**: Indicates that the `payer` account may be mutated (e.g., lamports debited) during the instruction. + /// + /// ## Purpose: + /// Ensures that the entity dispatching the root has the authority and funds to cover the necessary fees. + /// + /// ## Security Considerations: + /// - **Authority**: Only authorized signers should be able to invoke this instruction to prevent unauthorized fee payments. + /// - **Funds Management**: Ensures that the payer has sufficient lamports to cover the Wormhole fee. #[account(mut)] /// Payer will pay Wormhole fee to post a message. pub payer: Signer<'info>, + /// The `config` account holds the snapshotter's configuration and state. + /// + /// - **Type**: `Account<'info, Config>` + /// - **Attributes**: + /// - **`seeds = [Config::SEED_PREFIX]`**: Specifies that the `config` account is derived from a PDA using `Config::SEED_PREFIX` as the seed. + /// - **`bump`**: The bump seed used in conjunction with the seeds to find the PDA. + /// + /// ## Purpose: + /// Acts as the central configuration hub, storing essential data required for dispatching roots, + /// managing subscriptions, and maintaining program integrity. + /// + /// ## Security Considerations: + /// - **PDA Derivation**: Ensures that the correct `config` account is accessed, preventing unauthorized access. + /// - **Read-Only**: Not marked as mutable, indicating that it won't be modified during this instruction, enhancing security by preventing unintended state changes. #[account( seeds = [Config::SEED_PREFIX], bump, @@ -23,9 +49,29 @@ pub struct DispatchRoot<'info> { /// against the Wormhole accounts in this context. Read-only. pub config: Account<'info, Config>, - /// Wormhole program. + /// The `wormhole_program` is the Wormhole protocol's program. + /// + /// - **Type**: `Program<'info, Wormhole>` + /// + /// ## Purpose: + /// Facilitates interactions with the Wormhole protocol, such as posting messages across chains. + /// + /// ## Security Considerations: + /// - **Program Integrity**: Ensures that interactions are only made with the legitimate Wormhole program. pub wormhole_program: Program<'info, Wormhole>, + /// The `wormhole_bridge` account holds the Wormhole bridge data. + /// + /// - **Type**: `Account<'info, wormhole::BridgeData>` + /// - **Attributes**: + /// - **`mut`**: Indicates that the account may be mutated during the instruction. + /// - **`address = config.wormhole.bridge @ ErrorCode::InvalidWormholeConfig`**: Ensures that the provided `wormhole_bridge` account matches the expected bridge address stored in `config.wormhole.bridge`. + /// + /// ## Purpose: + /// Maintains bridge-specific data required for posting messages via Wormhole. + /// + /// ## Security Considerations: + /// - **Address Constraint**: Prevents unauthorized accounts from being used by enforcing that the `wormhole_bridge` matches the expected address. #[account( mut, address = config.wormhole.bridge @ ErrorCode::InvalidWormholeConfig @@ -34,6 +80,18 @@ pub struct DispatchRoot<'info> { /// be mutable. pub wormhole_bridge: Account<'info, wormhole::BridgeData>, + /// The `wormhole_fee_collector` account collects fees associated with Wormhole messages. + /// + /// - **Type**: `Account<'info, wormhole::FeeCollector>` + /// - **Attributes**: + /// - **`mut`**: Indicates that the account may be mutated during the instruction. + /// - **`address = config.wormhole.fee_collector @ ErrorCode::InvalidWormholeFeeCollector`**: Ensures that the provided `wormhole_fee_collector` account matches the expected fee collector address stored in `config.wormhole.fee_collector`. + /// + /// ## Purpose: + /// Handles the collection and management of fees for Wormhole message dispatches. + /// + /// ## Security Considerations: + /// - **Address Constraint**: Prevents unauthorized accounts from being used by enforcing that the `wormhole_fee_collector` matches the expected address. #[account( mut, address = config.wormhole.fee_collector @ ErrorCode::InvalidWormholeFeeCollector @@ -42,6 +100,19 @@ pub struct DispatchRoot<'info> { /// account be mutable. pub wormhole_fee_collector: Account<'info, wormhole::FeeCollector>, + /// The `wormhole_emitter` account is the program's emitter account. + /// + /// - **Type**: `Account<'info, WormholeEmitter>` + /// - **Attributes**: + /// - **`seeds = [WormholeEmitter::SEED_PREFIX]`**: Specifies the seed used to derive the PDA for the `wormhole_emitter` account. + /// - **`bump`**: The bump seed used in conjunction with the seeds to find the PDA. + /// + /// ## Purpose: + /// Acts as the emitter responsible for generating and managing Wormhole messages. + /// + /// ## Security Considerations: + /// - **PDA Derivation**: Ensures that only the legitimate emitter account is accessed, preventing unauthorized message emissions. + /// - **Read-Only**: Not marked as mutable, indicating that it won't be modified during this instruction, enhancing security by preventing unintended state changes. #[account( seeds = [WormholeEmitter::SEED_PREFIX], bump, @@ -49,6 +120,18 @@ pub struct DispatchRoot<'info> { /// Program's emitter account. Read-only. pub wormhole_emitter: Account<'info, WormholeEmitter>, + /// The `wormhole_sequence` account tracks the sequence number for Wormhole messages. + /// + /// - **Type**: `Account<'info, wormhole::SequenceTracker>` + /// - **Attributes**: + /// - **`mut`**: Indicates that the account may be mutated during the instruction. + /// - **`address = config.wormhole.sequence @ ErrorCode::InvalidWormholeSequence`**: Ensures that the provided `wormhole_sequence` account matches the expected sequence tracker address stored in `config.wormhole.sequence`. + /// + /// ## Purpose: + /// Maintains and updates the sequence number for each Wormhole message, ensuring proper ordering and uniqueness. + /// + /// ## Security Considerations: + /// - **Address Constraint**: Prevents unauthorized accounts from being used by enforcing that the `wormhole_sequence` matches the expected address. #[account( mut, address = config.wormhole.sequence @ ErrorCode::InvalidWormholeSequence @@ -57,6 +140,20 @@ pub struct DispatchRoot<'info> { /// account be mutable. pub wormhole_sequence: Account<'info, wormhole::SequenceTracker>, + /// The `wormhole_message` account represents the Wormhole message to be dispatched. + /// + /// - **Type**: `UncheckedAccount<'info>` + /// - **Attributes**: + /// - **`mut`**: Indicates that the account may be mutated during the instruction. + /// - **`seeds = [SEED_PREFIX_SENT, &wormhole_sequence.next_value().to_le_bytes()[..]]`**: Specifies the seeds used to derive the PDA for the `wormhole_message` account, incorporating a dynamic component based on the sequence number. + /// - **`bump`**: The bump seed used in conjunction with the seeds to find the PDA. + /// + /// ## Purpose: + /// Holds the serialized Wormhole message that will be dispatched to the target chain. + /// + /// ## Security Considerations: + /// - **UncheckedAccount**: Since this is an `UncheckedAccount`, Anchor does not perform type or ownership checks. It is crucial to manually validate that this account is correctly derived and holds valid message data. + /// - **Address Constraint**: Ensures that the `wormhole_message` account is uniquely derived based on the current sequence number, preventing message duplication or replay. #[account( mut, seeds = [ @@ -69,19 +166,56 @@ pub struct DispatchRoot<'info> { /// account be mutable. pub wormhole_message: UncheckedAccount<'info>, - /// CHECK: Snapshotter program + /// The `snapshotter_config` account represents the snapshotter's configuration. + /// + /// - **Type**: `UncheckedAccount<'info>` + /// - **Attributes**: + /// - **`mut`**: Indicates that the account may be mutated during the instruction. + /// - **`address = config.snapshotter_config @ ErrorCode::InvalidSnapshotterConfig`**: Ensures that the provided `snapshotter_config` account matches the expected snapshotter configuration address stored in `config.snapshotter_config`. + /// + /// ## Purpose: + /// Maintains the snapshotter's configuration, ensuring that dispatch operations are consistent with the current configuration. + /// + /// ## Security Considerations: + /// - **Address Constraint**: Enforces that the `snapshotter_config` account provided is the one expected by the `config` account, preventing unauthorized modifications. + /// - **UncheckedAccount**: Requires manual validation to ensure that the account's data aligns with program expectations. #[account( mut, address = config.snapshotter_config @ ErrorCode::InvalidSnapshotterConfig )] + /// CHECK: Snapshotter program pub snapshotter_config: UncheckedAccount<'info>, - /// System program. + /// The `system_program` is the Solana System Program responsible for creating and allocating accounts. + /// + /// - **Type**: `Program<'info, System>` + /// + /// ## Purpose: + /// Facilitates interactions with the Solana runtime, such as account creation, funding, and lamport transfers. + /// + /// ## Security Considerations: + /// - **Standardization**: By referencing the standard System Program, the program ensures compatibility and reliability in account management operations. pub system_program: Program<'info, System>, - /// Clock sysvar. + /// The `clock` sysvar provides access to the Solana cluster's clock data. + /// + /// - **Type**: `Sysvar<'info, Clock>` + /// + /// ## Purpose: + /// Allows the program to access time-related data, such as the current slot, epoch, and unix timestamp. + /// + /// ## Security Considerations: + /// - **Immutable**: Sysvars like `Clock` are read-only, ensuring that programs cannot tamper with time data. pub clock: Sysvar<'info, Clock>, - /// Rent sysvar. + /// The `rent` sysvar provides access to the rent-related data of the Solana cluster. + /// + /// - **Type**: `Sysvar<'info, Rent>` + /// + /// ## Purpose: + /// Allows the program to query rent rates and determine whether an account is rent-exempt. + /// + /// ## Security Considerations: + /// - **Immutable**: Sysvars like `Rent` are read-only, ensuring that programs cannot tamper with rent data. pub rent: Sysvar<'info, Rent>, } diff --git a/packages/solana/programs/wormhole-reporter/src/contexts/initialize.rs b/packages/solana/programs/wormhole-reporter/src/contexts/initialize.rs index dbcec6b3..c98bc05c 100644 --- a/packages/solana/programs/wormhole-reporter/src/contexts/initialize.rs +++ b/packages/solana/programs/wormhole-reporter/src/contexts/initialize.rs @@ -8,38 +8,110 @@ pub const SEED_PREFIX_SENT: &[u8; 4] = b"sent"; #[derive(Accounts)] pub struct Initialize<'info> { + /// The `owner` is a Signer account, indicating that whoever calls this instruction + /// must sign the transaction with their private key. This ensures that the initializer + /// has authority. + /// + /// `#[account(mut)]` is used here because the `owner` account's lamports are used + /// to fund the creation of the `config` and `wormhole_emitter` accounts. + /// + /// ## Attributes + /// + /// - **`mut`**: Marks the `owner` account as mutable, allowing its lamports to be debited. #[account(mut)] /// Whoever initializes the config will be the owner of the program. Signer /// for creating the [`Config`] account and posting a Wormhole message /// indicating that the program is alive. pub owner: Signer<'info>, + /// The `config` account will be created (initialized) by this instruction. + /// + /// The `init` attribute indicates that this account should be created (allocated and assigned) + /// and initialized with the given seeds, bump, and space. + /// + /// - **`payer = owner`**: The `owner` account pays for the rent and creation cost of this account. + /// - **`seeds = [Config::SEED_PREFIX]`**: Sets the PDA (program-derived address) seed that + /// uniquely identifies the `config` account. This ensures that the correct PDA is referenced. + /// - **`bump`**: Used in combination with the seeds to find the PDA. The `bump` ensures a valid PDA + /// that is not already taken by another account. + /// - **`space = Config::MAXIMUM_SIZE`**: Allocates the appropriate amount of space for the `config` account's data based on the `Config` structure. + /// + /// ## Attributes + /// + /// - **`init`**: Indicates that this account should be initialized by the instruction. + /// - **`payer = owner`**: Specifies that the `owner` account will pay for the account's rent and creation. + /// - **`seeds = [Config::SEED_PREFIX]`**: Defines the seed used to derive the PDA for the `config` account. + /// - **`bump`**: Provides the bump seed necessary for PDA derivation. + /// - **`space = Config::MAXIMUM_SIZE`**: Allocates sufficient space for the `config` account's data. + /// + /// ## Purpose: + /// Acts as the central configuration hub, storing essential data required for dispatching roots, + /// managing subscriptions, and maintaining program integrity. + /// + /// ## Security Considerations: + /// - **PDA Derivation**: Ensures that the correct `config` account is accessed, preventing unauthorized access. + /// - **Read-Only**: Not marked as mutable, indicating that it won't be modified during this instruction, enhancing security by preventing unintended state changes. #[account( init, payer = owner, seeds = [Config::SEED_PREFIX], bump, space = Config::MAXIMUM_SIZE, - )] /// Config account, which saves program data useful for other instructions. /// Also saves the payer of the [`initialize`](crate::initialize) instruction /// as the program's owner. pub config: Account<'info, Config>, - /// Wormhole program. + /// The `wormhole_program` is the Wormhole protocol's program. + /// + /// - **Type**: `Program<'info, Wormhole>` + /// + /// ## Purpose: + /// Facilitates interactions with the Wormhole protocol, such as posting messages across chains. + /// + /// ## Security Considerations: + /// - **Program Integrity**: Ensures that interactions are only made with the legitimate Wormhole program. pub wormhole_program: Program<'info, Wormhole>, + /// The `wormhole_bridge` account holds the Wormhole bridge data. + /// + /// - **Type**: `Account<'info, wormhole::BridgeData>` + /// - **Attributes**: + /// - **`mut`**: Indicates that the account may be mutated during the instruction. + /// - **`seeds = [wormhole::BridgeData::SEED_PREFIX]`**: Specifies the seed used to derive the PDA for the `wormhole_bridge` account. + /// - **`bump`**: The bump seed used in conjunction with the seeds to find the PDA. + /// - **`seeds::program = wormhole_program.key`**: Ensures that the PDA is derived using the Wormhole program's ID, preventing cross-program address collisions. + /// + /// ## Purpose: + /// Maintains bridge-specific data required for posting messages via Wormhole. + /// + /// ## Security Considerations: + /// - **Address Constraint**: Prevents unauthorized or incorrect bridge accounts from being used, ensuring that messages are routed through the legitimate bridge. #[account( mut, seeds = [wormhole::BridgeData::SEED_PREFIX], bump, - seeds::program = wormhole_program.key, + seeds::program = wormhole_program.key )] /// Wormhole bridge data account (a.k.a. its config). /// [`wormhole::post_message`] requires this account be mutable. pub wormhole_bridge: Account<'info, wormhole::BridgeData>, + /// The `wormhole_fee_collector` account collects fees associated with Wormhole messages. + /// + /// - **Type**: `Account<'info, wormhole::FeeCollector>` + /// - **Attributes**: + /// - **`mut`**: Indicates that the account may be mutated during the instruction. + /// - **`seeds = [wormhole::FeeCollector::SEED_PREFIX]`**: Specifies the seed used to derive the PDA for the `wormhole_fee_collector` account. + /// - **`bump`**: The bump seed used in conjunction with the seeds to find the PDA. + /// - **`seeds::program = wormhole_program.key`**: Ensures that the PDA is derived using the Wormhole program's ID, preventing cross-program address collisions. + /// + /// ## Purpose: + /// Handles the collection and management of fees for Wormhole message dispatches. + /// + /// ## Security Considerations: + /// - **Address Constraint**: Prevents unauthorized accounts from intercepting or mismanaging fees by enforcing that the `wormhole_fee_collector` matches the expected address. #[account( mut, seeds = [wormhole::FeeCollector::SEED_PREFIX], @@ -51,6 +123,22 @@ pub struct Initialize<'info> { /// [`wormhole::post_message`] requires this account be mutable. pub wormhole_fee_collector: Account<'info, wormhole::FeeCollector>, + /// The `wormhole_emitter` account is the program's emitter account. + /// + /// - **Type**: `Account<'info, WormholeEmitter>` + /// - **Attributes**: + /// - **`init`**: Specifies that this account should be initialized (allocated and assigned) by this instruction. + /// - **`payer = owner`**: The `owner` account will pay for the rent and creation costs of the `wormhole_emitter` account. + /// - **`seeds = [WormholeEmitter::SEED_PREFIX]`**: Defines the seed used to derive the PDA for the `wormhole_emitter` account. + /// - **`bump`**: The bump seed used in conjunction with the seeds to find the PDA. + /// - **`space = WormholeEmitter::MAXIMUM_SIZE`**: Allocates sufficient space for the `wormhole_emitter` account's data based on the `WormholeEmitter` structure's maximum size. + /// + /// ## Purpose: + /// Serves as the emitter responsible for generating and managing Wormhole messages. + /// + /// ## Security Considerations: + /// - **PDA Derivation**: Ensures that only the legitimate emitter account is accessed, preventing unauthorized message emissions. + /// - **Read-Only Access**: Not marked as mutable, preventing unintended state changes and enhancing security. #[account( init, payer = owner, @@ -63,6 +151,21 @@ pub struct Initialize<'info> { /// [`wormhole::post_message`] only needs it to be read-only. pub wormhole_emitter: Account<'info, WormholeEmitter>, + /// The `wormhole_sequence` account tracks the sequence number for Wormhole messages. + /// + /// - **Type**: `UncheckedAccount<'info>` + /// - **Attributes**: + /// - **`mut`**: Indicates that the account may be mutated during the instruction. + /// - **`seeds = [wormhole::SequenceTracker::SEED_PREFIX, wormhole_emitter.key().as_ref()]`**: Specifies the seeds used to derive the PDA for the `wormhole_sequence` account, incorporating the emitter's public key to ensure uniqueness. + /// - **`bump`**: The bump seed used in conjunction with the seeds to find the PDA. + /// - **`seeds::program = wormhole_program.key`**: Ensures that the PDA is derived using the Wormhole program's ID, preventing cross-program address collisions. + /// + /// ## Purpose: + /// Maintains and updates the sequence number for each Wormhole message, ensuring proper ordering and uniqueness. + /// + /// ## Security Considerations: + /// - **Address Constraint**: Enforces that the `wormhole_sequence` account matches the expected address stored in `config.wormhole.sequence`. + /// - **UncheckedAccount**: Since this is an `UncheckedAccount`, Anchor does not perform type or ownership checks. It is crucial to manually validate that this account is correctly derived and holds valid sequence data. #[account( mut, seeds = [ @@ -78,6 +181,20 @@ pub struct Initialize<'info> { /// [`wormhole::post_message`] requires this account be mutable. pub wormhole_sequence: UncheckedAccount<'info>, + /// The `wormhole_message` account represents the Wormhole message to be dispatched. + /// + /// - **Type**: `UncheckedAccount<'info>` + /// - **Attributes**: + /// - **`mut`**: Indicates that the account may be mutated during the instruction. + /// - **`seeds = [SEED_PREFIX_SENT, &wormhole::INITIAL_SEQUENCE.to_le_bytes()[..]]`**: Specifies the seeds used to derive the PDA for the `wormhole_message` account, incorporating a static initial sequence to ensure uniqueness. + /// - **`bump`**: The bump seed used in conjunction with the seeds to find the PDA. + /// + /// ## Purpose: + /// Holds the serialized Wormhole message that will be dispatched to the target chain. + /// + /// ## Security Considerations: + /// - **UncheckedAccount**: Since this is an `UncheckedAccount`, Anchor does not perform type or ownership checks. It is crucial to manually validate that this account is correctly derived and holds valid message data. + /// - **Address Derivation**: Incorporating a static initial sequence ensures that each message account is uniquely derived, preventing address collisions and replay attacks. #[account( mut, seeds = [ @@ -91,15 +208,49 @@ pub struct Initialize<'info> { /// [`wormhole::post_message`] requires this account be mutable. pub wormhole_message: UncheckedAccount<'info>, + /// The `snapshotter_config` account represents the snapshotter's configuration. + /// + /// - **Type**: `UncheckedAccount<'info>` + /// + /// ## Purpose: + /// Maintains the snapshotter's configuration, ensuring that dispatch operations are consistent with the current configuration. + /// + /// ## Security Considerations: + /// - **Address Constraint**: Enforces that the `snapshotter_config` account provided is the one expected by the `config` account, preventing unauthorized modifications. + /// - **UncheckedAccount**: Requires manual validation to ensure that the account's data aligns with program expectations. /// CHECK: Snapshotter program pub snapshotter_config: UncheckedAccount<'info>, - /// Clock sysvar. + /// The `clock` sysvar provides access to the Solana cluster's clock data. + /// + /// - **Type**: `Sysvar<'info, Clock>` + /// + /// ## Purpose: + /// Allows the program to access time-related data, such as the current slot, epoch, and Unix timestamp. + /// + /// ## Security Considerations: + /// - **Immutable**: Sysvars like `Clock` are read-only, ensuring that programs cannot tamper with time data. pub clock: Sysvar<'info, Clock>, - /// Rent sysvar. + /// The `rent` sysvar provides access to the rent-related data of the Solana cluster. + /// + /// - **Type**: `Sysvar<'info, Rent>` + /// + /// ## Purpose: + /// Allows the program to query rent rates and determine whether an account is rent-exempt. + /// + /// ## Security Considerations: + /// - **Immutable**: Sysvars like `Rent` are read-only, ensuring that programs cannot tamper with rent data. pub rent: Sysvar<'info, Rent>, - /// System program. + /// The `system_program` is the Solana System Program responsible for creating and allocating accounts. + /// + /// - **Type**: `Program<'info, System>` + /// + /// ## Purpose: + /// Facilitates interactions with the Solana runtime, such as creating and funding accounts. + /// + /// ## Security Considerations: + /// - **Standardization**: By referencing the standard System Program, the program ensures compatibility and reliability in account management operations. pub system_program: Program<'info, System>, } diff --git a/packages/solana/programs/wormhole-reporter/src/state/config.rs b/packages/solana/programs/wormhole-reporter/src/state/config.rs index 2e4df0bb..bbef4d73 100644 --- a/packages/solana/programs/wormhole-reporter/src/state/config.rs +++ b/packages/solana/programs/wormhole-reporter/src/state/config.rs @@ -1,19 +1,35 @@ use anchor_lang::prelude::*; #[derive(Default, AnchorSerialize, AnchorDeserialize, Clone, PartialEq, Eq)] -/// Wormhole program related addresses. pub struct WormholeAddresses { /// [BridgeData](wormhole_anchor_sdk::wormhole::BridgeData) address. + /// + /// The BridgeData account holds configuration and state information necessary + /// for the Wormhole bridge operations. pub bridge: Pubkey, + /// [FeeCollector](wormhole_anchor_sdk::wormhole::FeeCollector) address. + /// + /// The FeeCollector account is responsible for accumulating fees associated + /// with Wormhole message dispatches. It ensures that the program can cover + /// the costs of cross-chain messaging. pub fee_collector: Pubkey, + /// [SequenceTracker](wormhole_anchor_sdk::wormhole::SequenceTracker) address. + /// + /// The SequenceTracker account maintains the sequence number for Wormhole messages, + /// ensuring proper ordering and uniqueness. It is crucial for preventing replay + /// attacks and maintaining message integrity. pub sequence: Pubkey, } impl WormholeAddresses { + /// The total length of the `WormholeAddresses` structure in bytes. + /// + /// This constant is used to allocate sufficient space for the `WormholeAddresses` + /// within other account structures, such as `Config`. pub const LEN: usize = - 32 // config + 32 // bridge + 32 // fee_collector + 32 // sequence ; @@ -21,31 +37,59 @@ impl WormholeAddresses { #[account] #[derive(Default)] -/// Config account data. pub struct Config { /// Program's owner. + /// + /// The `owner` field holds the public key of the entity that owns the program. + /// This account is typically the signer who initializes the program and has administrative + /// privileges over its operations. pub owner: Pubkey, + /// Wormhole program's relevant addresses. + /// + /// The `wormhole` field contains a `WormholeAddresses` structure, which encapsulates + /// all necessary Wormhole-related public keys required for cross-chain messaging. pub wormhole: WormholeAddresses, - /// AKA nonce. Just zero, but saving this information in this account - /// anyway. + + /// Batch identifier. + /// + /// The `batch_id` serves as an identifier for batches of operations or messages. + /// It can be used to group related actions or track the program's state across different + /// operational phases. pub batch_id: u32, - /// AKA consistency level. u8 representation of Solana's - /// [Finality](wormhole_anchor_sdk::wormhole::Finality). + + /// Finality level. + /// + /// The `finality` field represents the consistency level for Solana transactions, + /// typically corresponding to Solana's [Finality](wormhole_anchor_sdk::wormhole::Finality) + /// enum. It determines how finalized a transaction should be before it's considered + /// complete or irreversible. pub finality: u8, - /// Snapshotter config address. - pub snapshotter_config: Pubkey + + /// Snapshotter configuration address. + /// + /// The `snapshotter_config` holds the public key of the Snapshotter program's configuration + /// account. This allows the program to interact with the Snapshotter for maintaining + /// consistent states or snapshots of data as required. + pub snapshotter_config: Pubkey, } impl Config { - pub const MAXIMUM_SIZE: usize = 8 // discriminator + /// The maximum size of the `Config` account in bytes. + /// + /// This constant ensures that the `Config` account has enough allocated space to store + /// all its fields, including the discriminator used by Anchor. + pub const MAXIMUM_SIZE: usize = 8 // Discriminator + 32 // owner - + WormholeAddresses::LEN + + WormholeAddresses::LEN // wormhole + 4 // batch_id + 1 // finality + 32 // snapshotter_config - ; - /// AKA `b"config"`. + + /// The seed prefix used for deriving the PDA (Program Derived Address) of the `Config` account. + /// + /// Using a consistent seed prefix ensures that the `Config` account can be reliably + /// derived and accessed across different instructions and transactions. pub const SEED_PREFIX: &'static [u8; 6] = b"config"; -} \ No newline at end of file +} diff --git a/packages/solana/programs/wormhole-reporter/src/state/wormhole_emitter.rs b/packages/solana/programs/wormhole-reporter/src/state/wormhole_emitter.rs index 28729c0b..805f603c 100644 --- a/packages/solana/programs/wormhole-reporter/src/state/wormhole_emitter.rs +++ b/packages/solana/programs/wormhole-reporter/src/state/wormhole_emitter.rs @@ -3,17 +3,23 @@ use wormhole_anchor_sdk::wormhole; #[account] #[derive(Default)] -/// Wormhole emitter account. pub struct WormholeEmitter { /// PDA bump. pub bump: u8, } impl WormholeEmitter { - pub const MAXIMUM_SIZE: usize = 8 // discriminator - + 1 // bump - ; - /// AKA `b"emitter` (see - /// [`SEED_PREFIX_EMITTER`](wormhole::SEED_PREFIX_EMITTER)). + /// The maximum size of the `WormholeEmitter` account in bytes. + /// + /// This constant ensures that the account has enough allocated space to store + /// all its fields, including the discriminator used by Anchor. + pub const MAXIMUM_SIZE: usize = 8 // Discriminator (Anchor) + + 1 // bump + ; + + /// The seed prefix used for deriving the PDA (Program Derived Address) of the `WormholeEmitter` account. + /// + /// Using a consistent seed prefix ensures that the `WormholeEmitter` account can be reliably + /// derived and accessed across different instructions and transactions. pub const SEED_PREFIX: &'static [u8; 7] = wormhole::SEED_PREFIX_EMITTER; }