Skip to content

Commit

Permalink
we have the technology
Browse files Browse the repository at this point in the history
  • Loading branch information
tkporter committed Feb 20, 2025
1 parent 517c80f commit 291597f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 14 deletions.
101 changes: 94 additions & 7 deletions rust/sealevel/client/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ use std::{

use solana_client::rpc_client::RpcClient;
use solana_program::instruction::Instruction;
use solana_sdk::{commitment_config::CommitmentConfig, pubkey::Pubkey};
use solana_sdk::{
account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
commitment_config::CommitmentConfig,
pubkey::Pubkey,
};

use account_utils::DiscriminatorData;
use hyperlane_sealevel_connection_client::router::RemoteRouterConfig;
Expand Down Expand Up @@ -382,12 +387,6 @@ pub(crate) fn deploy_routers<
.get(*chain_name)
.unwrap_or_else(|| panic!("Chain config not found for chain: {}", chain_name));

if let Some(configured_owner) = app_config.router_config().ownable.owner {
if configured_owner != ctx.payer_pubkey {
println!("WARNING: Ownership transfer is not yet supported in this deploy tooling, ownership is granted to the payer account");
}
}

adjust_gas_price_if_needed(chain_name.as_str(), ctx);

// Deploy - this is idempotent.
Expand Down Expand Up @@ -423,6 +422,8 @@ pub(crate) fn deploy_routers<
app_config.router_config(),
chain_config,
);

configure_upgrade_authority(ctx, &program_id, app_config.router_config(), chain_config);
}

// Now enroll all the routers.
Expand Down Expand Up @@ -540,6 +541,16 @@ fn configure_owner(
let expected_owner = Some(router_config.ownable.owner(ctx.payer_pubkey));

if actual_owner != expected_owner {
if actual_owner != Some(ctx.payer_pubkey) {
println!(
"WARNING: Ownership transfer cannot be completed for chain: {} ({}) from {:?} to {:?}, the existing owner is not the payer account",
chain_config.name,
chain_config.domain_id(),
actual_owner,
expected_owner,
);
return;
}
ctx.new_txn()
.add_with_description(
deployer.set_owner_instruction(&client, program_id, expected_owner),
Expand All @@ -555,6 +566,82 @@ fn configure_owner(
}
}

/// Idempotent. Attempts to set the upgrade authority to the intended owner if
/// the payer can change the upgrade authority.
fn configure_upgrade_authority(
ctx: &mut Context,
program_id: &Pubkey,
router_config: &RouterConfig,
chain_config: &ChainMetadata,
) {
let client = chain_config.client();

let program_account = client.get_account(program_id).unwrap();
// If the program isn't upgradeable, exit
if program_account.owner == bpf_loader_upgradeable::id() {
return;
}

// The program id must actually be a program
let programdata_address = if let Ok(UpgradeableLoaderState::Program {
programdata_address,
}) = program_account.state()
{
programdata_address
} else {
return;
};

let program_data_account = client.get_account(&programdata_address).unwrap();

// The program data account must actually a program data account
let actual_upgrade_authority = if let Ok(UpgradeableLoaderState::ProgramData {
upgrade_authority_address,
slot: _,
}) = program_data_account.state()
{
upgrade_authority_address
} else {
return;
};

let expected_upgrade_authority = Some(router_config.ownable.owner(ctx.payer_pubkey));

// And the upgrade authority is not what we expect...
if actual_upgrade_authority.is_some() && actual_upgrade_authority != expected_upgrade_authority
{
// Flag if we can't change the upgrade authority
if actual_upgrade_authority != Some(ctx.payer_pubkey) {
println!(
"WARNING: Upgrade authority transfer cannot be completed for chain: {} ({}) from {:?} to {:?}, the existing upgrade authority is not the payer account",
chain_config.name,
chain_config.domain_id(),
actual_upgrade_authority,
expected_upgrade_authority,
);
return;
}

// Then set the upgrade authority to what we expect.
ctx.new_txn()
.add_with_description(
bpf_loader_upgradeable::set_upgrade_authority(
program_id,
actual_upgrade_authority.as_ref().unwrap(),
expected_upgrade_authority.as_ref(),
),
format!(
"Setting upgrade authority for chain: {} ({}) to {:?}",
chain_config.name,
chain_config.domain_id(),
expected_upgrade_authority,
),
)
.with_client(&client)
.send_with_payer();
}
}

/// For each chain in app_configs_to_deploy, enrolls all the remote routers.
/// Idempotent.
fn enroll_all_remote_routers<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"hyperevm": {
"hex": "0x00000000000000000000000096029bcf706fac4176492f4a05f63f7d23ce78fb",
"base58": "11111111111136DQQztgVwcA4ZYDq9QhZhnprvHp"
},
"solanamainnet": {
"hex": "0x2f7bbb8b14ccafc48c417e6ba387fa05db8df469156c7a0a923257ad994016cc",
"base58": "4CMbJtieJ7EboZZGSbXTQjW5i2sL638jFvE3dWTYG3SK"
},
"hyperevm": {
"hex": "0x00000000000000000000000096029bcf706fac4176492f4a05f63f7d23ce78fb",
"base58": "11111111111136DQQztgVwcA4ZYDq9QhZhnprvHp"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"solanamainnet": {
"type": "native",
"decimals": 9,
"interchainGasPaymaster": "AkeHBbE5JkwVppujCQQ6WuxsVsJtruBAjUo6fDCFp6fF"
"interchainGasPaymaster": "AkeHBbE5JkwVppujCQQ6WuxsVsJtruBAjUo6fDCFp6fF",
"owner": "BNGDJ1h9brgt6FFVd8No1TVAH48Fp44d7jkuydr1URwJ"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"solanatestnet": {
"type": "native",
"decimals": 9,
"interchainGasPaymaster": "hBHAApi5ZoeCYHqDdCKkCzVKmBdwywdT3hMqe327eZB"
"interchainGasPaymaster": "hBHAApi5ZoeCYHqDdCKkCzVKmBdwywdT3hMqe327eZB",
"owner": "6DjHX6Ezjpq3zZMZ8KsqyoFYo1zPSDoiZmLLkxD4xKXS"
},
"sonicsvmtestnet": {
"type": "native",
"decimals": 9,
"interchainGasPaymaster": "9Nq8bJdER4criKNYtkKt3WJDA2LjzHYCH11xKy53fX9"
"interchainGasPaymaster": "9Nq8bJdER4criKNYtkKt3WJDA2LjzHYCH11xKy53fX9",
"owner": "6DjHX6Ezjpq3zZMZ8KsqyoFYo1zPSDoiZmLLkxD4xKXS"
}
}

0 comments on commit 291597f

Please sign in to comment.