Skip to content

Commit

Permalink
Merge branch 'main' into sequence-numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara authored Feb 13, 2025
2 parents 7cefe37 + b5aba80 commit 9953815
Show file tree
Hide file tree
Showing 18 changed files with 785 additions and 269 deletions.
8 changes: 8 additions & 0 deletions chains/solana/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ docker-build-contracts:
-e CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse \
${ANCHOR_IMAGE} anchor build

.PHONY: docker-update-contracts
docker-update-contracts:
docker run --rm \
-v $(shell pwd)/contracts:/workdir \
-v ${TARGET_DIR}:/workdir/target \
-e CARGO_TARGET_DIR=/workdir/target \
-e CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse \
${ANCHOR_IMAGE} anchor keys sync

.PHONY: solana-checks
solana-checks: clippy anchor-go-gen format gomodtidy lint-go rust-tests go-tests build-contracts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use anchor_lang::prelude::*;

use crate::context::{
AcceptOwnership, AddBillingTokenConfig, AddDestChain, AddPriceUpdater, GasPriceUpdate, GetFee,
RemovePriceUpdater, SetTokenTransferFeeConfig, TokenPriceUpdate, UpdateBillingTokenConfig,
UpdateConfig, UpdateDestChainConfig, UpdatePrices,
};
use crate::messages::{GetFeeResult, SVM2AnyMessage};
use crate::state::{BillingTokenConfig, CodeVersion, DestChainConfig, TokenTransferFeeConfig};

pub trait Public {
fn get_fee<'info>(
&self,
ctx: Context<'_, '_, 'info, 'info, GetFee>,
dest_chain_selector: u64,
message: SVM2AnyMessage,
) -> Result<GetFeeResult>;
}

pub trait Prices {
fn update_prices<'info>(
&self,
ctx: Context<'_, '_, 'info, 'info, UpdatePrices<'info>>,
token_updates: Vec<TokenPriceUpdate>,
gas_updates: Vec<GasPriceUpdate>,
) -> Result<()>;
}

pub trait Admin {
fn transfer_ownership(&self, ctx: Context<UpdateConfig>, proposed_owner: Pubkey) -> Result<()>;

fn accept_ownership(&self, ctx: Context<AcceptOwnership>) -> Result<()>;

fn set_default_code_version(
&self,
ctx: Context<UpdateConfig>,
code_version: CodeVersion,
) -> Result<()>;

fn add_billing_token_config(
&self,
ctx: Context<AddBillingTokenConfig>,
config: BillingTokenConfig,
) -> Result<()>;

fn update_billing_token_config(
&self,
ctx: Context<UpdateBillingTokenConfig>,
config: BillingTokenConfig,
) -> Result<()>;

fn add_dest_chain(
&self,
ctx: Context<AddDestChain>,
chain_selector: u64,
dest_chain_config: DestChainConfig,
) -> Result<()>;

fn disable_dest_chain(
&self,
ctx: Context<UpdateDestChainConfig>,
chain_selector: u64,
) -> Result<()>;

fn update_dest_chain_config(
&self,
ctx: Context<UpdateDestChainConfig>,
chain_selector: u64,
dest_chain_config: DestChainConfig,
) -> Result<()>;

fn add_price_updater(
&self,
_ctx: Context<AddPriceUpdater>,
price_updater: Pubkey,
) -> Result<()>;

fn remove_price_updater(
&self,
_ctx: Context<RemovePriceUpdater>,
price_updater: Pubkey,
) -> Result<()>;

fn set_token_transfer_fee_config(
&self,
ctx: Context<SetTokenTransferFeeConfig>,
chain_selector: u64,
mint: Pubkey,
cfg: TokenTransferFeeConfig,
) -> Result<()>;
}
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pub mod v1;
mod interfaces;
mod v1;

pub mod router;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::state::CodeVersion;

use super::interfaces::*;
use super::v1;

/**
* This file routes traffic between multiple versions of our business logic, which can be upgraded in a
* backwards-compatible way and so we can gradually shift traffic between versions (and rollback if there are issues).
* This also supports flexible criteria on how to shift traffic between versions (e.g. per-lane, all at once, etc)
* for each module (e.g. the criteria for admin actions may differ the criteria for public-facing interfaces).
*
* On any code changes to the business logic, a new version of the module should be created and leave the previous one
* untouched. The new version should be added to the match statement below so that traffic can be progressively shifted,
* and is possible to rollback easily via config changes without having to redeploy.
*
* As we currently have a single version, all branches lead to the same outcome, but the code is structured in a way
* that is easy to extend to multiple versions.
*/

pub fn public(
lane_code_version: CodeVersion,
default_code_version: CodeVersion,
) -> &'static dyn Public {
// The lane-specific code version takes precedence over the default code version.
// If the lane just specifies using the default, then we use that one.
match lane_code_version {
CodeVersion::V1 => &v1::public::Impl,
CodeVersion::Default => match default_code_version {
CodeVersion::Default => &v1::public::Impl,
CodeVersion::V1 => &v1::public::Impl,
},
}
}

pub fn prices(code_version: CodeVersion) -> &'static dyn Prices {
match code_version {
CodeVersion::Default => &v1::prices::Impl,
CodeVersion::V1 => &v1::prices::Impl,
}
}

pub fn admin(code_version: CodeVersion) -> &'static dyn Admin {
match code_version {
CodeVersion::Default => &v1::admin::Impl,
CodeVersion::V1 => &v1::admin::Impl,
}
}
Loading

0 comments on commit 9953815

Please sign in to comment.