From 8effae6cb593da80da356a894fc4241c07198e8c Mon Sep 17 00:00:00 2001 From: Reisen Date: Tue, 4 May 2021 04:13:18 +0000 Subject: [PATCH] Add a fixed size message type, hacky for now Change-Id: I62f3bbe6bb760c7dd3c21f6bd98de54dfb0bb00b --- .../anchor-bridge/src/api/publish_message.rs | 37 ++++++++++++++++++- .../programs/anchor-bridge/src/lib.rs | 13 +++---- .../programs/anchor-bridge/src/types.rs | 8 ++++ 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/solana/anchor-bridge/programs/anchor-bridge/src/api/publish_message.rs b/solana/anchor-bridge/programs/anchor-bridge/src/api/publish_message.rs index d157a63f..d40d26ea 100644 --- a/solana/anchor-bridge/programs/anchor-bridge/src/api/publish_message.rs +++ b/solana/anchor-bridge/programs/anchor-bridge/src/api/publish_message.rs @@ -3,15 +3,18 @@ use anchor_lang::{prelude::*, solana_program}; use crate::{ accounts, anchor_bridge::Bridge, - types::{BridgeConfig, Index}, + types::{BridgeConfig, Index, Chain}, PublishMessage, Result, MAX_LEN_GUARDIAN_KEYS, }; -// Constant fee for VAA transactions, measured in lamports. +/// Constant fee for VAA transactions, measured in lamports. const VAA_TX_FEE: u64 = 18 * 10000; +/// Maximum size of a posted VAA +pub const MAX_PAYLOAD_SIZE: usize = 400; + pub fn publish_message(bridge: &mut Bridge, ctx: Context) -> Result<()> { Ok(()) } @@ -50,6 +53,36 @@ pub struct SignatureState { pub struct ClaimedVAA { /// hash of the vaa pub hash: [u8; 32], + /// time the vaa was submitted pub vaa_time: u32, } + +/// Record of a posted wormhole message. +#[repr(C)] +#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)] +pub struct PostedMessage { + /// header of the posted VAA + pub vaa_version: u8, + + /// time the vaa was submitted + pub vaa_time: u32, + + /// Account where signatures are stored + pub vaa_signature_account: Pubkey, + + /// time the posted message was created + pub submission_time: u32, + + /// unique nonce for this message + pub nonce: u32, + + /// emitter of the message + pub emitter_chain: Chain, + + /// emitter of the message + pub emitter_address: [u8; 32], + + /// message payload + pub payload: [[u8; 32]; 13], +} diff --git a/solana/anchor-bridge/programs/anchor-bridge/src/lib.rs b/solana/anchor-bridge/programs/anchor-bridge/src/lib.rs index 47eb4148..94fc9b8a 100644 --- a/solana/anchor-bridge/programs/anchor-bridge/src/lib.rs +++ b/solana/anchor-bridge/programs/anchor-bridge/src/lib.rs @@ -3,19 +3,13 @@ use anchor_lang::{prelude::*, solana_program}; mod api; mod types; -use types::{Index, BridgeConfig}; +use api::PostedMessage; +use types::{Index, BridgeConfig, Chain}; // Without this, Anchor's derivation macros break. It requires names with no path components at all // otherwise it errors. use anchor_bridge::Bridge; -/// An enum with labeled network identifiers. These must be consistent accross all wormhole -/// contracts deployed on each chain. -#[repr(u8)] -pub enum Chain { - Solana = 1u8, -} - /// chain id of this chain pub const CHAIN_ID_SOLANA: u8 = Chain::Solana as u8; /// maximum number of guardians @@ -90,6 +84,9 @@ pub struct PublishMessage<'info> { #[account(signer)] pub emitter: AccountInfo<'info>, + /// State struct, derived by #[state], used for associated accounts. + pub state: ProgramState<'info, Bridge>, + /// Instructions used for transaction reflection. pub instructions: AccountInfo<'info>, diff --git a/solana/anchor-bridge/programs/anchor-bridge/src/types.rs b/solana/anchor-bridge/programs/anchor-bridge/src/types.rs index adcc8cb1..89371031 100644 --- a/solana/anchor-bridge/programs/anchor-bridge/src/types.rs +++ b/solana/anchor-bridge/programs/anchor-bridge/src/types.rs @@ -12,3 +12,11 @@ pub struct BridgeConfig { /// this period we still trust the old guardian set. pub guardian_set_expiration_time: u32, } + +/// An enum with labeled network identifiers. These must be consistent accross all wormhole +/// contracts deployed on each chain. +#[repr(u8)] +#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)] +pub enum Chain { + Solana = 1u8, +}