Skip to content

Commit

Permalink
Merge branch 'hyperlane-xyz:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mshojaei-txfusion authored Jan 21, 2025
2 parents aec3579 + e8fb7ef commit 9f42411
Show file tree
Hide file tree
Showing 40 changed files with 1,427 additions and 621 deletions.
78 changes: 51 additions & 27 deletions rust/main/utils/run-locally/src/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ const SBF_OUT_PATH: &str = "target/dist";
const SOLANA_LOCAL_CHAIN_ID: &str = "13375";
const SOLANA_REMOTE_CHAIN_ID: &str = "13376";

const SEALEVELTEST1_IGP_PROGRAM_ID: &str = "GwHaw8ewMyzZn9vvrZEnTEAAYpLdkGYs195XWcLDCN4U";
const SEALEVELTEST2_IGP_PROGRAM_ID: &str = "FArd4tEikwz2fk3MB7S9kC82NGhkgT6f9aXi3C5cw1E5";

// TODO: use a temp dir instead!
pub const SOLANA_CHECKPOINT_LOCATION: &str =
"/tmp/test_sealevel_checkpoints_0x70997970c51812dc3a010c7d01b50e0d17dc79c8";

const SOLANA_GAS_ORACLE_CONFIG_FILE: &str =
"../sealevel/environments/local-e2e/gas-oracle-configs.json";
const SOLANA_OVERHEAD_CONFIG_FILE: &str = "../sealevel/environments/local-e2e/overheads.json";

// Install the CLI tools and return the path to the bin dir.
#[apply(as_task)]
Expand Down Expand Up @@ -233,23 +235,41 @@ pub fn start_solana_test_validator(
.cmd("deploy")
.arg("environment", SOLANA_ENV_NAME)
.arg("environments-dir", SOLANA_ENVS_DIR)
.arg("built-so-dir", SBF_OUT_PATH)
.arg("overhead-config-file", SOLANA_OVERHEAD_CONFIG_FILE);
.arg("built-so-dir", SBF_OUT_PATH);

// Deploy sealeveltest1 core
sealevel_client_deploy_core
.clone()
.arg("local-domain", SOLANA_LOCAL_CHAIN_ID)
.arg(
"remote-domains",
[SOLANA_REMOTE_CHAIN_ID, "9913371", "9913372", "9913373"].join(","),
)
.arg("chain", "sealeveltest1")
.run()
.join();

// Deploy sealeveltest2 core
sealevel_client_deploy_core
.arg("local-domain", SOLANA_REMOTE_CHAIN_ID)
.arg("remote-domains", SOLANA_LOCAL_CHAIN_ID)
.arg("chain", "sealeveltest2")
.run()
.join();

let igp_configure_command = sealevel_client
.clone()
.cmd("igp")
.cmd("configure")
.arg("gas-oracle-config-file", SOLANA_GAS_ORACLE_CONFIG_FILE)
.arg("chain-config-file", SOLANA_CHAIN_CONFIG_FILE);

// Configure sealeveltest1 IGP
igp_configure_command
.clone()
.arg("program-id", SEALEVELTEST1_IGP_PROGRAM_ID)
.arg("chain", "sealeveltest1")
.run()
.join();

// Configure sealeveltest2 IGP
igp_configure_command
.arg("program-id", SEALEVELTEST2_IGP_PROGRAM_ID)
.arg("chain", "sealeveltest2")
.run()
.join();
Expand Down Expand Up @@ -294,40 +314,44 @@ pub fn start_solana_test_validator(
.run()
.join();

// So we can test paying for gas with a different IGP account
const ALTERNATIVE_SALT: &str =
"0x0000000000000000000000000000000000000000000000000000000000000001";
const ALTERNATIVE_IGP_ACCOUNT: &str = "8EniU8dQaGQ3HWWtT77V7hrksheygvEu6TtzJ3pX1nKM";

sealevel_client
.clone()
.cmd("igp")
.cmd("init-igp-account")
.arg("program-id", "GwHaw8ewMyzZn9vvrZEnTEAAYpLdkGYs195XWcLDCN4U")
.arg("program-id", SEALEVELTEST1_IGP_PROGRAM_ID)
.arg("environment", SOLANA_ENV_NAME)
.arg("environments-dir", SOLANA_ENVS_DIR)
.arg("chain", "sealeveltest1")
.arg("chain-config-file", SOLANA_CHAIN_CONFIG_FILE)
.arg("gas-oracle-config-file", SOLANA_GAS_ORACLE_CONFIG_FILE)
.arg(
"account-salt",
"0x0000000000000000000000000000000000000000000000000000000000000001",
)
.arg("account-salt", ALTERNATIVE_SALT)
.run()
.join();

sealevel_client
.clone()
.cmd("igp")
.cmd("init-overhead-igp-account")
.arg("program-id", "GwHaw8ewMyzZn9vvrZEnTEAAYpLdkGYs195XWcLDCN4U")
.arg("program-id", SEALEVELTEST1_IGP_PROGRAM_ID)
.arg("environment", SOLANA_ENV_NAME)
.arg("environments-dir", SOLANA_ENVS_DIR)
.arg("chain", "sealeveltest1")
.arg("inner-igp-account", ALTERNATIVE_IGP_ACCOUNT)
.arg("account-salt", ALTERNATIVE_SALT)
.run()
.join();

sealevel_client
.cmd("igp")
.cmd("configure")
.arg("program-id", SEALEVELTEST1_IGP_PROGRAM_ID)
.arg("gas-oracle-config-file", SOLANA_GAS_ORACLE_CONFIG_FILE)
.arg("chain-config-file", SOLANA_CHAIN_CONFIG_FILE)
.arg("overhead-config-file", SOLANA_OVERHEAD_CONFIG_FILE)
.arg(
"inner-igp-account",
"8EniU8dQaGQ3HWWtT77V7hrksheygvEu6TtzJ3pX1nKM",
)
.arg(
"account-salt",
"0x0000000000000000000000000000000000000000000000000000000000000001",
)
.arg("chain", "sealeveltest1")
.arg("account-salt", ALTERNATIVE_SALT)
.run()
.join();

Expand Down Expand Up @@ -372,7 +396,7 @@ pub fn initiate_solana_hyperlane_transfer(
sealevel_client(&solana_cli_tools_path, &solana_config_path)
.cmd("igp")
.cmd("pay-for-gas")
.arg("program-id", "GwHaw8ewMyzZn9vvrZEnTEAAYpLdkGYs195XWcLDCN4U")
.arg("program-id", SEALEVELTEST1_IGP_PROGRAM_ID)
.arg("message-id", message_id.clone())
.arg("destination-domain", SOLANA_REMOTE_CHAIN_ID)
.arg("gas", "100000")
Expand Down Expand Up @@ -419,7 +443,7 @@ pub fn initiate_solana_non_matching_igp_paying_transfer(
sealevel_client(&solana_cli_tools_path, &solana_config_path)
.cmd("igp")
.cmd("pay-for-gas")
.arg("program-id", "GwHaw8ewMyzZn9vvrZEnTEAAYpLdkGYs195XWcLDCN4U")
.arg("program-id", SEALEVELTEST1_IGP_PROGRAM_ID)
.arg("message-id", non_matching_igp_message_id.clone())
.arg("destination-domain", SOLANA_REMOTE_CHAIN_ID)
.arg("gas", "100000")
Expand Down
94 changes: 2 additions & 92 deletions rust/sealevel/client/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use serde::{Deserialize, Serialize};
use solana_program::pubkey::Pubkey;
use solana_sdk::{compute_budget, compute_budget::ComputeBudgetInstruction};

use std::collections::HashMap;
use std::{fs::File, path::Path};

use crate::cmd_utils::get_compute_unit_price_micro_lamports_for_chain_name;
Expand All @@ -17,7 +16,6 @@ use crate::{
Context, CoreCmd, CoreDeploy, CoreSubCmd,
};
use hyperlane_core::H256;
use hyperlane_sealevel_igp::accounts::{SOL_DECIMALS, TOKEN_EXCHANGE_RATE_SCALE};

pub(crate) fn adjust_gas_price_if_needed(chain_name: &str, ctx: &mut Context) {
if chain_name.eq("solanamainnet") {
Expand Down Expand Up @@ -206,56 +204,9 @@ fn deploy_validator_announce(
program_id
}

#[allow(clippy::too_many_arguments)]
/// Deploys the IGP program and initializes the zero salt IGP and overhead IGP accounts.
/// Configuration of gas oracles is expected to be done separately.
fn deploy_igp(ctx: &mut Context, core: &CoreDeploy, key_dir: &Path) -> (Pubkey, Pubkey, Pubkey) {
use hyperlane_sealevel_igp::{
accounts::{GasOracle, RemoteGasData},
instruction::{GasOracleConfig, GasOverheadConfig},
};

let mut gas_oracle_configs = core
.gas_oracle_config_file
.as_deref()
.map(|p| {
let file = File::open(p).expect("Failed to open oracle config file");
serde_json::from_reader::<_, Vec<GasOracleConfig>>(file)
.expect("Failed to parse oracle config file")
})
.unwrap_or_default()
.into_iter()
.filter(|c| c.domain != core.local_domain)
.map(|c| (c.domain, c))
.collect::<HashMap<_, _>>();
for &remote in &core.remote_domains {
gas_oracle_configs
.entry(remote)
.or_insert_with(|| GasOracleConfig {
domain: remote,
gas_oracle: Some(GasOracle::RemoteGasData(RemoteGasData {
token_exchange_rate: TOKEN_EXCHANGE_RATE_SCALE,
gas_price: 1,
token_decimals: SOL_DECIMALS,
})),
});
}
let gas_oracle_configs = gas_oracle_configs.into_values().collect::<Vec<_>>();

let overhead_configs = core
.overhead_config_file
.as_deref()
.map(|p| {
let file = File::open(p).expect("Failed to open overhead config file");
serde_json::from_reader::<_, Vec<GasOverheadConfig>>(file)
.expect("Failed to parse overhead config file")
})
.unwrap_or_default()
.into_iter()
.filter(|c| c.destination_domain != core.local_domain)
.map(|c| (c.destination_domain, c))
.collect::<HashMap<_, _>>() // dedup
.into_values()
.collect::<Vec<_>>();

let program_id = deploy_program(
ctx.payer_keypair_path(),
key_dir,
Expand Down Expand Up @@ -319,47 +270,6 @@ fn deploy_igp(ctx: &mut Context, core: &CoreDeploy, key_dir: &Path) -> (Pubkey,

println!("Initialized overhead IGP account {}", overhead_igp_account);

if !gas_oracle_configs.is_empty() {
let domains = gas_oracle_configs
.iter()
.map(|c| c.domain)
.collect::<Vec<_>>();
let instruction = hyperlane_sealevel_igp::instruction::set_gas_oracle_configs_instruction(
program_id,
igp_account,
ctx.payer_pubkey,
gas_oracle_configs,
)
.unwrap();

ctx.new_txn().add(instruction).send_with_payer();

println!("Set gas oracle for remote domains {domains:?}",);
} else {
println!("Skipping settings gas oracle config");
}

if !overhead_configs.is_empty() {
let domains = overhead_configs
.iter()
.map(|c| c.destination_domain)
.collect::<Vec<_>>();

let instruction = hyperlane_sealevel_igp::instruction::set_destination_gas_overheads(
program_id,
overhead_igp_account,
ctx.payer_pubkey,
overhead_configs,
)
.unwrap();

ctx.new_txn().add(instruction).send_with_payer();

println!("Set gas overheads for remote domains {domains:?}",)
} else {
println!("Skipping setting gas overheads");
}

(program_id, overhead_igp_account, igp_account)
}

Expand Down
Loading

0 comments on commit 9f42411

Please sign in to comment.