From a128308d3e8de7896bc4cd91cb7e34ef41dcc540 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Tue, 8 Aug 2023 21:01:44 +0100 Subject: [PATCH 01/14] feat(cw-xc): centauri osmosis transfer --- PLAN | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 PLAN diff --git a/PLAN b/PLAN new file mode 100644 index 00000000000..2a1e9fb9209 --- /dev/null +++ b/PLAN @@ -0,0 +1,6 @@ +1. fix sender +2. tune AR to be more symmetric +3. fix recevier +4. write spawn back +5. fix AR for back +6. write Osmosis origination \ No newline at end of file From d0c54ba743da7e33e851f90a808232c3e9bd9e48 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Tue, 8 Aug 2023 21:19:28 +0100 Subject: [PATCH 02/14] split xcmv config --- .../cosmwasm/contracts/gateway/src/contract/execute.rs | 3 ++- .../cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs | 6 ++++-- code/xcvm/lib/core/src/transport/ibc/mod.rs | 8 +++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs index 5bfaf936fc6..860bea9807a 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs @@ -47,6 +47,7 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: msg::ExecuteMsg) } }, msg::ExecuteMsg::MessageHook(msg) => { + deps.api.debug(&serde_json_wasm::to_string(&msg)?); let auth = auth::WasmHook::authorise(deps.storage, &env, &info, msg.from_network_id)?; super::ibc::ics20::ics20_message_hook(auth, msg, env, info) }, @@ -176,7 +177,7 @@ pub(crate) fn handle_execute_program_privilleged( let interpreter_code_id = match config.gateway.expect("expected setup") { msg::GatewayId::CosmWasm { interpreter_code_id, .. } => interpreter_code_id, }; - + deps.api.debug("instantiating interpreter"); let instantiate_msg: CosmosMsg = WasmMsg::Instantiate { // router is the default admin of a contract admin: Some(env.contract.address.clone().into_string()), diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs index dbfb3f65e87..cf21fc10e21 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs @@ -29,11 +29,13 @@ pub(crate) fn handle_bridge_forward( info: MessageInfo, msg: xc_core::gateway::BridgeForwardMsg, ) -> Result { + deps.api.debug(&serde_json_wasm::to_string(&msg)?); ensure_eq!(msg.msg.assets.0.len(), 1, ContractError::ProgramCannotBeHandledByDestination); // algorithm to handle for multihop // 1. recurse on program until can with memo // 2. as soon as see no Spawn/Transfer, stop memo and do Wasm call with remaining Packet + let packet = XcPacket { interpreter: String::from(info.sender).into_bytes(), user_origin: msg.interpreter_origin.user_origin, @@ -45,7 +47,7 @@ pub(crate) fn handle_bridge_forward( let (local_asset, amount) = packet.assets.0.get(0).expect("proved above"); let route = get_route(deps.storage, msg.to, *local_asset)?; - + deps.api.debug(&serde_json_wasm::to_string(&route)?); let mut event = make_event("bridge") .add_attribute("to_network_id", msg.to.to_string()) .add_attribute( @@ -121,7 +123,7 @@ pub(crate) fn ics20_message_hook( env: Env, info: MessageInfo, ) -> Result { - let packet: XcPacket = decode_packet(&msg.data).map_err(ContractError::Protobuf)?; + let packet: XcPacket = msg.packet; ensure_anonymous(&packet.program)?; let call_origin = CallOrigin::Remote { user_origin: packet.user_origin }; diff --git a/code/xcvm/lib/core/src/transport/ibc/mod.rs b/code/xcvm/lib/core/src/transport/ibc/mod.rs index 3a4ec890a9a..c772179bb6c 100644 --- a/code/xcvm/lib/core/src/transport/ibc/mod.rs +++ b/code/xcvm/lib/core/src/transport/ibc/mod.rs @@ -19,7 +19,7 @@ use self::ics20::{ #[cfg_attr(feature = "std", derive(schemars::JsonSchema))] pub struct XcMessageData { pub from_network_id: NetworkId, - pub data: Binary, + pub packet: XcPacket, } /// Message type for `sudo` entry_point @@ -31,7 +31,10 @@ pub enum SudoMsg { IBCLifecycleComplete(IBCLifecycleComplete), } + +/// route is used to describe how to send a packet to another network #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[cfg_attr(feature = "std", derive(schemars::JsonSchema))] #[serde(rename_all = "snake_case")] pub struct IbcRoute { pub from_network: NetworkId, @@ -46,12 +49,11 @@ pub struct IbcRoute { pub fn to_cw_message(coin: Coin, route: IbcRoute, packet: XcPacket) -> StdResult> { let memo = - XcMessageData { from_network_id: route.from_network, data: Binary::from(packet.encode()) }; + XcMessageData { from_network_id: route.from_network, packet }; let memo = SendMemo { inner: Memo { wasm: Some(Callback { contract: route.gateway_to_send_to.clone(), - msg: serde_cw_value::to_value(memo).expect("can always serde"), }), forward: None, From 8dc09590a28e1b20460591914afcec90627b2dba Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Tue, 8 Aug 2023 21:59:03 +0100 Subject: [PATCH 03/14] split keys --- Dockerfile | 2 +- flake/cosmos.nix | 8 ++++ .../composable-centauri/flake-module.nix | 48 ++++++++++++++----- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6babc8a84de..088b7570a3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,7 @@ RUN mkdir --parents /etc/nix/ && \ echo "cores = 32" >> /etc/nix/nix.conf && \ echo "allow-import-from-derivation = true" >> /etc/nix/nix.conf && \ echo "narinfo-cache-negative-ttl = 30" >> /etc/nix/nix.conf && \ - echo "trusted-users = root vscode actiions-runner" >> /etc/nix/nix.conf && \ + echo "trusted-users = root vscode actions-runner" >> /etc/nix/nix.conf && \ echo "substitute = true" >> /etc/nix/nix.conf && \ echo "substituters = https://cache.nixos.org/ https://composable-community.cachix.org/ https://devenv.cachix.org/ https://nix-community.cachix.org/" >> /etc/nix/nix.conf && \ echo "require-sigs = false" >> /etc/nix/nix.conf && \ diff --git a/flake/cosmos.nix b/flake/cosmos.nix index 7ddc85b6216..c2589297dbd 100644 --- a/flake/cosmos.nix +++ b/flake/cosmos.nix @@ -15,6 +15,14 @@ osmosis = "osmo12smx2wdlyttvyzvzg54y2vnqwq2qjateuf7thj"; }; + xcvm = { + mnemonic = + "apart ahead month tennis merge canvas possible cannon lady reward traffic city hamster monitor lesson nasty midnight sniff enough spatial rare multiply keep task"; + centauri = "centauri1qq0k7d56juu7h49arelzgw09jccdk8sujrcrjd"; + key = "A03mRJjzKKa8+4INiSDSdIzaMuA1nhbNs/B0fOVLlYNI"; + moniker = "xcvm"; + osmosis = "osmo1qq0k7d56juu7h49arelzgw09jccdk8su7jx0qv"; + }; }; }; } diff --git a/inputs/notional-labs/composable-centauri/flake-module.nix b/inputs/notional-labs/composable-centauri/flake-module.nix index 78724415062..91a2ec90020 100644 --- a/inputs/notional-labs/composable-centauri/flake-module.nix +++ b/inputs/notional-labs/composable-centauri/flake-module.nix @@ -82,8 +82,10 @@ sleep $BLOCK_SECONDS GATEWAY_CONTRACT_ADDRESS=$("$BINARY" query wasm list-contract-by-code "$GATEWAY_CODE_ID" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --home "$CHAIN_DATA" | dasel --read json '.contracts.[0]' --write yaml) + echo "$GATEWAY_CONTRACT_ADDRESS" > "$CHAIN_DATA/gateway_contract_address" } + INSTANTIATE=$(cat << EOF { "admin" : "$VALIDATOR_KEY", @@ -94,6 +96,39 @@ init_xcvm "$INSTANTIATE" + # light client + centaurid tx gov submit-proposal ${ics10-grandpa-cw-proposal}/ics10_grandpa_cw.wasm.json --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166ppica --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json + sleep $BLOCK_SECONDS + centaurid query auth module-account gov --chain-id "$CHAIN_ID" --node tcp://localhost:26657 --home "$CHAIN_DATA" | jq '.account.base_account.address' --raw-output + PROPOSAL_ID=1 + centaurid tx gov vote $PROPOSAL_ID yes --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166ppica --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json + sleep 20 + centaurid query gov proposal $PROPOSAL_ID --chain-id "$CHAIN_ID" --node tcp://localhost:26657 --home "$CHAIN_DATA" | + jq '.status' + sleep $BLOCK_SECONDS + centaurid query 08-wasm all-wasm-code --chain-id "$CHAIN_ID" --home "$CHAIN_DATA" --output json --node tcp://localhost:26657 | jq '.code_ids[0]' --raw-output | tee "$CHAIN_DATA/code_id" + ''; + }; + + centaurid-xcvm = pkgs.writeShellApplication { + name = "centaurid-init"; + runtimeInputs = devnetTools.withBaseContainerTools + ++ [ centaurid pkgs.jq self'.packages.xc-cw-contracts ]; + + text = '' + CHAIN_DATA="${devnet-root-directory}/.centaurid" + + CHAIN_ID="centauri-dev" + KEYRING_TEST="$CHAIN_DATA/keyring-test" + VALIDATOR_KEY=${validator-key} + PORT=26657 + BLOCK_SECONDS=5 + FEE=ppica + NETWORK_ID=2 + BINARY=centaurid + + GATEWAY_CONTRACT_ADDRESS =$(cat $CHAIN_DATA/gateway_contract_address)" + FORCE_NETWORK_OSMOSIS=$(cat << EOF { "config": { @@ -296,21 +331,8 @@ EOF ) "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_UATOM" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace - echo "$GATEWAY_CONTRACT_ADDRESS" > "$CHAIN_DATA/gateway_contract_address" sleep $BLOCK_SECONDS "$BINARY" query wasm contract-state all "$GATEWAY_CONTRACT_ADDRESS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --home "$CHAIN_DATA" - - # light client - centaurid tx gov submit-proposal ${ics10-grandpa-cw-proposal}/ics10_grandpa_cw.wasm.json --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166ppica --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json - sleep $BLOCK_SECONDS - centaurid query auth module-account gov --chain-id "$CHAIN_ID" --node tcp://localhost:26657 --home "$CHAIN_DATA" | jq '.account.base_account.address' --raw-output - PROPOSAL_ID=1 - centaurid tx gov vote $PROPOSAL_ID yes --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166ppica --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json - sleep 20 - centaurid query gov proposal $PROPOSAL_ID --chain-id "$CHAIN_ID" --node tcp://localhost:26657 --home "$CHAIN_DATA" | - jq '.status' - sleep $BLOCK_SECONDS - centaurid query 08-wasm all-wasm-code --chain-id "$CHAIN_ID" --home "$CHAIN_DATA" --output json --node tcp://localhost:26657 | jq '.code_ids[0]' --raw-output | tee "$CHAIN_DATA/code_id" ''; }; From 47c9286b4f8644736d15eb5f1399d64d4a7f28a5 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Tue, 8 Aug 2023 22:09:24 +0100 Subject: [PATCH 04/14] data reuse --- .../composable-centauri/flake-module.nix | 189 ++++++++++++------ 1 file changed, 124 insertions(+), 65 deletions(-) diff --git a/inputs/notional-labs/composable-centauri/flake-module.nix b/inputs/notional-labs/composable-centauri/flake-module.nix index 91a2ec90020..7036c9d2486 100644 --- a/inputs/notional-labs/composable-centauri/flake-module.nix +++ b/inputs/notional-labs/composable-centauri/flake-module.nix @@ -62,6 +62,36 @@ NETWORK_ID=2 BINARY=centaurid + "$BINARY" tx gov submit-proposal ${ics10-grandpa-cw-proposal}/ics10_grandpa_cw.wasm.json --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166ppica --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json + sleep $BLOCK_SECONDS + "$BINARY" query auth module-account gov --chain-id "$CHAIN_ID" --node tcp://localhost:26657 --home "$CHAIN_DATA" | jq '.account.base_account.address' --raw-output + PROPOSAL_ID=1 + "$BINARY" tx gov vote $PROPOSAL_ID yes --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166ppica --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json + sleep 20 + "$BINARY" query gov proposal $PROPOSAL_ID --chain-id "$CHAIN_ID" --node tcp://localhost:26657 --home "$CHAIN_DATA" | + jq '.status' + sleep $BLOCK_SECONDS + "$BINARY" query 08-wasm all-wasm-code --chain-id "$CHAIN_ID" --home "$CHAIN_DATA" --output json --node tcp://localhost:26657 | jq '.code_ids[0]' --raw-output | tee "$CHAIN_DATA/code_id" + ''; + }; + + centaurid-xcvm-init = pkgs.writeShellApplication { + name = "centaurid-init"; + runtimeInputs = devnetTools.withBaseContainerTools + ++ [ centaurid pkgs.jq self'.packages.xc-cw-contracts ]; + + text = '' + CHAIN_DATA="${devnet-root-directory}/.centaurid" + + CHAIN_ID="centauri-dev" + KEYRING_TEST="$CHAIN_DATA/keyring-test" + VALIDATOR_KEY=${cosmosTools.xcvm.centauri} + PORT=26657 + BLOCK_SECONDS=5 + FEE=ppica + NETWORK_ID=2 + BINARY=centaurid + function init_xcvm() { local INSTANTIATE=$1 echo $VALIDATOR_KEY @@ -94,23 +124,11 @@ EOF ) - init_xcvm "$INSTANTIATE" - - # light client - centaurid tx gov submit-proposal ${ics10-grandpa-cw-proposal}/ics10_grandpa_cw.wasm.json --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166ppica --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json - sleep $BLOCK_SECONDS - centaurid query auth module-account gov --chain-id "$CHAIN_ID" --node tcp://localhost:26657 --home "$CHAIN_DATA" | jq '.account.base_account.address' --raw-output - PROPOSAL_ID=1 - centaurid tx gov vote $PROPOSAL_ID yes --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166ppica --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json - sleep 20 - centaurid query gov proposal $PROPOSAL_ID --chain-id "$CHAIN_ID" --node tcp://localhost:26657 --home "$CHAIN_DATA" | - jq '.status' - sleep $BLOCK_SECONDS - centaurid query 08-wasm all-wasm-code --chain-id "$CHAIN_ID" --home "$CHAIN_DATA" --output json --node tcp://localhost:26657 | jq '.code_ids[0]' --raw-output | tee "$CHAIN_DATA/code_id" + init_xcvm "$INSTANTIATE" ''; }; - centaurid-xcvm = pkgs.writeShellApplication { + centaurid-xcvm-config = pkgs.writeShellApplication { name = "centaurid-init"; runtimeInputs = devnetTools.withBaseContainerTools ++ [ centaurid pkgs.jq self'.packages.xc-cw-contracts ]; @@ -127,7 +145,43 @@ NETWORK_ID=2 BINARY=centaurid - GATEWAY_CONTRACT_ADDRESS =$(cat $CHAIN_DATA/gateway_contract_address)" + + + function init_xcvm() { + local INSTANTIATE=$1 + echo $VALIDATOR_KEY + echo $NETWORK_ID + "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_gateway.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" + GATEWAY_CODE_ID=1 + + sleep $BLOCK_SECONDS + "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_interpreter.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" + INTERPRETER_CODE_ID=2 + + sleep $BLOCK_SECONDS + "$BINARY" tx wasm store "${self'.packages.cw20_base}" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" + + sleep $BLOCK_SECONDS + + "$BINARY" tx wasm instantiate2 $GATEWAY_CODE_ID "$INSTANTIATE" "1234" --label "xc-gateway" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --admin "$VALIDATOR_KEY" + + sleep $BLOCK_SECONDS + GATEWAY_CONTRACT_ADDRESS=$("$BINARY" query wasm list-contract-by-code "$GATEWAY_CODE_ID" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --home "$CHAIN_DATA" | dasel --read json '.contracts.[0]' --write yaml) + echo "$GATEWAY_CONTRACT_ADDRESS" > "$CHAIN_DATA/gateway_contract_address" + } + + + INSTANTIATE=$(cat << EOF + { + "admin" : "$VALIDATOR_KEY", + "here_id" : $NETWORK_ID + } + EOF + ) + + init_xcvm "$INSTANTIATE" + + GATEWAY_CONTRACT_ADDRESS=$(cat $CHAIN_DATA/gateway_contract_address)" FORCE_NETWORK_OSMOSIS=$(cat << EOF { @@ -421,58 +475,63 @@ echo "removing data dir" rm --force --recursive "$CHAIN_DATA" fi + if [[ ! -d "$CHAIN_DATA" ]]; then + mkdir --parents "$CHAIN_DATA" + mkdir --parents "$CHAIN_DATA/config/gentx" + mkdir --parents "$KEYRING_TEST" + echo "${validator-mnemonic}" | centaurid init "$CHAIN_ID" --chain-id "$CHAIN_ID" --default-denom ${native_denom} --home "$CHAIN_DATA" --recover + + function jq-genesis() { + jq -r "$1" > "$CHAIN_DATA/config/genesis-update.json" < "$CHAIN_DATA/config/genesis.json" + mv --force "$CHAIN_DATA/config/genesis-update.json" "$CHAIN_DATA/config/genesis.json" + } - mkdir --parents "$CHAIN_DATA" - mkdir --parents "$CHAIN_DATA/config/gentx" - mkdir --parents "$KEYRING_TEST" - echo "${validator-mnemonic}" | centaurid init "$CHAIN_ID" --chain-id "$CHAIN_ID" --default-denom ${native_denom} --home "$CHAIN_DATA" --recover - - function jq-genesis() { - jq -r "$1" > "$CHAIN_DATA/config/genesis-update.json" < "$CHAIN_DATA/config/genesis.json" - mv --force "$CHAIN_DATA/config/genesis-update.json" "$CHAIN_DATA/config/genesis.json" - } - - jq-genesis '.consensus_params.block.max_gas |= "-1"' - jq-genesis '.app_state.gov.params.voting_period |= "${gov.voting_period}"' - jq-genesis '.app_state.gov.params.max_deposit_period |= "${gov.max_deposit_period}"' - - jq-genesis '.app_state.transmiddleware.token_infos[0].ibc_denom |= "ibc/632DBFDB06584976F1351A66E873BF0F7A19FAA083425FEC9890C90993E5F0A4"' - jq-genesis '.app_state.transmiddleware.token_infos[0].channel_id |= "channel-0"' - jq-genesis '.app_state.transmiddleware.token_infos[0].native_denom |= "ppica"' - jq-genesis '.app_state.transmiddleware.token_infos[0].asset_id |= "1"' - - sed -i 's/keyring-backend = "os"/keyring-backend = "test"/' "$CHAIN_DATA/config/client.toml" - sed -i 's/keyring-backend = "os"/keyring-backend = "test"/' "$CHAIN_DATA/config/client.toml" - sed -i 's/keyring-backend = "os"/keyring-backend = "test"/' "$CHAIN_DATA/config/client.toml" - sed -i 's/output = "text"/output = "json"/' "$CHAIN_DATA/config/client.toml" - sed -i "s/cors_allowed_origins = \[\]/cors_allowed_origins = \[\"\*\"\]/" "$CHAIN_DATA/config/config.toml" - sed -i "s/swagger = false/swagger = true/" "$CHAIN_DATA/config/app.toml" - sed -i "s/rpc-max-body-bytes = 1000000/rpc-max-body-bytes = 10000000/" "$CHAIN_DATA/config/app.toml" - sed -i "s/max_body_bytes = 1000000/max_body_bytes = 10000000/" "$CHAIN_DATA/config/config.toml" - sed -i "s/max_header_bytes = 1048576/max_header_bytes = 10485760/" "$CHAIN_DATA/config/config.toml" - sed -i "s/max_tx_bytes = 1048576/max_tx_bytes = 10485760/" "$CHAIN_DATA/config/config.toml" - - echo "document prefer nurse marriage flavor cheese west when knee drink sorry minimum thunder tilt cherry behave cute stove elder couch badge gown coral expire" | centaurid keys add alice --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true - echo "bleak slush nose opinion document sample embark couple cabbage soccer cage slow father witness canyon ring distance hub denial topic great beyond actress problem" | centaurid keys add bob --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true - echo "coffee hospital claim ability wrap load display submit lecture solid secret law base barrel miss tattoo desert want wall bar ketchup sauce real unknown" | centaurid keys add charlie --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true - echo "${validator-mnemonic}" | centaurid keys add ${cosmosTools.validators.moniker} --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true - echo "notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius" | centaurid keys add test1 --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true - echo "quality vacuum heart guard buzz spike sight swarm shove special gym robust assume sudden deposit grid alcohol choice devote leader tilt noodle tide penalty" | centaurid keys add test2 --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true - echo "symbol force gallery make bulk round subway violin worry mixture penalty kingdom boring survey tool fringe patrol sausage hard admit remember broken alien absorb" | centaurid keys add test3 --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true - echo "black frequent sponsor nice claim rally hunt suit parent size stumble expire forest avocado mistake agree trend witness lounge shiver image smoke stool chicken" | centaurid keys add relayer --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true - function add-genesis-account () { - centaurid --keyring-backend test add-genesis-account "$1" "10000000000000000000000ppica" --keyring-backend test --home "$CHAIN_DATA" - } + jq-genesis '.consensus_params.block.max_gas |= "-1"' + jq-genesis '.app_state.gov.params.voting_period |= "${gov.voting_period}"' + jq-genesis '.app_state.gov.params.max_deposit_period |= "${gov.max_deposit_period}"' + + jq-genesis '.app_state.transmiddleware.token_infos[0].ibc_denom |= "ibc/632DBFDB06584976F1351A66E873BF0F7A19FAA083425FEC9890C90993E5F0A4"' + jq-genesis '.app_state.transmiddleware.token_infos[0].channel_id |= "channel-0"' + jq-genesis '.app_state.transmiddleware.token_infos[0].native_denom |= "ppica"' + jq-genesis '.app_state.transmiddleware.token_infos[0].asset_id |= "1"' + + sed -i 's/keyring-backend = "os"/keyring-backend = "test"/' "$CHAIN_DATA/config/client.toml" + sed -i 's/keyring-backend = "os"/keyring-backend = "test"/' "$CHAIN_DATA/config/client.toml" + sed -i 's/keyring-backend = "os"/keyring-backend = "test"/' "$CHAIN_DATA/config/client.toml" + sed -i 's/output = "text"/output = "json"/' "$CHAIN_DATA/config/client.toml" + sed -i "s/cors_allowed_origins = \[\]/cors_allowed_origins = \[\"\*\"\]/" "$CHAIN_DATA/config/config.toml" + sed -i "s/swagger = false/swagger = true/" "$CHAIN_DATA/config/app.toml" + sed -i "s/rpc-max-body-bytes = 1000000/rpc-max-body-bytes = 10000000/" "$CHAIN_DATA/config/app.toml" + sed -i "s/max_body_bytes = 1000000/max_body_bytes = 10000000/" "$CHAIN_DATA/config/config.toml" + sed -i "s/max_header_bytes = 1048576/max_header_bytes = 10485760/" "$CHAIN_DATA/config/config.toml" + sed -i "s/max_tx_bytes = 1048576/max_tx_bytes = 10485760/" "$CHAIN_DATA/config/config.toml" + + echo "document prefer nurse marriage flavor cheese west when knee drink sorry minimum thunder tilt cherry behave cute stove elder couch badge gown coral expire" | centaurid keys add alice --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true + echo "bleak slush nose opinion document sample embark couple cabbage soccer cage slow father witness canyon ring distance hub denial topic great beyond actress problem" | centaurid keys add bob --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true + echo "coffee hospital claim ability wrap load display submit lecture solid secret law base barrel miss tattoo desert want wall bar ketchup sauce real unknown" | centaurid keys add charlie --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true + echo "${validator-mnemonic}" | centaurid keys add ${cosmosTools.validators.moniker} --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true + echo "${cosmosTools.xcvm.mnemonic}" | centaurid keys add ${cosmosTools.xcvm.moniker} --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true + echo "notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius" | centaurid keys add test1 --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true + echo "quality vacuum heart guard buzz spike sight swarm shove special gym robust assume sudden deposit grid alcohol choice devote leader tilt noodle tide penalty" | centaurid keys add test2 --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true + echo "symbol force gallery make bulk round subway violin worry mixture penalty kingdom boring survey tool fringe patrol sausage hard admit remember broken alien absorb" | centaurid keys add test3 --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true + echo "black frequent sponsor nice claim rally hunt suit parent size stumble expire forest avocado mistake agree trend witness lounge shiver image smoke stool chicken" | centaurid keys add relayer --recover --keyring-backend test --keyring-dir "$KEYRING_TEST" || true + function add-genesis-account () { + centaurid --keyring-backend test add-genesis-account "$1" "10000000000000000000000ppica" --keyring-backend test --home "$CHAIN_DATA" + } - add-genesis-account centauri1qvdeu4x34rapp3wc8fym5g4wu343mswxxgc6wf - add-genesis-account centauri1zr4ng42laatyh9zx238n20r74spcrlct6jsqaw - add-genesis-account centauri1makf5hslxqxzl29uyeyyddf89ff7edxyr7ewm5 - add-genesis-account ${validator-key} - add-genesis-account centauri1cyyzpxplxdzkeea7kwsydadg87357qnamvg3y3 - add-genesis-account centauri18s5lynnmx37hq4wlrw9gdn68sg2uxp5ry85k7d - add-genesis-account centauri1qwexv7c6sm95lwhzn9027vyu2ccneaqapystyu - centaurid --keyring-backend test --keyring-dir "$KEYRING_TEST" --home "$CHAIN_DATA" gentx ${cosmosTools.validators.moniker} "250000000000000ppica" --chain-id="$CHAIN_ID" --amount="250000000000000ppica" - centaurid collect-gentxs --home "$CHAIN_DATA" --gentx-dir "$CHAIN_DATA/config/gentx" + add-genesis-account centauri1qvdeu4x34rapp3wc8fym5g4wu343mswxxgc6wf + add-genesis-account centauri1zr4ng42laatyh9zx238n20r74spcrlct6jsqaw + add-genesis-account centauri1makf5hslxqxzl29uyeyyddf89ff7edxyr7ewm5 + add-genesis-account ${validator-key} + add-genesis-account ${cosmosTools.xcvm.centauri} + add-genesis-account centauri1cyyzpxplxdzkeea7kwsydadg87357qnamvg3y3 + add-genesis-account centauri18s5lynnmx37hq4wlrw9gdn68sg2uxp5ry85k7d + add-genesis-account centauri1qwexv7c6sm95lwhzn9027vyu2ccneaqapystyu + centaurid --keyring-backend test --keyring-dir "$KEYRING_TEST" --home "$CHAIN_DATA" gentx ${cosmosTools.validators.moniker} "250000000000000ppica" --chain-id="$CHAIN_ID" --amount="250000000000000ppica" + centaurid collect-gentxs --home "$CHAIN_DATA" --gentx-dir "$CHAIN_DATA/config/gentx" + else + echo "WARNING: REUSING EXISTING DATA FOLDER" + fi centaurid start --rpc.unsafe --rpc.laddr tcp://0.0.0.0:26657 --pruning=nothing --minimum-gas-prices=0ppica --log_level debug --home "$CHAIN_DATA" --db_dir "$CHAIN_DATA/data" --trace --with-tendermint true --transport socket --trace-store $CHAIN_DATA/kvstore.log --grpc.address localhost:9090 --grpc.enable true --grpc-web.enable false --api.enable true --cpu-profile $CHAIN_DATA/cpu-profile.log --p2p.pex false --p2p.upnp false ''; }; From 73cda39ddb5d395f2650a6e550e7829a3a68001e Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Tue, 8 Aug 2023 23:00:20 +0100 Subject: [PATCH 05/14] centaurid --- flake/process-compose.nix | 15 +++ .../composable-centauri/flake-module.nix | 109 +++++------------- 2 files changed, 46 insertions(+), 78 deletions(-) diff --git a/flake/process-compose.nix b/flake/process-compose.nix index 4e28286d4c2..47e6415cca0 100644 --- a/flake/process-compose.nix +++ b/flake/process-compose.nix @@ -439,6 +439,21 @@ availability = { restart = "on_failure"; }; }; + centauri-xcvm-init = { + command = self'.packages.centaurid-xcvm-init; + depends_on."centauri".condition = "process_healthy"; + log_location = "/tmp/composable-devnet/centauri-xcvm-init.log"; + availability = { restart = "on_failure"; }; + }; + + centauri-xcvm-config = { + command = self'.packages.centaurid-xcvm-config; + depends_on."centauri-xcvm-init".condition = "process_completed_successfully"; + log_location = "/tmp/composable-devnet/centauri-xcvm-config.log"; + availability = { restart = "on_failure"; }; + }; + + osmosis = { command = self'.packages.osmosisd-gen; readiness_probe.http_get = { diff --git a/inputs/notional-labs/composable-centauri/flake-module.nix b/inputs/notional-labs/composable-centauri/flake-module.nix index 7036c9d2486..4c0077d0ae0 100644 --- a/inputs/notional-labs/composable-centauri/flake-module.nix +++ b/inputs/notional-labs/composable-centauri/flake-module.nix @@ -58,25 +58,23 @@ VALIDATOR_KEY=${validator-key} PORT=26657 BLOCK_SECONDS=5 - FEE=ppica - NETWORK_ID=2 + FEE=ppica BINARY=centaurid - "$BINARY" tx gov submit-proposal ${ics10-grandpa-cw-proposal}/ics10_grandpa_cw.wasm.json --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166ppica --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json + "$BINARY" tx gov submit-proposal ${ics10-grandpa-cw-proposal}/ics10_grandpa_cw.wasm.json --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166$FEE --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json sleep $BLOCK_SECONDS - "$BINARY" query auth module-account gov --chain-id "$CHAIN_ID" --node tcp://localhost:26657 --home "$CHAIN_DATA" | jq '.account.base_account.address' --raw-output + "$BINARY" query auth module-account gov --chain-id "$CHAIN_ID" --node tcp://localhost:$PORT --home "$CHAIN_DATA" | jq '.account.base_account.address' --raw-output PROPOSAL_ID=1 - "$BINARY" tx gov vote $PROPOSAL_ID yes --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166ppica --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json + "$BINARY" tx gov vote $PROPOSAL_ID yes --from "$VALIDATOR_KEY" --keyring-backend test --gas 9021526220000 --fees 92000000166$FEE --keyring-dir "$KEYRING_TEST" --chain-id "$CHAIN_ID" --yes --home "$CHAIN_DATA" --output json sleep 20 - "$BINARY" query gov proposal $PROPOSAL_ID --chain-id "$CHAIN_ID" --node tcp://localhost:26657 --home "$CHAIN_DATA" | - jq '.status' + "$BINARY" query gov proposal $PROPOSAL_ID --chain-id "$CHAIN_ID" --node tcp://localhost:$PORT --home "$CHAIN_DATA" | jq '.status' sleep $BLOCK_SECONDS - "$BINARY" query 08-wasm all-wasm-code --chain-id "$CHAIN_ID" --home "$CHAIN_DATA" --output json --node tcp://localhost:26657 | jq '.code_ids[0]' --raw-output | tee "$CHAIN_DATA/code_id" + "$BINARY" query 08-wasm all-wasm-code --chain-id "$CHAIN_ID" --home "$CHAIN_DATA" --output json --node tcp://localhost:$PORT | jq '.code_ids[0]' --raw-output | tee "$CHAIN_DATA/code_id" ''; }; centaurid-xcvm-init = pkgs.writeShellApplication { - name = "centaurid-init"; + name = "centaurid-xcvm-init"; runtimeInputs = devnetTools.withBaseContainerTools ++ [ centaurid pkgs.jq self'.packages.xc-cw-contracts ]; @@ -85,7 +83,7 @@ CHAIN_ID="centauri-dev" KEYRING_TEST="$CHAIN_DATA/keyring-test" - VALIDATOR_KEY=${cosmosTools.xcvm.centauri} + KEY=${cosmosTools.xcvm.centauri} PORT=26657 BLOCK_SECONDS=5 FEE=ppica @@ -94,31 +92,28 @@ function init_xcvm() { local INSTANTIATE=$1 - echo $VALIDATOR_KEY - echo $NETWORK_ID - "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_gateway.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" + "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_gateway.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" GATEWAY_CODE_ID=1 sleep $BLOCK_SECONDS - "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_interpreter.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" - INTERPRETER_CODE_ID=2 + "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_interpreter.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" sleep $BLOCK_SECONDS - "$BINARY" tx wasm store "${self'.packages.cw20_base}" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" + "$BINARY" tx wasm store "${self'.packages.cw20_base}" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" sleep $BLOCK_SECONDS - "$BINARY" tx wasm instantiate2 $GATEWAY_CODE_ID "$INSTANTIATE" "1234" --label "xc-gateway" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --admin "$VALIDATOR_KEY" + "$BINARY" tx wasm instantiate2 $GATEWAY_CODE_ID "$INSTANTIATE" "1234" --label "xc-gateway" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" --admin "$KEY" sleep $BLOCK_SECONDS GATEWAY_CONTRACT_ADDRESS=$("$BINARY" query wasm list-contract-by-code "$GATEWAY_CODE_ID" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --home "$CHAIN_DATA" | dasel --read json '.contracts.[0]' --write yaml) echo "$GATEWAY_CONTRACT_ADDRESS" > "$CHAIN_DATA/gateway_contract_address" + echo "2" > "$CHAIN_DATA/interpreter_code_id" } - INSTANTIATE=$(cat << EOF { - "admin" : "$VALIDATOR_KEY", + "admin" : "$KEY", "here_id" : $NETWORK_ID } EOF @@ -129,7 +124,7 @@ }; centaurid-xcvm-config = pkgs.writeShellApplication { - name = "centaurid-init"; + name = "centaurid-xcvm-config"; runtimeInputs = devnetTools.withBaseContainerTools ++ [ centaurid pkgs.jq self'.packages.xc-cw-contracts ]; @@ -138,50 +133,13 @@ CHAIN_ID="centauri-dev" KEYRING_TEST="$CHAIN_DATA/keyring-test" - VALIDATOR_KEY=${validator-key} + KEY=${cosmosTools.xcvm.centauri} PORT=26657 BLOCK_SECONDS=5 FEE=ppica - NETWORK_ID=2 BINARY=centaurid - - - - function init_xcvm() { - local INSTANTIATE=$1 - echo $VALIDATOR_KEY - echo $NETWORK_ID - "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_gateway.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" - GATEWAY_CODE_ID=1 - - sleep $BLOCK_SECONDS - "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_interpreter.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" - INTERPRETER_CODE_ID=2 - - sleep $BLOCK_SECONDS - "$BINARY" tx wasm store "${self'.packages.cw20_base}" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" - - sleep $BLOCK_SECONDS - - "$BINARY" tx wasm instantiate2 $GATEWAY_CODE_ID "$INSTANTIATE" "1234" --label "xc-gateway" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --admin "$VALIDATOR_KEY" - - sleep $BLOCK_SECONDS - GATEWAY_CONTRACT_ADDRESS=$("$BINARY" query wasm list-contract-by-code "$GATEWAY_CODE_ID" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --home "$CHAIN_DATA" | dasel --read json '.contracts.[0]' --write yaml) - echo "$GATEWAY_CONTRACT_ADDRESS" > "$CHAIN_DATA/gateway_contract_address" - } - - - INSTANTIATE=$(cat << EOF - { - "admin" : "$VALIDATOR_KEY", - "here_id" : $NETWORK_ID - } - EOF - ) - - init_xcvm "$INSTANTIATE" - - GATEWAY_CONTRACT_ADDRESS=$(cat $CHAIN_DATA/gateway_contract_address)" + GATEWAY_CONTRACT_ADDRESS=$(cat $CHAIN_DATA/gateway_contract_address) + INTERPRETER_CODE_ID=$(cat $CHAIN_DATA/interpreter_code_id) FORCE_NETWORK_OSMOSIS=$(cat << EOF { @@ -195,7 +153,7 @@ "cosm_wasm": { "contract": "$GATEWAY_CONTRACT_ADDRESS", "interpreter_code_id": $INTERPRETER_CODE_ID, - "admin": "${validator-key}" + "admin": "$KEY" } }, "ibc": { @@ -216,7 +174,7 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_NETWORK_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_NETWORK_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS FORCE_NETWORK_CENTAURI=$(cat << EOF @@ -231,7 +189,7 @@ "cosm_wasm": { "contract": "$GATEWAY_CONTRACT_ADDRESS", "interpreter_code_id": $INTERPRETER_CODE_ID, - "admin": "${validator-key}" + "admin": "$KEY" } }, "ibc": { @@ -252,7 +210,7 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_NETWORK_CENTAURI" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_NETWORK_CENTAURI" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS @@ -277,9 +235,7 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_CENTAURI_TO_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace - - # + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_CENTAURI_TO_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS FORCE_PICA=$(cat << EOF @@ -306,7 +262,7 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_PICA" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_PICA" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS @@ -334,7 +290,7 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_PICA_ON_CENTAURI" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_PICA_ON_CENTAURI" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS @@ -362,9 +318,7 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_PICA_ON_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace - - + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_PICA_ON_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS @@ -384,7 +338,7 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_UATOM" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_UATOM" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS "$BINARY" query wasm contract-state all "$GATEWAY_CONTRACT_ADDRESS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --home "$CHAIN_DATA" ''; @@ -448,7 +402,7 @@ BLOCK_SECONDS=5 BINARY=centaurid GATEWAY_CONTRACT_ADDRESS=$(cat "$CHAIN_DATA/gateway_contract_address") - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$TRANSFER_PICA_TO_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 1000000000"$FEE" --amount 1000000000"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$TRANSFER_PICA_TO_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 1000000000"$FEE" --amount 1000000000"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS ''; }; @@ -457,8 +411,7 @@ name = "centaurid-gen-fresh"; runtimeInputs = [ centaurid-gen ]; text = '' - rm --force --recursive ${devnet-root-directory} - centaurid-gen + centaurid-gen fresh ''; }; @@ -471,7 +424,7 @@ CHAIN_ID="centauri-dev" KEYRING_TEST="$CHAIN_DATA/keyring-test" - if test "''${1-reuse}" == "fresh" ; then + if test "''${1-reuse}" == "fresh"; then echo "removing data dir" rm --force --recursive "$CHAIN_DATA" fi @@ -538,7 +491,7 @@ in { packages = rec { inherit centaurid centaurid-gen centaurid-init centaurid-gen-fresh - ics10-grandpa-cw-proposal xc-transfer-pica-from-centauri-to-osmosis; + ics10-grandpa-cw-proposal xc-transfer-pica-from-centauri-to-osmosis centaurid-xcvm-init centaurid-xcvm-config; }; }; } From 05373ef64d0531eb77b12468d7b7bc7999195b5f Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Tue, 8 Aug 2023 23:13:52 +0100 Subject: [PATCH 06/14] wtf? --- .../contracts/gateway/src/contract/execute.rs | 4 +- .../composable-centauri/flake-module.nix | 163 ++++++++++-------- 2 files changed, 92 insertions(+), 75 deletions(-) diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs index 860bea9807a..78ecceab877 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs @@ -178,8 +178,7 @@ pub(crate) fn handle_execute_program_privilleged( msg::GatewayId::CosmWasm { interpreter_code_id, .. } => interpreter_code_id, }; deps.api.debug("instantiating interpreter"); - let instantiate_msg: CosmosMsg = WasmMsg::Instantiate { - // router is the default admin of a contract + let instantiate_msg: CosmosMsg = WasmMsg::Instantiate2 { admin: Some(env.contract.address.clone().into_string()), code_id: interpreter_code_id, msg: to_binary(&cw_xc_interpreter::msg::InstantiateMsg { @@ -188,6 +187,7 @@ pub(crate) fn handle_execute_program_privilleged( })?, funds: vec![], label: format!("xcvm-interpreter-{interpreter_origin}"), + salt: interpreter_origin.to_string().bytes().into(), } .into(); diff --git a/inputs/notional-labs/composable-centauri/flake-module.nix b/inputs/notional-labs/composable-centauri/flake-module.nix index 4c0077d0ae0..9f1e5bd29ce 100644 --- a/inputs/notional-labs/composable-centauri/flake-module.nix +++ b/inputs/notional-labs/composable-centauri/flake-module.nix @@ -1,6 +1,18 @@ { self, ... }: { - perSystem = { config, self', inputs', pkgs, lib, system, crane - , systemCommonRust, subnix, devnetTools, cosmosTools, ... }: + perSystem = + { config + , self' + , inputs' + , pkgs + , lib + , system + , crane + , systemCommonRust + , subnix + , devnetTools + , cosmosTools + , ... + }: let devnet-root-directory = cosmosTools.devnet-root-directory; validator-mnemonic = cosmosTools.validators.mnemonic; @@ -31,20 +43,22 @@ "summary" = "none"; }; - ics10-grandpa-cw-proposal = let - code = builtins.readFile - "${self'.packages.ics10-grandpa-cw}/lib/ics10_grandpa_cw.wasm.gz.txt"; - code-file = builtins.toFile "ics10_grandpa_cw.wasm.json" - (builtins.toJSON - (ibc-lightclients-wasm-v1-msg-push-new-wasm-code code)); - in pkgs.stdenv.mkDerivation { - name = "ics10-grandpa-cw-proposal"; - dontUnpack = true; - installPhase = '' - mkdir --parents $out - cp ${code-file} $out/ics10_grandpa_cw.wasm.json - ''; - }; + ics10-grandpa-cw-proposal = + let + code = builtins.readFile + "${self'.packages.ics10-grandpa-cw}/lib/ics10_grandpa_cw.wasm.gz.txt"; + code-file = builtins.toFile "ics10_grandpa_cw.wasm.json" + (builtins.toJSON + (ibc-lightclients-wasm-v1-msg-push-new-wasm-code code)); + in + pkgs.stdenv.mkDerivation { + name = "ics10-grandpa-cw-proposal"; + dontUnpack = true; + installPhase = '' + mkdir --parents $out + cp ${code-file} $out/ics10_grandpa_cw.wasm.json + ''; + }; centaurid-init = pkgs.writeShellApplication { name = "centaurid-init"; runtimeInputs = devnetTools.withBaseContainerTools @@ -349,62 +363,64 @@ runtimeInputs = devnetTools.withBaseContainerTools ++ [ centaurid pkgs.jq ]; text = '' - TRANSFER_PICA_TO_OSMOSIS=$(cat < Date: Wed, 9 Aug 2023 00:14:01 +0100 Subject: [PATCH 07/14] fixes --- .../contracts/gateway/src/contract/execute.rs | 2 +- .../gateway/src/contract/ibc/ics20.rs | 1 - code/xcvm/lib/core/src/gateway/mod.rs | 79 +++++++++++ code/xcvm/lib/core/src/gateway/sad.json | 1 + code/xcvm/lib/core/src/transport/ibc/mod.rs | 2 +- flake/osmosis.nix | 130 +++++++++++++++--- flake/process-compose.nix | 20 +-- 7 files changed, 201 insertions(+), 34 deletions(-) create mode 100644 code/xcvm/lib/core/src/gateway/sad.json diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs index 78ecceab877..28ffcfea42c 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs @@ -187,7 +187,7 @@ pub(crate) fn handle_execute_program_privilleged( })?, funds: vec![], label: format!("xcvm-interpreter-{interpreter_origin}"), - salt: interpreter_origin.to_string().bytes().into(), + salt: to_binary(&interpreter_origin.to_string().as_bytes())?, } .into(); diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs index cf21fc10e21..13a2123001a 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs @@ -8,7 +8,6 @@ use cosmwasm_std::{ }; use xc_core::{ gateway::{AssetItem, ExecuteMsg, ExecuteProgramMsg, GatewayId, OtherNetworkItem}, - proto::decode_packet, shared::{XcPacket, XcProgram}, transport::ibc::{to_cw_message, IbcRoute, XcMessageData}, AssetId, CallOrigin, diff --git a/code/xcvm/lib/core/src/gateway/mod.rs b/code/xcvm/lib/core/src/gateway/mod.rs index 270b39c17db..205bd5c2299 100644 --- a/code/xcvm/lib/core/src/gateway/mod.rs +++ b/code/xcvm/lib/core/src/gateway/mod.rs @@ -274,4 +274,83 @@ mod tests { .unwrap(); assert_eq!(program, expected) } + + #[test] + fn osmosis_spawn_with_asset() { + let osmo_on_osmosis = generate_asset_id(3.into(), 0, 1001); + let osmo_on_centauri = generate_asset_id(2.into(), 0, 1001); + let program: ExecuteMsg = ExecuteMsg::ExecuteProgram { + execute_program: ExecuteProgramMsg { + salt: b"spawn_with_asset".to_vec(), + program: XcProgram { + tag: b"spawn_with_asset".to_vec(), + instructions: [Instruction::Spawn { + network: 2.into(), + salt: b"spawn_with_asset".to_vec(), + assets: vec![(osmo_on_centauri, 1_000_000_000u128)].into(), + program: XcProgram { + tag: b"spawn_with_asset".to_vec(), + instructions: [].into(), + }, + }] + .into(), + }, + assets: vec![(osmo_on_osmosis, 1_000_000_000u128)].into(), + }, + tip: Addr::unchecked("osmo12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n"), + }; + + let program = serde_json_wasm::to_string(&program).expect("serde"); + //assert_eq!(program, "123"); + let expected = serde_json_wasm::to_string( + &serde_json_wasm::from_str::( + r#" + { + "execute_program": { + "execute_program": { + "salt": "737061776e5f776974685f6173736574", + "program": { + "tag": "737061776e5f776974685f6173736574", + "instructions": [ + { + "spawn": { + "network": 2, + "salt": "737061776e5f776974685f6173736574", + "assets": [ + [ + "158456325028528675187087901673", + { + "amount": { + "intercept": "1000000000", + "slope": "0" + }, + "is_unit": false + } + ] + ], + "program": { + "tag": "737061776e5f776974685f6173736574", + "instructions": [] + } + } + } + ] + }, + "assets": [ + [ + "237684487542793012780631852009", + "1000000000" + ] + ] + }, + "tip": "osmo12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n" + } + } + "#, + ) + .unwrap(), + ) + .unwrap(); + assert_eq!(program, expected) + } } diff --git a/code/xcvm/lib/core/src/gateway/sad.json b/code/xcvm/lib/core/src/gateway/sad.json new file mode 100644 index 00000000000..60b4b6b05d2 --- /dev/null +++ b/code/xcvm/lib/core/src/gateway/sad.json @@ -0,0 +1 @@ +"{\"execute_program\":{\"execute_program\":{\"salt\":\"737061776e5f776974685f6173736574\",\"program\":{\"tag\":\"737061776e5f776974685f6173736574\",\"instructions\":[{\"spawn\":{\"network\":2,\"salt\":\"737061776e5f776974685f6173736574\",\"assets\":[[\"237684487542793012780631852009\",{\"amount\":{\"intercept\":\"1000000000\",\"slope\":\"0\"},\"is_unit\":false}]],\"program\":{\"tag\":\"737061776e5f776974685f6173736574\",\"instructions\":[]}}}]},\"assets\":[[\"237684487542793012780631852009\",\"1000000000\"]]},\"tip\":\"osmo12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n\"}} \ No newline at end of file diff --git a/code/xcvm/lib/core/src/transport/ibc/mod.rs b/code/xcvm/lib/core/src/transport/ibc/mod.rs index c772179bb6c..bb4ec436215 100644 --- a/code/xcvm/lib/core/src/transport/ibc/mod.rs +++ b/code/xcvm/lib/core/src/transport/ibc/mod.rs @@ -1,7 +1,7 @@ pub mod ics20; pub mod picasso; -use crate::{prelude::*, proto::Encodable, shared::XcPacket, AssetId, NetworkId}; +use crate::{prelude::*, shared::XcPacket, AssetId, NetworkId}; use cosmwasm_std::{to_binary, CosmosMsg, IbcEndpoint, IbcTimeout, StdResult, WasmMsg}; use ibc_rs_scale::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; diff --git a/flake/osmosis.nix b/flake/osmosis.nix index bdb057172ce..8f8b61471a5 100644 --- a/flake/osmosis.nix +++ b/flake/osmosis.nix @@ -103,6 +103,7 @@ add-genesis-account "$VALIDATOR_MNEMONIC" "$VALIDATOR_MONIKER" add-genesis-account "$FAUCET_MNEMONIC" "faucet" add-genesis-account "$RELAYER_MNEMONIC" "relayer" + add-genesis-account "${cosmosTools.xcvm.mnemonic}" "xcvm" osmosisd gentx $VALIDATOR_MONIKER 500000000uosmo --keyring-backend=test --chain-id=$CHAIN_ID --home "$CHAIN_DATA" osmosisd collect-gentxs --home "$CHAIN_DATA" @@ -133,7 +134,7 @@ dasel put --type string --file $CONFIG_FOLDER/client.toml --value "test" '.keyring-backend' dasel put --type string --file $CONFIG_FOLDER/client.toml --value "json" '.output' - osmosisd start --home "$CHAIN_DATA" --rpc.unsafe --rpc.laddr tcp://0.0.0.0:$PORT --pruning=nothing --grpc.address localhost:19090 --address "tcp://0.0.0.0:36658" --p2p.external-address 43421 --p2p.laddr "tcp://0.0.0.0:36656" --p2p.pex false --p2p.upnp false --p2p.seed_mode true --log_level trace + osmosisd start --home "$CHAIN_DATA" --rpc.unsafe --rpc.laddr tcp://0.0.0.0:$PORT --pruning=nothing --grpc.address localhost:19090 --address "tcp://0.0.0.0:36658" --p2p.external-address 43421 --p2p.laddr "tcp://0.0.0.0:36656" --p2p.pex false --p2p.upnp false --p2p.seed_mode true --log_level trace --trace ''; }; @@ -151,7 +152,6 @@ runtimeInputs = devnetTools.withBaseContainerTools ++ [ osmosisd pkgs.jq pkgs.dasel ]; text = '' - # shellcheck disable=SC2034 HOME=/tmp/composable-devnet export HOME CHAIN_DATA="$HOME/.osmosisd" @@ -160,35 +160,35 @@ PORT=36657 BLOCK_SECONDS=5 FEE=uosmo - NETWORK_ID=4 - VALIDATOR_KEY=${validator-key} + NETWORK_ID=3 + KEY=${cosmosTools.xcvm.osmosis} BINARY=osmosisd - function init_xcvm() { + function init_xcvm() { local INSTANTIATE=$1 - echo $VALIDATOR_KEY echo $NETWORK_ID - "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_gateway.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" + "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_gateway.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" GATEWAY_CODE_ID=1 sleep $BLOCK_SECONDS - "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_interpreter.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" + "$BINARY" tx wasm store "${self'.packages.xc-cw-contracts}/lib/cw_xc_interpreter.wasm" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" INTERPRETER_CODE_ID=2 sleep $BLOCK_SECONDS - "$BINARY" tx wasm store "${self'.packages.cw20_base}" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" + "$BINARY" tx wasm store "${self'.packages.cw20_base}" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" sleep $BLOCK_SECONDS - "$BINARY" tx wasm instantiate2 $GATEWAY_CODE_ID "$INSTANTIATE" "1234" --label "xc-gateway" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --admin "$VALIDATOR_KEY" + "$BINARY" tx wasm instantiate2 $GATEWAY_CODE_ID "$INSTANTIATE" "1234" --label "xc-gateway" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166$FEE --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" --admin "$KEY" sleep $BLOCK_SECONDS GATEWAY_CONTRACT_ADDRESS=$("$BINARY" query wasm list-contract-by-code "$GATEWAY_CODE_ID" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --home "$CHAIN_DATA" | dasel --read json '.contracts.[0]' --write yaml) + echo "$GATEWAY_CONTRACT_ADDRESS" > "$CHAIN_DATA/gateway_contract_address" } INSTANTIATE=$(cat << EOF { - "admin" : "$VALIDATOR_KEY", + "admin" : "$KEY", "here_id" : $NETWORK_ID } EOF @@ -208,7 +208,7 @@ "cosm_wasm": { "contract": "$GATEWAY_CONTRACT_ADDRESS", "interpreter_code_id": $INTERPRETER_CODE_ID, - "admin": "${validator-key}" + "admin": "$KEY" } }, "ibc": { @@ -229,7 +229,7 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_NETWORK_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_NETWORK_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS FORCE_NETWORK_CENTAURI=$(cat << EOF @@ -244,7 +244,7 @@ "cosm_wasm": { "contract": "$GATEWAY_CONTRACT_ADDRESS", "interpreter_code_id": $INTERPRETER_CODE_ID, - "admin": "${validator-key}" + "admin": "$KEY" } }, "ibc": { @@ -265,7 +265,7 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_NETWORK_CENTAURI" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_NETWORK_CENTAURI" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS @@ -290,7 +290,7 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_CENTAURI_TO_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_CENTAURI_TO_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS @@ -318,19 +318,19 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_PICA" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_PICA" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" --trace --log_level trace sleep $BLOCK_SECONDS - FORCE_UATOM=$(cat << EOF + FORCE_OSMO_DIRECT_ON_CENTAURI=$(cat << EOF { "config": { "force_asset": { - "asset_id": "237684487542793012780631851010", + "asset_id": "158456325028528675187087901673", "from_network_id": 3, "local": { "native": { - "denom" : "uatom" + "denom" : "uosmo" } } } @@ -338,12 +338,100 @@ } EOF ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_UATOM" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.validators.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_OSMO_DIRECT_ON_CENTAURI" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" --trace --log_level trace + + sleep $BLOCK_SECONDS + FORCE_OSMO_ON_OSMOSIS=$(cat << EOF + { + "config": { + "force_asset": { + "asset_id": "237684487542793012780631852009", + "from_network_id": 3, + "local": { + "native": { + "denom" : "uosmo" + } + } + } + } + } + EOF + ) + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$FORCE_OSMO_ON_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from "$KEY" --keyring-dir "$KEYRING_TEST" --trace --log_level trace + sleep $BLOCK_SECONDS "$BINARY" query wasm contract-state all "$GATEWAY_CONTRACT_ADDRESS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --home "$CHAIN_DATA" ''; }; + + xc-transfer-osmo-from--osmosis-to-centauri = pkgs.writeShellApplication { + name = "xc-transfer-osmo-from--osmosis-to-centauri"; + runtimeInputs = devnetTools.withBaseContainerTools + ++ [ osmosisd pkgs.jq ]; + text = '' + HOME=/tmp/composable-devnet + export HOME + CHAIN_DATA="$HOME/.osmosisd" + KEYRING_TEST=$CHAIN_DATA + CHAIN_ID="osmosis-dev" + PORT=36657 + BLOCK_SECONDS=5 + FEE=uosmo + BINARY=osmosisd + GATEWAY_CONTRACT_ADDRESS=$(cat "$CHAIN_DATA/gateway_contract_address") + + TRANSFER_PICA_TO_OSMOSIS=$(cat << EOF + { + "execute_program": { + "execute_program": { + "salt": "737061776e5f776974685f6173736574", + "program": { + "tag": "737061776e5f776974685f6173736574", + "instructions": [ + { + "spawn": { + "network": 2, + "salt": "737061776e5f776974685f6173736574", + "assets": [ + [ + "158456325028528675187087901673", + { + "amount": { + "intercept": "1000000000", + "slope": "0" + }, + "is_unit": false + } + ] + ], + "program": { + "tag": "737061776e5f776974685f6173736574", + "instructions": [] + } + } + } + ] + }, + "assets": [ + [ + "237684487542793012780631852009", + "1000000000" + ] + ] + }, + "tip": "osmo12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n" + } + } + EOF + ) + + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$TRANSFER_PICA_TO_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 1000000000"$FEE" --amount 1000000000"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + sleep "$BLOCK_SECONDS" + '' + ; + }; + }; }; } diff --git a/flake/process-compose.nix b/flake/process-compose.nix index 47e6415cca0..26c7dafe1a2 100644 --- a/flake/process-compose.nix +++ b/flake/process-compose.nix @@ -480,16 +480,16 @@ availability = { restart = "on_failure"; }; }; - osmosis-centauri-hermes-relay = { - command = self'.packages.osmosis-centauri-hermes-relay; - depends_on = { - "osmosis-centauri-hermes-init".condition = - "process_completed_successfully"; - }; - log_location = - "/tmp/composable-devnet/osmosis-centauri-hermes-relay.log"; - availability = { restart = relay; }; - }; + # osmosis-centauri-hermes-relay = { + # command = self'.packages.osmosis-centauri-hermes-relay; + # depends_on = { + # "osmosis-centauri-hermes-init".condition = + # "process_completed_successfully"; + # }; + # log_location = + # "/tmp/composable-devnet/osmosis-centauri-hermes-relay.log"; + # availability = { restart = relay; }; + # }; }; }; }; From b014c4d5b2c6e16683254d7ffbfa0ef252891ca4 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 9 Aug 2023 09:44:05 +0100 Subject: [PATCH 08/14] making label shorter --- code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs index 28ffcfea42c..73d2b47a23d 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs @@ -186,7 +186,7 @@ pub(crate) fn handle_execute_program_privilleged( interpreter_origin: interpreter_origin.clone(), })?, funds: vec![], - label: format!("xcvm-interpreter-{interpreter_origin}"), + label: interpreter_origin.to_string(), salt: to_binary(&interpreter_origin.to_string().as_bytes())?, } .into(); From 546a13b294ee58a9e05ecacd6f6e9180f8eebc27 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 9 Aug 2023 16:43:16 +0100 Subject: [PATCH 09/14] added a way to call instantantiate --- .../contracts/gateway/src/contract/execute.rs | 19 ++++++++++++++++++- code/xcvm/lib/core/src/gateway/mod.rs | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs index 73d2b47a23d..514f9bcecb4 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs @@ -52,6 +52,23 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: msg::ExecuteMsg) super::ibc::ics20::ics20_message_hook(auth, msg, env, info) }, msg::ExecuteMsg::Shortcut(msg) => handle_shortcut(deps, env, info, msg), + msg::ExecuteMsg::Test(msg) => handle_test(deps, env, info, msg), + } +} + +fn handle_test(deps: DepsMut, env: Env, info: MessageInfo, msg: msg::TestSubMsg) -> Result { + let mut response = Response::new(); + match msg { + msg::TestSubMsg::InstantiateContract { code_id, msg } => { + let msg = WasmMsg::Instantiate { + admin: None, + code_id, + msg: to_binary(&msg)?, + funds: vec![], + label: "test".into(), + }; + return Ok(response.add_message(msg).add_event(make_event("test.instantiated"))) + }, } } @@ -178,7 +195,7 @@ pub(crate) fn handle_execute_program_privilleged( msg::GatewayId::CosmWasm { interpreter_code_id, .. } => interpreter_code_id, }; deps.api.debug("instantiating interpreter"); - let instantiate_msg: CosmosMsg = WasmMsg::Instantiate2 { + let instantiate_msg: CosmosMsg = WasmMsg::Instantiate2 { admin: Some(env.contract.address.clone().into_string()), code_id: interpreter_code_id, msg: to_binary(&cw_xc_interpreter::msg::InstantiateMsg { diff --git a/code/xcvm/lib/core/src/gateway/mod.rs b/code/xcvm/lib/core/src/gateway/mod.rs index 205bd5c2299..84838c9345b 100644 --- a/code/xcvm/lib/core/src/gateway/mod.rs +++ b/code/xcvm/lib/core/src/gateway/mod.rs @@ -51,6 +51,22 @@ pub enum ExecuteMsg { /// executed by host as part of memo handling MessageHook(XcMessageData), + + /// Allow to test if CW host supports some features + Test(TestSubMsg), +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[serde(rename_all = "snake_case")] +#[cfg_attr(feature = "std", derive(schemars::JsonSchema))] +pub enum TestSubMsg { + /// instantiates contract + InstantiateContract { + /// code of contract to instantiate + code_id: u64, + /// body of instantiate message + msg: serde_cw_value::Value, + }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] From ff1348cd102876b702645d86cf32500a26e549bf Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 9 Aug 2023 17:06:09 +0100 Subject: [PATCH 10/14] force instantaite --- .../contracts/gateway/src/contract/execute.rs | 21 +++---------------- .../cosmwasm/contracts/gateway/src/lib.rs | 1 + .../cosmwasm/contracts/gateway/src/user.rs | 10 +++++++++ code/xcvm/lib/core/schema/raw/asd.json | 17 +++++++++++++++ code/xcvm/lib/core/src/gateway/config.rs | 3 +++ code/xcvm/lib/core/src/gateway/mod.rs | 3 --- 6 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 code/xcvm/cosmwasm/contracts/gateway/src/user.rs create mode 100644 code/xcvm/lib/core/schema/raw/asd.json diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs index 514f9bcecb4..b073e20686e 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs @@ -5,7 +5,7 @@ use crate::{ events::make_event, msg, network::{self, load_this}, - state, + state, user, }; use cosmwasm_std::{ @@ -52,23 +52,6 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: msg::ExecuteMsg) super::ibc::ics20::ics20_message_hook(auth, msg, env, info) }, msg::ExecuteMsg::Shortcut(msg) => handle_shortcut(deps, env, info, msg), - msg::ExecuteMsg::Test(msg) => handle_test(deps, env, info, msg), - } -} - -fn handle_test(deps: DepsMut, env: Env, info: MessageInfo, msg: msg::TestSubMsg) -> Result { - let mut response = Response::new(); - match msg { - msg::TestSubMsg::InstantiateContract { code_id, msg } => { - let msg = WasmMsg::Instantiate { - admin: None, - code_id, - msg: to_binary(&msg)?, - funds: vec![], - label: "test".into(), - }; - return Ok(response.add_message(msg).add_event(make_event("test.instantiated"))) - }, } } @@ -81,6 +64,8 @@ fn handle_config_msg(auth: auth::Admin, deps: DepsMut, msg: ConfigSubMsg) -> Res ConfigSubMsg::ForceRemoveAsset { asset_id } => assets::force_remove_asset(auth, deps, asset_id), ConfigSubMsg::ForceNetwork(msg) => network::force_network(auth, deps, msg), + ConfigSubMsg::ForceInstantiate { network_id, user_origin, salt } => + user::force_instantiate(auth, deps, network_id, user_origin, salt), } } diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs b/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs index c3a280e4d16..aea165cd6e6 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs @@ -11,3 +11,4 @@ mod events; mod network; mod prelude; pub mod state; +pub mod user; diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/user.rs b/code/xcvm/cosmwasm/contracts/gateway/src/user.rs new file mode 100644 index 00000000000..ad3d118f532 --- /dev/null +++ b/code/xcvm/cosmwasm/contracts/gateway/src/user.rs @@ -0,0 +1,10 @@ +use crate::prelude::*; + +pub(crate) fn force_instantiate(auth: crate::auth::Auth, deps: cosmwasm_std::DepsMut<'_>, network_id: xc_core::NetworkId, user_origin: String, salt: cosmwasm_std::Binary) -> Result { + + NETWORK.save(deps.storage, msg.network_id, &msg)?; + Ok(Response::new().add_event( + make_event("network.forced").add_attribute("network_id", msg.network_id.to_string()), + )) +} + diff --git a/code/xcvm/lib/core/schema/raw/asd.json b/code/xcvm/lib/core/schema/raw/asd.json new file mode 100644 index 00000000000..09201298198 --- /dev/null +++ b/code/xcvm/lib/core/schema/raw/asd.json @@ -0,0 +1,17 @@ +{ + "test": { + "instantiate_contract": { + "code_id": 2, + "msg": { + "gateway_address": "centauri1e0nh3davd6d3yh73sldwndww7zchetwsae8m9rz9x6hlg7w4ysrqhmaqju", + "interpreter_origin": { + "salt": "737061776e5f776974685f6173736574", + "user_origin": { + "network_id": 2, + "user_id": "test" + } + } + } + } + } +} \ No newline at end of file diff --git a/code/xcvm/lib/core/src/gateway/config.rs b/code/xcvm/lib/core/src/gateway/config.rs index 3a4d8030d61..ffb5ddeeb7a 100644 --- a/code/xcvm/lib/core/src/gateway/config.rs +++ b/code/xcvm/lib/core/src/gateway/config.rs @@ -161,6 +161,9 @@ pub enum ConfigSubMsg { /// Message sent by an admin to remove an asset from registry. ForceRemoveAsset { asset_id: AssetId }, + + /// instantiates interpreter on behalf of user + ForceInstantiate { network_id : NetworkId, user_origin: String, salt: Binary, } } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] diff --git a/code/xcvm/lib/core/src/gateway/mod.rs b/code/xcvm/lib/core/src/gateway/mod.rs index 84838c9345b..bb0cbae77e9 100644 --- a/code/xcvm/lib/core/src/gateway/mod.rs +++ b/code/xcvm/lib/core/src/gateway/mod.rs @@ -51,9 +51,6 @@ pub enum ExecuteMsg { /// executed by host as part of memo handling MessageHook(XcMessageData), - - /// Allow to test if CW host supports some features - Test(TestSubMsg), } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] From f5aca732c26d405ea59e8513b174defd0216bc62 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 9 Aug 2023 20:06:35 +0100 Subject: [PATCH 11/14] interpreter --- .../cosmwasm/contracts/gateway/src/auth.rs | 5 +- .../contracts/gateway/src/contract/execute.rs | 71 ++---------- .../contracts/gateway/src/contract/mod.rs | 4 +- .../contracts/gateway/src/interpreter.rs | 102 ++++++++++++++++++ .../cosmwasm/contracts/gateway/src/lib.rs | 2 +- .../gateway/src/state/interpreter.rs | 21 +++- .../cosmwasm/contracts/gateway/src/user.rs | 10 -- code/xcvm/lib/core/src/gateway/config.rs | 4 +- 8 files changed, 139 insertions(+), 80 deletions(-) create mode 100644 code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs delete mode 100644 code/xcvm/cosmwasm/contracts/gateway/src/user.rs diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/auth.rs b/code/xcvm/cosmwasm/contracts/gateway/src/auth.rs index 249b582850d..ad1b3d644bd 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/auth.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/auth.rs @@ -70,9 +70,8 @@ impl Auth { info: &MessageInfo, interpreter_origin: xc_core::InterpreterOrigin, ) -> Result { - let interpreter_address = state::interpreter::INTERPRETERS - .may_load(deps.storage, interpreter_origin)? - .map(|int| int.address); + let interpreter_address = state::interpreter::get_by_origin(deps, interpreter_origin) + .map(|int| int.address).ok(); Self::new(Some(&info.sender) == interpreter_address.as_ref()) } } diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs index b073e20686e..4b3dafd3e13 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs @@ -5,7 +5,7 @@ use crate::{ events::make_event, msg, network::{self, load_this}, - state, user, + state, interpreter, }; use cosmwasm_std::{ @@ -25,7 +25,7 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: msg::ExecuteMsg) match msg { ExecuteMsg::Config(msg) => { let auth = auth::Admin::authorise(deps.as_ref(), &info)?; - handle_config_msg(auth, deps, msg) + handle_config_msg(auth, deps, msg, env) }, msg::ExecuteMsg::ExecuteProgram { execute_program, tip } => @@ -55,7 +55,7 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: msg::ExecuteMsg) } } -fn handle_config_msg(auth: auth::Admin, deps: DepsMut, msg: ConfigSubMsg) -> Result { +fn handle_config_msg(auth: auth::Admin, deps: DepsMut, msg: ConfigSubMsg, env: Env) -> Result { deps.api.debug(serde_json_wasm::to_string(&msg)?.as_str()); match msg { ConfigSubMsg::ForceNetworkToNetwork(msg) => @@ -64,8 +64,8 @@ fn handle_config_msg(auth: auth::Admin, deps: DepsMut, msg: ConfigSubMsg) -> Res ConfigSubMsg::ForceRemoveAsset { asset_id } => assets::force_remove_asset(auth, deps, asset_id), ConfigSubMsg::ForceNetwork(msg) => network::force_network(auth, deps, msg), - ConfigSubMsg::ForceInstantiate { network_id, user_origin, salt } => - user::force_instantiate(auth, deps, network_id, user_origin, salt), + ConfigSubMsg::ForceInstantiate { user_origin, } => + interpreter::force_instantiate(auth, env.contract.address, deps, user_origin), } } @@ -158,9 +158,8 @@ pub(crate) fn handle_execute_program_privilleged( let config = load_this(deps.storage)?; let interpreter_origin = InterpreterOrigin { user_origin: call_origin.user(config.network_id), salt }; - let interpreter = - state::interpreter::INTERPRETERS.may_load(deps.storage, interpreter_origin.clone())?; - if let Some(state::interpreter::Interpreter { address }) = interpreter { + let interpreter = state::interpreter::get_by_origin(deps.as_ref(), interpreter_origin).ok(); + if let Some(state::interpreter::Interpreter { address, .. }) = interpreter { deps.api.debug("reusing existing interpreter and adding funds"); let response = send_funds_to_interpreter(deps.as_ref(), address.clone(), assets)?; let wasm_msg = wasm_execute( @@ -180,21 +179,10 @@ pub(crate) fn handle_execute_program_privilleged( msg::GatewayId::CosmWasm { interpreter_code_id, .. } => interpreter_code_id, }; deps.api.debug("instantiating interpreter"); - let instantiate_msg: CosmosMsg = WasmMsg::Instantiate2 { - admin: Some(env.contract.address.clone().into_string()), - code_id: interpreter_code_id, - msg: to_binary(&cw_xc_interpreter::msg::InstantiateMsg { - gateway_address: env.contract.address.clone().into_string(), - interpreter_origin: interpreter_origin.clone(), - })?, - funds: vec![], - label: interpreter_origin.to_string(), - salt: to_binary(&interpreter_origin.to_string().as_bytes())?, - } - .into(); + let admin = env.contract.address; + + let interpreter_instantiate_submessage = crate::interpreter::instantiate(deps.as_ref(), admin, interpreter_code_id, &interpreter_origin)?; - let interpreter_instantiate_submessage = - SubMsg::reply_on_success(instantiate_msg, INSTANTIATE_INTERPRETER_REPLY_ID); // Secondly, call itself again with the same parameters, so that this functions goes // into `Ok` state and properly executes the interpreter let self_call_message: CosmosMsg = wasm_execute( @@ -218,6 +206,7 @@ pub(crate) fn handle_execute_program_privilleged( } } + /// Transfer funds attached to a [`XCVMProgram`] before dispatching the program to the interpreter. fn send_funds_to_interpreter( deps: Deps, @@ -252,41 +241,3 @@ fn send_funds_to_interpreter( Ok(response) } -pub(crate) fn handle_instantiate_reply(deps: DepsMut, msg: Reply) -> StdResult { - let response = msg.result.into_result().map_err(StdError::generic_err)?; - - // Catch the default `instantiate` event which contains `_contract_address` attribute that - // has the instantiated contract's address - let address = &response - .events - .iter() - .find(|event| event.ty == "instantiate") - .ok_or_else(|| StdError::not_found("instantiate event not found"))? - .attributes - .iter() - .find(|attr| &attr.key == "_contract_address") - .ok_or_else(|| StdError::not_found("_contract_address attribute not found"))? - .value; - let interpreter_address = deps.api.addr_validate(address)?; - - // Interpreter provides `network_id, user_id` pair as an event for the router to know which - // pair is instantiated - let event_name = format!("wasm-{}", XCVM_INTERPRETER_EVENT_PREFIX); - let interpreter_origin = &response - .events - .iter() - .find(|event| event.ty.starts_with(&event_name)) - .ok_or_else(|| StdError::not_found("interpreter event not found"))? - .attributes - .iter() - .find(|attr| &attr.key == XCVM_INTERPRETER_EVENT_DATA_ORIGIN) - .ok_or_else(|| StdError::not_found("no data is returned from 'xcvm_interpreter'"))? - .value; - let interpreter_origin = - xc_core::shared::decode_base64::<_, InterpreterOrigin>(interpreter_origin.as_str())?; - - let interpreter = state::interpreter::Interpreter { address: interpreter_address }; - state::interpreter::INTERPRETERS.save(deps.storage, interpreter_origin, &interpreter)?; - - Ok(Response::new()) -} diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/mod.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/mod.rs index 4ce7e91cad3..40637539bd8 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/mod.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/mod.rs @@ -16,7 +16,7 @@ use cw2::set_contract_version; use cw_utils::ensure_from_older_version; use xc_core::XCVMAck; -use self::{execute::handle_instantiate_reply, ibc::make_ibc_failure_event}; +use self::{ibc::make_ibc_failure_event}; const CONTRACT_NAME: &str = "composable:xcvm-gateway"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -57,7 +57,7 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result { match msg.id { EXEC_PROGRAM_REPLY_ID => handle_exec_reply(msg), INSTANTIATE_INTERPRETER_REPLY_ID => - handle_instantiate_reply(deps, msg).map_err(ContractError::from), + crate::interpreter::handle_instantiate_reply(deps, msg).map_err(ContractError::from), _ => Err(ContractError::UnknownReply), } } diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs b/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs new file mode 100644 index 00000000000..c18c287443f --- /dev/null +++ b/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs @@ -0,0 +1,102 @@ +use crate::{ + contract::INSTANTIATE_INTERPRETER_REPLY_ID, + error::{Result, ContractError}, + events::make_event, + network::load_this, + state::{self, interpreter}, +}; +use cosmwasm_std::{to_binary, DepsMut, Reply, Response, StdError, StdResult, SubMsg, WasmMsg, Deps, Storage}; +use cw_xc_interpreter::contract::{XCVM_INTERPRETER_EVENT_PREFIX, XCVM_INTERPRETER_EVENT_DATA_ORIGIN}; +use xc_core::{CallOrigin, InterpreterOrigin, NetworkId}; + +use crate::{auth, prelude::*}; + +pub(crate) fn force_instantiate( + auth: auth::Admin, + gateway: Addr, + deps: DepsMut, + user_origin: Addr, +) -> Result { + let config = load_this(deps.storage)?; + let interpreter_code_id = match config.gateway.expect("expected setup") { + GatewayId::CosmWasm { interpreter_code_id, .. } => interpreter_code_id, + }; + + let call_origin = CallOrigin::Local { user: user_origin }; + let interpreter_origin = InterpreterOrigin { + user_origin: call_origin.user(config.network_id), + salt: b"default".to_vec(), + }; + let msg = instantiate(deps.as_ref(), gateway, interpreter_code_id, &interpreter_origin)?; + Ok(Response::new().add_submessage(msg).add_event(make_event("interpreter.forced"))) +} + +pub fn instantiate(deps: Deps, admin: Addr, interpreter_code_id: u64, interpreter_origin: &InterpreterOrigin) -> Result { + let next_interpreter_id: u128 = state::interpreter::INTERPRETERS_COUNT.get(deps.storage)? + 1; + let instantiate_msg = WasmMsg::Instantiate2 { + admin: Some(admin.clone().into_string()), + code_id: interpreter_code_id, + msg: to_binary(&cw_xc_interpreter::msg::InstantiateMsg { + gateway_address: admin.clone().into_string(), + interpreter_origin: interpreter_origin.clone(), + })?, + funds: vec![], + label: ["xcvm_interpreter", &next_interpreter_id.to_string()].join("_"), + salt: to_binary(&interpreter_origin.to_string().as_bytes())?, + }; + let interpreter_instantiate_submessage = + SubMsg::reply_on_success(instantiate_msg, INSTANTIATE_INTERPRETER_REPLY_ID); + Ok(interpreter_instantiate_submessage) +} + + +pub(crate) fn handle_instantiate_reply(deps: DepsMut, msg: Reply) -> StdResult { + let response = msg.result.into_result().map_err(StdError::generic_err)?; + + // Catch the default `instantiate` event which contains `_contract_address` attribute that + // has the instantiated contract's address + let address = &response + .events + .iter() + .find(|event| event.ty == "instantiate") + .ok_or_else(|| StdError::not_found("instantiate event not found"))? + .attributes + .iter() + .find(|attr| &attr.key == "_contract_address") + .ok_or_else(|| StdError::not_found("_contract_address attribute not found"))? + .value; + let interpreter_address = deps.api.addr_validate(address)?; + + // Interpreter provides `network_id, user_id` pair as an event for the router to know which + // pair is instantiated + let event_name = format!("wasm-{}", XCVM_INTERPRETER_EVENT_PREFIX); + let interpreter_origin = &response + .events + .iter() + .find(|event| event.ty.starts_with(&event_name)) + .ok_or_else(|| StdError::not_found("interpreter event not found"))? + .attributes + .iter() + .find(|attr| &attr.key == XCVM_INTERPRETER_EVENT_DATA_ORIGIN) + .ok_or_else(|| StdError::not_found("no data is returned from 'xcvm_interpreter'"))? + .value; + let interpreter_origin = + xc_core::shared::decode_base64::<_, InterpreterOrigin>(interpreter_origin.as_str())?; + + let interpreter_id = state::interpreter::INTERPRETERS_COUNT.get(deps.storage)? + 1; + let interpreter = + state::interpreter::Interpreter { address: interpreter_address, interpreter_id }; + + state::interpreter::INTERPRETERS_COUNT.save(deps.storage, &interpreter_id)?; + state::interpreter::INTERPRETERS.save(deps.storage, interpreter_id.0, &interpreter)?; + state::interpreter::INTERPRETERS_ORIGIN_TO_ID.save( + deps.storage, + interpreter_origin, + &interpreter_id, + )?; + + Ok(Response::new().add_event( + make_event("xcvm.interpreter.instantiated") + .add_attribute("interpreter_id", interpreter_id.to_string()), + )) +} diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs b/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs index aea165cd6e6..d6693a3f1d4 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs @@ -11,4 +11,4 @@ mod events; mod network; mod prelude; pub mod state; -pub mod user; +pub mod interpreter; diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/state/interpreter.rs b/code/xcvm/cosmwasm/contracts/gateway/src/state/interpreter.rs index 6da9432dc1c..97389495dc3 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/state/interpreter.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/state/interpreter.rs @@ -1,11 +1,28 @@ -use xc_core::InterpreterOrigin; +use cosmwasm_std::{Deps, StdResult, StdError, Storage}; +use cw_storage_plus::Item; +use xc_core::{InterpreterOrigin, Displayed}; use crate::prelude::*; +pub type InterpreterId = Displayed; + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[cfg_attr(feature = "std", derive(schemars::JsonSchema))] pub(crate) struct Interpreter { pub address: Addr, + pub interpreter_id : InterpreterId + +} + +pub fn get_by_origin(deps: Deps, origin: InterpreterOrigin) -> StdResult { + INTERPRETERS_ORIGIN_TO_ID + .may_load(deps.storage, origin)? + .and_then(|id| INTERPRETERS.may_load(deps.storage, &id.0)) + .and_then(|interpreter| interpreter.ok_or_else(|| StdError::not_found("interpreter"))) } -pub(crate) const INTERPRETERS: Map = Map::new("interpreters"); +pub const INTERPRETERS_COUNT: Item = Item::new("interpreter_count"); + +pub(crate) const INTERPRETERS_ORIGIN_TO_ID: Map = Map::new("interpreters_origin_to_id"); + +pub(crate) const INTERPRETERS: Map = Map::new("interpreters"); diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/user.rs b/code/xcvm/cosmwasm/contracts/gateway/src/user.rs deleted file mode 100644 index ad3d118f532..00000000000 --- a/code/xcvm/cosmwasm/contracts/gateway/src/user.rs +++ /dev/null @@ -1,10 +0,0 @@ -use crate::prelude::*; - -pub(crate) fn force_instantiate(auth: crate::auth::Auth, deps: cosmwasm_std::DepsMut<'_>, network_id: xc_core::NetworkId, user_origin: String, salt: cosmwasm_std::Binary) -> Result { - - NETWORK.save(deps.storage, msg.network_id, &msg)?; - Ok(Response::new().add_event( - make_event("network.forced").add_attribute("network_id", msg.network_id.to_string()), - )) -} - diff --git a/code/xcvm/lib/core/src/gateway/config.rs b/code/xcvm/lib/core/src/gateway/config.rs index ffb5ddeeb7a..2bb8142a909 100644 --- a/code/xcvm/lib/core/src/gateway/config.rs +++ b/code/xcvm/lib/core/src/gateway/config.rs @@ -162,8 +162,8 @@ pub enum ConfigSubMsg { /// Message sent by an admin to remove an asset from registry. ForceRemoveAsset { asset_id: AssetId }, - /// instantiates interpreter on behalf of user - ForceInstantiate { network_id : NetworkId, user_origin: String, salt: Binary, } + /// instantiates default interpreter on behalf of user + ForceInstantiate { user_origin: Addr, } } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] From af8f6e1ab89e3939d356e5b46b84fbc06111b8e5 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 9 Aug 2023 20:30:03 +0100 Subject: [PATCH 12/14] fmt --- .../cosmwasm/contracts/gateway/src/auth.rs | 3 +- .../contracts/gateway/src/contract/execute.rs | 24 ++- .../gateway/src/contract/ibc/ics20.rs | 1 - .../contracts/gateway/src/contract/mod.rs | 4 +- .../contracts/gateway/src/interpreter.rs | 62 +++--- .../cosmwasm/contracts/gateway/src/lib.rs | 2 +- .../gateway/src/state/interpreter.rs | 22 +-- code/xcvm/lib/core/src/gateway/config.rs | 6 +- code/xcvm/lib/core/src/gateway/mod.rs | 2 +- code/xcvm/lib/core/src/transport/ibc/mod.rs | 4 +- flake/osmosis.nix | 118 ++++++------ flake/process-compose.nix | 9 +- .../composable-centauri/flake-module.nix | 181 +++++++++--------- 13 files changed, 227 insertions(+), 211 deletions(-) diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/auth.rs b/code/xcvm/cosmwasm/contracts/gateway/src/auth.rs index ad1b3d644bd..17d3f488dc1 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/auth.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/auth.rs @@ -71,7 +71,8 @@ impl Auth { interpreter_origin: xc_core::InterpreterOrigin, ) -> Result { let interpreter_address = state::interpreter::get_by_origin(deps, interpreter_origin) - .map(|int| int.address).ok(); + .map(|int| int.address) + .ok(); Self::new(Some(&info.sender) == interpreter_address.as_ref()) } } diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs index 4b3dafd3e13..3702cfec92e 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs @@ -3,9 +3,9 @@ use crate::{ contract::INSTANTIATE_INTERPRETER_REPLY_ID, error::{ContractError, Result}, events::make_event, - msg, + interpreter, msg, network::{self, load_this}, - state, interpreter, + state, }; use cosmwasm_std::{ @@ -64,8 +64,8 @@ fn handle_config_msg(auth: auth::Admin, deps: DepsMut, msg: ConfigSubMsg, env: E ConfigSubMsg::ForceRemoveAsset { asset_id } => assets::force_remove_asset(auth, deps, asset_id), ConfigSubMsg::ForceNetwork(msg) => network::force_network(auth, deps, msg), - ConfigSubMsg::ForceInstantiate { user_origin, } => - interpreter::force_instantiate(auth, env.contract.address, deps, user_origin), + ConfigSubMsg::ForceInstantiate { user_origin } => + interpreter::force_instantiate(auth, env.contract.address, deps, user_origin), } } @@ -158,7 +158,8 @@ pub(crate) fn handle_execute_program_privilleged( let config = load_this(deps.storage)?; let interpreter_origin = InterpreterOrigin { user_origin: call_origin.user(config.network_id), salt }; - let interpreter = state::interpreter::get_by_origin(deps.as_ref(), interpreter_origin).ok(); + let interpreter = + state::interpreter::get_by_origin(deps.as_ref(), interpreter_origin.clone()).ok(); if let Some(state::interpreter::Interpreter { address, .. }) = interpreter { deps.api.debug("reusing existing interpreter and adding funds"); let response = send_funds_to_interpreter(deps.as_ref(), address.clone(), assets)?; @@ -179,9 +180,14 @@ pub(crate) fn handle_execute_program_privilleged( msg::GatewayId::CosmWasm { interpreter_code_id, .. } => interpreter_code_id, }; deps.api.debug("instantiating interpreter"); - let admin = env.contract.address; - - let interpreter_instantiate_submessage = crate::interpreter::instantiate(deps.as_ref(), admin, interpreter_code_id, &interpreter_origin)?; + let admin = env.contract.address.clone(); + + let interpreter_instantiate_submessage = crate::interpreter::instantiate( + deps.as_ref(), + admin, + interpreter_code_id, + &interpreter_origin, + )?; // Secondly, call itself again with the same parameters, so that this functions goes // into `Ok` state and properly executes the interpreter @@ -206,7 +212,6 @@ pub(crate) fn handle_execute_program_privilleged( } } - /// Transfer funds attached to a [`XCVMProgram`] before dispatching the program to the interpreter. fn send_funds_to_interpreter( deps: Deps, @@ -240,4 +245,3 @@ fn send_funds_to_interpreter( } Ok(response) } - diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs index 13a2123001a..ed0888d8043 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/ibc/ics20.rs @@ -34,7 +34,6 @@ pub(crate) fn handle_bridge_forward( // 1. recurse on program until can with memo // 2. as soon as see no Spawn/Transfer, stop memo and do Wasm call with remaining Packet - let packet = XcPacket { interpreter: String::from(info.sender).into_bytes(), user_origin: msg.interpreter_origin.user_origin, diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/mod.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/mod.rs index 40637539bd8..82c2acda6f8 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/mod.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/mod.rs @@ -16,7 +16,7 @@ use cw2::set_contract_version; use cw_utils::ensure_from_older_version; use xc_core::XCVMAck; -use self::{ibc::make_ibc_failure_event}; +use self::ibc::make_ibc_failure_event; const CONTRACT_NAME: &str = "composable:xcvm-gateway"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -57,7 +57,7 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result { match msg.id { EXEC_PROGRAM_REPLY_ID => handle_exec_reply(msg), INSTANTIATE_INTERPRETER_REPLY_ID => - crate::interpreter::handle_instantiate_reply(deps, msg).map_err(ContractError::from), + crate::interpreter::handle_instantiate_reply(deps, msg).map_err(ContractError::from), _ => Err(ContractError::UnknownReply), } } diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs b/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs index c18c287443f..844fe648497 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs @@ -1,12 +1,16 @@ use crate::{ contract::INSTANTIATE_INTERPRETER_REPLY_ID, - error::{Result, ContractError}, + error::{ContractError, Result}, events::make_event, network::load_this, state::{self, interpreter}, }; -use cosmwasm_std::{to_binary, DepsMut, Reply, Response, StdError, StdResult, SubMsg, WasmMsg, Deps, Storage}; -use cw_xc_interpreter::contract::{XCVM_INTERPRETER_EVENT_PREFIX, XCVM_INTERPRETER_EVENT_DATA_ORIGIN}; +use cosmwasm_std::{ + to_binary, Deps, DepsMut, Reply, Response, StdError, StdResult, Storage, SubMsg, WasmMsg, +}; +use cw_xc_interpreter::contract::{ + XCVM_INTERPRETER_EVENT_DATA_ORIGIN, XCVM_INTERPRETER_EVENT_PREFIX, +}; use xc_core::{CallOrigin, InterpreterOrigin, NetworkId}; use crate::{auth, prelude::*}; @@ -31,28 +35,32 @@ pub(crate) fn force_instantiate( Ok(Response::new().add_submessage(msg).add_event(make_event("interpreter.forced"))) } -pub fn instantiate(deps: Deps, admin: Addr, interpreter_code_id: u64, interpreter_origin: &InterpreterOrigin) -> Result { - let next_interpreter_id: u128 = state::interpreter::INTERPRETERS_COUNT.get(deps.storage)? + 1; - let instantiate_msg = WasmMsg::Instantiate2 { - admin: Some(admin.clone().into_string()), - code_id: interpreter_code_id, - msg: to_binary(&cw_xc_interpreter::msg::InstantiateMsg { - gateway_address: admin.clone().into_string(), - interpreter_origin: interpreter_origin.clone(), - })?, - funds: vec![], - label: ["xcvm_interpreter", &next_interpreter_id.to_string()].join("_"), - salt: to_binary(&interpreter_origin.to_string().as_bytes())?, - }; - let interpreter_instantiate_submessage = - SubMsg::reply_on_success(instantiate_msg, INSTANTIATE_INTERPRETER_REPLY_ID); - Ok(interpreter_instantiate_submessage) +pub fn instantiate( + deps: Deps, + admin: Addr, + interpreter_code_id: u64, + interpreter_origin: &InterpreterOrigin, +) -> Result { + let next_interpreter_id: u128 = state::interpreter::INTERPRETERS_COUNT.load(deps.storage)? + 1; + let instantiate_msg = WasmMsg::Instantiate2 { + admin: Some(admin.clone().into_string()), + code_id: interpreter_code_id, + msg: to_binary(&cw_xc_interpreter::msg::InstantiateMsg { + gateway_address: admin.clone().into_string(), + interpreter_origin: interpreter_origin.clone(), + })?, + funds: vec![], + label: ["xcvm_interpreter", &next_interpreter_id.to_string()].join("_"), + salt: to_binary(&interpreter_origin.to_string().as_bytes())?, + }; + let interpreter_instantiate_submessage = + SubMsg::reply_on_success(instantiate_msg, INSTANTIATE_INTERPRETER_REPLY_ID); + Ok(interpreter_instantiate_submessage) } - pub(crate) fn handle_instantiate_reply(deps: DepsMut, msg: Reply) -> StdResult { + deps.api.debug(&serde_json_wasm::to_string(&msg)?); let response = msg.result.into_result().map_err(StdError::generic_err)?; - // Catch the default `instantiate` event which contains `_contract_address` attribute that // has the instantiated contract's address let address = &response @@ -83,18 +91,22 @@ pub(crate) fn handle_instantiate_reply(deps: DepsMut, msg: Reply) -> StdResult(interpreter_origin.as_str())?; - let interpreter_id = state::interpreter::INTERPRETERS_COUNT.get(deps.storage)? + 1; - let interpreter = - state::interpreter::Interpreter { address: interpreter_address, interpreter_id }; + let interpreter_id = state::interpreter::INTERPRETERS_COUNT.load(deps.storage)? + 1; + let interpreter = state::interpreter::Interpreter { + address: interpreter_address, + interpreter_id: interpreter_id.into(), + }; state::interpreter::INTERPRETERS_COUNT.save(deps.storage, &interpreter_id)?; - state::interpreter::INTERPRETERS.save(deps.storage, interpreter_id.0, &interpreter)?; + state::interpreter::INTERPRETERS.save(deps.storage, interpreter_id, &interpreter)?; state::interpreter::INTERPRETERS_ORIGIN_TO_ID.save( deps.storage, interpreter_origin, &interpreter_id, )?; + deps.api.debug("saved interpreter"); + Ok(Response::new().add_event( make_event("xcvm.interpreter.instantiated") .add_attribute("interpreter_id", interpreter_id.to_string()), diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs b/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs index d6693a3f1d4..798d57c19d9 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/lib.rs @@ -8,7 +8,7 @@ pub mod auth; pub mod contract; pub mod error; mod events; +pub mod interpreter; mod network; mod prelude; pub mod state; -pub mod interpreter; diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/state/interpreter.rs b/code/xcvm/cosmwasm/contracts/gateway/src/state/interpreter.rs index 97389495dc3..c3ab67e23c4 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/state/interpreter.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/state/interpreter.rs @@ -1,6 +1,6 @@ -use cosmwasm_std::{Deps, StdResult, StdError, Storage}; +use cosmwasm_std::{Deps, StdError, StdResult, Storage}; use cw_storage_plus::Item; -use xc_core::{InterpreterOrigin, Displayed}; +use xc_core::{Displayed, InterpreterOrigin}; use crate::prelude::*; @@ -10,19 +10,17 @@ pub type InterpreterId = Displayed; #[cfg_attr(feature = "std", derive(schemars::JsonSchema))] pub(crate) struct Interpreter { pub address: Addr, - pub interpreter_id : InterpreterId - + pub interpreter_id: InterpreterId, } -pub fn get_by_origin(deps: Deps, origin: InterpreterOrigin) -> StdResult { - INTERPRETERS_ORIGIN_TO_ID - .may_load(deps.storage, origin)? - .and_then(|id| INTERPRETERS.may_load(deps.storage, &id.0)) - .and_then(|interpreter| interpreter.ok_or_else(|| StdError::not_found("interpreter"))) +pub(crate) fn get_by_origin(deps: Deps, origin: InterpreterOrigin) -> StdResult { + let id = INTERPRETERS_ORIGIN_TO_ID.load(deps.storage, origin)?; + INTERPRETERS.load(deps.storage, id) } -pub const INTERPRETERS_COUNT: Item = Item::new("interpreter_count"); +pub(crate) const INTERPRETERS_COUNT: Item = Item::new("interpreter_count"); -pub(crate) const INTERPRETERS_ORIGIN_TO_ID: Map = Map::new("interpreters_origin_to_id"); +pub(crate) const INTERPRETERS_ORIGIN_TO_ID: Map = + Map::new("interpreters_origin_to_id"); -pub(crate) const INTERPRETERS: Map = Map::new("interpreters"); +pub(crate) const INTERPRETERS: Map = Map::new("interpreters"); diff --git a/code/xcvm/lib/core/src/gateway/config.rs b/code/xcvm/lib/core/src/gateway/config.rs index 2bb8142a909..3bf0feefa34 100644 --- a/code/xcvm/lib/core/src/gateway/config.rs +++ b/code/xcvm/lib/core/src/gateway/config.rs @@ -161,9 +161,9 @@ pub enum ConfigSubMsg { /// Message sent by an admin to remove an asset from registry. ForceRemoveAsset { asset_id: AssetId }, - - /// instantiates default interpreter on behalf of user - ForceInstantiate { user_origin: Addr, } + + /// instantiates default interpreter on behalf of user + ForceInstantiate { user_origin: Addr }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] diff --git a/code/xcvm/lib/core/src/gateway/mod.rs b/code/xcvm/lib/core/src/gateway/mod.rs index bb0cbae77e9..b838cac08a8 100644 --- a/code/xcvm/lib/core/src/gateway/mod.rs +++ b/code/xcvm/lib/core/src/gateway/mod.rs @@ -61,7 +61,7 @@ pub enum TestSubMsg { InstantiateContract { /// code of contract to instantiate code_id: u64, - /// body of instantiate message + /// body of instantiate message msg: serde_cw_value::Value, }, } diff --git a/code/xcvm/lib/core/src/transport/ibc/mod.rs b/code/xcvm/lib/core/src/transport/ibc/mod.rs index bb4ec436215..3ca223921bd 100644 --- a/code/xcvm/lib/core/src/transport/ibc/mod.rs +++ b/code/xcvm/lib/core/src/transport/ibc/mod.rs @@ -31,7 +31,6 @@ pub enum SudoMsg { IBCLifecycleComplete(IBCLifecycleComplete), } - /// route is used to describe how to send a packet to another network #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[cfg_attr(feature = "std", derive(schemars::JsonSchema))] @@ -48,8 +47,7 @@ pub struct IbcRoute { } pub fn to_cw_message(coin: Coin, route: IbcRoute, packet: XcPacket) -> StdResult> { - let memo = - XcMessageData { from_network_id: route.from_network, packet }; + let memo = XcMessageData { from_network_id: route.from_network, packet }; let memo = SendMemo { inner: Memo { wasm: Some(Callback { diff --git a/flake/osmosis.nix b/flake/osmosis.nix index 8f8b61471a5..badc1affb92 100644 --- a/flake/osmosis.nix +++ b/flake/osmosis.nix @@ -365,72 +365,72 @@ ''; }; - xc-transfer-osmo-from--osmosis-to-centauri = pkgs.writeShellApplication { - name = "xc-transfer-osmo-from--osmosis-to-centauri"; - runtimeInputs = devnetTools.withBaseContainerTools - ++ [ osmosisd pkgs.jq ]; - text = '' - HOME=/tmp/composable-devnet - export HOME - CHAIN_DATA="$HOME/.osmosisd" - KEYRING_TEST=$CHAIN_DATA - CHAIN_ID="osmosis-dev" - PORT=36657 - BLOCK_SECONDS=5 - FEE=uosmo - BINARY=osmosisd - GATEWAY_CONTRACT_ADDRESS=$(cat "$CHAIN_DATA/gateway_contract_address") - - TRANSFER_PICA_TO_OSMOSIS=$(cat << EOF - { + xc-transfer-osmo-from--osmosis-to-centauri = + pkgs.writeShellApplication { + name = "xc-transfer-osmo-from--osmosis-to-centauri"; + runtimeInputs = devnetTools.withBaseContainerTools + ++ [ osmosisd pkgs.jq ]; + text = '' + HOME=/tmp/composable-devnet + export HOME + CHAIN_DATA="$HOME/.osmosisd" + KEYRING_TEST=$CHAIN_DATA + CHAIN_ID="osmosis-dev" + PORT=36657 + BLOCK_SECONDS=5 + FEE=uosmo + BINARY=osmosisd + GATEWAY_CONTRACT_ADDRESS=$(cat "$CHAIN_DATA/gateway_contract_address") + + TRANSFER_PICA_TO_OSMOSIS=$(cat << EOF + { + "execute_program": { "execute_program": { - "execute_program": { - "salt": "737061776e5f776974685f6173736574", - "program": { - "tag": "737061776e5f776974685f6173736574", - "instructions": [ - { - "spawn": { - "network": 2, - "salt": "737061776e5f776974685f6173736574", - "assets": [ - [ - "158456325028528675187087901673", - { - "amount": { - "intercept": "1000000000", - "slope": "0" - }, - "is_unit": false - } - ] - ], - "program": { - "tag": "737061776e5f776974685f6173736574", - "instructions": [] - } + "salt": "737061776e5f776974685f6173736574", + "program": { + "tag": "737061776e5f776974685f6173736574", + "instructions": [ + { + "spawn": { + "network": 2, + "salt": "737061776e5f776974685f6173736574", + "assets": [ + [ + "158456325028528675187087901673", + { + "amount": { + "intercept": "1000000000", + "slope": "0" + }, + "is_unit": false + } + ] + ], + "program": { + "tag": "737061776e5f776974685f6173736574", + "instructions": [] } } - ] - }, - "assets": [ - [ - "237684487542793012780631852009", - "1000000000" - ] + } ] }, - "tip": "osmo12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n" - } + "assets": [ + [ + "237684487542793012780631852009", + "1000000000" + ] + ] + }, + "tip": "osmo12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n" } - EOF - ) + } + EOF + ) - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$TRANSFER_PICA_TO_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 1000000000"$FEE" --amount 1000000000"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace - sleep "$BLOCK_SECONDS" - '' - ; - }; + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$TRANSFER_PICA_TO_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 1000000000"$FEE" --amount 1000000000"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + sleep "$BLOCK_SECONDS" + ''; + }; }; }; diff --git a/flake/process-compose.nix b/flake/process-compose.nix index 26c7dafe1a2..0001c10dcf1 100644 --- a/flake/process-compose.nix +++ b/flake/process-compose.nix @@ -445,14 +445,15 @@ log_location = "/tmp/composable-devnet/centauri-xcvm-init.log"; availability = { restart = "on_failure"; }; }; - + centauri-xcvm-config = { command = self'.packages.centaurid-xcvm-config; - depends_on."centauri-xcvm-init".condition = "process_completed_successfully"; - log_location = "/tmp/composable-devnet/centauri-xcvm-config.log"; + depends_on."centauri-xcvm-init".condition = + "process_completed_successfully"; + log_location = + "/tmp/composable-devnet/centauri-xcvm-config.log"; availability = { restart = "on_failure"; }; }; - osmosis = { command = self'.packages.osmosisd-gen; diff --git a/inputs/notional-labs/composable-centauri/flake-module.nix b/inputs/notional-labs/composable-centauri/flake-module.nix index 9f1e5bd29ce..cc5ac77033f 100644 --- a/inputs/notional-labs/composable-centauri/flake-module.nix +++ b/inputs/notional-labs/composable-centauri/flake-module.nix @@ -1,18 +1,6 @@ { self, ... }: { - perSystem = - { config - , self' - , inputs' - , pkgs - , lib - , system - , crane - , systemCommonRust - , subnix - , devnetTools - , cosmosTools - , ... - }: + perSystem = { config, self', inputs', pkgs, lib, system, crane + , systemCommonRust, subnix, devnetTools, cosmosTools, ... }: let devnet-root-directory = cosmosTools.devnet-root-directory; validator-mnemonic = cosmosTools.validators.mnemonic; @@ -43,22 +31,20 @@ "summary" = "none"; }; - ics10-grandpa-cw-proposal = - let - code = builtins.readFile - "${self'.packages.ics10-grandpa-cw}/lib/ics10_grandpa_cw.wasm.gz.txt"; - code-file = builtins.toFile "ics10_grandpa_cw.wasm.json" - (builtins.toJSON - (ibc-lightclients-wasm-v1-msg-push-new-wasm-code code)); - in - pkgs.stdenv.mkDerivation { - name = "ics10-grandpa-cw-proposal"; - dontUnpack = true; - installPhase = '' - mkdir --parents $out - cp ${code-file} $out/ics10_grandpa_cw.wasm.json - ''; - }; + ics10-grandpa-cw-proposal = let + code = builtins.readFile + "${self'.packages.ics10-grandpa-cw}/lib/ics10_grandpa_cw.wasm.gz.txt"; + code-file = builtins.toFile "ics10_grandpa_cw.wasm.json" + (builtins.toJSON + (ibc-lightclients-wasm-v1-msg-push-new-wasm-code code)); + in pkgs.stdenv.mkDerivation { + name = "ics10-grandpa-cw-proposal"; + dontUnpack = true; + installPhase = '' + mkdir --parents $out + cp ${code-file} $out/ics10_grandpa_cw.wasm.json + ''; + }; centaurid-init = pkgs.writeShellApplication { name = "centaurid-init"; runtimeInputs = devnetTools.withBaseContainerTools @@ -363,64 +349,63 @@ runtimeInputs = devnetTools.withBaseContainerTools ++ [ centaurid pkgs.jq ]; text = '' - CHAIN_DATA="${devnet-root-directory}/.centaurid" - CHAIN_ID="centauri-dev" - KEYRING_TEST="$CHAIN_DATA/keyring-test" - PORT=26657 - FEE=ppica - BLOCK_SECONDS=5 - BINARY=centaurid - GATEWAY_CONTRACT_ADDRESS=$(cat "$CHAIN_DATA/gateway_contract_address") - - TRANSFER_PICA_TO_OSMOSIS=$(cat << EOF - { - "execute_program": { - "execute_program": { - "salt": "737061776e5f776974685f6173736574", - "program": { - "tag": "737061776e5f776974685f6173736574", - "instructions": [ - { - "spawn": { - "network": 3, - "salt": "737061776e5f776974685f6173736574", - "assets": [ - [ - "237684487542793012780631851009", - { - "amount": { - "intercept": "1000000000", - "slope": "0" - }, - "is_unit": false - } - ] - ], - "program": { - "tag": "737061776e5f776974685f6173736574", - "instructions": [] - } - } - } - ] - }, - "assets": [ - [ - "158456325028528675187087900673", - "1000000000" - ] - ] + CHAIN_DATA="${devnet-root-directory}/.centaurid" + CHAIN_ID="centauri-dev" + KEYRING_TEST="$CHAIN_DATA/keyring-test" + PORT=26657 + FEE=ppica + BLOCK_SECONDS=5 + BINARY=centaurid + GATEWAY_CONTRACT_ADDRESS=$(cat "$CHAIN_DATA/gateway_contract_address") + + TRANSFER_PICA_TO_OSMOSIS=$(cat << EOF + { + "execute_program": { + "execute_program": { + "salt": "737061776e5f776974685f6173736574", + "program": { + "tag": "737061776e5f776974685f6173736574", + "instructions": [ + { + "spawn": { + "network": 3, + "salt": "737061776e5f776974685f6173736574", + "assets": [ + [ + "237684487542793012780631851009", + { + "amount": { + "intercept": "1000000000", + "slope": "0" }, - "tip": "centauri12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n" + "is_unit": false } - } - EOF - ) - - "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$TRANSFER_PICA_TO_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 1000000000"$FEE" --amount 1000000000"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace - sleep "$BLOCK_SECONDS" - '' - ; + ] + ], + "program": { + "tag": "737061776e5f776974685f6173736574", + "instructions": [] + } + } + } + ] + }, + "assets": [ + [ + "158456325028528675187087900673", + "1000000000" + ] + ] + }, + "tip": "centauri12smx2wdlyttvyzvzg54y2vnqwq2qjatescq89n" + } + } + EOF + ) + + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$TRANSFER_PICA_TO_OSMOSIS" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 1000000000"$FEE" --amount 1000000000"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + sleep "$BLOCK_SECONDS" + ''; }; centaurid-gen-fresh = pkgs.writeShellApplication { @@ -504,11 +489,29 @@ centaurid start --rpc.unsafe --rpc.laddr tcp://0.0.0.0:26657 --pruning=nothing --minimum-gas-prices=0ppica --log_level debug --home "$CHAIN_DATA" --db_dir "$CHAIN_DATA/data" --trace --with-tendermint true --transport socket --trace-store $CHAIN_DATA/kvstore.log --grpc.address localhost:9090 --grpc.enable true --grpc-web.enable false --api.enable true --cpu-profile $CHAIN_DATA/cpu-profile.log --p2p.pex false --p2p.upnp false ''; }; - in - { + in { packages = rec { inherit centaurid centaurid-gen centaurid-init centaurid-gen-fresh - ics10-grandpa-cw-proposal xc-transfer-pica-from-centauri-to-osmosis centaurid-xcvm-init centaurid-xcvm-config; + ics10-grandpa-cw-proposal xc-transfer-pica-from-centauri-to-osmosis + centaurid-xcvm-init centaurid-xcvm-config; + + centauri-exec = pkgs.writeShellApplication { + name = "centaurid-xcvm-config"; + runtimeInputs = devnetTools.withBaseContainerTools + ++ [ centaurid pkgs.jq self'.packages.xc-cw-contracts ]; + + text = '' + CHAIN_DATA="${devnet-root-directory}/.centaurid" + CHAIN_ID="centauri-dev" + KEYRING_TEST="$CHAIN_DATA/keyring-test" + PORT=26657 + FEE=ppica + BINARY=centaurid + GATEWAY_CONTRACT_ADDRESS=$(cat $CHAIN_DATA/gateway_contract_address) + MSG='{ "config": { "force_instantiate" : { "user_origin" : "centauri1e0nh3davd6d3yh73sldwndww7zchetwsae8m9rz9x6hlg7w4ysrqhmaqju" } }}' + "$BINARY" tx wasm execute "$GATEWAY_CONTRACT_ADDRESS" "$MSG" --chain-id="$CHAIN_ID" --node "tcp://localhost:$PORT" --output json --yes --gas 25000000 --fees 920000166"$FEE" --log_level info --keyring-backend test --home "$CHAIN_DATA" --from ${cosmosTools.xcvm.moniker} --keyring-dir "$KEYRING_TEST" --trace --log_level trace + ''; + }; }; }; } From ee25ba11bc58767fb826e508ee996f66b6093adf Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 9 Aug 2023 21:24:20 +0100 Subject: [PATCH 13/14] generic --- PLAN | 6 ---- .../contracts/gateway/src/contract/execute.rs | 8 ++--- .../contracts/gateway/src/interpreter.rs | 29 ++++++++++++------- .../gateway/src/state/interpreter.rs | 2 +- code/xcvm/lib/core/schema/raw/asd.json | 17 ----------- flake/process-compose.nix | 20 ++++++------- .../composable-centauri/flake-module.nix | 2 +- 7 files changed, 33 insertions(+), 51 deletions(-) delete mode 100644 PLAN delete mode 100644 code/xcvm/lib/core/schema/raw/asd.json diff --git a/PLAN b/PLAN deleted file mode 100644 index 2a1e9fb9209..00000000000 --- a/PLAN +++ /dev/null @@ -1,6 +0,0 @@ -1. fix sender -2. tune AR to be more symmetric -3. fix recevier -4. write spawn back -5. fix AR for back -6. write Osmosis origination \ No newline at end of file diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs index 3702cfec92e..41f4ce0c85d 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs @@ -1,6 +1,5 @@ use crate::{ assets, auth, - contract::INSTANTIATE_INTERPRETER_REPLY_ID, error::{ContractError, Result}, events::make_event, interpreter, msg, @@ -9,13 +8,10 @@ use crate::{ }; use cosmwasm_std::{ - entry_point, to_binary, wasm_execute, Addr, BankMsg, Coin, CosmosMsg, Deps, DepsMut, Env, - MessageInfo, Reply, Response, StdError, StdResult, SubMsg, WasmMsg, + entry_point, wasm_execute, Addr, BankMsg, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, + Response, }; use cw20::{Cw20Contract, Cw20ExecuteMsg}; -use cw_xc_interpreter::contract::{ - XCVM_INTERPRETER_EVENT_DATA_ORIGIN, XCVM_INTERPRETER_EVENT_PREFIX, -}; use xc_core::{gateway::ConfigSubMsg, CallOrigin, Displayed, Funds, InterpreterOrigin}; diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs b/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs index 844fe648497..48ec49e177b 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs @@ -3,20 +3,20 @@ use crate::{ error::{ContractError, Result}, events::make_event, network::load_this, - state::{self, interpreter}, + state, }; use cosmwasm_std::{ - to_binary, Deps, DepsMut, Reply, Response, StdError, StdResult, Storage, SubMsg, WasmMsg, + to_binary, Deps, DepsMut, Reply, Response, StdError, StdResult, SubMsg, WasmMsg, }; use cw_xc_interpreter::contract::{ XCVM_INTERPRETER_EVENT_DATA_ORIGIN, XCVM_INTERPRETER_EVENT_PREFIX, }; -use xc_core::{CallOrigin, InterpreterOrigin, NetworkId}; +use xc_core::{CallOrigin, InterpreterOrigin}; use crate::{auth, prelude::*}; pub(crate) fn force_instantiate( - auth: auth::Admin, + _: auth::Admin, gateway: Addr, deps: DepsMut, user_origin: Addr, @@ -41,7 +41,12 @@ pub fn instantiate( interpreter_code_id: u64, interpreter_origin: &InterpreterOrigin, ) -> Result { - let next_interpreter_id: u128 = state::interpreter::INTERPRETERS_COUNT.load(deps.storage)? + 1; + let next_interpreter_id: u128 = + state::interpreter::INTERPRETERS_COUNT.load(deps.storage).unwrap_or_default() + 1; + + // salt limit is 64 characters + // and label has some unknown limits too (including usage of special characters) + let label = ["xcvm_interpreter", &next_interpreter_id.to_string()].join("_"); let instantiate_msg = WasmMsg::Instantiate2 { admin: Some(admin.clone().into_string()), code_id: interpreter_code_id, @@ -50,8 +55,8 @@ pub fn instantiate( interpreter_origin: interpreter_origin.clone(), })?, funds: vec![], - label: ["xcvm_interpreter", &next_interpreter_id.to_string()].join("_"), - salt: to_binary(&interpreter_origin.to_string().as_bytes())?, + label, + salt: to_binary("default")?, }; let interpreter_instantiate_submessage = SubMsg::reply_on_success(instantiate_msg, INSTANTIATE_INTERPRETER_REPLY_ID); @@ -59,7 +64,10 @@ pub fn instantiate( } pub(crate) fn handle_instantiate_reply(deps: DepsMut, msg: Reply) -> StdResult { - deps.api.debug(&serde_json_wasm::to_string(&msg)?); + deps.api.debug(&format!( + "xcvm:: {}", + serde_json_wasm::to_string(&msg).map_err(|e| StdError::generic_err(e.to_string()))? + )); let response = msg.result.into_result().map_err(StdError::generic_err)?; // Catch the default `instantiate` event which contains `_contract_address` attribute that // has the instantiated contract's address @@ -91,7 +99,8 @@ pub(crate) fn handle_instantiate_reply(deps: DepsMut, msg: Reply) -> StdResult(interpreter_origin.as_str())?; - let interpreter_id = state::interpreter::INTERPRETERS_COUNT.load(deps.storage)? + 1; + let interpreter_id: u128 = + state::interpreter::INTERPRETERS_COUNT.load(deps.storage).unwrap_or_default() + 1; let interpreter = state::interpreter::Interpreter { address: interpreter_address, interpreter_id: interpreter_id.into(), @@ -105,7 +114,7 @@ pub(crate) fn handle_instantiate_reply(deps: DepsMut, msg: Reply) -> StdResult Date: Thu, 10 Aug 2023 11:49:38 +0100 Subject: [PATCH 14/14] fixes --- .../contracts/gateway/src/contract/execute.rs | 7 ++++--- .../contracts/gateway/src/interpreter.rs | 21 ++++++++++++------- code/xcvm/lib/core/src/gateway/config.rs | 3 ++- code/xcvm/lib/core/src/gateway/mod.rs | 13 ------------ 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs index 41f4ce0c85d..eb3e289a63f 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/contract/execute.rs @@ -60,8 +60,8 @@ fn handle_config_msg(auth: auth::Admin, deps: DepsMut, msg: ConfigSubMsg, env: E ConfigSubMsg::ForceRemoveAsset { asset_id } => assets::force_remove_asset(auth, deps, asset_id), ConfigSubMsg::ForceNetwork(msg) => network::force_network(auth, deps, msg), - ConfigSubMsg::ForceInstantiate { user_origin } => - interpreter::force_instantiate(auth, env.contract.address, deps, user_origin), + ConfigSubMsg::ForceInstantiate { user_origin, salt } => + interpreter::force_instantiate(auth, env.contract.address, deps, user_origin, salt), } } @@ -153,7 +153,7 @@ pub(crate) fn handle_execute_program_privilleged( ) -> Result { let config = load_this(deps.storage)?; let interpreter_origin = - InterpreterOrigin { user_origin: call_origin.user(config.network_id), salt }; + InterpreterOrigin { user_origin: call_origin.user(config.network_id), salt: salt.clone() }; let interpreter = state::interpreter::get_by_origin(deps.as_ref(), interpreter_origin.clone()).ok(); if let Some(state::interpreter::Interpreter { address, .. }) = interpreter { @@ -183,6 +183,7 @@ pub(crate) fn handle_execute_program_privilleged( admin, interpreter_code_id, &interpreter_origin, + salt, )?; // Secondly, call itself again with the same parameters, so that this functions goes diff --git a/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs b/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs index 48ec49e177b..9c9fd63fdb0 100644 --- a/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs +++ b/code/xcvm/cosmwasm/contracts/gateway/src/interpreter.rs @@ -20,6 +20,7 @@ pub(crate) fn force_instantiate( gateway: Addr, deps: DepsMut, user_origin: Addr, + salt: Option, ) -> Result { let config = load_this(deps.storage)?; let interpreter_code_id = match config.gateway.expect("expected setup") { @@ -29,9 +30,15 @@ pub(crate) fn force_instantiate( let call_origin = CallOrigin::Local { user: user_origin }; let interpreter_origin = InterpreterOrigin { user_origin: call_origin.user(config.network_id), - salt: b"default".to_vec(), + salt: salt.clone().map(|x| x.into_bytes()).unwrap_or_default(), }; - let msg = instantiate(deps.as_ref(), gateway, interpreter_code_id, &interpreter_origin)?; + let msg = instantiate( + deps.as_ref(), + gateway, + interpreter_code_id, + &interpreter_origin, + salt.map(|x| x.into_bytes()).unwrap_or_default(), + )?; Ok(Response::new().add_submessage(msg).add_event(make_event("interpreter.forced"))) } @@ -40,13 +47,11 @@ pub fn instantiate( admin: Addr, interpreter_code_id: u64, interpreter_origin: &InterpreterOrigin, + salt: Vec, ) -> Result { let next_interpreter_id: u128 = state::interpreter::INTERPRETERS_COUNT.load(deps.storage).unwrap_or_default() + 1; - // salt limit is 64 characters - // and label has some unknown limits too (including usage of special characters) - let label = ["xcvm_interpreter", &next_interpreter_id.to_string()].join("_"); let instantiate_msg = WasmMsg::Instantiate2 { admin: Some(admin.clone().into_string()), code_id: interpreter_code_id, @@ -55,8 +60,10 @@ pub fn instantiate( interpreter_origin: interpreter_origin.clone(), })?, funds: vec![], - label, - salt: to_binary("default")?, + // and label has some unknown limits (including usage of special characters) + label: format!("xcvm_interpreter_{}", &next_interpreter_id), + // salt limit is 64 characters + salt: to_binary(&salt)?, }; let interpreter_instantiate_submessage = SubMsg::reply_on_success(instantiate_msg, INSTANTIATE_INTERPRETER_REPLY_ID); diff --git a/code/xcvm/lib/core/src/gateway/config.rs b/code/xcvm/lib/core/src/gateway/config.rs index 3bf0feefa34..4b5e6ed781d 100644 --- a/code/xcvm/lib/core/src/gateway/config.rs +++ b/code/xcvm/lib/core/src/gateway/config.rs @@ -163,7 +163,8 @@ pub enum ConfigSubMsg { ForceRemoveAsset { asset_id: AssetId }, /// instantiates default interpreter on behalf of user - ForceInstantiate { user_origin: Addr }, + /// `salt` - human string, converted to hex or base64 depending on implementation + ForceInstantiate { user_origin: Addr, salt: Option }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] diff --git a/code/xcvm/lib/core/src/gateway/mod.rs b/code/xcvm/lib/core/src/gateway/mod.rs index b838cac08a8..205bd5c2299 100644 --- a/code/xcvm/lib/core/src/gateway/mod.rs +++ b/code/xcvm/lib/core/src/gateway/mod.rs @@ -53,19 +53,6 @@ pub enum ExecuteMsg { MessageHook(XcMessageData), } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -#[serde(rename_all = "snake_case")] -#[cfg_attr(feature = "std", derive(schemars::JsonSchema))] -pub enum TestSubMsg { - /// instantiates contract - InstantiateContract { - /// code of contract to instantiate - code_id: u64, - /// body of instantiate message - msg: serde_cw_value::Value, - }, -} - #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[serde(rename_all = "snake_case")] #[cfg_attr(feature = "std", derive(schemars::JsonSchema))]