From 9d8838fa139fedc7f3227a244c6963721745291a Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 15 Jun 2023 00:18:27 +0200 Subject: [PATCH 1/4] removed older scripts --- .../test/scripts/configure-statemine.sh | 161 ------------------ .../helpers/generateHexEncodedCallData.js | 147 ---------------- cumulus | 2 +- 3 files changed, 1 insertion(+), 309 deletions(-) delete mode 100755 core/packages/test/scripts/configure-statemine.sh delete mode 100644 core/packages/test/scripts/helpers/generateHexEncodedCallData.js diff --git a/core/packages/test/scripts/configure-statemine.sh b/core/packages/test/scripts/configure-statemine.sh deleted file mode 100755 index b064cec029..0000000000 --- a/core/packages/test/scripts/configure-statemine.sh +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/env sh -set -eu - -source scripts/xcm-helper.sh - -generate_hex_encoded_call_data() { - local type=$1 - local endpoint=$2 - local output=$3 - shift - shift - shift - echo "Input params: $@" - - node scripts/helpers/generateHexEncodedCallData.js "$type" "$endpoint" "$output" "$@" - local retVal=$? - - if [ $type != "check" ]; then - local hex_encoded_data=$(cat $output) - echo "Generated hex-encoded bytes to file '$output': $hex_encoded_data" - fi - - return $retVal -} - -add_exporter_config() { - echo " calling add_exporter_config:" - - local bridged_network=$(jq --null-input \ - --arg eth_chain_id "$eth_chain_id" \ - ' - { - "Ethereum": { - "chainId": $eth_chain_id - } - } - ' - ) - # Generate data for Transact (add_exporter_config) - local bridge_config=$(jq --null-input \ - --arg bridgehub_para_id "$bridgehub_para_id" \ - --arg bridged_network "$bridged_network" \ - ' - { - "bridgeLocation": { - "parents": 1, - "interior": { - "X1": { "Parachain": $bridgehub_para_id } - } - }, - "allowedTargetLocation": { - "parents": 2, - "interior": { - "X1": { - "GlobalConsensus": $bridged_network | fromjson, - } - } - } - } - ' - ) - - echo "" - echo " bridged_network:" - echo "${bridged_network}" - echo "" - echo " bridge_config:" - echo "${bridge_config}" - echo "" - echo "--------------------------------------------------" - - local tmp_output_file=$(mktemp) - generate_hex_encoded_call_data \ - "add-exporter-config" \ - "$statemine_ws_url" \ - "$tmp_output_file" \ - "$bridged_network" \ - "$bridge_config" - local hex_encoded_data=$(cat $tmp_output_file) - rm $tmp_output_file - - send_governance_transact_from_relaychain "${statemine_para_id}" "${hex_encoded_data}" 200000000 12000 -} - -add_universal_alias() { - echo " calling add_universal_alias:" - local location=$(jq --null-input \ - --arg bridgehub_para_id "$bridgehub_para_id" \ - '{ "V3": { "parents": 1, "interior": { "X1": { "Parachain": $bridgehub_para_id } } } }') # BridgeHub - - local junction=$(jq --null-input \ - --arg eth_chain_id "$eth_chain_id" \ - '{ "GlobalConsensus": { "Ethereum": { "chainId": $eth_chain_id } } }') - - echo "" - echo " location:" - echo "${location}" - echo "" - echo " junction:" - echo "${junction}" - echo "" - echo "--------------------------------------------------" - - local tmp_output_file=$(mktemp) - generate_hex_encoded_call_data "add-universal-alias" "${statemine_ws_url}" "${tmp_output_file}" "$location" "$junction" - local hex_encoded_data=$(cat $tmp_output_file) - rm $tmp_output_file - - send_governance_transact_from_relaychain "${statemine_para_id}" "${hex_encoded_data}" 200000000 12000 -} - -add_reserve_location() { - echo " calling add_reserve_location:" - - local nativeTokens=$1 - # Ethereum Native Tokens contract - local reserve_location=$(jq --null-input \ - --arg eth_chain_id "$eth_chain_id" \ - --arg nativeTokens "$nativeTokens" \ - '{ "V3": { - "parents": 2, - "interior": { - "X2": [ - { - "GlobalConsensus": { "Ethereum": { "chainId": $eth_chain_id } }, - }, - { - "AccountKey20": { "network": { "Ethereum": { "chainId": $eth_chain_id } }, "key": $nativeTokens } - } - ] - } - } }') - - echo "" - echo " reserve_location:" - echo "${reserve_location}" - echo "" - echo "--------------------------------------------------" - - local tmp_output_file=$(mktemp) - generate_hex_encoded_call_data "add-reserve-location" "${statemine_ws_url}" "${tmp_output_file}" "$reserve_location" - local hex_encoded_data=$(cat $tmp_output_file) - rm $tmp_output_file - - send_governance_transact_from_relaychain "${statemine_para_id}" "${hex_encoded_data}" 200000000 12000 -} - -configure_statemine() { - # Allows messages to be sent from Substrate to ETH. - add_exporter_config - # Allow messages to be sent from ETH to Substrate. - add_universal_alias - # Allow NativeTokens contract to ReserveAssetDeposited xcm instruction. - add_reserve_location $(address_for NativeTokens) -} - -if [ -z "${from_start_services:-}" ]; then - echo "configuring statemine" - configure_statemine - wait -fi diff --git a/core/packages/test/scripts/helpers/generateHexEncodedCallData.js b/core/packages/test/scripts/helpers/generateHexEncodedCallData.js deleted file mode 100644 index a813910b51..0000000000 --- a/core/packages/test/scripts/helpers/generateHexEncodedCallData.js +++ /dev/null @@ -1,147 +0,0 @@ -const fs = require("fs"); -const { exit } = require("process"); -const { WsProvider, ApiPromise } = require("@polkadot/api"); -const util = require("@polkadot/util"); - -// connect to a substrate chain and return the api object -async function connect(endpoint, types = {}) { - const provider = new WsProvider(endpoint); - const api = await ApiPromise.create({ - provider, - types, - throwOnConnect: false, - }); - return api; -} - -function writeHexEncodedBytesToOutput(method, outputFile) { - const hex = method.toHex(); - console.log("Payload (hex): ", hex); - console.log("Payload (bytes): ", Array.from(method.toU8a())); - fs.writeFileSync(outputFile, hex); -} - -function remarkWithEvent(endpoint, outputFile) { - console.log(`Generating remarkWithEvent from RPC endpoint: ${endpoint} to outputFile: ${outputFile}`); - connect(endpoint) - .then((api) => { - const call = api.tx.system.remarkWithEvent("Hello"); - writeHexEncodedBytesToOutput(call.method, outputFile); - exit(0); - }) - .catch((e) => { - console.error(e); - exit(1); - }); -} - -function addExporterConfig(endpoint, outputFile, bridgedNetwork, bridgeConfig) { - console.log(`Generating addExporterConfig from RPC endpoint: ${endpoint} to outputFile: ${outputFile} based on bridgedNetwork: ${bridgedNetwork}, bridgeConfig: ${bridgeConfig}`); - connect(endpoint) - .then((api) => { - const call = api.tx.bridgeTransfer.addExporterConfig(JSON.parse(bridgedNetwork), JSON.parse(bridgeConfig)); - writeHexEncodedBytesToOutput(call.method, outputFile); - exit(0); - }) - .catch((e) => { - console.error(e); - exit(1); - }); -} - -function addUniversalAlias(endpoint, outputFile, location, junction) { - console.log(`Generating addUniversalAlias from RPC endpoint: ${endpoint} to outputFile: ${outputFile} based on location: ${location}, junction: ${junction}`); - connect(endpoint) - .then((api) => { - const call = api.tx.bridgeTransfer.addUniversalAlias(JSON.parse(location), JSON.parse(junction)); - writeHexEncodedBytesToOutput(call.method, outputFile); - exit(0); - }) - .catch((e) => { - console.error(e); - exit(1); - }); -} - -function addReserveLocation(endpoint, outputFile, reserve_location) { - console.log(`Generating addReserveLocation from RPC endpoint: ${endpoint} to outputFile: ${outputFile} based on reserve_location: ${reserve_location}`); - connect(endpoint) - .then((api) => { - const call = api.tx.bridgeTransfer.addReserveLocation(JSON.parse(reserve_location)); - writeHexEncodedBytesToOutput(call.method, outputFile); - exit(0); - }) - .catch((e) => { - console.error(e); - exit(1); - }); -} - -function removeExporterConfig(endpoint, outputFile, bridgedNetwork) { - console.log(`Generating removeExporterConfig from RPC endpoint: ${endpoint} to outputFile: ${outputFile} based on bridgedNetwork: ${bridgedNetwork}`); - connect(endpoint) - .then((api) => { - const call = api.tx.bridgeTransfer.removeExporterConfig(bridgedNetwork); - writeHexEncodedBytesToOutput(call.method, outputFile); - exit(0); - }) - .catch((e) => { - console.error(e); - exit(1); - }); -} - -function forceCreateAsset(endpoint, outputFile, assetId, assetOwnerAccountId, isSufficient, minBalance) { - console.log(`Generating forceCreateAsset from RPC endpoint: ${endpoint} to outputFile: ${outputFile} based on assetId: ${assetId}, assetOwnerAccountId: ${assetOwnerAccountId}, isSufficient: ${isSufficient}, minBalance: ${minBalance}`); - connect(endpoint) - .then((api) => { - const call = api.tx.foreignAssets.forceCreate(JSON.parse(assetId), assetOwnerAccountId, isSufficient, minBalance); - writeHexEncodedBytesToOutput(call.method, outputFile); - exit(0); - }) - .catch((e) => { - console.error(e); - exit(1); - }); -} - -if (!process.argv[2] || !process.argv[3]) { - console.log("usage: node ./script/generate_hex_encoded_call "); - exit(1); -} - -const type = process.argv[2]; -const rpcEndpoint = process.argv[3]; -const output = process.argv[4]; -const inputArgs = process.argv.slice(5, process.argv.length); -console.log(`Generating hex-encoded call data for:`); -console.log(` type: ${type}`); -console.log(` rpcEndpoint: ${rpcEndpoint}`); -console.log(` output: ${output}`); -console.log(` inputArgs: ${inputArgs}`); - -switch (type) { - case 'remark-with-event': - remarkWithEvent(rpcEndpoint, output); - break; - case 'add-exporter-config': - addExporterConfig(rpcEndpoint, output, inputArgs[0], inputArgs[1]); - break; - case 'remove-exporter-config': - removeExporterConfig(rpcEndpoint, output, inputArgs[0], inputArgs[1]); - break; - case 'add-universal-alias': - addUniversalAlias(rpcEndpoint, output, inputArgs[0], inputArgs[1]); - break; - case 'add-reserve-location': - addReserveLocation(rpcEndpoint, output, inputArgs[0]); - break; - case 'force-create-asset': - forceCreateAsset(rpcEndpoint, output, inputArgs[0], inputArgs[1], inputArgs[2], inputArgs[3]); - break; - case 'check': - console.log(`Checking nodejs installation, if you see this everything is ready!`); - break; - default: - console.log(`Sorry, we are out of ${type} - not yet supported!`); -} diff --git a/cumulus b/cumulus index d8cee8116a..5d377bcd55 160000 --- a/cumulus +++ b/cumulus @@ -1 +1 @@ -Subproject commit d8cee8116a740cc29605b254eacfef5e1dd5803d +Subproject commit 5d377bcd55039c8bd336cc5b544f54e30a3c321a From a95efc9f0ae92ff24df21d5aef1c1fae1c96f596 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 15 Jun 2023 00:31:30 +0200 Subject: [PATCH 2/4] update cumulus --- cumulus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus b/cumulus index 5d377bcd55..e144737369 160000 --- a/cumulus +++ b/cumulus @@ -1 +1 @@ -Subproject commit 5d377bcd55039c8bd336cc5b544f54e30a3c321a +Subproject commit e1447373693e99e1e95dfb8db0d843cf0e807b5b From ec6e771f89c6e6664ebd3a6159ce6068857e50b1 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 15 Jun 2023 22:26:07 +0200 Subject: [PATCH 3/4] fix after merge --- core/packages/test/scripts/start-services.sh | 7 +------ cumulus | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/core/packages/test/scripts/start-services.sh b/core/packages/test/scripts/start-services.sh index 2d76ca1ddd..6c81c0f04f 100755 --- a/core/packages/test/scripts/start-services.sh +++ b/core/packages/test/scripts/start-services.sh @@ -54,13 +54,8 @@ echo "Config beacon client" source scripts/configure-beacon.sh configure_beacon -# 7. Configure bridgehub exporter on statemine -echo "Config bridgehub exporter on statemine" -source scripts/configure-statemine.sh -configure_statemine > "$output_dir/configure_statemine.log" 2>&1 & - if [ "$skip_relayer" == "false" ]; then - # 8. start relayer + # 7. start relayer echo "Starting relayers" source scripts/start-relayer.sh deploy_relayer diff --git a/cumulus b/cumulus index e144737369..afe157381b 160000 --- a/cumulus +++ b/cumulus @@ -1 +1 @@ -Subproject commit e1447373693e99e1e95dfb8db0d843cf0e807b5b +Subproject commit afe157381b40081d67329e5e1a5a1dba9eced5fe From 534bd764935cfb615ebe629f74812df6f8b82aad Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 15 Jun 2023 22:34:25 +0200 Subject: [PATCH 4/4] update cumulus --- cumulus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus b/cumulus index afe157381b..c755a6bc93 160000 --- a/cumulus +++ b/cumulus @@ -1 +1 @@ -Subproject commit afe157381b40081d67329e5e1a5a1dba9eced5fe +Subproject commit c755a6bc93944366ca1e732ece250c4d0472db5c