diff --git a/cosmwasm/cosmwasm.nix b/cosmwasm/cosmwasm.nix index 1556d645a5..942ecee1d7 100644 --- a/cosmwasm/cosmwasm.nix +++ b/cosmwasm/cosmwasm.nix @@ -797,6 +797,7 @@ _: { lightclients, apps, private_key, + ucs04-chain-id, rpc_url, bech32_prefix, gas_config, @@ -817,26 +818,14 @@ _: { cosmwasm-deployer ]; text = '' - DEPLOYER=$( - PRIVATE_KEY=${private_key} \ - cosmwasm-deployer \ - address-of-private-key \ - --bech32-prefix ${bech32_prefix} - ) - echo "deployer address: $DEPLOYER" - ADDRESSES=$(ibc-union-contract-addresses "$DEPLOYER") - PRIVATE_KEY=${private_key} \ RUST_LOG=info \ cosmwasm-deployer \ - migrate \ + upgrade \ --rpc-url ${rpc_url} \ - --address "$(echo "$ADDRESSES" | jq '.lightclient."${ - (get-lightclient (l: l.name == lc)).client-type - }"' -r)" \ + --address ${(getDeployment ucs04-chain-id).lightclient.${lc}.address} \ --new-bytecode ${(mk-lightclient lc).release} \ - ${mk-gas-args gas_config} \ - "$@" + ${mk-gas-args gas_config} "$@" ''; }; } @@ -947,27 +936,17 @@ _: { ${name} = pkgs.writeShellApplication { name = "${args.name}-${name}"; runtimeInputs = [ - ibc-union-contract-addresses cosmwasm-deployer ]; text = '' - DEPLOYER=$( - PRIVATE_KEY=${private_key} \ - cosmwasm-deployer \ - address-of-private-key \ - --bech32-prefix ${bech32_prefix} - ) - echo "deployer address: $DEPLOYER" - ADDRESSES=$(ibc-union-contract-addresses "$DEPLOYER") - PRIVATE_KEY=${private_key} \ RUST_LOG=info \ cosmwasm-deployer \ - migrate \ + upgrade \ --rpc-url ${rpc_url} \ - --address "$(echo "$ADDRESSES" | jq '.core' -r)" \ + --address ${(getDeployment ucs04-chain-id).core.address} \ --new-bytecode ${ibc-union.release} \ - ${mk-gas-args gas_config} + ${mk-gas-args gas_config} "$@" ''; }; } diff --git a/cosmwasm/cw-escrow-vault/src/contract.rs b/cosmwasm/cw-escrow-vault/src/contract.rs index 8159c8d4d6..37a81d20d7 100644 --- a/cosmwasm/cw-escrow-vault/src/contract.rs +++ b/cosmwasm/cw-escrow-vault/src/contract.rs @@ -20,7 +20,7 @@ use crate::{ msg::{ ExecuteMsg, FungibleLaneConfig, InstantiateMsg, MigrateMsg, QueryMsg, RestrictedExecuteMsg, }, - state::{Admin, FungibleCounterparty, FungibleLane, IntentWhitelist, Zkgm}, + state::{FungibleCounterparty, FungibleLane, IntentWhitelist, Zkgm}, }; /// Major state versions of this contract, used in the [`frissitheto`] migrations. @@ -61,12 +61,8 @@ pub fn migrate( Ok((Response::new(), Some(version::LATEST))) }, - |mut deps, msg, version| match version { - version::INIT => { - access_managed::init(deps.branch(), msg.access_managed_init_msg)?; - deps.storage.delete_item::(); - Ok((Response::default(), Some(version::MANAGED))) - } + |_, _, version| match version { + version::INIT => Err(StdError::generic_err("unsupported version: INIT").into()), version::MANAGED => Ok((Response::default(), None)), _ => Err(UpgradeError::UnknownStateVersion(version).into()), }, diff --git a/cosmwasm/cw-escrow-vault/src/msg.rs b/cosmwasm/cw-escrow-vault/src/msg.rs index a505147778..631aee3f1e 100644 --- a/cosmwasm/cw-escrow-vault/src/msg.rs +++ b/cosmwasm/cw-escrow-vault/src/msg.rs @@ -17,9 +17,7 @@ pub struct InstantiateMsg { #[derive(Debug, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(deny_unknown_fields, rename_all = "snake_case")] -pub struct MigrateMsg { - pub access_managed_init_msg: access_managed::InitMsg, -} +pub struct MigrateMsg {} #[derive(Debug, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] diff --git a/cosmwasm/cw-escrow-vault/src/state.rs b/cosmwasm/cw-escrow-vault/src/state.rs index 003468b3b9..1303122784 100644 --- a/cosmwasm/cw-escrow-vault/src/state.rs +++ b/cosmwasm/cw-escrow-vault/src/state.rs @@ -41,17 +41,6 @@ impl ValueCodecViaEncoding for FungibleCounterparty { type Encoding = Bincode; } -pub enum Admin {} -impl Store for Admin { - const PREFIX: Prefix = Prefix::new(b"admin"); - - type Key = (); - type Value = Addr; -} -impl ValueCodecViaEncoding for Admin { - type Encoding = RawAddrEncoding; -} - pub enum Zkgm {} impl Store for Zkgm { const PREFIX: Prefix = Prefix::new(b"zkgm"); diff --git a/cosmwasm/cw-unionversal-token/src/contract.rs b/cosmwasm/cw-unionversal-token/src/contract.rs index 4d102e7c51..540ab0ebb7 100644 --- a/cosmwasm/cw-unionversal-token/src/contract.rs +++ b/cosmwasm/cw-unionversal-token/src/contract.rs @@ -20,8 +20,7 @@ use crate::{ error::ContractError, msg::{Cw20InstantiateMsg, ExecuteMsg, InitMsg, QueryMsg, RestrictedExecuteMsg}, state::{ - Admin, Cw20ImplType, Cw20Type, FungibleCounterparty, FungibleLane, IntentWhitelist, - Minters, Zkgm, + Cw20ImplType, Cw20Type, FungibleCounterparty, FungibleLane, IntentWhitelist, Minters, Zkgm, }, }; @@ -49,9 +48,7 @@ pub fn instantiate(_: DepsMut, _: Env, _: MessageInfo, _: ()) -> StdResult { - access_managed::init(deps.branch(), msg.access_managed_init_msg)?; - - deps.storage.delete_item::(); - - Ok((Response::default(), Some(version::MANAGED))) - } + |_, _, version| match version { + version::INIT => Err(StdError::generic_err("unsupported version: INIT").into()), version::MANAGED => Ok((Response::default(), None)), _ => Err(UpgradeError::UnknownStateVersion(version).into()), }, diff --git a/cosmwasm/cw-unionversal-token/src/state.rs b/cosmwasm/cw-unionversal-token/src/state.rs index 0b86777951..0aa8aee10a 100644 --- a/cosmwasm/cw-unionversal-token/src/state.rs +++ b/cosmwasm/cw-unionversal-token/src/state.rs @@ -45,17 +45,6 @@ impl ValueCodecViaEncoding for FungibleCounterparty { type Encoding = Bincode; } -pub enum Admin {} -impl Store for Admin { - const PREFIX: Prefix = Prefix::new(b"admin"); - - type Key = (); - type Value = Addr; -} -impl ValueCodecViaEncoding for Admin { - type Encoding = RawAddrEncoding; -} - pub enum Zkgm {} impl Store for Zkgm { const PREFIX: Prefix = Prefix::new(b"zkgm"); diff --git a/cosmwasm/deployer/src/main.rs b/cosmwasm/deployer/src/main.rs index 8bfa1f2141..64d0351112 100644 --- a/cosmwasm/deployer/src/main.rs +++ b/cosmwasm/deployer/src/main.rs @@ -20,13 +20,14 @@ use cosmwasm_std::{Addr, Decimal, Uint256}; use flate2::{Compression, write::GzEncoder}; use futures::{TryStreamExt, future::OptionFuture, stream::FuturesOrdered}; use hex_literal::hex; +use ibc_union_light_client::upgradable::msg::Upgradable; use protos::cosmwasm::wasm::v1::{QuerySmartContractStateRequest, QuerySmartContractStateResponse}; use rand_chacha::{ ChaChaCore, rand_core::{SeedableRng, block::BlockRng}, }; use serde::{Deserialize, Serialize, de::DeserializeOwned}; -use serde_json::{Value, json, to_value}; +use serde_json::{Value, json}; use sha2::Digest; use tracing::{info, instrument}; use tracing_subscriber::EnvFilter; @@ -34,10 +35,12 @@ use ucs03_zkgm::msg::TokenMinterInitParams; use unionlabs::{ cosmos::{bank::msg_send::MsgSend, base::coin::Coin}, cosmwasm::wasm::{ - access_config::AccessConfig, msg_execute_contract::MsgExecuteContract, + access_config::AccessConfig, + msg_execute_contract::MsgExecuteContract, msg_instantiate_contract2::MsgInstantiateContract2, msg_migrate_contract::MsgMigrateContract, - msg_store_and_migrate_contract::MsgStoreAndMigrateContract, msg_store_code::MsgStoreCode, + msg_store_and_migrate_contract::MsgStoreAndMigrateContract, + msg_store_code::{MsgStoreCode, response::MsgStoreCodeResponse}, msg_update_admin::MsgUpdateAdmin, msg_update_instantiate_config::MsgUpdateInstantiateConfig, }, @@ -133,32 +136,43 @@ enum App { #[arg(long)] salt_hex: bool, }, - MigrateToAccessManaged { + Migrate { #[arg(long)] rpc_url: String, - #[arg(long, env)] - private_key: Option, - #[arg(long)] - contracts: PathBuf, + #[arg(long, env, required_unless_present("dump_to"))] + private_key: String, #[arg(long)] - addresses: PathBuf, + address: Bech32, #[arg(long)] - manager: Bech32, + new_bytecode: PathBuf, + #[arg(long, conflicts_with = "private_key")] + dump_to: Option, + #[arg(long, conflicts_with = "private_key")] + sender: Option>, + #[arg( + long, + // the autoref value parser selector chooses From before FromStr, but Value's From impl always returns Value::String(..), whereas FromStr actually parses the json contained within the string + value_parser(serde_json::Value::from_str), + default_value_t = serde_json::Value::Object(serde_json::Map::new()) + )] + message: Value, + #[arg(long, default_value_t = false)] + force: bool, #[command(flatten)] gas_config: GasFillerArgs, }, - Migrate { + Upgrade { #[arg(long)] rpc_url: String, - #[arg(long, env, required_unless_present("dump_to"))] - private_key: Option, + #[arg(long, env)] + private_key: H256, #[arg(long)] address: Bech32, #[arg(long)] new_bytecode: PathBuf, - #[arg(long, conflicts_with = "private_key")] + #[arg(long, requires = "sender")] dump_to: Option, - #[arg(long, conflicts_with = "private_key")] + #[arg(long)] sender: Option>, #[arg( long, @@ -664,125 +678,89 @@ async fn do_main() -> Result<()> { write_output(output, heights)?; } - App::MigrateToAccessManaged { + App::Migrate { rpc_url, private_key, - contracts, - addresses, - manager, + address, + new_bytecode, + dump_to, + sender, + message, + force, gas_config, } => { - let contracts = serde_json::from_slice::( - &std::fs::read(contracts).context("reading contracts path")?, - )?; + let (new_checksum, new_bytecode) = read_bytecode(new_bytecode)?; - let addresses = serde_json::from_slice::( - &std::fs::read(addresses).context("reading addresses path")?, - )?; - - let ctx = Deployer::new(rpc_url, private_key.unwrap_or(sha2("")), &gas_config).await?; - - let do_migrate = async |address, bytecode, message: Value| { - let raw_bytecode = std::fs::read(bytecode).context("reading bytecode")?; - - let mut gz_encoder = GzEncoder::new(Vec::new(), Compression::best()); - gz_encoder.write_all(&raw_bytecode)?; - let bytecode = gz_encoder.finish()?; + let ctx = Deployer::new( + rpc_url, + if private_key.is_empty() { + sha2("") + } else { + private_key.parse()? + }, + &gas_config, + ) + .await?; - let contract_info = ctx - .contract_info(&address) - .await? - .with_context(|| format!("contract {address} does not exist"))?; + let contract_info = ctx + .contract_info(&address) + .await? + .with_context(|| format!("contract {address} does not exist"))?; - let checksum = ctx.code_checksum(contract_info.code_id).await?.unwrap(); + let checksum = ctx.code_checksum(contract_info.code_id).await?.unwrap(); - if checksum == sha2(BYTECODE_BASE_BYTECODE) { - bail!( - "contract {address} has not yet been initiated, it must be fully deployed before it can be migrated" - ) - } else if checksum == sha2(&raw_bytecode) { + if checksum == sha2(BYTECODE_BASE_BYTECODE) { + bail!( + "contract {address} has not yet been initiated, it must be fully deployed before it can be migrated" + ) + } else if checksum == new_checksum { + if force { + info!( + "contract {address} has already been migrated to this bytecode, migrating anyways since --force was passed" + ); + } else { info!("contract {address} has already been migrated to this bytecode"); return Ok(()); } + } - let message = json!({ "migrate": message }); + let message = json!({ "migrate": message }); - info!("migrate message: {message}"); + info!("migrate message: {message}"); - info!("migrating {address}"); + let msg = MsgStoreAndMigrateContract { + sender: sender + .unwrap_or_else(|| ctx.wallet().address()) + .map_data(Into::into), + wasm_byte_code: new_bytecode.into_encoding(), + instantiate_permission: None, + contract: address.clone(), + msg: message.to_string().into_bytes().into(), + }; - let msg = MsgStoreAndMigrateContract { - sender: ctx.wallet().address().map_data(Into::into), - contract: address.clone(), - wasm_byte_code: bytecode.into(), - instantiate_permission: None, - msg: message.to_string().into_bytes().into(), - }; + if let Some(dump_to) = dump_to { + write_output( + Some(dump_to.clone()), + json!({ + "body": { + "messages": [Any(msg)], + }, + }), + )?; - let (tx_hash, _) = ctx + info!("raw tx body written to {}", dump_to.display()); + } else { + info!("migrating address {address}"); + + let (tx_hash, _migrate_response) = ctx .tx(msg, "", gas_config.simulate) .await .context("migrate")?; info!(%tx_hash, "migrated"); - - Ok(()) - }; - - let access_managed_init_msg = access_manager_types::managed::msg::InitMsg { - initial_authority: Addr::unchecked(manager.to_string()), - }; - - do_migrate( - addresses.core.clone(), - &contracts.core, - to_value(ibc_union::contract::MigrateMsg { - access_managed_init_msg: access_managed_init_msg.clone(), - }) - .unwrap(), - ) - .await?; - - for (salt, path) in &contracts.lightclient { - do_migrate( - addresses.lightclient[salt].clone(), - path, - to_value(ibc_union_light_client::msg::MigrateMsg { - access_managed_init_msg: access_managed_init_msg.clone(), - }) - .unwrap(), - ) - .await?; - } - - if let Some(address) = addresses.app.ucs03.clone() { - do_migrate( - address, - &contracts.app.ucs03.as_ref().unwrap().path, - to_value(ucs03_zkgm::msg::MigrateMsg { - access_managed_init_msg: access_managed_init_msg.clone(), - }) - .unwrap(), - ) - .await?; } - - if let Some(address) = addresses.escrow_vault.clone() { - do_migrate( - address, - &contracts.escrow_vault.unwrap(), - to_value(cw_escrow_vault::msg::MigrateMsg { - access_managed_init_msg: access_managed_init_msg.clone(), - }) - .unwrap(), - ) - .await?; - } - - info!("migrated contracts"); - info!("roles have not been set up, use `cosmwasm-deployer setup-roles`"); } - App::Migrate { + App::Upgrade { rpc_url, private_key, address, @@ -795,7 +773,7 @@ async fn do_main() -> Result<()> { } => { let new_bytecode = std::fs::read(new_bytecode).context("reading new bytecode")?; - let ctx = Deployer::new(rpc_url, private_key.unwrap_or(sha2("")), &gas_config).await?; + let ctx = Deployer::new(rpc_url, private_key, &gas_config).await?; let contract_info = ctx .contract_info(&address) @@ -819,26 +797,41 @@ async fn do_main() -> Result<()> { } } - let message = json!({ "migrate": message }); + info!("storing code for {address}"); - info!("migrate message: {message}"); + let (tx_hash, MsgStoreCodeResponse { code_id, .. }) = ctx + .tx( + MsgStoreCode { + sender: ctx.wallet().address().map_data(Into::into), + wasm_byte_code: new_bytecode.clone().into(), + instantiate_permission: None, + }, + "", + gas_config.simulate, + ) + .await + .context("migrate")?; - let msg = MsgStoreAndMigrateContract { - sender: sender - .unwrap_or_else(|| ctx.wallet().address()) - .map_data(Into::into), - wasm_byte_code: new_bytecode.into(), - instantiate_permission: None, - contract: address.clone(), - msg: message.to_string().into_bytes().into(), - }; + info!(%tx_hash, "migrated"); + + let message = serde_json::to_string(&Upgradable::Upgrade { + new_code_id: code_id, + msg: message, + })?; + + info!("upgrade message: {message}"); if let Some(dump_to) = dump_to { write_output( Some(dump_to.clone()), json!({ "body": { - "messages": [Any(msg)], + "messages": [Any(MsgExecuteContract { + sender: sender.unwrap().map_data(Into::into), + contract: address, + msg: message.into_bytes().into(), + funds: vec![], + })], }, }), )?; @@ -847,8 +840,17 @@ async fn do_main() -> Result<()> { } else { info!("migrating address {address}"); - let (tx_hash, _migrate_response) = ctx - .tx(msg, "", gas_config.simulate) + let (tx_hash, _) = ctx + .tx( + MsgExecuteContract { + sender: ctx.wallet().address().map_data(Into::into), + contract: address, + msg: message.into_bytes().into(), + funds: vec![], + }, + "", + gas_config.simulate, + ) .await .context("migrate")?; @@ -956,7 +958,7 @@ async fn do_main() -> Result<()> { gas_config, output, } => { - let bytecode = std::fs::read(bytecode).context("reading bytecode path")?; + let (_, bytecode) = read_bytecode(bytecode)?; let deployer = Deployer::new(rpc_url.clone(), private_key, &gas_config).await?; @@ -964,7 +966,7 @@ async fn do_main() -> Result<()> { .tx( MsgStoreCode { sender: deployer.wallet().address().map_data(Into::into), - wasm_byte_code: bytecode.into(), + wasm_byte_code: bytecode.into_encoding(), // TODO: Support permissions instantiate_permission: None, }, @@ -990,7 +992,7 @@ async fn do_main() -> Result<()> { salt_hex, gas_config, } => { - let bytecode = std::fs::read(bytecode).context("reading bytecode path")?; + let (_, bytecode) = read_bytecode(bytecode)?; let deployer = Deployer::new(rpc_url.clone(), private_key, &gas_config).await?; @@ -1016,7 +1018,7 @@ async fn do_main() -> Result<()> { output, gas_config, } => { - let bytecode = std::fs::read(bytecode).context("reading bytecode path")?; + let (_, bytecode) = read_bytecode(bytecode)?; let deployer = Deployer::new(rpc_url.clone(), private_key, &gas_config).await?; @@ -1313,6 +1315,18 @@ async fn do_main() -> Result<()> { Ok(()) } +fn read_bytecode(bytecode: PathBuf) -> Result<(H256, Bytes)> { + let bytecode = std::fs::read(bytecode).context("reading bytecode path")?; + + let checksum = sha2(&bytecode); + + let mut gz = GzEncoder::new(vec![], Compression::best()); + gz.write_all(&bytecode)?; + let bytecode = gz.finish()?; + + Ok((checksum, bytecode.into())) +} + async fn deploy_full( rpc_url: String, private_key: H256, @@ -1332,7 +1346,7 @@ async fn deploy_full( let manager = ctx .deploy_and_initiate( - std::fs::read(contracts.manager)?, + read_bytecode(contracts.manager)?.1, bytecode_base_code_id, access_manager_types::manager::msg::InitMsg { initial_admin: Addr::unchecked(manager_admin.to_string()), @@ -1348,7 +1362,7 @@ async fn deploy_full( let core_address = ctx .deploy_and_initiate( - std::fs::read(contracts.core)?, + read_bytecode(contracts.core)?.1, bytecode_base_code_id, ibc_union_msg::msg::InitMsg { access_managed_init_msg: access_managed_init_msg.clone(), @@ -1379,7 +1393,7 @@ async fn deploy_full( for (client_type, path) in contracts.lightclient { let address = ctx .deploy_and_initiate( - std::fs::read(path)?, + read_bytecode(path)?.1, bytecode_base_code_id, ibc_union_light_client::msg::InitMsg { ibc_host: core_address.to_string(), @@ -1610,7 +1624,7 @@ async fn deploy_full( } ctx.deploy_and_initiate( - std::fs::read(ucs03_config.path)?, + read_bytecode(ucs03_config.path)?.1, bytecode_base_code_id, ucs03_zkgm::msg::InitMsg { config: ucs03_zkgm::msg::Config { @@ -1633,7 +1647,7 @@ async fn deploy_full( if let Some(escrow_vault_path) = contracts.escrow_vault { let escrow_vault_address = ctx .deploy_and_initiate( - std::fs::read(escrow_vault_path)?, + read_bytecode(escrow_vault_path)?.1, bytecode_base_code_id, cw_escrow_vault::msg::InstantiateMsg { zkgm: Addr::unchecked(ucs03_address.to_string()), @@ -1650,7 +1664,7 @@ async fn deploy_full( } ctx.deploy_and_initiate( - std::fs::read(contracts.on_zkgm_call_proxy)?, + read_bytecode(contracts.on_zkgm_call_proxy)?.1, bytecode_base_code_id, on_zkgm_call_proxy::InitMsg { zkgm: Addr::unchecked(ucs03_address.to_string()), @@ -2107,7 +2121,7 @@ impl Deployer { #[instrument(skip_all, fields(%salt))] async fn deploy_and_initiate( &self, - wasm_byte_code: Vec, + wasm_byte_code: Bytes, bytecode_base_code_id: NonZeroU64, msg: impl Serialize, salt: &Salt, @@ -2153,7 +2167,7 @@ impl Deployer { .tx( MsgStoreCode { sender: self.wallet().address().map_data(Into::into), - wasm_byte_code: wasm_byte_code.into(), + wasm_byte_code: wasm_byte_code.into_encoding(), instantiate_permission: None, }, "", @@ -2211,7 +2225,7 @@ impl Deployer { std::cmp::Ordering::Less => panic!("impossible"), std::cmp::Ordering::Equal => { info!( - "contract {address} has already been instantaited with the base bytecode but not yet initiated" + "contract {address} has already been instantiated with the base bytecode but not yet initiated" ); Ok(ContractDeployState::Instantiated) } diff --git a/cosmwasm/ibc-union/app/ucs03-zkgm/src/contract.rs b/cosmwasm/ibc-union/app/ucs03-zkgm/src/contract.rs index 41346d2b6d..f596e2f14b 100644 --- a/cosmwasm/ibc-union/app/ucs03-zkgm/src/contract.rs +++ b/cosmwasm/ibc-union/app/ucs03-zkgm/src/contract.rs @@ -3076,11 +3076,8 @@ pub fn migrate( Ok((res, Some(version::LATEST))) }, - |mut deps, migrate_msg, version| match version { - version::INIT => { - access_managed::init(deps.branch(), migrate_msg.access_managed_init_msg)?; - Ok((Response::default(), Some(version::MANAGED))) - } + |_, _, version| match version { + version::INIT => Err(StdError::generic_err("unsupported version: INIT").into()), version::MANAGED => Ok((Response::default(), None)), _ => Err(UpgradeError::UnknownStateVersion(version).into()), }, diff --git a/cosmwasm/ibc-union/app/ucs03-zkgm/src/msg.rs b/cosmwasm/ibc-union/app/ucs03-zkgm/src/msg.rs index 8034ded484..5e3c1a59cd 100644 --- a/cosmwasm/ibc-union/app/ucs03-zkgm/src/msg.rs +++ b/cosmwasm/ibc-union/app/ucs03-zkgm/src/msg.rs @@ -21,9 +21,7 @@ pub struct InitMsg { #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "snake_case", deny_unknown_fields)] -pub struct MigrateMsg { - pub access_managed_init_msg: access_managed::InitMsg, -} +pub struct MigrateMsg {} #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] diff --git a/cosmwasm/ibc-union/core/light-client-interface/src/lib.rs b/cosmwasm/ibc-union/core/light-client-interface/src/lib.rs index 825c57ae77..63f32ee0d4 100644 --- a/cosmwasm/ibc-union/core/light-client-interface/src/lib.rs +++ b/cosmwasm/ibc-union/core/light-client-interface/src/lib.rs @@ -145,12 +145,8 @@ macro_rules! default_migrate { Ok((res, Some($crate::version::LATEST))) }, - |mut deps, msg, version| match version { - $crate::version::INIT => { - $crate::access_managed::init(deps.branch(), msg.access_managed_init_msg)?; - - Ok((::cosmwasm_std::Response::default(), Some($crate::version::MANAGED))) - } + |_, _, version| match version { + $crate::version::INIT => Err(::cosmwasm_std::StdError::generic_err("unsupported version: INIT").into()), $crate::version::MANAGED => Ok((::cosmwasm_std::Response::default(), None)), _ => Err(::frissitheto::UpgradeError::UnknownStateVersion(version).into()), }, diff --git a/cosmwasm/ibc-union/core/msg/src/lightclient.rs b/cosmwasm/ibc-union/core/msg/src/lightclient.rs index 304814b277..8f9b6ac4cd 100644 --- a/cosmwasm/ibc-union/core/msg/src/lightclient.rs +++ b/cosmwasm/ibc-union/core/msg/src/lightclient.rs @@ -20,9 +20,7 @@ pub struct InitMsg { } #[derive(Debug, Serialize, Deserialize)] -pub struct MigrateMsg { - pub access_managed_init_msg: access_managed::InitMsg, -} +pub struct MigrateMsg {} #[derive(Debug, PartialEq, Serialize, Deserialize)] #[serde(deny_unknown_fields, rename_all = "snake_case")] diff --git a/cosmwasm/ibc-union/core/src/contract.rs b/cosmwasm/ibc-union/core/src/contract.rs index b6d173e09c..753fb8bce5 100644 --- a/cosmwasm/ibc-union/core/src/contract.rs +++ b/cosmwasm/ibc-union/core/src/contract.rs @@ -50,7 +50,7 @@ use crate::{ state::{ ChannelOwner, Channels, ClientConsensusStates, ClientImpls, ClientRegistry, ClientStates, ClientStore, ClientTypes, Commitments, Connections, ContractChannels, NextChannelId, - NextClientId, NextConnectionId, QueryStore, WhitelistedRelayers, WhitelistedRelayersAdmin, + NextClientId, NextConnectionId, QueryStore, }, }; @@ -646,9 +646,7 @@ pub fn instantiate(_: DepsMut, _: Env, _: MessageInfo, _: ()) -> StdResult, ) -> Result { - msg.run(deps, init, |mut deps, msg, version| match version { - version::INIT => { - access_managed::init(deps.branch(), msg.access_managed_init_msg)?; - - deps.storage.delete_item::(); - - for (k, ()) in deps - .storage - .iter::(cosmwasm_std::Order::Ascending) - .collect::, _>>()? - { - deps.storage.delete::(&k); - } + msg.run(deps, init, |_, _, version| match version { + version::INIT => Err(StdError::generic_err("unsupported version: INIT").into()), - Ok((Response::new(), Some(version::MANAGED))) - } version::MANAGED => Ok((Response::new(), None)), _ => Err(UpgradeError::UnknownStateVersion(version).into()), }) diff --git a/cosmwasm/ibc-union/core/src/state.rs b/cosmwasm/ibc-union/core/src/state.rs index 0fe6904b40..edab32dc7b 100644 --- a/cosmwasm/ibc-union/core/src/state.rs +++ b/cosmwasm/ibc-union/core/src/state.rs @@ -1,10 +1,7 @@ use std::{collections::BTreeSet, marker::PhantomData}; use cosmwasm_std::{Addr, StdError, StdResult}; -use depolama::{ - KeyCodec, Prefix, Store, ValueCodec, - value::{ValueCodecViaEncoding, ValueUnitEncoding}, -}; +use depolama::{KeyCodec, Prefix, Store, ValueCodec, value::ValueCodecViaEncoding}; use ibc_union_spec::{Channel, ChannelId, ClientId, Connection, ConnectionId}; use unionlabs::{ encoding::Bincode, @@ -361,38 +358,6 @@ impl ValueCodec for Commitments { } } -pub enum WhitelistedRelayersAdmin {} -impl Store for WhitelistedRelayersAdmin { - const PREFIX: Prefix = Prefix::new(b"whitelisted_relayers_admin"); - - type Key = (); - type Value = Addr; -} -addr_value!(WhitelistedRelayersAdmin); - -pub enum WhitelistedRelayers {} -impl Store for WhitelistedRelayers { - const PREFIX: Prefix = Prefix::new(b"whitelisted_relayers"); - - type Key = Addr; - type Value = (); -} - -impl KeyCodec for WhitelistedRelayers { - fn encode_key(key: &Addr) -> Bytes { - key.as_bytes().into() - } - - fn decode_key(raw: &Bytes) -> StdResult { - String::from_utf8(raw.to_vec()) - .map(Addr::unchecked) - .map_err(|e| StdError::generic_err(format!("invalid key: {e}"))) - } -} -impl ValueCodecViaEncoding for WhitelistedRelayers { - type Encoding = ValueUnitEncoding; -} - fn read_fixed_bytes(raw: &Bytes) -> StdResult<[u8; N]> { raw.try_into().map_err(|_| { StdError::generic_err(format!( diff --git a/cosmwasm/ibc-union/lightclient/bob/src/contract.rs b/cosmwasm/ibc-union/lightclient/bob/src/contract.rs index 70ad5d51da..a987545c15 100644 --- a/cosmwasm/ibc-union/lightclient/bob/src/contract.rs +++ b/cosmwasm/ibc-union/lightclient/bob/src/contract.rs @@ -1,15 +1,11 @@ use cosmwasm_std::{DepsMut, Env, MessageInfo, Response, StdError, wasm_execute}; use depolama::StorageExt; -use frissitheto::UpgradeMsg; use ibc_union_light_client::{ IbcClientError, access_managed::{EnsureCanCallResult, Restricted, state::Authority}, - default_query, default_reply, - msg::{InitMsg, MigrateMsg}, - read_client_state, read_consensus_state, + default_migrate, default_query, default_reply, read_client_state, read_consensus_state, spec::ClientId, state::IbcHost, - version, }; use ibc_union_msg::msg::MsgMigrateState; use serde::{Deserialize, Serialize}; @@ -22,6 +18,7 @@ use crate::client::BobLightClient; default_query!(BobLightClient); default_reply!(); +default_migrate!(BobLightClient); #[derive(Debug, PartialEq, Serialize, Deserialize)] #[serde(deny_unknown_fields, rename_all = "snake_case")] @@ -126,36 +123,3 @@ pub fn execute( } } } - -#[cosmwasm_std::entry_point] -pub fn migrate( - deps: DepsMut, - _: Env, - msg: UpgradeMsg, -) -> Result> { - msg.run( - deps, - |deps, init_msg| { - let res = ibc_union_light_client::init(deps, init_msg)?; - Ok((res, Some(version::LATEST))) - }, - |mut deps, msg, version| match version { - version::INIT => { - ibc_union_light_client::access_managed::init( - deps.branch(), - msg.access_managed_init_msg, - )?; - Ok((Response::default(), Some(version::MANAGED))) - } - // NOTE: We messed with the state version previously, this is required to standardize it between all of the contracts - version::MANAGED => { - ibc_union_light_client::access_managed::init( - deps.branch(), - msg.access_managed_init_msg, - )?; - Ok((Response::default(), None)) - } - _ => Err(::frissitheto::UpgradeError::UnknownStateVersion(version).into()), - }, - ) -}