From 661956149e6ad0f714bf0a698d074f13af9b4ee6 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Fri, 28 Jan 2022 05:54:17 +0100 Subject: [PATCH] merged with main --- .github/workflows/benchmark.yml | 15 +- .github/workflows/check.yml | 8 +- .github/workflows/devnet-release.yml | 24 +-- .github/workflows/release-drafter.yml | 102 ------------ .github/workflows/release-pipeline.yml | 106 ++++++++++++ .github/workflows/simnode.yml | 16 +- .maintain/check_runtime.sh | 15 +- .maintain/client_release.sh | 6 +- .maintain/common/lib.sh | 10 +- .maintain/run_benchmarks.sh | 40 ++--- .maintain/run_simnode.sh | 4 +- .maintain/runtime_release.sh | 20 +-- Cargo.lock | 117 ++++++++++++- frame/assets-registry/src/lib.rs | 31 ++++ frame/assets-registry/src/tests.rs | 34 ++++ integration-tests/Cargo.toml | 21 ++- integration-tests/src/cross_chain_transfer.rs | 156 +++++++++++++++++- node/Cargo.toml | 2 +- runtime/dali/src/lib.rs | 1 + scripts/polkadot-launch/composable.json | 6 + 20 files changed, 549 insertions(+), 185 deletions(-) delete mode 100644 .github/workflows/release-drafter.yml create mode 100644 .github/workflows/release-pipeline.yml diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 24f4df8b84f..9b55948f9b6 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -7,7 +7,7 @@ on: - main jobs: - benchmark: + benchmark: name: Benchmark runs-on: - self-hosted @@ -24,18 +24,27 @@ jobs: - uses: actions/checkout@v2 with: - ref: main + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} + + - name: Get branch name + id: branch-name + uses: tj-actions/branch-names@v5.1 - name: Check for runtime changes env: BASE_BRANCH: ${{ github.event.pull_request.base.ref }} + GITHUB_BRANCH_NAME: ${{ steps.branch-name.outputs.current_branch }} + id: check_runtime if: github.event.label.name == 'needs-benchmarks' run: .maintain/check_runtime.sh - + - name: Benchmark Test env: BASE_BRANCH: ${{ github.event.pull_request.base.ref }} + GITHUB_BRANCH_NAME: ${{ steps.branch-name.outputs.current_branch }} + if: env.RUNTIME_CHECK == 1 id: run_benchmarks run: .maintain/run_benchmarks.sh diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 2d821850d75..db2e54ce68a 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -11,6 +11,10 @@ on: workflow_dispatch: +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + env: DOCKER_USER_OPTION: '$UID:$GID' @@ -63,7 +67,7 @@ jobs: # TODO: https://github.com/ComposableFi/composable/issues/535 /home/runner/.cargo/bin/cargo install -f cargo-llvm-cov /home/runner/.cargo/bin/rustup component add llvm-tools-preview --toolchain=nightly-2021-11-08 - SKIP_WASM_BUILD=1 /home/runner/.cargo/bin/cargo +nightly-2021-11-08 llvm-cov --workspace --locked --release --verbose --features=runtime-benchmarks --exclude=integration-tests --lcov --output-path lcov.info + SKIP_WASM_BUILD=1 /home/runner/.cargo/bin/cargo +nightly-2021-11-08 llvm-cov --workspace --locked --release --verbose --features=runtime-benchmarks --lcov --output-path lcov.info - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 with: @@ -93,7 +97,7 @@ jobs: - uses: actions/checkout@v2 - name: Run Test run: | - SKIP_WASM_BUILD=1 cargo test --workspace --locked --release --verbose --features=runtime-benchmarks --exclude=integration-tests + SKIP_WASM_BUILD=1 cargo test --workspace --locked --release --verbose --features=runtime-benchmarks linters: name: Linters diff --git a/.github/workflows/devnet-release.yml b/.github/workflows/devnet-release.yml index d0a444cc788..6f47088b2a2 100644 --- a/.github/workflows/devnet-release.yml +++ b/.github/workflows/devnet-release.yml @@ -7,19 +7,11 @@ on: jobs: deploy-devnet: - runs-on: - - ubuntu-latest + runs-on: ubuntu-latest concurrency: group: deploy-devnet cancel-in-progress: false steps: - - name: Clean up - continue-on-error: true - run: | - sudo chown -R $USER:$USER $GITHUB_WORKSPACE - docker system prune --force --all --volumes - - - uses: actions/checkout@v2 - uses: google-github-actions/setup-gcloud@master @@ -43,9 +35,20 @@ jobs: run: | echo "RELEASE_VERSION=$GITHUB_SHA" >> $GITHUB_ENV + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - name: Install latest Nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + target: wasm32-unknown-unknown + - name: Push artifact run: | - /home/runner/.cargo/bin/cargo build --release + cargo build --release tar -czvf composable-picasso-${{ env.RELEASE_VERSION }}.tar.gz target/release/composable gsutil mv *.tar.gz gs://composable-binaries/community-releases/picasso/ @@ -85,4 +88,3 @@ jobs: env: NIXOPS_STATE: "deployment.nixops" NIXOPS_STATE_URL: "gs://composable-state" - diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml deleted file mode 100644 index c99521a2cfa..00000000000 --- a/.github/workflows/release-drafter.yml +++ /dev/null @@ -1,102 +0,0 @@ -name: Release Drafter -on: - push: - branches: - - releases -jobs: - build-and-publish: - runs-on: - - self-hosted - - linux - - x64 - - sre - strategy: - fail-fast: true - steps: - - name: Clean up - continue-on-error: true - run: | - sudo chown -R $USER:$USER $GITHUB_WORKSPACE - docker system prune --force --all --volumes - - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - - name: Install srtool - run: | - cargo install --git https://github.com/chevdor/srtool-cli - cargo install --locked --git https://github.com/chevdor/subwasm --tag v0.16.1 - - - name: Runtime wasm builds - id: runtime_release - run: | - .maintain/runtime_release.sh - - - uses: release-drafter/release-drafter@v5 - id: release_drafter - - - name: Set Permission - continue-on-error: true - run: | - sudo su runner - - - uses: actions/setup-node@v2 - with: - node-version: '16' - - - name: Add runtime metadata to release body - run: | - cd scripts/github && npm install - printf "\n%s" "${{ steps.release_drafter.outputs.body }}" >> $GITHUB_WORKSPACE/release.md - npm run update-release-body -- --id=${{ steps.release_drafter.outputs.id }} --repo=composableFi/composable --body="$GITHUB_WORKSPACE/release.md" - cd $GITHUB_WORKSPACE - - - name: Upload Dali wasm - id: upload-dali-wasm - if: env.dali_wasm == 1 - uses: actions/upload-release-asset@v1 - with: - upload_url: ${{ steps.release_drafter.outputs.upload_url }} - asset_path: ./runtime/dali/target/srtool/release/wbuild/dali-runtime/dali_runtime.compact.wasm - asset_name: dali_runtime.compact.wasm - asset_content_type: application/octet-stream - - - name: Upload Picasso wasm - id: upload-picasso-wasm - if: env.picasso_wasm == 1 - uses: actions/upload-release-asset@v1 - with: - upload_url: ${{ steps.release_drafter.outputs.upload_url }} - asset_path: ./runtime/picasso/target/srtool/release/wbuild/picasso-runtime/picasso_runtime.compact.wasm - asset_name: picasso_runtime.compact.wasm - asset_content_type: application/octet-stream - - - name: Upload Composable wasm - id: upload-composable-wasm - if: env.composable_wasm == 1 - uses: actions/upload-release-asset@v1 - with: - upload_url: ${{ steps.release_drafter.outputs.upload_url }} - asset_path: ./runtime/composable/target/srtool/release/wbuild/composable-runtime/composable_runtime.compact.wasm - asset_name: composable_runtime.compact.wasm - asset_content_type: application/octet-stream - - - name: 🔨 Build Composable Binary - run: | - .maintain/client_release.sh - - - name: Upload Composable Node Binaries - id: upload-composable-binary - if: env.client_release == 1 - uses: actions/upload-release-asset@v1 - - with: - upload_url: ${{ steps.release_drafter.outputs.upload_url }} - asset_path: ./target/release/composable - asset_name: composable - asset_content_type: application/octet-stream diff --git a/.github/workflows/release-pipeline.yml b/.github/workflows/release-pipeline.yml new file mode 100644 index 00000000000..0880763e3d3 --- /dev/null +++ b/.github/workflows/release-pipeline.yml @@ -0,0 +1,106 @@ +name: Release Pipeline +on: + push: + branches: + - releases +jobs: + build-and-publish: + runs-on: + - self-hosted + - linux + - x64 + - sre + strategy: + fail-fast: true + steps: + - name: Clean up + continue-on-error: true + run: | + sudo chown -R $USER:$USER $GITHUB_WORKSPACE + docker system prune --force --all --volumes + + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - name: Install srtool + run: | + cargo install --git https://github.com/chevdor/srtool-cli + cargo install --locked --git https://github.com/chevdor/subwasm --tag v0.16.1 + + - name: Runtime wasm builds + id: runtime_release + env: + + run: | + .maintain/runtime_release.sh + + - uses: release-drafter/release-drafter@v5 + id: release_drafter + + - name: Set Permission + continue-on-error: true + run: | + sudo su runner + + - uses: actions/setup-node@v2 + with: + node-version: "16" + + - name: Add runtime metadata to release body + run: | + cd scripts/github && npm install + printf "\n%s" "${{ steps.release_drafter.outputs.body }}" >> $GITHUB_WORKSPACE/release.md + npm run update-release-body -- --id=${{ steps.release_drafter.outputs.id }} --repo=composableFi/composable --body="$GITHUB_WORKSPACE/release.md" + cd $GITHUB_WORKSPACE + + - name: Upload Dali wasm + id: upload-dali-wasm + if: env.dali_wasm == 1 + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.release_drafter.outputs.upload_url }} + asset_path: ./runtime/dali/target/srtool/release/wbuild/dali-runtime/dali_runtime.compact.wasm + asset_name: dali_runtime.compact.wasm + asset_content_type: application/octet-stream + + - name: Upload Picasso wasm + id: upload-picasso-wasm + if: env.picasso_wasm == 1 + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.release_drafter.outputs.upload_url }} + asset_path: ./runtime/picasso/target/srtool/release/wbuild/picasso-runtime/picasso_runtime.compact.wasm + asset_name: picasso_runtime.compact.wasm + asset_content_type: application/octet-stream + + - name: Upload Composable wasm + id: upload-composable-wasm + if: env.composable_wasm == 1 + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.release_drafter.outputs.upload_url }} + asset_path: ./runtime/composable/target/srtool/release/wbuild/composable-runtime/composable_runtime.compact.wasm + asset_name: composable_runtime.compact.wasm + asset_content_type: application/octet-stream + + - name: 🔨 Build Composable Binary + env: + + run: | + .maintain/client_release.sh + + - name: Upload Composable Node Binaries + id: upload-composable-binary + if: env.client_release == 1 + uses: actions/upload-release-asset@v1 + + with: + upload_url: ${{ steps.release_drafter.outputs.upload_url }} + asset_path: ./target/release/composable + asset_name: composable + asset_content_type: application/octet-stream diff --git a/.github/workflows/simnode.yml b/.github/workflows/simnode.yml index 092c209b003..edfe8c37144 100644 --- a/.github/workflows/simnode.yml +++ b/.github/workflows/simnode.yml @@ -6,7 +6,7 @@ on: - main jobs: simnode: - runs-on: + runs-on: - self-hosted - linux - x64 @@ -18,20 +18,28 @@ jobs: run: | sudo chown -R $USER:$USER $GITHUB_WORKSPACE docker system prune --force --all --volumes - + - uses: actions/checkout@v2 - with: - ref: main + with: + fetch-depth: 0 + + - name: Get branch name + id: branch-name + uses: tj-actions/branch-names@v5.1 - name: Check for runtime changes id: check_runtime env: BASE_BRANCH: ${{ github.event.pull_request.base.ref }} + GITHUB_BRANCH_NAME: ${{ steps.branch-name.outputs.current_branch }} + run: .maintain/check_runtime.sh - name: Run Simnode env: BASE_BRANCH: ${{ github.event.pull_request.base.ref }} + GITHUB_BRANCH_NAME: ${{ steps.branch-name.outputs.current_branch }} + if: env.RUNTIME_CHECK == 1 id: run_simnode run: .maintain/run_simnode.sh diff --git a/.maintain/check_runtime.sh b/.maintain/check_runtime.sh index fbe276cf70b..7b47c63dcb9 100755 --- a/.maintain/check_runtime.sh +++ b/.maintain/check_runtime.sh @@ -5,7 +5,7 @@ # "auto-fail" the PR if there isn't a change in the runtime/src/lib.rs file # that alters the version. -#set -e # fail on any error +set -e # fail on any error #shellcheck source=../common/lib.sh . "$(dirname "${0}")/./common/lib.sh" @@ -14,18 +14,17 @@ VERSIONS_FILES=( "runtime/picasso/src/lib.rs,picasso,picasso" "runtime/dali/src/lib.rs,dali-chachacha,dali" - "runtime/composable/src/lib.rs,composable,composable" + "runtime/composable/src/lib.rs,composable,composable" ) - echo "make sure the main branch and release tag are available in shallow clones" - git fetch --depth="${GIT_DEPTH:-100}" origin "${BASE_BRANCH}" +echo "make sure the main branch and release tag are available in shallow clones" +git fetch --depth="${GIT_DEPTH:-100}" origin "${BASE_BRANCH}" simnode_check() { VERSIONS_FILE="$1" - if has_runtime_changes "${BASE_BRANCH}" "${GITHUB_REF_NAME}" "$2" && check_runtime "$VERSIONS_FILE" "$2" - then + if has_runtime_changes "${BASE_BRANCH}" "${GITHUB_BRANCH_NAME}" "$2" && check_runtime "$VERSIONS_FILE" "$2"; then echo "Wasm sources have changed for $3" - echo "RUNTIME_CHECK=1" >> $GITHUB_ENV + echo "RUNTIME_CHECK=1" >>$GITHUB_ENV fi } @@ -33,7 +32,7 @@ for i in "${VERSIONS_FILES[@]}"; do while IFS=',' read -r output chain folder; do boldprint "Check if the wasm sources changed for $chain" simnode_check $output $folder $chain - done <<< "$i" + done <<<"$i" done # dropped through. there's something wrong; exit 1. diff --git a/.maintain/client_release.sh b/.maintain/client_release.sh index 85861f04fce..74e21e822d3 100755 --- a/.maintain/client_release.sh +++ b/.maintain/client_release.sh @@ -10,14 +10,12 @@ #shellcheck source=../common/lib.sh . "$(dirname "${0}")/./common/lib.sh" -RELEASE_VERSION=$(git tag --sort=committerdate | grep -E '^v[0-9]' | tail -1 ) +RELEASE_VERSION=$(git tag --sort=committerdate | grep -E '^v[0-9]' | tail -1) # Because this script runs when a tag has been published, the previous tag is the # last two tags PREV_TAG=$(gh release list -L=2 | sed -n '2 p' | awk '{print $(NF-1)}') - -if has_client_changes "${PREV_TAG}" "${GITHUB_REF_NAME}" -then +if has_client_changes "${PREV_TAG}" "${GITHUB_REF_NAME}"; then boldprint "Building new client binaries" cargo build --release -p composable tar -czvf composable-"${RELEASE_VERSION}".tar.gz target/release/composable diff --git a/.maintain/common/lib.sh b/.maintain/common/lib.sh index e1858c20c7e..1259a866691 100644 --- a/.maintain/common/lib.sh +++ b/.maintain/common/lib.sh @@ -26,7 +26,7 @@ has_runtime_changes() { from=$1 to=$2 echo "diffing $from & $to" - if git diff --name-only "${from}...${to}" | + if git diff --name-only "origin/${from}...origin/${to}" | grep -q -e '^frame/' -e "^runtime/$3/"; then return 0 @@ -51,9 +51,9 @@ has_client_changes() { # checks if the spec/impl version has increased check_runtime() { VERSIONS_FILE="$1" - add_spec_version="$(git diff "${LATEST_TAG_NAME}" "${GITHUB_REF_NAME}" -- "${VERSIONS_FILE}" | + add_spec_version="$(git diff "${LATEST_TAG_NAME}" "origin/${GITHUB_REF_NAME}" -- "${VERSIONS_FILE}" | sed -n -r "s/^\+[[:space:]]+spec_version: +([0-9]+),$/\1/p")" - sub_spec_version="$(git diff "${LATEST_TAG_NAME}" "${GITHUB_REF_NAME}" -- "${VERSIONS_FILE}" | + sub_spec_version="$(git diff "${LATEST_TAG_NAME}" "origin/${GITHUB_REF_NAME}" -- "${VERSIONS_FILE}" | sed -n -r "s/^\-[[:space:]]+spec_version: +([0-9]+),$/\1/p")" if [ "${add_spec_version}" != "${sub_spec_version}" ]; then @@ -70,9 +70,9 @@ check_runtime() { # check for impl_version updates: if only the impl versions changed, we assume # there is no consensus-critical logic that has changed. - add_impl_version="$(git diff "${LATEST_TAG_NAME}" "${GITHUB_REF_NAME}" -- "${VERSIONS_FILE}" | + add_impl_version="$(git diff "${LATEST_TAG_NAME}" "origin/${GITHUB_REF_NAME}" -- "${VERSIONS_FILE}" | sed -n -r 's/^\+[[:space:]]+impl_version: +([0-9]+),$/\1/p')" - sub_impl_version="$(git diff "${LATEST_TAG_NAME}" "${GITHUB_REF_NAME}" -- "${VERSIONS_FILE}" | + sub_impl_version="$(git diff "${LATEST_TAG_NAME}" "origin/${GITHUB_REF_NAME}" -- "${VERSIONS_FILE}" | sed -n -r 's/^\-[[:space:]]+impl_version: +([0-9]+),$/\1/p')" # see if the impl version changed diff --git a/.maintain/run_benchmarks.sh b/.maintain/run_benchmarks.sh index 9775dd3116d..01c2722f66f 100755 --- a/.maintain/run_benchmarks.sh +++ b/.maintain/run_benchmarks.sh @@ -17,26 +17,26 @@ steps=50 repeat=20 pallets=( - oracle - frame_system - timestamp - session - balances - indices - membership - treasury - scheduler - collective - democracy - collator_selection - utility - lending - dutch_auction + oracle + frame_system + timestamp + session + balances + indices + membership + treasury + scheduler + collective + democracy + collator_selection + utility + lending + dutch_auction ) /home/runner/.cargo/bin/rustup install nightly -/home/runner/.cargo/bin/rustup target add wasm32-unknown-unknown --toolchain nightly -/home/runner/.cargo/bin/cargo build --release -p composable --features=runtime-benchmarks +/home/runner/.cargo/bin/rustup target add wasm32-unknown-unknown --toolchain nightly +/home/runner/.cargo/bin/cargo build --release -p composable --features=runtime-benchmarks run_benchmarks() { OUTPUT=$1 @@ -62,16 +62,16 @@ run_benchmarks() { USERNAME=$(gcloud secrets versions access latest --secret=github-api-username) PASSWORD=$(gcloud secrets versions access latest --secret=github-api-token) git remote set-url origin https://"$USERNAME":"$PASSWORD"@github.com/ComposableFi/composable.git - git pull origin "$GITHUB_REF_NAME" + git pull origin "$GITHUB_BRANCH_NAME" git add runtime/"$FOLDER" git commit -m "Updates weights for $CHAIN" - git push origin "$GITHUB_REF_NAME" + git push origin "$GITHUB_BRANCH_NAME" # ToDO: Setup gpg signing and create a bot account for pushing } for i in "${VERSIONS_FILES[@]}"; do while IFS=',' read -r output chain folder; do - if has_runtime_changes "${BASE_BRANCH}" "${GITHUB_REF_NAME}" "$folder"; then + if has_runtime_changes "${BASE_BRANCH}" "${GITHUB_BRANCH_NAME}" "$folder"; then run_benchmarks $output $chain $folder fi done <<<"$i" diff --git a/.maintain/run_simnode.sh b/.maintain/run_simnode.sh index d057b3a6aaa..f0e00811eb0 100755 --- a/.maintain/run_simnode.sh +++ b/.maintain/run_simnode.sh @@ -18,7 +18,7 @@ VERSIONS_FILES=( /home/runner/.cargo/bin/rustup target add wasm32-unknown-unknown --toolchain nightly /home/runner/.cargo/bin/cargo build --release -p simnode sudo chown -R runner:runner target/release/simnode && sudo chmod +x target/release/simnode -sudo chown -R runner:runner /tmp/db +sudo chown -R runner:runner /tmp/db YDATE=$(date -d yesterday +'%m-%d-%Y') run_simnode() { @@ -35,7 +35,7 @@ run_simnode() { for i in "${VERSIONS_FILES[@]}"; do while IFS=',' read -r chain folder; do echo "check if the wasm sources changed for $chain" - if has_runtime_changes "${BASE_BRANCH}" "${GITHUB_REF_NAME}" "$folder"; then + if has_runtime_changes "${BASE_BRANCH}" "${GITHUB_BRANCH_NAME}" "$folder"; then # shellcheck disable=SC2086 run_simnode $chain fi diff --git a/.maintain/runtime_release.sh b/.maintain/runtime_release.sh index 6bc358ad033..b082fcf0270 100755 --- a/.maintain/runtime_release.sh +++ b/.maintain/runtime_release.sh @@ -13,8 +13,8 @@ # shellcheck disable=SC2039 VERSIONS_FILES=( "runtime/picasso/src/lib.rs,picasso,picasso" - "runtime/dali/src/lib.rs,dali-chachacha,dali" - "runtime/composable/src/lib.rs,composable,composable" + "runtime/dali/src/lib.rs,dali-chachacha,dali" + "runtime/composable/src/lib.rs,composable,composable" ) # Because this script runs when a tag has been published, the previous tag is the # last two tags @@ -25,26 +25,24 @@ CURRENT_TAG=$(gh release list -L=1 | sed -n '1 p' | awk '{print $(NF-1)}') cargo install --git https://github.com/chevdor/srtool-cli cargo install --locked --git https://github.com/chevdor/subwasm --tag v0.16.1 - -build_runtime () { +build_runtime() { chain=$3 # srtool for reproducible builds srtool build --package "$chain"-runtime --profile release --runtime-dir runtime/"$chain" # subwasm for runtime metadata - echo "# $chain Runtime " >> release.md - subwasm info ./runtime/"$chain"/target/srtool/release/wbuild/"$chain"-runtime/"$chain"_runtime.compact.wasm >> release.md + echo "# $chain Runtime " >>release.md + subwasm info ./runtime/"$chain"/target/srtool/release/wbuild/"$chain"-runtime/"$chain"_runtime.compact.wasm >>release.md } # Check which runtimes have changed and build them for i in "${VERSIONS_FILES[@]}"; do while IFS=',' read -r output chain folder; do echo "check if the wasm sources changed for $chain" - if has_runtime_changes "${PREV_TAG}" "${GITHUB_REF_NAME}" "$folder" - then + if has_runtime_changes "${PREV_TAG}" "${GITHUB_REF_NAME}" "$folder"; then build_runtime $output $chain $folder CHANGES=gh view release tag $CURRENT_TAG - echo $CHANGES | sed '1,/--/ d' >> release.md - echo "$chain-wasm=1" >> "$GITHUB_ENV" + echo $CHANGES | sed '1,/--/ d' >>release.md + echo "$chain-wasm=1" >>"$GITHUB_ENV" fi - done <<< "$i" + done <<<"$i" done diff --git a/Cargo.lock b/Cargo.lock index 65a4beeaeab..0a08b6dc3fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7614,6 +7614,23 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "pallet-xcm-benchmarks" +version = "0.9.8" +source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log 0.4.14", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", + "xcm", + "xcm-executor", +] + [[package]] name = "parachain-info" version = "0.1.0" @@ -8947,12 +8964,15 @@ source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.13#7d8f dependencies = [ "beefy-primitives", "bitvec", + "frame-benchmarking", "frame-election-provider-support", "frame-executive", "frame-support", "frame-system", + "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", + "hex-literal", "log 0.4.14", "pallet-authority-discovery", "pallet-authorship", @@ -8973,9 +8993,11 @@ dependencies = [ "pallet-multisig", "pallet-nicks", "pallet-offences", + "pallet-offences-benchmarking", "pallet-proxy", "pallet-scheduler", "pallet-session", + "pallet-session-benchmarking", "pallet-staking", "pallet-staking-reward-curve", "pallet-timestamp", @@ -9115,6 +9137,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "futures 0.3.19", "hex-literal", + "kusama-runtime", "kvdb", "kvdb-rocksdb", "lru 0.7.2", @@ -9199,6 +9222,7 @@ dependencies = [ "substrate-prometheus-endpoint", "thiserror", "tracing", + "westend-runtime", ] [[package]] @@ -10075,10 +10099,12 @@ dependencies = [ "bp-runtime", "bp-wococo", "bridge-runtime-common", + "frame-benchmarking", "frame-executive", "frame-support", "frame-system", "frame-system-rpc-runtime-api", + "hex-literal", "log 0.4.14", "pallet-authority-discovery", "pallet-authorship", @@ -13466,7 +13492,7 @@ dependencies = [ "chrono", "lazy_static", "matchers", - "parking_lot 0.11.2", + "parking_lot 0.9.0", "regex", "serde", "serde_json", @@ -13646,8 +13672,8 @@ version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" dependencies = [ - "cfg-if 1.0.0", - "rand 0.8.4", + "cfg-if 0.1.10", + "rand 0.6.5", "static_assertions", ] @@ -14318,6 +14344,90 @@ dependencies = [ "cc", ] +[[package]] +name = "westend-runtime" +version = "0.9.13" +source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +dependencies = [ + "beefy-primitives", + "bitvec", + "frame-benchmarking", + "frame-election-provider-support", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-benchmarking", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex-literal", + "log 0.4.14", + "pallet-authority-discovery", + "pallet-authorship", + "pallet-babe", + "pallet-bags-list", + "pallet-balances", + "pallet-collective", + "pallet-democracy 4.0.0-dev", + "pallet-election-provider-multi-phase", + "pallet-elections-phragmen", + "pallet-grandpa", + "pallet-identity", + "pallet-im-online", + "pallet-indices", + "pallet-membership", + "pallet-mmr-primitives", + "pallet-multisig", + "pallet-nicks", + "pallet-offences", + "pallet-offences-benchmarking", + "pallet-proxy", + "pallet-recovery", + "pallet-scheduler", + "pallet-session", + "pallet-session-benchmarking", + "pallet-society", + "pallet-staking", + "pallet-staking-reward-curve", + "pallet-sudo", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", + "pallet-utility", + "pallet-vesting 4.0.0-dev", + "pallet-xcm", + "pallet-xcm-benchmarks", + "parity-scale-codec", + "polkadot-parachain", + "polkadot-primitives", + "polkadot-runtime-common", + "polkadot-runtime-parachains", + "rustc-hex", + "scale-info", + "serde", + "serde_derive", + "smallvec 1.8.0", + "sp-api", + "sp-authority-discovery", + "sp-block-builder", + "sp-consensus-babe", + "sp-core", + "sp-inherents", + "sp-io", + "sp-npos-elections", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", + "sp-transaction-pool", + "sp-version", + "substrate-wasm-builder", + "xcm", + "xcm-builder", + "xcm-executor", +] + [[package]] name = "which" version = "4.2.2" @@ -14494,6 +14604,7 @@ name = "xcm-executor" version = "0.9.13" source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" dependencies = [ + "frame-benchmarking", "frame-support", "impl-trait-for-tuples", "log 0.4.14", diff --git a/frame/assets-registry/src/lib.rs b/frame/assets-registry/src/lib.rs index a1c7e5d60c5..7c85bfee1d5 100644 --- a/frame/assets-registry/src/lib.rs +++ b/frame/assets-registry/src/lib.rs @@ -73,6 +73,11 @@ pub mod pallet { ForeignAdminApproved, } + #[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode, TypeInfo)] + pub struct ForeignMetadata { + pub decimals: u8, + } + #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); @@ -114,6 +119,12 @@ pub mod pallet { OptionQuery, >; + #[pallet::storage] + #[pallet::getter(fn foreign_asset_metadata)] + /// Mapping local asset to foreign asset metadata. + pub type ForeignAssetMetadata = + StorageMap<_, Blake2_128Concat, T::LocalAssetId, ForeignMetadata, OptionQuery>; + #[pallet::type_value] pub fn LocalAdminOnEmpty() -> T::AccountId { T::AccountId::default() @@ -170,6 +181,7 @@ pub mod pallet { local_asset_id: T::LocalAssetId, foreign_asset_id: T::ForeignAssetId, }, + AssetMetadataUpdated(T::LocalAssetId), } #[pallet::error] @@ -177,6 +189,7 @@ pub mod pallet { OnlyAllowedForAdmins, LocalAssetIdAlreadyUsed, ForeignAssetIdAlreadyUsed, + LocalAssetIdNotFound, } #[pallet::call] @@ -226,6 +239,24 @@ pub mod pallet { }); Ok(().into()) } + + #[pallet::weight(10_000)] + pub fn set_metadata( + origin: OriginFor, + local_asset_id: T::LocalAssetId, + metadata: ForeignMetadata, + ) -> DispatchResultWithPostInfo { + let _ = ensure_signed(origin.clone())?; + Self::ensure_admins_only(origin)?; + ensure!( + >::contains_key(local_asset_id), + Error::::LocalAssetIdNotFound + ); + + >::insert(local_asset_id, metadata); + Self::deposit_event(Event::AssetMetadataUpdated(local_asset_id)); + Ok(().into()) + } } impl RemoteAssetRegistry for Pallet { diff --git a/frame/assets-registry/src/tests.rs b/frame/assets-registry/src/tests.rs index 79e589d47e3..c1026d1eebd 100644 --- a/frame/assets-registry/src/tests.rs +++ b/frame/assets-registry/src/tests.rs @@ -98,3 +98,37 @@ fn approve_assets_mapping_candidate_tests() { ); }) } + +#[test] +fn set_metadata_tests() { + new_test_ext().execute_with(|| { + let (local_asset_id, foreign_asset_id) = (0, 100); + assert_ok!(AssetsRegistry::set_local_admin(Origin::signed(ROOT), ALICE)); + assert_ok!(AssetsRegistry::set_foreign_admin(Origin::signed(ROOT), BOB)); + + assert_noop!( + AssetsRegistry::set_metadata( + Origin::signed(ALICE), + local_asset_id, + ForeignMetadata { decimals: 12 } + ), + Error::::LocalAssetIdNotFound + ); + + assert_ok!(AssetsRegistry::approve_assets_mapping_candidate( + Origin::signed(ALICE), + local_asset_id, + foreign_asset_id + )); + assert_ok!(AssetsRegistry::approve_assets_mapping_candidate( + Origin::signed(BOB), + local_asset_id, + foreign_asset_id + )); + assert_ok!(AssetsRegistry::set_metadata( + Origin::signed(ALICE), + local_asset_id, + ForeignMetadata { decimals: 12 } + )); + }) +} diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 1ce356507ab..076c9751a3d 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -100,11 +100,11 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0 # added on top of runtime for emulation of network paste = "1.0.5" -polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13" } +polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13", default-features = false } xcm-emulator = { git = "https://github.com/dzmitry-lahoda-forks/xcm-simulator", branch = "dz/0.9.13", default-features = false } -kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13" } -polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13" } -polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13" } +kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13", default-features = false } +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13", default-features = false } +polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13", default-features = false } picasso-runtime = { package = "dali-runtime", path = "../runtime/dali", default-features = false } [dev-dependencies] @@ -125,9 +125,9 @@ std = [ "sp-block-builder/std", "sp-transaction-pool/std", "sp-inherents/std", - "support/std", + "support/std", "executive/std", - "frame-system/std", + "frame-system/std", "utility/std", "authorship/std", "balances/std", @@ -163,7 +163,11 @@ std = [ "xcm-executor/std", "aura/std", "sp-consensus-aura/std", - "scale-info/std", + "scale-info/std", + "kusama-runtime/std", + "polkadot-core-primitives/std", + "polkadot-primitives/std", + "polkadot-runtime-parachains/std", ] runtime-benchmarks = [ @@ -189,6 +193,9 @@ runtime-benchmarks = [ "democracy/runtime-benchmarks", "utility/runtime-benchmarks", "kusama-runtime/runtime-benchmarks", + "picasso-runtime/runtime-benchmarks", + "polkadot-primitives/runtime-benchmarks", + "polkadot-runtime-parachains/runtime-benchmarks", ] develop = [ diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index a95f81810b6..89be0f0fd7d 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -10,6 +10,7 @@ use sp_runtime::traits::AccountIdConversion; use support::assert_ok; use xcm::latest::prelude::*; use xcm_emulator::TestExt; +use xcm_executor::XcmExecutor; /// assumes that our parachain has native relay token on relay account /// and kusama can send xcm message to our network and transfer native token onto local network @@ -202,7 +203,7 @@ fn transfer_insufficient_amount_should_fail() { MultiLocation::new( 1, X2( - Junction::Parachain(2000), + Junction::Parachain(PICASSO_PARA_ID), Junction::AccountId32 { id: BOB, network: NetworkId::Any } ) ) @@ -222,9 +223,133 @@ fn transfer_insufficient_amount_should_fail() { }); } +/// Acala's tests +#[test] +#[ignore] +fn transfer_from_relay_chain_deposit_to_treasury_if_below_ed() { + KusamaRelay::execute_with(|| { + assert_ok!(kusama_runtime::XcmPallet::reserve_transfer_assets( + kusama_runtime::Origin::signed(ALICE.into()), + Box::new(Parachain(PICASSO_PARA_ID).into().into()), + Box::new(Junction::AccountId32 { id: BOB, network: NetworkId::Any }.into().into()), + Box::new((Here, 128_000_111).into()), + 0 + )); + }); + + Picasso::execute_with(|| { + assert_eq!( + picasso_runtime::Tokens::free_balance(CurrencyId::KSM, &AccountId::from(BOB)), + 0 + ); + assert_eq!( + picasso_runtime::Tokens::free_balance( + CurrencyId::KSM, + &picasso_runtime::TreasuryAccount::get() + ), + 1_000_128_000_111 + ); + }); +} + +#[test] +#[ignore] +fn xcm_transfer_execution_barrier_trader_works() { + let expect_weight_limit = 600_000_000; + let weight_limit_too_low = 500_000_000; + let unit_instruction_weight = 200_000_000; + + // relay-chain use normal account to send xcm, destination para-chain can't pass Barrier check + let message = Xcm(vec![ + ReserveAssetDeposited((Parent, 100).into()), + BuyExecution { fees: (Parent, 100).into(), weight_limit: Unlimited }, + DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() }, + ]); + KusamaRelay::execute_with(|| { + let r = pallet_xcm::Pallet::::send( + kusama_runtime::Origin::signed(ALICE.into()), + Box::new(Parachain(PICASSO_PARA_ID).into().into()), + Box::new(xcm::VersionedXcm::from(message)), + ); + assert_ok!(r); + }); + Picasso::execute_with(|| { + assert!(picasso_runtime::System::events().iter().any(|r| matches!( + r.event, + picasso_runtime::Event::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward( + _, + Outcome::Error(XcmError::Barrier) + )) + ))); + }); + + // AllowTopLevelPaidExecutionFrom barrier test case: + // para-chain use XcmExecutor `execute_xcm()` method to execute xcm. + // if `weight_limit` in BuyExecution is less than `xcm_weight(max_weight)`, then Barrier can't + // pass. other situation when `weight_limit` is `Unlimited` or large than `xcm_weight`, then + // it's ok. + let message = Xcm::(vec![ + ReserveAssetDeposited((Parent, 100).into()), + BuyExecution { fees: (Parent, 100).into(), weight_limit: Limited(weight_limit_too_low) }, + DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() }, + ]); + Picasso::execute_with(|| { + let r = XcmExecutor::::execute_xcm( + Parent, + message, + expect_weight_limit, + ); + assert_eq!(r, Outcome::Error(XcmError::Barrier)); + }); + + // trader inside BuyExecution have TooExpensive error if payment less than calculated weight + // amount. the minimum of calculated weight amount(`FixedRateOfFungible`) is + // 96_000_000 + let message = Xcm::(vec![ + ReserveAssetDeposited((Parent, 95_999_999).into()), + BuyExecution { + fees: (Parent, 95_999_999).into(), + weight_limit: Limited(expect_weight_limit), + }, + DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() }, + ]); + Picasso::execute_with(|| { + let r = XcmExecutor::::execute_xcm( + Parent, + message, + expect_weight_limit, + ); + assert_eq!( + r, + Outcome::Incomplete( + expect_weight_limit - unit_instruction_weight, + XcmError::TooExpensive + ) + ); + }); + + // all situation fulfilled, execute success + let message = Xcm::(vec![ + ReserveAssetDeposited((Parent, 96_000_000).into()), + BuyExecution { + fees: (Parent, 96_000_000).into(), + weight_limit: Limited(expect_weight_limit), + }, + DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() }, + ]); + Picasso::execute_with(|| { + let r = XcmExecutor::::execute_xcm( + Parent, + message, + expect_weight_limit, + ); + assert_eq!(r, Outcome::Complete(expect_weight_limit)); + }); +} + #[test] +#[ignore] fn subscribe_version_notify_works() { - env_logger_init(); // relay chain subscribe version notify of para chain KusamaRelay::execute_with(|| { let r = pallet_xcm::Pallet::::force_subscribe_version_notify( @@ -258,4 +383,31 @@ fn subscribe_version_notify_works() { ), )); }); + + // para chain subscribe version notify of sibling chain + Picasso::execute_with(|| { + let r = pallet_xcm::Pallet::::force_subscribe_version_notify( + picasso_runtime::Origin::root(), + Box::new((Parent, Parachain(2001)).into()), + ); + assert_ok!(r); + }); + Picasso::execute_with(|| { + assert!(picasso_runtime::System::events().iter().any(|r| matches!( + r.event, + picasso_runtime::Event::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent( + Some(_) + )) + ))); + }); + Dali::execute_with(|| { + assert!(dali_runtime::System::events().iter().any(|r| matches!( + r.event, + picasso_runtime::Event::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent( + Some(_) + )) | picasso_runtime::Event::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success( + Some(_) + )) + ))); + }); } diff --git a/node/Cargo.toml b/node/Cargo.toml index 7ba04523bec..769aa9a1546 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -91,7 +91,7 @@ hex = "0.4.3" [features] default = [] -runtime-benchmarks = ["picasso-runtime/runtime-benchmarks", "composable-runtime/runtime-benchmarks", "dali-runtime/runtime-benchmarks"] +runtime-benchmarks = ["polkadot-service/runtime-benchmarks", "picasso-runtime/runtime-benchmarks", "composable-runtime/runtime-benchmarks", "dali-runtime/runtime-benchmarks"] ocw = [] dali = ["dali-runtime"] composable = ["composable-runtime"] diff --git a/runtime/dali/src/lib.rs b/runtime/dali/src/lib.rs index 71a270c7bf8..a1befd10929 100644 --- a/runtime/dali/src/lib.rs +++ b/runtime/dali/src/lib.rs @@ -64,6 +64,7 @@ use system::{ EnsureRoot, }; use transaction_payment::{Multiplier, TargetedFeeAdjustment}; +pub use xcmp::XcmConfig; /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats diff --git a/scripts/polkadot-launch/composable.json b/scripts/polkadot-launch/composable.json index c1fdeccb56d..98254046276 100644 --- a/scripts/polkadot-launch/composable.json +++ b/scripts/polkadot-launch/composable.json @@ -26,6 +26,12 @@ "wsPort": 9977, "basePath": "/tmp/polkadot-launch/relaychains/dave", "port": 30777 + }, + { + "name": "ferdie", + "wsPort": 9978, + "basePath": "/tmp/polkadot-launch/relaychains/ferdie", + "port": 30778 } ], "genesis": {