From 724c763a87bd674891587aa082d9aa6b32dbd1f2 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Thu, 29 Aug 2024 09:44:55 +0200 Subject: [PATCH] simplify client (#1328) * simplify client * zepter --- .github/workflows/frontier-rpc-tests.yml | 6 +- .github/workflows/release.yml | 862 ++++++++-------- Cargo.lock | 5 + Cargo.toml | 5 + bin/collator/Cargo.toml | 30 +- bin/collator/src/cli.rs | 2 - bin/collator/src/command.rs | 517 ++-------- bin/collator/src/local/service.rs | 22 +- .../src/parachain/fake_runtime_api.rs | 299 ++++++ bin/collator/src/parachain/mod.rs | 7 +- bin/collator/src/parachain/service.rs | 935 +++--------------- bin/collator/src/rpc.rs | 45 - runtime/local/Cargo.toml | 5 - runtime/local/src/lib.rs | 2 - 14 files changed, 982 insertions(+), 1760 deletions(-) create mode 100644 bin/collator/src/parachain/fake_runtime_api.rs diff --git a/.github/workflows/frontier-rpc-tests.yml b/.github/workflows/frontier-rpc-tests.yml index 231ad7e93d..1ccf2c1dea 100644 --- a/.github/workflows/frontier-rpc-tests.yml +++ b/.github/workflows/frontier-rpc-tests.yml @@ -2,7 +2,7 @@ name: Frontier RPC Tests on: workflow_dispatch: push: - branches: [ master ] + branches: [master] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -25,7 +25,7 @@ jobs: run: rustup target list --installed - name: Build astar-collator - run: cargo build --release --locked --features manual-seal,evm-tracing --bin astar-collator + run: cargo build --release --locked --features manual-seal --bin astar-collator - name: Clone frontier tests run: git clone https://github.com/AstarNetwork/frontier-tests.git --depth 1 @@ -34,7 +34,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: 18.x - cache: 'npm' + cache: "npm" cache-dependency-path: frontier-tests/package-lock.json - name: Install dependencies diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3a20c67eb6..5476a68ab1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: Release Build on: push: tags: - - v[0-9]+.[0-9]+.[0-9]+* + - v[0-9]+.[0-9]+.[0-9]+* workflow_dispatch: env: SUBWASM_VERSION: 0.16.1 @@ -10,37 +10,37 @@ jobs: checks-and-tests: runs-on: [self-hosted, Linux, X64] steps: - - name: Free disk space - run: | - sudo rm -rf /usr/share/dotnet - sudo rm -rf /usr/local/lib/android - sudo rm -rf /opt/ghc - sudo rm -rf "/usr/local/share/boost" - sudo rm -rf "$AGENT_TOOLSDIRECTORY" - df -h + - name: Free disk space + run: | + sudo rm -rf /usr/share/dotnet + sudo rm -rf /usr/local/lib/android + sudo rm -rf /opt/ghc + sudo rm -rf "/usr/local/share/boost" + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + df -h - - name: Checkout the source code - uses: actions/checkout@v4 - with: - submodules: true + - name: Checkout the source code + uses: actions/checkout@v4 + with: + submodules: true - - name: Install deps - run: sudo apt -y install protobuf-compiler + - name: Install deps + run: sudo apt -y install protobuf-compiler - - name: Install & display rust toolchain - run: rustup show + - name: Install & display rust toolchain + run: rustup show - - name: Check targets are installed correctly - run: rustup target list --installed + - name: Check targets are installed correctly + run: rustup target list --installed - - name: Install cargo-nextest - run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin + - name: Install cargo-nextest + run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin - - name: Check all features compilation - run: cargo check --verbose --features try-runtime,runtime-benchmarks --locked + - name: Check all features compilation + run: cargo check --features try-runtime,runtime-benchmarks --locked - - name: Run all tests - run: make test-all + - name: Run all tests + run: make test-all native-linux: needs: checks-and-tests @@ -48,114 +48,102 @@ jobs: strategy: matrix: target: - - x86_64-unknown-linux-gnu - - aarch64-unknown-linux-gnu + - x86_64-unknown-linux-gnu + - aarch64-unknown-linux-gnu steps: - - name: Checkout the source code - uses: actions/checkout@v4 - with: - submodules: true - - - name: Install deps - run: sudo apt -y install protobuf-compiler - - - name: aarch64 setup - if: contains(matrix.target, 'aarch64') - shell: bash - run: | - sudo apt update - sudo apt install -y gcc-multilib g++-multilib - sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - - mkdir -p .cargo - touch .cargo/config - printf '[target.aarch64-unknown-linux-gnu]\nlinker = "aarch64-linux-gnu-gcc"' >> .cargo/config - - - name: x86_64 setup - if: contains(matrix.target, 'x86_64') - run: | - mkdir -p .cargo - touch .cargo/config - printf '[target.x86_64-unknown-linux-gnu]\nrustflags = ["-Clink-arg=-fuse-ld=lld"]' >> .cargo/config - - - name: Install & display rust toolchain - run: rustup show - - - name: Add aarch64 target - if: contains(matrix.target, 'aarch64') - run: rustup target add ${{ matrix.target }} - - - name: Check targets are installed correctly - run: rustup target list --installed - - - name: Build optimized binary - run: CARGO_PROFILE_RELEASE_LTO=true RUSTFLAGS="-C codegen-units=1" cargo build --release --target ${{ matrix.target }} --verbose --locked - - - name: Set artifact name - env: - TARGET: ${{ matrix.target }} - id: artifact-name - run: echo "::set-output name=name::astar-ubuntu-latest-${TARGET%%-*}" - - - uses: actions/upload-artifact@v3 - with: - name: ${{ steps.artifact-name.outputs.name }} - path: target/${{ matrix.target }}/release/astar-collator - - evm-tracing-native-linux: - needs: checks-and-tests - runs-on: [self-hosted, Linux, X64] - steps: + - name: Checkout the source code + uses: actions/checkout@v4 + with: + submodules: true - - name: Checkout the source code - uses: actions/checkout@v4 - with: - submodules: true + - name: Install deps + run: sudo apt -y install protobuf-compiler - - name: Install deps - run: sudo apt -y install protobuf-compiler + - name: aarch64 setup + if: contains(matrix.target, 'aarch64') + shell: bash + run: | + sudo apt update + sudo apt install -y gcc-multilib g++-multilib + sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - - name: x86_64 setup - run: | - mkdir -p .cargo - touch .cargo/config - printf '[target.x86_64-unknown-linux-gnu]\nrustflags = ["-Clink-arg=-fuse-ld=lld"]' >> .cargo/config + mkdir -p .cargo + touch .cargo/config + printf '[target.aarch64-unknown-linux-gnu]\nlinker = "aarch64-linux-gnu-gcc"' >> .cargo/config - - name: Install & display rust toolchain - run: rustup show + - name: x86_64 setup + if: contains(matrix.target, 'x86_64') + run: | + mkdir -p .cargo + touch .cargo/config + printf '[target.x86_64-unknown-linux-gnu]\nrustflags = ["-Clink-arg=-fuse-ld=lld"]' >> .cargo/config - - name: Check targets are installed correctly - run: rustup target list --installed + - name: Install & display rust toolchain + run: rustup show - - name: Build optimized binary with evm tracing - run: CARGO_PROFILE_RELEASE_LTO=true RUSTFLAGS="-C codegen-units=1" cargo build --release --target x86_64-unknown-linux-gnu --features on-chain-release-build,evm-tracing --verbose --locked + - name: Add aarch64 target + if: contains(matrix.target, 'aarch64') + run: rustup target add ${{ matrix.target }} - - uses: actions/upload-artifact@v3 - with: - name: astar-evm-tracing-ubuntu-latest-x86_64-unknown-linux-gnu - path: target/x86_64-unknown-linux-gnu/release/astar-collator + - name: Check targets are installed correctly + run: rustup target list --installed - - name: rename evm tracing runtimes - run: | - mv target/x86_64-unknown-linux-gnu/release/wbuild/astar-runtime/astar_runtime.compact.compressed.wasm target/x86_64-unknown-linux-gnu/release/wbuild/astar-runtime/astar_evm_tracing_runtime.compact.compressed.wasm - mv target/x86_64-unknown-linux-gnu/release/wbuild/shiden-runtime/shiden_runtime.compact.compressed.wasm target/x86_64-unknown-linux-gnu/release/wbuild/shiden-runtime/shiden_evm_tracing_runtime.compact.compressed.wasm - mv target/x86_64-unknown-linux-gnu/release/wbuild/shibuya-runtime/shibuya_runtime.compact.compressed.wasm target/x86_64-unknown-linux-gnu/release/wbuild/shibuya-runtime/shibuya_evm_tracing_runtime.compact.compressed.wasm + - name: Build optimized binary + run: cargo build --profile production --target ${{ matrix.target }} --locked - - uses: actions/upload-artifact@v3 - with: - name: astar-evm-tracing-runtime - path: target/x86_64-unknown-linux-gnu/release/wbuild/astar-runtime/astar_evm_tracing_runtime.compact.compressed.wasm + - name: Set artifact name + env: + TARGET: ${{ matrix.target }} + id: artifact-name + run: echo "::set-output name=name::astar-ubuntu-latest-${TARGET%%-*}" - - uses: actions/upload-artifact@v3 - with: - name: shiden-evm-tracing-runtime - path: target/x86_64-unknown-linux-gnu/release/wbuild/shiden-runtime/shiden_evm_tracing_runtime.compact.compressed.wasm + - uses: actions/upload-artifact@v3 + with: + name: ${{ steps.artifact-name.outputs.name }} + path: target/${{ matrix.target }}/production/astar-collator - - uses: actions/upload-artifact@v3 - with: - name: shibuya-evm-tracing-runtime - path: target/x86_64-unknown-linux-gnu/release/wbuild/shibuya-runtime/shibuya_evm_tracing_runtime.compact.compressed.wasm + evm-tracing-runtimes: + needs: checks-and-tests + runs-on: [self-hosted, Linux, X64] + steps: + - name: Checkout the source code + uses: actions/checkout@v4 + with: + submodules: true + + - name: Install deps + run: sudo apt -y install protobuf-compiler + + - name: Install & display rust toolchain + run: rustup show + + - name: Check targets are installed correctly + run: rustup target list --installed + + - name: Build optimized runtimes with evm tracing + run: cargo build --profile production --locked --features on-chain-release-build,evm-tracing -p astar-runtime -p shiden-runtime -p shibuya-runtime + + - name: rename evm tracing runtimes + run: | + mv target/production/wbuild/astar-runtime/astar_runtime.compact.compressed.wasm target/production/wbuild/astar-runtime/astar_evm_tracing_runtime.compact.compressed.wasm + mv target/production/wbuild/shiden-runtime/shiden_runtime.compact.compressed.wasm target/production/wbuild/shiden-runtime/shiden_evm_tracing_runtime.compact.compressed.wasm + mv target/production/wbuild/shibuya-runtime/shibuya_runtime.compact.compressed.wasm target/production/wbuild/shibuya-runtime/shibuya_evm_tracing_runtime.compact.compressed.wasm + + - uses: actions/upload-artifact@v3 + with: + name: astar-evm-tracing-runtime + path: target/production/wbuild/astar-runtime/astar_evm_tracing_runtime.compact.compressed.wasm + + - uses: actions/upload-artifact@v3 + with: + name: shiden-evm-tracing-runtime + path: target/production/wbuild/shiden-runtime/shiden_evm_tracing_runtime.compact.compressed.wasm + + - uses: actions/upload-artifact@v3 + with: + name: shibuya-evm-tracing-runtime + path: target/production/wbuild/shibuya-runtime/shibuya_evm_tracing_runtime.compact.compressed.wasm native-macos: needs: checks-and-tests @@ -169,80 +157,80 @@ jobs: id-token: write contents: read steps: - - name: Checkout the source code - uses: actions/checkout@v4 - with: - submodules: true + - name: Checkout the source code + uses: actions/checkout@v4 + with: + submodules: true - - name: configure aws credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: ${{ secrets.SCCACHE_ROLE }} - role-session-name: github_astar_mac - aws-region: ${{ secrets.SCCACHE_REGION }} + - name: configure aws credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.SCCACHE_ROLE }} + role-session-name: github_astar_mac + aws-region: ${{ secrets.SCCACHE_REGION }} - - name: Install deps - run: brew install protobuf sccache + - name: Install deps + run: brew install protobuf sccache - - name: Install & display rust toolchain - run: rustup show + - name: Install & display rust toolchain + run: rustup show - - name: Check targets are installed correctly - run: rustup target list --installed + - name: Check targets are installed correctly + run: rustup target list --installed - - name: Build optimized binary - run: cargo build --release --verbose --locked + - name: Build optimized binary + run: cargo build --locked --profile production - - name: Show sccache stats - run: sccache --show-stats + - name: Show sccache stats + run: sccache --show-stats - - uses: actions/upload-artifact@v3 - with: - name: astar-macOS-latest-x86_64 - path: target/release/astar-collator + - uses: actions/upload-artifact@v3 + with: + name: astar-macOS-latest-x86_64 + path: target/production/astar-collator docker: needs: native-linux runs-on: ubuntu-latest steps: - - name: Checkout the source code - uses: actions/checkout@v4 - with: - submodules: true - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Docker meta - id: docker_meta - uses: crazy-max/ghaction-docker-meta@v1 - with: - images: staketechnologies/astar-collator - tag-custom: shiden - tag-sha: true # add git short SHA as Docker tag - - - name: Download pre-built linux collator binary - uses: actions/download-artifact@v3 - with: - name: astar-ubuntu-latest-x86_64 - - - name: Make binary executable and copy it to docker folder - run: chmod +x astar-collator && cp astar-collator third-party/docker - - - name: Build & Push docker image - uses: docker/build-push-action@v2 - with: - context: third-party/docker - platforms: linux/amd64 - labels: ${{ steps.docker_meta.outputs.labels }} - tags: ${{ steps.docker_meta.outputs.tags }} - push: true + - name: Checkout the source code + uses: actions/checkout@v4 + with: + submodules: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Docker meta + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: staketechnologies/astar-collator + tag-custom: shiden + tag-sha: true # add git short SHA as Docker tag + + - name: Download pre-built linux collator binary + uses: actions/download-artifact@v3 + with: + name: astar-ubuntu-latest-x86_64 + + - name: Make binary executable and copy it to docker folder + run: chmod +x astar-collator && cp astar-collator third-party/docker + + - name: Build & Push docker image + uses: docker/build-push-action@v2 + with: + context: third-party/docker + platforms: linux/amd64 + labels: ${{ steps.docker_meta.outputs.labels }} + tags: ${{ steps.docker_meta.outputs.tags }} + push: true srtool: needs: checks-and-tests @@ -251,138 +239,139 @@ jobs: matrix: chain: ["astar", "shiden", "shibuya"] steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Srtool build - id: srtool_build - uses: chevdor/srtool-actions@v0.8.0 - env: - # needed to enable metadata hash generation - BUILD_OPTS: "--features on-chain-release-build" - with: - chain: ${{ matrix.chain }} - runtime_dir: runtime/${{ matrix.chain }} - - - name: Summary - run: | - echo '${{ steps.srtool_build.outputs.json }}' | jq > ${{ matrix.chain }}-srtool-digest.json - cat ${{ matrix.chain }}-srtool-digest.json - echo "Compact Runtime: ${{ steps.srtool_build.outputs.wasm }}" - echo "Compressed Runtime: ${{ steps.srtool_build.outputs.wasm_compressed }}" - cp ${{ steps.srtool_build.outputs.wasm }} ${{ matrix.chain }}_runtime.compact.wasm - cp ${{ steps.srtool_build.outputs.wasm_compressed }} ${{ matrix.chain }}_runtime.compact.compressed.wasm - - # it takes a while to build the runtime, so let's save the artifact as soon as we have it - - name: Archive Artifacts for ${{ matrix.chain }} - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.chain }}-runtime - path: | - ${{ matrix.chain }}_runtime.compact.wasm - ${{ matrix.chain }}_runtime.compact.compressed.wasm - ${{ matrix.chain }}-srtool-digest.json - - # We now get extra information thanks to subwasm - - name: Install subwasm - run: | - wget https://github.com/chevdor/subwasm/releases/download/v${{ env.SUBWASM_VERSION }}/subwasm_linux_amd64_v${{ env.SUBWASM_VERSION }}.deb - sudo dpkg -i subwasm_linux_amd64_v${{ env.SUBWASM_VERSION }}.deb - subwasm --version - - - name: Show Runtime information - shell: bash - run: | - subwasm info ${{ steps.srtool_build.outputs.wasm }} - subwasm info ${{ steps.srtool_build.outputs.wasm_compressed }} - subwasm --json info ${{ steps.srtool_build.outputs.wasm }} > ${{ matrix.chain }}-info.json - subwasm --json info ${{ steps.srtool_build.outputs.wasm_compressed }} > ${{ matrix.chain }}-compressed-info.json - - - name: Extract the metadata - shell: bash - run: | - subwasm meta ${{ steps.srtool_build.outputs.wasm }} - subwasm --json meta ${{ steps.srtool_build.outputs.wasm }} > ${{ matrix.chain }}-metadata.json - - - name: Check the metadata diff - shell: bash - # the following subwasm call will error for chains that are not known and/or live, that includes shell for instance - run: | - subwasm diff ${{ steps.srtool_build.outputs.wasm }} --chain-b ${{ matrix.chain }} || \ - echo "Subwasm call failed, check the logs. This is likely because ${{ matrix.chain }} is not known by subwasm" | \ - tee ${{ matrix.chain }}-diff.txt - - - name: Archive Subwasm results - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.chain }}-runtime - path: | - ${{ matrix.chain }}-info.json - ${{ matrix.chain }}-compressed-info.json - ${{ matrix.chain }}-metadata.json - ${{ matrix.chain }}-diff.txt + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Srtool build + id: srtool_build + uses: chevdor/srtool-actions@v0.8.0 + env: + # needed to enable metadata hash generation + BUILD_OPTS: "--features on-chain-release-build" + with: + profile: production + chain: ${{ matrix.chain }} + runtime_dir: runtime/${{ matrix.chain }} + + - name: Summary + run: | + echo '${{ steps.srtool_build.outputs.json }}' | jq > ${{ matrix.chain }}-srtool-digest.json + cat ${{ matrix.chain }}-srtool-digest.json + echo "Compact Runtime: ${{ steps.srtool_build.outputs.wasm }}" + echo "Compressed Runtime: ${{ steps.srtool_build.outputs.wasm_compressed }}" + cp ${{ steps.srtool_build.outputs.wasm }} ${{ matrix.chain }}_runtime.compact.wasm + cp ${{ steps.srtool_build.outputs.wasm_compressed }} ${{ matrix.chain }}_runtime.compact.compressed.wasm + + # it takes a while to build the runtime, so let's save the artifact as soon as we have it + - name: Archive Artifacts for ${{ matrix.chain }} + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.chain }}-runtime + path: | + ${{ matrix.chain }}_runtime.compact.wasm + ${{ matrix.chain }}_runtime.compact.compressed.wasm + ${{ matrix.chain }}-srtool-digest.json + + # We now get extra information thanks to subwasm + - name: Install subwasm + run: | + wget https://github.com/chevdor/subwasm/releases/download/v${{ env.SUBWASM_VERSION }}/subwasm_linux_amd64_v${{ env.SUBWASM_VERSION }}.deb + sudo dpkg -i subwasm_linux_amd64_v${{ env.SUBWASM_VERSION }}.deb + subwasm --version + + - name: Show Runtime information + shell: bash + run: | + subwasm info ${{ steps.srtool_build.outputs.wasm }} + subwasm info ${{ steps.srtool_build.outputs.wasm_compressed }} + subwasm --json info ${{ steps.srtool_build.outputs.wasm }} > ${{ matrix.chain }}-info.json + subwasm --json info ${{ steps.srtool_build.outputs.wasm_compressed }} > ${{ matrix.chain }}-compressed-info.json + + - name: Extract the metadata + shell: bash + run: | + subwasm meta ${{ steps.srtool_build.outputs.wasm }} + subwasm --json meta ${{ steps.srtool_build.outputs.wasm }} > ${{ matrix.chain }}-metadata.json + + - name: Check the metadata diff + shell: bash + # the following subwasm call will error for chains that are not known and/or live, that includes shell for instance + run: | + subwasm diff ${{ steps.srtool_build.outputs.wasm }} --chain-b ${{ matrix.chain }} || \ + echo "Subwasm call failed, check the logs. This is likely because ${{ matrix.chain }} is not known by subwasm" | \ + tee ${{ matrix.chain }}-diff.txt + + - name: Archive Subwasm results + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.chain }}-runtime + path: | + ${{ matrix.chain }}-info.json + ${{ matrix.chain }}-compressed-info.json + ${{ matrix.chain }}-metadata.json + ${{ matrix.chain }}-diff.txt publish-release-draft: - needs: [native-linux, evm-tracing-native-linux, native-macOS, docker, srtool] + needs: [native-linux, evm-tracing-runtimes, native-macOS, docker, srtool] runs-on: ubuntu-latest outputs: release_url: ${{ steps.create-release.outputs.html_url }} upload_url: ${{ steps.create-release.outputs.upload_url }} steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Download astar runtime - uses: actions/download-artifact@v3 - with: - name: astar-runtime - path: runtime-artifacts - - - name: Download shiden runtime - uses: actions/download-artifact@v3 - with: - name: shiden-runtime - path: runtime-artifacts - - - name: Download shibuya runtime - uses: actions/download-artifact@v3 - with: - name: shibuya-runtime - path: runtime-artifacts - - - name: Use Node.js 18.x - uses: actions/setup-node@v2 - with: - node-version: 18.x - - - name: Get the latest release - id: latest-release - uses: pozetroninc/github-action-get-latest-release@v0.5.0 - with: - repository: AstarNetwork/Astar - excludes: "prerelease, draft" - - - name: Generate Release Body - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - id: generate-release-body - run: | - cd .github/scripts - yarn - yarn -s run ts-node generate-release-body.ts generate --owner "${{ github.repository_owner }}" --repo "$(basename ${{ github.repository }})" --from "${{ steps.latest-release.outputs.release }}" --to "${{ github.ref_name }}" --srtool-report-folder '../../runtime-artifacts/' > ../../body.md - - - name: Create Release Draft - id: create-release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref_name }} - release_name: ${{ github.ref_name }} - body_path: body.md - draft: true + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Download astar runtime + uses: actions/download-artifact@v3 + with: + name: astar-runtime + path: runtime-artifacts + + - name: Download shiden runtime + uses: actions/download-artifact@v3 + with: + name: shiden-runtime + path: runtime-artifacts + + - name: Download shibuya runtime + uses: actions/download-artifact@v3 + with: + name: shibuya-runtime + path: runtime-artifacts + + - name: Use Node.js 18.x + uses: actions/setup-node@v2 + with: + node-version: 18.x + + - name: Get the latest release + id: latest-release + uses: pozetroninc/github-action-get-latest-release@v0.5.0 + with: + repository: AstarNetwork/Astar + excludes: "prerelease, draft" + + - name: Generate Release Body + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + id: generate-release-body + run: | + cd .github/scripts + yarn + yarn -s run ts-node generate-release-body.ts generate --owner "${{ github.repository_owner }}" --repo "$(basename ${{ github.repository }})" --from "${{ steps.latest-release.outputs.release }}" --to "${{ github.ref_name }}" --srtool-report-folder '../../runtime-artifacts/' > ../../body.md + + - name: Create Release Draft + id: create-release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref_name }} + release_name: ${{ github.ref_name }} + body_path: body.md + draft: true upload-binaries: needs: publish-release-draft @@ -392,35 +381,35 @@ jobs: os: ["ubuntu", "macOS"] arch: ["x86_64", "aarch64"] exclude: - - os: macOS - arch: aarch64 + - os: macOS + arch: aarch64 steps: - - name: Create download folder - run: | - mkdir -p ${{ matrix.os }}-${{ matrix.arch }}-bin - mkdir -p ubuntu-tracing-bin - - - name: Download pre-built collator binary - uses: actions/download-artifact@v3 - with: - name: astar-${{ matrix.os }}-latest-${{ matrix.arch }} - path: ${{ matrix.os }}-${{ matrix.arch }}-bin - - - name: Make binary executable and tar gzip - run: | - cd ${{ matrix.os }}-${{ matrix.arch }}-bin - chmod +x astar-collator - tar zcvf astar-collator.tar.gz astar-collator - - - name: Upload binary artifact - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} - asset_path: ${{ matrix.os }}-${{ matrix.arch }}-bin/astar-collator.tar.gz - asset_name: astar-collator-${{ github.ref_name }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz - asset_content_type: application/gzip + - name: Create download folder + run: | + mkdir -p ${{ matrix.os }}-${{ matrix.arch }}-bin + mkdir -p ubuntu-tracing-bin + + - name: Download pre-built collator binary + uses: actions/download-artifact@v3 + with: + name: astar-${{ matrix.os }}-latest-${{ matrix.arch }} + path: ${{ matrix.os }}-${{ matrix.arch }}-bin + + - name: Make binary executable and tar gzip + run: | + cd ${{ matrix.os }}-${{ matrix.arch }}-bin + chmod +x astar-collator + tar zcvf astar-collator.tar.gz astar-collator + + - name: Upload binary artifact + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} + asset_path: ${{ matrix.os }}-${{ matrix.arch }}-bin/astar-collator.tar.gz + asset_name: astar-collator-${{ github.ref_name }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz + asset_content_type: application/gzip upload-runtimes: needs: publish-release-draft @@ -429,60 +418,60 @@ jobs: matrix: chain: ["astar", "shiden", "shibuya"] steps: - - name: Download runtime - uses: actions/download-artifact@v3 - with: - name: ${{ matrix.chain }}-runtime - - - name: Get runtime version - id: get-runtime-version - run: | - ls -R - chain=${{ matrix.chain }} - runtime_version=$(cat $chain-compressed-info.json | jq '.core_version' | tr -d '"' | cut -d ' ' -f 1) - echo $runtime_version - echo "runtime=$(echo $runtime_version)" >> $GITHUB_ENV - echo "${{ matrix.chain }}=$(echo $runtime_version)" >> $GITHUB_OUTPUT - - - name: Upload ${{ matrix.chain }} Wasm - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} - asset_path: ${{ matrix.chain }}_runtime.compact.compressed.wasm - asset_name: ${{ env.runtime }}.wasm - asset_content_type: application/wasm - - - name: Upload ${{ matrix.chain }} Metadata - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} - asset_path: ${{ matrix.chain }}-metadata.json - asset_name: ${{ matrix.chain }}-metadata.json - asset_content_type: application/json - - - name: Upload ${{ matrix.chain }} Compressed Info - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} - asset_path: ${{ matrix.chain }}-compressed-info.json - asset_name: ${{ matrix.chain }}-compressed-info.json - asset_content_type: application/json - - - name: Upload ${{ matrix.chain }} Srtool Digest - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} - asset_path: ${{ matrix.chain }}-srtool-digest.json - asset_name: ${{ matrix.chain }}-srtool-digest.json - asset_content_type: application/json + - name: Download runtime + uses: actions/download-artifact@v3 + with: + name: ${{ matrix.chain }}-runtime + + - name: Get runtime version + id: get-runtime-version + run: | + ls -R + chain=${{ matrix.chain }} + runtime_version=$(cat $chain-compressed-info.json | jq '.core_version' | tr -d '"' | cut -d ' ' -f 1) + echo $runtime_version + echo "runtime=$(echo $runtime_version)" >> $GITHUB_ENV + echo "${{ matrix.chain }}=$(echo $runtime_version)" >> $GITHUB_OUTPUT + + - name: Upload ${{ matrix.chain }} Wasm + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} + asset_path: ${{ matrix.chain }}_runtime.compact.compressed.wasm + asset_name: ${{ env.runtime }}.wasm + asset_content_type: application/wasm + + - name: Upload ${{ matrix.chain }} Metadata + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} + asset_path: ${{ matrix.chain }}-metadata.json + asset_name: ${{ matrix.chain }}-metadata.json + asset_content_type: application/json + + - name: Upload ${{ matrix.chain }} Compressed Info + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} + asset_path: ${{ matrix.chain }}-compressed-info.json + asset_name: ${{ matrix.chain }}-compressed-info.json + asset_content_type: application/json + + - name: Upload ${{ matrix.chain }} Srtool Digest + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} + asset_path: ${{ matrix.chain }}-srtool-digest.json + asset_name: ${{ matrix.chain }}-srtool-digest.json + asset_content_type: application/json outputs: astar_runtime_version: ${{ steps.get-runtime-version.outputs.astar }} @@ -490,61 +479,54 @@ jobs: shibuya_runtime_version: ${{ steps.get-runtime-version.outputs.shibuya }} upload-evm-tracing-artifacts: - needs: [publish-release-draft,upload-runtimes] + needs: [publish-release-draft, upload-runtimes] runs-on: ubuntu-latest steps: - - name: Download pre-built collator binary for evm tracing - uses: actions/download-artifact@v3 - with: - name: astar-evm-tracing-ubuntu-latest-x86_64-unknown-linux-gnu - path: evm-tracing-artifacts - - - name: Download evm tracing runtime - uses: actions/download-artifact@v3 - with: - name: astar-evm-tracing-runtime - path: evm-tracing-artifacts - - - name: Download evm tracing runtime - uses: actions/download-artifact@v3 - with: - name: shiden-evm-tracing-runtime - path: evm-tracing-artifacts - - - name: Download evm tracing runtime - uses: actions/download-artifact@v3 - with: - name: shibuya-evm-tracing-runtime - path: evm-tracing-artifacts - - - name: Make evm tracing binary executable and rename - run: | - cd evm-tracing-artifacts - chmod +x astar-collator - mv astar_evm_tracing_runtime.compact.compressed.wasm ${{needs.upload-runtimes.outputs.astar_runtime_version}}_evm_tracing_runtime.compact.compressed.wasm - mv shiden_evm_tracing_runtime.compact.compressed.wasm ${{needs.upload-runtimes.outputs.shiden_runtime_version}}_evm_tracing_runtime.compact.compressed.wasm - mv shibuya_evm_tracing_runtime.compact.compressed.wasm ${{needs.upload-runtimes.outputs.shibuya_runtime_version}}_evm_tracing_runtime.compact.compressed.wasm - - - name: Compress folder - run: | - tar zcvf evm-tracing-artifacts.tar.gz evm-tracing-artifacts - - - name: Upload evm tracing binary artifact - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} - asset_path: evm-tracing-artifacts.tar.gz - asset_name: evm-tracing-artifacts-${{ github.ref_name }}.tar.gz - asset_content_type: application/gzip + - name: Download evm tracing runtime + uses: actions/download-artifact@v3 + with: + name: astar-evm-tracing-runtime + path: evm-tracing-artifacts + + - name: Download evm tracing runtime + uses: actions/download-artifact@v3 + with: + name: shiden-evm-tracing-runtime + path: evm-tracing-artifacts + + - name: Download evm tracing runtime + uses: actions/download-artifact@v3 + with: + name: shibuya-evm-tracing-runtime + path: evm-tracing-artifacts + + - name: Rename evm tracing + run: | + cd evm-tracing-artifacts + mv astar_evm_tracing_runtime.compact.compressed.wasm ${{needs.upload-runtimes.outputs.astar_runtime_version}}_evm_tracing_runtime.compact.compressed.wasm + mv shiden_evm_tracing_runtime.compact.compressed.wasm ${{needs.upload-runtimes.outputs.shiden_runtime_version}}_evm_tracing_runtime.compact.compressed.wasm + mv shibuya_evm_tracing_runtime.compact.compressed.wasm ${{needs.upload-runtimes.outputs.shibuya_runtime_version}}_evm_tracing_runtime.compact.compressed.wasm + + - name: Compress folder + run: | + tar zcvf evm-tracing-artifacts.tar.gz evm-tracing-artifacts + + - name: Upload evm tracing binary artifact + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.publish-release-draft.outputs.upload_url }} + asset_path: evm-tracing-artifacts.tar.gz + asset_name: evm-tracing-artifacts-${{ github.ref_name }}.tar.gz + asset_content_type: application/gzip chain-sync-smoke: needs: native-linux runs-on: ubuntu-latest strategy: matrix: - chain: [ "astar", "shiden", "shibuya" ] + chain: ["astar", "shiden", "shibuya"] steps: - name: Checkout the source code @@ -566,7 +548,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - chain: [ "astar-dev", "shiden-dev", "shibuya-dev" ] + chain: ["astar-dev", "shiden-dev", "shibuya-dev"] steps: - name: Checkout the source code @@ -576,12 +558,10 @@ jobs: uses: actions/download-artifact@v3 with: name: astar-ubuntu-latest-x86_64 - path: target/release + path: third-party/zombienet - name: Setup - run: | - chmod +x target/release/astar-collator - mv target/release/astar-collator third-party/zombienet + run: chmod +x third-party/zombienet/astar-collator - name: Setup zombienet working-directory: third-party/zombienet diff --git a/Cargo.lock b/Cargo.lock index 3da296baa3..3b3eed91e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -645,7 +645,9 @@ dependencies = [ "frame-benchmarking", "frame-benchmarking-cli", "frame-metadata-hash-extension", + "frame-support", "frame-system", + "frame-system-rpc-runtime-api", "frame-try-runtime", "futures 0.3.30", "jsonrpsee", @@ -661,6 +663,7 @@ dependencies = [ "pallet-evm", "pallet-transaction-payment", "pallet-transaction-payment-rpc", + "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", "polkadot-cli", "polkadot-core-primitives", @@ -706,9 +709,11 @@ dependencies = [ "sp-offchain", "sp-runtime", "sp-session", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", "sp-timestamp", "sp-transaction-pool", "sp-trie", + "sp-version", "substrate-build-script-utils", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", diff --git a/Cargo.toml b/Cargo.toml index 159349e33f..08c448043a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,11 @@ exclude = ["vendor"] # Astar runtime requires unwinding. panic = "unwind" +[profile.production] +inherits = "release" +lto = true +codegen-units = 1 + [workspace.package] authors = ["Stake Technologies "] edition = "2021" diff --git a/bin/collator/Cargo.toml b/bin/collator/Cargo.toml index 1af68ec9d9..c843099e6d 100644 --- a/bin/collator/Cargo.toml +++ b/bin/collator/Cargo.toml @@ -40,12 +40,15 @@ sp-runtime = { workspace = true, features = ["std"] } sp-session = { workspace = true, features = ["std"] } sp-transaction-pool = { workspace = true, features = ["std"] } +frame-support = { workspace = true } sp-blockchain = { workspace = true } sp-consensus = { workspace = true } sp-keyring = { workspace = true, optional = true } sp-keystore = { workspace = true } +sp-std = { workspace = true } sp-timestamp = { workspace = true } sp-trie = { workspace = true } +sp-version = { workspace = true } # client dependencies sc-basic-authorship = { workspace = true } @@ -88,6 +91,7 @@ fc-storage = { workspace = true } fp-consensus = { workspace = true } fp-evm = { workspace = true, features = ["std"] } fp-storage = { workspace = true } +frame-system-rpc-runtime-api = { workspace = true } # astar-specific dependencies astar-runtime = { workspace = true, features = ["std"] } @@ -101,8 +105,9 @@ astar-primitives = { workspace = true } # frame dependencies frame-metadata-hash-extension = { workspace = true } frame-system = { workspace = true, features = ["std"] } -pallet-transaction-payment = { workspace = true, features = ["std"] } +pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc = { workspace = true } +pallet-transaction-payment-rpc-runtime-api = { workspace = true } substrate-frame-rpc-system = { workspace = true } # CLI-specific dependencies @@ -142,13 +147,13 @@ polkadot-runtime-common = { workspace = true, features = ["std"], optional = tru frame-try-runtime = { workspace = true, features = ["std"], optional = true } # evm-tracing -moonbeam-rpc-primitives-debug = { workspace = true, features = ["std"], optional = true } -moonbeam-rpc-primitives-txpool = { workspace = true, features = ["std"], optional = true } +moonbeam-rpc-primitives-debug = { workspace = true } +moonbeam-rpc-primitives-txpool = { workspace = true } moonbeam-primitives-ext = { workspace = true } -moonbeam-rpc-debug = { workspace = true, optional = true } -moonbeam-rpc-trace = { workspace = true, optional = true } -moonbeam-rpc-txpool = { workspace = true, optional = true } +moonbeam-rpc-debug = { workspace = true } +moonbeam-rpc-trace = { workspace = true } +moonbeam-rpc-txpool = { workspace = true } [build-dependencies] polkadot-cli = { workspace = true, optional = true } @@ -181,6 +186,7 @@ runtime-benchmarks = [ "sc-service/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", + "frame-support/runtime-benchmarks", ] try-runtime = [ "local-runtime/try-runtime", @@ -197,16 +203,6 @@ try-runtime = [ "shibuya-runtime/try-runtime", "shiden-runtime/try-runtime", "sp-runtime/try-runtime", -] -evm-tracing = [ - "moonbeam-rpc-debug", - "moonbeam-rpc-primitives-debug", - "moonbeam-rpc-primitives-txpool", - "moonbeam-rpc-trace", - "moonbeam-rpc-txpool", - "shibuya-runtime/evm-tracing", - "shiden-runtime/evm-tracing", - "astar-runtime/evm-tracing", - "local-runtime/evm-tracing", + "frame-support/try-runtime", ] manual-seal = ["sc-consensus-manual-seal"] diff --git a/bin/collator/src/cli.rs b/bin/collator/src/cli.rs index f0c03f2d70..ec709637cf 100644 --- a/bin/collator/src/cli.rs +++ b/bin/collator/src/cli.rs @@ -19,7 +19,6 @@ use clap::Parser; use std::path::PathBuf; -#[cfg(feature = "evm-tracing")] use crate::evm_tracing_types::EthApiOptions; /// An overarching CLI command definition. @@ -34,7 +33,6 @@ pub struct Cli { pub run: cumulus_client_cli::RunCmd, #[allow(missing_docs)] - #[cfg(feature = "evm-tracing")] #[clap(flatten)] pub eth_api_options: EthApiOptions, diff --git a/bin/collator/src/command.rs b/bin/collator/src/command.rs index 13f7ff2d3a..a2073426b8 100644 --- a/bin/collator/src/command.rs +++ b/bin/collator/src/command.rs @@ -19,14 +19,12 @@ //! Astar collator CLI handlers. use crate::{ cli::{Cli, RelayChainCli, Subcommand}, + evm_tracing_types::EvmTracingConfig, local::{self, development_config}, - parachain::{ - self, chain_spec, service::AdditionalConfig, start_astar_node, start_shibuya_node, - start_shiden_node, - }, + parachain::{self, chain_spec, service::AdditionalConfig}, }; use cumulus_primitives_core::ParaId; -use log::{error, info}; +use log::info; use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, Result, SharedParams, SubstrateCli, @@ -198,169 +196,49 @@ pub fn run() -> Result<()> { } Some(Subcommand::CheckBlock(cmd)) => { let runner = cli.create_runner(cmd)?; - if runner.config().chain_spec.is_astar() { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - import_queue, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - Ok((cmd.run(client, import_queue), task_manager)) - }) - } else if runner.config().chain_spec.is_shiden() { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - import_queue, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue_fallback, - )?; - Ok((cmd.run(client, import_queue), task_manager)) - }) - } else { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - import_queue, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - Ok((cmd.run(client, import_queue), task_manager)) - }) - } + runner.async_run(|config| { + let PartialComponents { + client, + task_manager, + import_queue, + .. + } = parachain::new_partial(&config)?; + Ok((cmd.run(client, import_queue), task_manager)) + }) } Some(Subcommand::ExportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; - if runner.config().chain_spec.is_astar() { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - Ok((cmd.run(client, config.database), task_manager)) - }) - } else if runner.config().chain_spec.is_shiden() { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue_fallback, - )?; - Ok((cmd.run(client, config.database), task_manager)) - }) - } else { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - Ok((cmd.run(client, config.database), task_manager)) - }) - } + runner.async_run(|config| { + let PartialComponents { + client, + task_manager, + .. + } = parachain::new_partial(&config)?; + Ok((cmd.run(client, config.database), task_manager)) + }) } Some(Subcommand::ExportState(cmd)) => { let runner = cli.create_runner(cmd)?; - if runner.config().chain_spec.is_astar() { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - Ok((cmd.run(client, config.chain_spec), task_manager)) - }) - } else if runner.config().chain_spec.is_shiden() { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue_fallback, - )?; - Ok((cmd.run(client, config.chain_spec), task_manager)) - }) - } else { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - Ok((cmd.run(client, config.chain_spec), task_manager)) - }) - } + runner.async_run(|config| { + let PartialComponents { + client, + task_manager, + .. + } = parachain::new_partial(&config)?; + Ok((cmd.run(client, config.chain_spec), task_manager)) + }) } Some(Subcommand::ImportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; - if runner.config().chain_spec.is_astar() { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - import_queue, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - Ok((cmd.run(client, import_queue), task_manager)) - }) - } else if runner.config().chain_spec.is_shiden() { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - import_queue, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue_fallback, - )?; - Ok((cmd.run(client, import_queue), task_manager)) - }) - } else { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - import_queue, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - Ok((cmd.run(client, import_queue), task_manager)) - }) - } + runner.async_run(|config| { + let PartialComponents { + client, + task_manager, + import_queue, + .. + } = parachain::new_partial(&config)?; + Ok((cmd.run(client, import_queue), task_manager)) + }) } Some(Subcommand::PurgeChain(cmd)) => { let runner = cli.create_runner(cmd)?; @@ -383,89 +261,26 @@ pub fn run() -> Result<()> { } Some(Subcommand::Revert(cmd)) => { let runner = cli.create_runner(cmd)?; - if runner.config().chain_spec.is_astar() { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - backend, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - let aux_revert = Box::new(|client, _, blocks| { - sc_consensus_grandpa::revert(client, blocks)?; - Ok(()) - }); - Ok((cmd.run(client, backend, Some(aux_revert)), task_manager)) - }) - } else if runner.config().chain_spec.is_shiden() { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - backend, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue_fallback, - )?; - let aux_revert = Box::new(|client, _, blocks| { - sc_consensus_grandpa::revert(client, blocks)?; - Ok(()) - }); - Ok((cmd.run(client, backend, Some(aux_revert)), task_manager)) - }) - } else { - runner.async_run(|config| { - let PartialComponents { - client, - task_manager, - backend, - .. - } = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - let aux_revert = Box::new(|client, _, blocks| { - sc_consensus_grandpa::revert(client, blocks)?; - Ok(()) - }); - Ok((cmd.run(client, backend, Some(aux_revert)), task_manager)) - }) - } + runner.async_run(|config| { + let PartialComponents { + client, + task_manager, + backend, + .. + } = parachain::new_partial(&config)?; + let aux_revert = Box::new(|client, _, blocks| { + sc_consensus_grandpa::revert(client, blocks)?; + Ok(()) + }); + Ok((cmd.run(client, backend, Some(aux_revert)), task_manager)) + }) } Some(Subcommand::ExportGenesisState(cmd)) => { let runner = cli.create_runner(cmd)?; - if runner.config().chain_spec.is_astar() { - runner.sync_run(|config| { - let PartialComponents { client, .. } = - parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - cmd.run(client) - }) - } else if runner.config().chain_spec.is_shiden() { - runner.sync_run(|config| { - let PartialComponents { client, .. } = - parachain::new_partial::( - &config, - parachain::build_import_queue_fallback, - )?; - cmd.run(client) - }) - } else { - runner.sync_run(|config| { - let PartialComponents { client, .. } = - parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - cmd.run(client) - }) - } + runner.sync_run(|config| { + let PartialComponents { client, .. } = parachain::new_partial(&config)?; + cmd.run(client) + }) } Some(Subcommand::ExportGenesisWasm(cmd)) => { let runner = cli.create_runner(cmd)?; @@ -517,66 +332,22 @@ pub fn run() -> Result<()> { } } BenchmarkCmd::Block(cmd) => { - if chain_spec.is_astar() { - runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - cmd.run(params.client) - }) - } else if chain_spec.is_shiden() { - runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue_fallback, - )?; - cmd.run(params.client) - }) - } else if chain_spec.is_shibuya() { + if chain_spec.is_dev() { runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; + let params = local::new_partial(&config)?; cmd.run(params.client) }) } else { runner.sync_run(|config| { - let params = local::new_partial(&config)?; + let params = parachain::new_partial(&config)?; cmd.run(params.client) }) } } BenchmarkCmd::Storage(cmd) => { - if chain_spec.is_astar() { - runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - let db = params.backend.expose_db(); - let storage = params.backend.expose_storage(); - - cmd.run(config, params.client, db, storage) - }) - } else if chain_spec.is_shiden() { + if chain_spec.is_dev() { runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue_fallback, - )?; - let db = params.backend.expose_db(); - let storage = params.backend.expose_storage(); - - cmd.run(config, params.client, db, storage) - }) - } else if chain_spec.is_shibuya() { - runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; + let params = local::new_partial(&config)?; let db = params.backend.expose_db(); let storage = params.backend.expose_storage(); @@ -584,7 +355,7 @@ pub fn run() -> Result<()> { }) } else { runner.sync_run(|config| { - let params = local::new_partial(&config)?; + let params = parachain::new_partial(&config)?; let db = params.backend.expose_db(); let storage = params.backend.expose_storage(); @@ -593,33 +364,11 @@ pub fn run() -> Result<()> { } } BenchmarkCmd::Overhead(cmd) => { - if chain_spec.is_astar() { + if chain_spec.is_dev() { runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - let ext_builder = RemarkBuilder::new(params.client.clone()); - let inherent_data = para_benchmark_inherent_data() - .map_err(|e| format!("generating inherent data: {:?}", e))?; - - cmd.run( - config, - params.client, - inherent_data, - Vec::new(), - &ext_builder, - ) - }) - } else if chain_spec.is_shiden() { - runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue_fallback, - )?; - + let params = local::new_partial(&config)?; let ext_builder = RemarkBuilder::new(params.client.clone()); - let inherent_data = para_benchmark_inherent_data() + let inherent_data = local_benchmark_inherent_data() .map_err(|e| format!("generating inherent data: {:?}", e))?; cmd.run( @@ -630,32 +379,14 @@ pub fn run() -> Result<()> { &ext_builder, ) }) - } else if chain_spec.is_shibuya() { + } else { runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; + let params = parachain::new_partial(&config)?; let ext_builder = RemarkBuilder::new(params.client.clone()); let inherent_data = para_benchmark_inherent_data() .map_err(|e| format!("generating inherent data: {:?}", e))?; - cmd.run( - config, - params.client, - inherent_data, - Vec::new(), - &ext_builder, - ) - }) - } else { - runner.sync_run(|config| { - let params = local::new_partial(&config)?; - let ext_builder = RemarkBuilder::new(params.client.clone()); - let inherent_data = local_benchmark_inherent_data() - .map_err(|e| format!("generating inherent data: {:?}", e))?; - cmd.run( config, params.client, @@ -667,54 +398,9 @@ pub fn run() -> Result<()> { } } BenchmarkCmd::Extrinsic(cmd) => { - if chain_spec.is_astar() { + if chain_spec.is_dev() { runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; - let remark_builder = RemarkBuilder::new(params.client.clone()); - let tka_builder = TransferKeepAliveBuilder::new( - params.client.clone(), - Sr25519Keyring::Alice.to_account_id(), - params.client.existential_deposit(), - ); - let ext_factory = ExtrinsicFactory(vec![ - Box::new(remark_builder), - Box::new(tka_builder), - ]); - let inherent_data = para_benchmark_inherent_data() - .map_err(|e| format!("generating inherent data: {:?}", e))?; - - cmd.run(params.client, inherent_data, Vec::new(), &ext_factory) - }) - } else if chain_spec.is_shiden() { - runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue_fallback, - )?; - let remark_builder = RemarkBuilder::new(params.client.clone()); - let tka_builder = TransferKeepAliveBuilder::new( - params.client.clone(), - Sr25519Keyring::Alice.to_account_id(), - params.client.existential_deposit(), - ); - let ext_factory = ExtrinsicFactory(vec![ - Box::new(remark_builder), - Box::new(tka_builder), - ]); - let inherent_data = para_benchmark_inherent_data() - .map_err(|e| format!("generating inherent data: {:?}", e))?; - - cmd.run(params.client, inherent_data, Vec::new(), &ext_factory) - }) - } else if chain_spec.is_shibuya() { - runner.sync_run(|config| { - let params = parachain::new_partial::( - &config, - parachain::build_import_queue, - )?; + let params = local::new_partial(&config)?; let remark_builder = RemarkBuilder::new(params.client.clone()); let tka_builder = TransferKeepAliveBuilder::new( params.client.clone(), @@ -725,14 +411,14 @@ pub fn run() -> Result<()> { Box::new(remark_builder), Box::new(tka_builder), ]); - let inherent_data = para_benchmark_inherent_data() + let inherent_data = local_benchmark_inherent_data() .map_err(|e| format!("generating inherent data: {:?}", e))?; cmd.run(params.client, inherent_data, Vec::new(), &ext_factory) }) } else { runner.sync_run(|config| { - let params = local::new_partial(&config)?; + let params = parachain::new_partial(&config)?; let remark_builder = RemarkBuilder::new(params.client.clone()); let tka_builder = TransferKeepAliveBuilder::new( params.client.clone(), @@ -743,7 +429,7 @@ pub fn run() -> Result<()> { Box::new(remark_builder), Box::new(tka_builder), ]); - let inherent_data = local_benchmark_inherent_data() + let inherent_data = para_benchmark_inherent_data() .map_err(|e| format!("generating inherent data: {:?}", e))?; cmd.run(params.client, inherent_data, Vec::new(), &ext_factory) @@ -759,8 +445,7 @@ pub fn run() -> Result<()> { let runner = cli.create_runner(&cli.run.normalize())?; let collator_options = cli.run.collator_options(); - #[cfg(feature = "evm-tracing")] - let evm_tracing_config = crate::evm_tracing_types::EvmTracingConfig { + let evm_tracing_config = EvmTracingConfig { ethapi: cli.eth_api_options.ethapi, ethapi_max_permits: cli.eth_api_options.ethapi_max_permits, ethapi_trace_max_count: cli.eth_api_options.ethapi_trace_max_count, @@ -773,7 +458,11 @@ pub fn run() -> Result<()> { runner.run_node_until_exit(|config| async move { if config.chain_spec.is_dev() { - return local::start_node::>(config, #[cfg(feature = "evm-tracing")] evm_tracing_config).map_err(Into::into); + return local::start_node::>( + config, + evm_tracing_config, + ) + .map_err(Into::into); } let polkadot_cli = RelayChainCli::new( @@ -786,11 +475,13 @@ pub fn run() -> Result<()> { let para_id = ParaId::from( chain_spec::Extensions::try_get(&*config.chain_spec) .map(|e| e.para_id) - .ok_or("ParaId not found in chain spec extension")? + .ok_or("ParaId not found in chain spec extension")?, ); let parachain_account = - AccountIdConversion::::into_account_truncating(¶_id); + AccountIdConversion::::into_account_truncating( + ¶_id, + ); let polkadot_config = SubstrateCli::create_configuration( &polkadot_cli, @@ -818,49 +509,23 @@ pub fn run() -> Result<()> { .flatten(); let additional_config = AdditionalConfig { - #[cfg(feature = "evm-tracing")] - evm_tracing_config: evm_tracing_config, + evm_tracing_config, enable_evm_rpc: cli.enable_evm_rpc, proposer_block_size_limit: cli.proposer_block_size_limit, proposer_soft_deadline_percent: cli.proposer_soft_deadline_percent, hwbench, }; - if config.chain_spec.is_astar() { - start_astar_node( - config, - polkadot_config, - collator_options, - para_id, - additional_config - ) - .await - .map(|r| r.0) - .map_err(Into::into) - } else if config.chain_spec.is_shiden() { - start_shiden_node( config, - polkadot_config, - collator_options, - para_id, - additional_config - ) - .await - .map(|r| r.0) - .map_err(Into::into) - } else if config.chain_spec.is_shibuya() { - start_shibuya_node( config, - polkadot_config, - collator_options, - para_id, - additional_config) - .await - .map(|r| r.0) - .map_err(Into::into) - } else { - let err_msg = "Unrecognized chain spec - name should start with one of: astar or shiden or shibuya"; - error!("{}", err_msg); - Err(err_msg.into()) - } + parachain::start_node( + config, + polkadot_config, + collator_options, + para_id, + additional_config, + ) + .await + .map(|r| r.0) + .map_err(Into::into) }) } } diff --git a/bin/collator/src/local/service.rs b/bin/collator/src/local/service.rs index e444eb7f9c..7c3c210441 100644 --- a/bin/collator/src/local/service.rs +++ b/bin/collator/src/local/service.rs @@ -18,6 +18,10 @@ //! Local Service and ServiceFactory implementation. Specialized wrapper over substrate service. +use crate::{ + evm_tracing_types::{EthApi as EthApiCmd, EvmTracingConfig}, + rpc::tracing, +}; use fc_consensus::FrontierBlockImport; use fc_rpc_core::types::{FeeHistoryCache, FilterPool}; use fc_storage::StorageOverrideHandler; @@ -29,14 +33,10 @@ use sc_network::NetworkBackend; use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; use sc_telemetry::{Telemetry, TelemetryWorker}; use sc_transaction_pool_api::OffchainTransactionPoolFactory; -use sp_runtime::traits::Block as BlockT; -use std::{collections::BTreeMap, sync::Arc, time::Duration}; - #[cfg(not(feature = "manual-seal"))] use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; - -#[cfg(feature = "evm-tracing")] -use crate::{evm_tracing_types::EthApi as EthApiCmd, rpc::tracing}; +use sp_runtime::traits::Block as BlockT; +use std::{collections::BTreeMap, sync::Arc, time::Duration}; pub use local_runtime::RuntimeApi; @@ -47,16 +47,11 @@ use astar_primitives::*; const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512; /// Parachain host functions -#[cfg(feature = "evm-tracing")] pub type HostFunctions = ( cumulus_client_service::ParachainHostFunctions, moonbeam_primitives_ext::moonbeam_ext::HostFunctions, ); -/// Parachain host functions -#[cfg(not(feature = "evm-tracing"))] -pub type HostFunctions = (cumulus_client_service::ParachainHostFunctions,); - type ParachainExecutor = WasmExecutor; type FullClient = sc_service::TFullClient; @@ -202,7 +197,7 @@ pub fn new_partial( /// Builds a new service. pub fn start_node( config: Configuration, - #[cfg(feature = "evm-tracing")] evm_tracing_config: crate::evm_tracing_types::EvmTracingConfig, + evm_tracing_config: EvmTracingConfig, ) -> Result where N: NetworkBackend::Hash>, @@ -290,10 +285,8 @@ where > = Default::default(); let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks); - #[cfg(feature = "evm-tracing")] let ethapi_cmd = evm_tracing_config.ethapi.clone(); - #[cfg(feature = "evm-tracing")] let tracing_requesters = if ethapi_cmd.contains(&EthApiCmd::Debug) || ethapi_cmd.contains(&EthApiCmd::Trace) { tracing::spawn_tracing_tasks( @@ -415,7 +408,6 @@ where deps, subscription, pubsub_notification_sinks.clone(), - #[cfg(feature = "evm-tracing")] crate::rpc::EvmTracingConfig { tracing_requesters: tracing_requesters.clone(), trace_filter_max_count: evm_tracing_config.ethapi_trace_max_count, diff --git a/bin/collator/src/parachain/fake_runtime_api.rs b/bin/collator/src/parachain/fake_runtime_api.rs new file mode 100644 index 0000000000..6583330f4d --- /dev/null +++ b/bin/collator/src/parachain/fake_runtime_api.rs @@ -0,0 +1,299 @@ +// This file is part of Astar. + +// Copyright (C) Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Astar is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Astar. If not, see . + +#![allow(missing_docs)] + +use astar_primitives::{AccountId, Balance, Block, Nonce}; +use frame_support::weights::Weight; +use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; +use sp_api::impl_runtime_apis; +use sp_consensus_aura::sr25519::AuthorityId as AuraId; +use sp_core::{OpaqueMetadata, H160, H256, U256}; +use sp_inherents::{CheckInherentsResult, InherentData}; +use sp_runtime::{ + traits::Block as BlockT, + transaction_validity::{TransactionSource, TransactionValidity}, + ApplyExtrinsicResult, Permill, +}; +use sp_version::RuntimeVersion; + +pub struct Runtime; + +impl_runtime_apis! { + impl sp_api::Core for Runtime { + fn version() -> RuntimeVersion { + unimplemented!() + } + + fn execute_block(_block: Block) { + unimplemented!() + } + + fn initialize_block(_header: &::Header) -> sp_runtime::ExtrinsicInclusionMode { + unimplemented!() + } + } + + impl sp_api::Metadata for Runtime { + fn metadata() -> OpaqueMetadata { + unimplemented!() + } + + fn metadata_at_version(_version: u32) -> Option { + unimplemented!() + } + + fn metadata_versions() -> sp_std::vec::Vec { + unimplemented!() + } + } + + impl cumulus_primitives_core::CollectCollationInfo for Runtime { + fn collect_collation_info(_header: &::Header) -> cumulus_primitives_core::CollationInfo { + unimplemented!() + } + } + + impl sp_consensus_aura::AuraApi for Runtime { + fn slot_duration() -> sp_consensus_aura::SlotDuration { + unimplemented!() + } + + fn authorities() -> Vec { + unimplemented!() + } + } + + impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { + fn can_build_upon(_included_hash: ::Hash, _slot: cumulus_primitives_aura::Slot) -> bool { + unimplemented!() + } + } + + impl sp_block_builder::BlockBuilder for Runtime { + fn apply_extrinsic(_extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { + unimplemented!() + } + + fn finalize_block() -> ::Header { + unimplemented!() + } + + fn inherent_extrinsics(_data: InherentData) -> Vec<::Extrinsic> { + unimplemented!() + } + + fn check_inherents(_block: Block, _data: InherentData) -> CheckInherentsResult { + unimplemented!() + } + } + + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + fn account_nonce(_account: AccountId) -> Nonce { + unimplemented!() + } + } + + impl sp_session::SessionKeys for Runtime { + fn generate_session_keys(_seed: Option>) -> Vec { + unimplemented!() + } + + fn decode_session_keys(_encoded: Vec) -> Option, sp_core::crypto::KeyTypeId)>> { + unimplemented!() + } + } + + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi< + Block, + Balance, + > for Runtime { + fn query_info(_uxt: ::Extrinsic, _len: u32) -> RuntimeDispatchInfo { + unimplemented!() + } + fn query_fee_details(_uxt: ::Extrinsic, _len: u32) -> FeeDetails { + unimplemented!() + } + fn query_weight_to_fee(_weight: Weight) -> Balance { + unimplemented!() + } + fn query_length_to_fee(_length: u32) -> Balance { + unimplemented!() + } + } + + impl fp_rpc::EthereumRuntimeRPCApi for Runtime { + fn chain_id() -> u64 { + unimplemented!() + } + + fn account_basic(_address: H160) -> pallet_evm::Account { + unimplemented!() + } + + fn gas_price() -> U256 { + unimplemented!() + } + + fn account_code_at(_address: H160) -> Vec { + unimplemented!() + } + + fn author() -> H160 { + unimplemented!() + } + + fn storage_at(_address: H160, _index: U256) -> H256 { + unimplemented!() + } + + fn call( + _from: H160, + _to: H160, + _data: Vec, + _value: U256, + _gas_limit: U256, + _max_fee_per_gas: Option, + _max_priority_fee_per_gas: Option, + _nonce: Option, + _estimate: bool, + _access_list: Option)>>, + ) -> Result { + unimplemented!() + } + + fn create( + _from: H160, + _data: Vec, + _value: U256, + _gas_limit: U256, + _max_fee_per_gas: Option, + _max_priority_fee_per_gas: Option, + _nonce: Option, + _estimate: bool, + _access_list: Option)>>, + ) -> Result { + unimplemented!() + } + + fn current_transaction_statuses() -> Option> { + unimplemented!() + } + + fn current_block() -> Option { + unimplemented!() + } + + fn current_receipts() -> Option> { + unimplemented!() + } + + fn current_all() -> ( + Option, + Option>, + Option>, + ) { + unimplemented!() + } + + fn extrinsic_filter(_xts: Vec<::Extrinsic>) -> Vec { + unimplemented!() + } + + fn elasticity() -> Option { + unimplemented!() + } + + fn gas_limit_multiplier_support() {} + + fn pending_block(_xts: Vec<::Extrinsic>) -> (Option, Option>) { + unimplemented!() + } + } + + impl fp_rpc::ConvertTransactionRuntimeApi for Runtime { + fn convert_transaction(_transaction: pallet_ethereum::Transaction) -> ::Extrinsic { + unimplemented!() + } + } + + impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { + fn validate_transaction(_source: TransactionSource, _tx: ::Extrinsic, _block_hash: ::Hash) -> TransactionValidity { + unimplemented!() + } + } + + impl sp_offchain::OffchainWorkerApi for Runtime { + fn offchain_worker(_header: &::Header) { + unimplemented!() + } + } + + impl moonbeam_rpc_primitives_debug::DebugRuntimeApi for Runtime { + fn trace_transaction(_extrinsics: Vec<::Extrinsic>, _traced_transaction: &pallet_ethereum::Transaction, _header: &::Header) -> Result<(), sp_runtime::DispatchError> { + unimplemented!() + } + + fn trace_block(_extrinsics: Vec<::Extrinsic>, _known_transactions: Vec, _header: &::Header) -> Result<(), sp_runtime::DispatchError> { + unimplemented!() + } + + fn trace_call( + _header: &::Header, + _from: H160, + _to: H160, + _data: Vec, + _value: U256, + _gas_limit: U256, + _max_fee_per_gas: Option, + _max_priority_fee_per_gas: Option, + _nonce: Option, + _access_list: Option)>>, + ) -> Result<(), sp_runtime::DispatchError> { + unimplemented!() + } + } + + impl moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi for Runtime { + fn extrinsic_filter(_xts_ready: Vec<::Extrinsic>, _xts_future: Vec<::Extrinsic>) -> moonbeam_rpc_primitives_txpool::TxPoolResponse { + unimplemented!() + } + } + + #[cfg(feature = "runtime-benchmarks")] + impl frame_benchmarking::Benchmark for Runtime { + fn benchmark_metadata(_extra: bool) -> (Vec, Vec) { + unimplemented!() + } + + fn dispatch_benchmark(_config: frame_benchmarking::BenchmarkConfig) -> Result, sp_runtime::RuntimeString> { + unimplemented!() + } + } + + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade(_checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { + unimplemented!() + } + + fn execute_block(_block: Block, _state_root_check: bool, _signature_check: bool, _select: frame_try_runtime::TryStateSelect) -> Weight { + unimplemented!() + } + } +} diff --git a/bin/collator/src/parachain/mod.rs b/bin/collator/src/parachain/mod.rs index b93711ae27..a33508da8d 100644 --- a/bin/collator/src/parachain/mod.rs +++ b/bin/collator/src/parachain/mod.rs @@ -27,10 +27,9 @@ pub mod service; /// Parachain specs. pub mod chain_spec; -pub use service::{ - build_import_queue, build_import_queue_fallback, new_partial, start_astar_node, - start_shibuya_node, start_shiden_node, HostFunctions, -}; +pub mod fake_runtime_api; + +pub use service::{build_import_queue, new_partial, start_node, HostFunctions}; pub(crate) use shell_upgrade::{ AuraConsensusDataProviderFallback, PendingCrateInherentDataProvider, diff --git a/bin/collator/src/parachain/service.rs b/bin/collator/src/parachain/service.rs index 7c60d8c941..a1dbb4b5b2 100644 --- a/bin/collator/src/parachain/service.rs +++ b/bin/collator/src/parachain/service.rs @@ -27,7 +27,6 @@ use cumulus_client_service::{ prepare_node_config, start_relay_chain_tasks, BuildNetworkParams, DARecoveryProfile, StartRelayChainTasksParams, }; -use cumulus_primitives_aura::AuraUnincludedSegmentApi; use cumulus_primitives_core::{ relay_chain::{CollatorPair, ValidationCode}, ParaId, @@ -42,105 +41,64 @@ use futures::StreamExt; use sc_client_api::BlockchainEvents; use sc_consensus::{import_queue::BasicQueue, ImportQueue}; use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; -use sc_network::{NetworkBackend, NetworkBlock}; +use sc_network::{config::NetworkBackendType, NetworkBackend, NetworkBlock}; use sc_network_sync::SyncingService; use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; -use sp_api::{ConstructRuntimeApi, ProvideRuntimeApi}; +use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_consensus_aura::{ sr25519::AuthorityId as AuraId, sr25519::AuthorityPair as AuraPair, AuraApi, }; use sp_keystore::KeystorePtr; -use sp_runtime::{ - traits::{BlakeTwo256, Block as BlockT}, - Percent, -}; +use sp_runtime::{traits::Block as BlockT, Percent}; use std::{collections::BTreeMap, sync::Arc, time::Duration}; use substrate_prometheus_endpoint::Registry; use super::shell_upgrade::*; -#[cfg(feature = "evm-tracing")] use crate::{ evm_tracing_types::{EthApi as EthApiCmd, EvmTracingConfig}, rpc::tracing, }; /// Parachain host functions -#[cfg(feature = "evm-tracing")] pub type HostFunctions = ( cumulus_client_service::ParachainHostFunctions, moonbeam_primitives_ext::moonbeam_ext::HostFunctions, ); -/// Parachain host functions -#[cfg(not(feature = "evm-tracing"))] -pub type HostFunctions = (cumulus_client_service::ParachainHostFunctions,); - /// Parachain executor pub type ParachainExecutor = WasmExecutor; +type FullClient = + TFullClient; + /// Starts a `ServiceBuilder` for a full service. /// /// Use this macro if you don't actually need the full service, but just the builder in order to /// be able to perform chain operations. -pub fn new_partial( +pub fn new_partial( config: &Configuration, - build_import_queue: BIQ, ) -> Result< PartialComponents< - TFullClient, + FullClient, TFullBackend, (), sc_consensus::DefaultImportQueue, - sc_transaction_pool::FullPool>, + sc_transaction_pool::FullPool, ( ParachainBlockImport< Block, - FrontierBlockImport< - Block, - Arc>, - TFullClient, - >, + FrontierBlockImport, FullClient>, TFullBackend, >, Option, Option, - Arc>>, + Arc>, ), >, sc_service::Error, -> -where - RuntimeApi: ConstructRuntimeApi> - + Send - + Sync - + 'static, - RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue - + sp_api::Metadata - + sp_session::SessionKeys - + sp_api::ApiExt - + sp_offchain::OffchainWorkerApi - + sp_block_builder::BlockBuilder - + fp_rpc::EthereumRuntimeRPCApi, - sc_client_api::StateBackendFor, Block>: - sc_client_api::backend::StateBackend, - BIQ: FnOnce( - Arc>, - ParachainBlockImport< - Block, - FrontierBlockImport< - Block, - Arc>, - TFullClient, - >, - TFullBackend, - >, - &Configuration, - Option, - &TaskManager, - ) -> sc_consensus::DefaultImportQueue, -{ +> { let telemetry = config .telemetry_endpoints .clone() @@ -167,7 +125,7 @@ where .build(); let (client, backend, keystore_container, task_manager) = - sc_service::new_full_parts_record_import::( + sc_service::new_full_parts_record_import::( config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), executor, @@ -251,309 +209,10 @@ async fn build_relay_chain_interface( ) } } -/// Start a node with the given parachain `Configuration` and relay chain `Configuration`. -/// -/// This is the actual implementation that is abstract over the executor and the runtime api. -#[cfg(not(feature = "evm-tracing"))] -#[sc_tracing::logging::prefix_logs_with("Parachain")] -async fn start_node_impl( - parachain_config: Configuration, - polkadot_config: Configuration, - collator_options: CollatorOptions, - id: ParaId, - additional_config: AdditionalConfig, - build_import_queue: BIQ, - start_consensus: SC, -) -> sc_service::error::Result<( - TaskManager, - Arc>, -)> -where - RuntimeApi: ConstructRuntimeApi> - + Send - + Sync - + 'static, - RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue - + sp_api::Metadata - + sp_session::SessionKeys - + sp_api::ApiExt - + sp_offchain::OffchainWorkerApi - + sp_block_builder::BlockBuilder - + substrate_frame_rpc_system::AccountNonceApi - + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi - + fp_rpc::EthereumRuntimeRPCApi - + fp_rpc::ConvertTransactionRuntimeApi - + cumulus_primitives_core::CollectCollationInfo - + AuraApi, - sc_client_api::StateBackendFor, Block>: - sc_client_api::backend::StateBackend, - BIQ: FnOnce( - Arc>, - ParachainBlockImport< - Block, - FrontierBlockImport< - Block, - Arc>, - TFullClient, - >, - TFullBackend, - >, - &Configuration, - Option, - &TaskManager, - ) -> sc_consensus::DefaultImportQueue, - SC: FnOnce( - Arc>, - Arc>, - ParachainBlockImport< - Block, - FrontierBlockImport< - Block, - Arc>, - TFullClient, - >, - TFullBackend, - >, - Option<&Registry>, - Option, - &TaskManager, - Arc, - Arc>>, - Arc>, - KeystorePtr, - ParaId, - CollatorPair, - AdditionalConfig, - ) -> Result<(), sc_service::Error>, - N: NetworkBackend::Hash>, -{ - let parachain_config = prepare_node_config(parachain_config); - - let params = new_partial::(¶chain_config, build_import_queue)?; - let (parachain_block_import, mut telemetry, telemetry_worker_handle, frontier_backend) = - params.other; - let net_config = - sc_network::config::FullNetworkConfiguration::<_, _, N>::new(¶chain_config.network); - - let client = params.client.clone(); - let backend = params.backend.clone(); - - let mut task_manager = params.task_manager; - let (relay_chain_interface, collator_key) = build_relay_chain_interface( - polkadot_config, - ¶chain_config, - telemetry_worker_handle, - &mut task_manager, - collator_options.clone(), - additional_config.hwbench.clone(), - ) - .await - .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?; - - let is_authority = parachain_config.role.is_authority(); - let prometheus_registry = parachain_config.prometheus_registry().cloned(); - let transaction_pool = params.transaction_pool.clone(); - let import_queue_service = params.import_queue.service(); - let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = - cumulus_client_service::build_network(BuildNetworkParams { - parachain_config: ¶chain_config, - net_config, - para_id: id, - client: client.clone(), - transaction_pool: transaction_pool.clone(), - spawn_handle: task_manager.spawn_handle(), - import_queue: params.import_queue, - relay_chain_interface: relay_chain_interface.clone(), - sybil_resistance_level: cumulus_client_service::CollatorSybilResistance::Resistant, - }) - .await?; - - let filter_pool: FilterPool = Arc::new(std::sync::Mutex::new(BTreeMap::new())); - let fee_history_cache: FeeHistoryCache = Arc::new(std::sync::Mutex::new(BTreeMap::new())); - let storage_override = Arc::new(StorageOverrideHandler::new(client.clone())); - - // Sinks for pubsub notifications. - // Everytime a new subscription is created, a new mpsc channel is added to the sink pool. - // The MappingSyncWorker sends through the channel on block import and the subscription emits a notification to the subscriber on receiving a message through this channel. - // This way we avoid race conditions when using native substrate block import notification stream. - let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks< - fc_mapping_sync::EthereumBlockNotification, - > = Default::default(); - let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks); - - // Frontier offchain DB task. Essential. - // Maps emulated ethereum data to substrate native data. - task_manager.spawn_essential_handle().spawn( - "frontier-mapping-sync-worker", - Some("frontier"), - fc_mapping_sync::kv::MappingSyncWorker::new( - client.import_notification_stream(), - Duration::new(6, 0), - client.clone(), - backend.clone(), - storage_override.clone(), - frontier_backend.clone(), - 3, - 0, - fc_mapping_sync::SyncStrategy::Parachain, - sync_service.clone(), - pubsub_notification_sinks.clone(), - ) - .for_each(|()| futures::future::ready(())), - ); - - // Frontier `EthFilterApi` maintenance. Manages the pool of user-created Filters. - // Each filter is allowed to stay in the pool for 100 blocks. - const FILTER_RETAIN_THRESHOLD: u64 = 100; - task_manager.spawn_essential_handle().spawn( - "frontier-filter-pool", - Some("frontier"), - fc_rpc::EthTask::filter_pool_task( - client.clone(), - filter_pool.clone(), - FILTER_RETAIN_THRESHOLD, - ), - ); - - const FEE_HISTORY_LIMIT: u64 = 2048; - task_manager.spawn_essential_handle().spawn( - "frontier-fee-history", - Some("frontier"), - fc_rpc::EthTask::fee_history_task( - client.clone(), - storage_override.clone(), - fee_history_cache.clone(), - FEE_HISTORY_LIMIT, - ), - ); - - let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new( - task_manager.spawn_handle(), - storage_override.clone(), - 50, - 50, - prometheus_registry.clone(), - )); - - let rpc_extensions_builder = { - let client = client.clone(); - let network = network.clone(); - let transaction_pool = transaction_pool.clone(); - let sync = sync_service.clone(); - let pubsub_notification_sinks = pubsub_notification_sinks.clone(); - - Box::new(move |deny_unsafe, subscription| { - let deps = crate::rpc::FullDeps { - client: client.clone(), - pool: transaction_pool.clone(), - graph: transaction_pool.pool().clone(), - network: network.clone(), - sync: sync.clone(), - is_authority, - deny_unsafe, - frontier_backend: frontier_backend.clone(), - filter_pool: filter_pool.clone(), - fee_history_limit: FEE_HISTORY_LIMIT, - fee_history_cache: fee_history_cache.clone(), - block_data_cache: block_data_cache.clone(), - storage_override: storage_override.clone(), - enable_evm_rpc: additional_config.enable_evm_rpc, - #[cfg(feature = "manual-seal")] - command_sink: None, - }; - - crate::rpc::create_full(deps, subscription, pubsub_notification_sinks.clone()) - .map_err(Into::into) - }) - }; - - // Spawn basic services. - sc_service::spawn_tasks(sc_service::SpawnTasksParams { - rpc_builder: rpc_extensions_builder, - client: client.clone(), - transaction_pool: transaction_pool.clone(), - task_manager: &mut task_manager, - config: parachain_config, - keystore: params.keystore_container.keystore(), - backend: backend.clone(), - network: network.clone(), - system_rpc_tx, - sync_service: sync_service.clone(), - tx_handler_controller, - telemetry: telemetry.as_mut(), - })?; - - if let Some(hwbench) = additional_config.hwbench.clone() { - sc_sysinfo::print_hwbench(&hwbench); - if is_authority { - warn_if_slow_hardware(&hwbench); - } - - if let Some(ref mut telemetry) = telemetry { - let telemetry_handle = telemetry.handle(); - task_manager.spawn_handle().spawn( - "telemetry_hwbench", - None, - sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench), - ); - } - } - - let announce_block = { - let sync_service = sync_service.clone(); - Arc::new(move |hash, data| sync_service.announce_block(hash, data)) - }; - - let relay_chain_slot_duration = Duration::from_secs(6); - - let overseer_handle = relay_chain_interface - .overseer_handle() - .map_err(|e| sc_service::Error::Application(Box::new(e)))?; - - start_relay_chain_tasks(StartRelayChainTasksParams { - client: client.clone(), - announce_block: announce_block.clone(), - task_manager: &mut task_manager, - para_id: id, - relay_chain_interface: relay_chain_interface.clone(), - relay_chain_slot_duration, - import_queue: import_queue_service, - recovery_handle: Box::new(overseer_handle.clone()), - sync_service: sync_service.clone(), - da_recovery_profile: if is_authority { - DARecoveryProfile::Collator - } else { - DARecoveryProfile::FullNode - }, - })?; - - if is_authority { - start_consensus( - client.clone(), - backend, - parachain_block_import, - prometheus_registry.as_ref(), - telemetry.map(|t| t.handle()), - &mut task_manager, - relay_chain_interface, - transaction_pool, - sync_service, - params.keystore_container.keystore(), - id, - collator_key.expect("Command line arguments do not allow this. qed"), - additional_config, - )?; - } - - start_network.start_network(); - - Ok((task_manager, client)) -} #[derive(Clone)] /// To add additional config to start_xyz_node functions pub struct AdditionalConfig { - #[cfg(feature = "evm-tracing")] /// EVM tracing configuration pub evm_tracing_config: EvmTracingConfig, @@ -573,93 +232,33 @@ pub struct AdditionalConfig { /// Start a node with the given parachain `Configuration` and relay chain `Configuration`. /// /// This is the actual implementation that is abstract over the executor and the runtime api. -#[cfg(feature = "evm-tracing")] #[sc_tracing::logging::prefix_logs_with("Parachain")] -async fn start_node_impl( +async fn start_node_impl( parachain_config: Configuration, polkadot_config: Configuration, collator_options: CollatorOptions, - id: ParaId, + para_id: ParaId, additional_config: AdditionalConfig, - build_import_queue: BIQ, - start_consensus: SC, -) -> sc_service::error::Result<( - TaskManager, - Arc>, -)> +) -> sc_service::error::Result<(TaskManager, Arc)> where - RuntimeApi: ConstructRuntimeApi> - + Send - + Sync - + 'static, - RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue - + sp_api::Metadata - + sp_session::SessionKeys - + sp_api::ApiExt - + sp_offchain::OffchainWorkerApi - + sp_block_builder::BlockBuilder - + substrate_frame_rpc_system::AccountNonceApi - + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi - + moonbeam_rpc_primitives_debug::DebugRuntimeApi - + moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi - + fp_rpc::EthereumRuntimeRPCApi - + fp_rpc::ConvertTransactionRuntimeApi - + cumulus_primitives_core::CollectCollationInfo - + AuraApi, - sc_client_api::StateBackendFor, Block>: - sc_client_api::backend::StateBackend, - BIQ: FnOnce( - Arc>, - ParachainBlockImport< - Block, - FrontierBlockImport< - Block, - Arc>, - TFullClient, - >, - TFullBackend, - >, - &Configuration, - Option, - &TaskManager, - ) -> sc_consensus::DefaultImportQueue, - SC: FnOnce( - Arc>, - Arc>, - ParachainBlockImport< - Block, - FrontierBlockImport< - Block, - Arc>, - TFullClient, - >, - TFullBackend, - >, - Option<&Registry>, - Option, - &TaskManager, - Arc, - Arc>>, - Arc>, - KeystorePtr, - ParaId, - CollatorPair, - AdditionalConfig, - ) -> Result<(), sc_service::Error>, N: NetworkBackend::Hash>, { let parachain_config = prepare_node_config(parachain_config); - let params = new_partial::(¶chain_config, build_import_queue)?; - let (parachain_block_import, mut telemetry, telemetry_worker_handle, frontier_backend) = - params.other; + let PartialComponents { + client, + backend, + mut task_manager, + keystore_container, + select_chain: _, + import_queue, + transaction_pool, + other: (parachain_block_import, mut telemetry, telemetry_worker_handle, frontier_backend), + } = new_partial(¶chain_config)?; + let net_config = sc_network::config::FullNetworkConfiguration::<_, _, N>::new(¶chain_config.network); - let client = params.client.clone(); - let backend = params.backend.clone(); - - let mut task_manager = params.task_manager; let (relay_chain_interface, collator_key) = build_relay_chain_interface( polkadot_config, ¶chain_config, @@ -673,17 +272,16 @@ where let is_authority = parachain_config.role.is_authority(); let prometheus_registry = parachain_config.prometheus_registry().cloned(); - let transaction_pool = params.transaction_pool.clone(); - let import_queue_service = params.import_queue.service(); + let import_queue_service = import_queue.service(); let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = cumulus_client_service::build_network(BuildNetworkParams { parachain_config: ¶chain_config, net_config, - para_id: id, + para_id, client: client.clone(), transaction_pool: transaction_pool.clone(), spawn_handle: task_manager.spawn_handle(), - import_queue: params.import_queue, + import_queue, relay_chain_interface: relay_chain_interface.clone(), sybil_resistance_level: cumulus_client_service::CollatorSybilResistance::Resistant, }) @@ -827,7 +425,7 @@ where transaction_pool: transaction_pool.clone(), task_manager: &mut task_manager, config: parachain_config, - keystore: params.keystore_container.keystore(), + keystore: keystore_container.keystore(), backend: backend.clone(), network: network.clone(), system_rpc_tx, @@ -857,8 +455,6 @@ where Arc::new(move |hash, data| sync_service.announce_block(hash, data)) }; - let relay_chain_slot_duration = Duration::from_secs(6); - let overseer_handle = relay_chain_interface .overseer_handle() .map_err(|e| sc_service::Error::Application(Box::new(e)))?; @@ -867,9 +463,9 @@ where client: client.clone(), announce_block: announce_block.clone(), task_manager: &mut task_manager, - para_id: id, + para_id, relay_chain_interface: relay_chain_interface.clone(), - relay_chain_slot_duration, + relay_chain_slot_duration: Duration::from_secs(6), import_queue: import_queue_service, recovery_handle: Box::new(overseer_handle.clone()), sync_service: sync_service.clone(), @@ -881,7 +477,7 @@ where })?; if is_authority { - start_consensus( + start_aura_consensus( client.clone(), backend, parachain_block_import, @@ -891,8 +487,8 @@ where relay_chain_interface, transaction_pool, sync_service, - params.keystore_container.keystore(), - id, + keystore_container.keystore(), + para_id, collator_key.expect("Command line arguments do not allow this. qed"), additional_config, )?; @@ -905,63 +501,44 @@ where /// Build aura import queue with fallback to relay-chain verifier. /// Starts with relay-chain verifier until aura becomes available. -pub fn build_import_queue_fallback( - client: Arc>, +pub fn build_import_queue( + client: Arc, block_import: ParachainBlockImport< Block, - FrontierBlockImport< - Block, - Arc>, - TFullClient, - >, + FrontierBlockImport, FullClient>, TFullBackend, >, config: &Configuration, telemetry_handle: Option, task_manager: &TaskManager, -) -> sc_consensus::DefaultImportQueue -where - RuntimeApi: ConstructRuntimeApi> - + Send - + Sync - + 'static, - RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue - + sp_api::Metadata - + sp_session::SessionKeys - + sp_api::ApiExt - + sp_offchain::OffchainWorkerApi - + sp_block_builder::BlockBuilder - + fp_rpc::EthereumRuntimeRPCApi - + AuraApi, - sc_client_api::StateBackendFor, Block>: - sc_client_api::StateBackend, -{ +) -> sc_consensus::DefaultImportQueue { let verifier_client = client.clone(); - let aura_verifier = cumulus_client_consensus_aura::build_verifier::( - cumulus_client_consensus_aura::BuildVerifierParams { - client: verifier_client.clone(), - create_inherent_data_providers: move |parent_hash, _| { - let cidp_client = verifier_client.clone(); - async move { - let slot_duration = cumulus_client_consensus_aura::slot_duration_at( - &*cidp_client, - parent_hash, - )?; - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = + let aura_verifier = Box::new(cumulus_client_consensus_aura::build_verifier::< + AuraPair, + _, + _, + _, + >(cumulus_client_consensus_aura::BuildVerifierParams { + client: verifier_client.clone(), + create_inherent_data_providers: move |parent_hash, _| { + let cidp_client = verifier_client.clone(); + async move { + let slot_duration = + cumulus_client_consensus_aura::slot_duration_at(&*cidp_client, parent_hash)?; + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + + let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( *timestamp, slot_duration, ); - Ok((slot, timestamp)) - } - }, - telemetry: telemetry_handle, + Ok((slot, timestamp)) + } }, - ); + telemetry: telemetry_handle, + })); let relay_chain_verifier = Box::new(RelayChainVerifier::new(client.clone(), |_, _| async { Ok(()) @@ -970,7 +547,7 @@ where let verifier = Verifier { client, relay_chain_verifier, - aura_verifier: Box::new(aura_verifier), + aura_verifier, }; let registry = config.prometheus_registry(); @@ -979,263 +556,26 @@ where BasicQueue::new(verifier, Box::new(block_import), None, &spawner, registry) } -/// Build aura only import queue. -pub fn build_import_queue( - client: Arc>, - block_import: ParachainBlockImport< - Block, - FrontierBlockImport< - Block, - Arc>, - TFullClient, - >, - TFullBackend, - >, - config: &Configuration, - telemetry_handle: Option, - task_manager: &TaskManager, -) -> sc_consensus::DefaultImportQueue -where - RuntimeApi: ConstructRuntimeApi> - + Send - + Sync - + 'static, - RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue - + sp_api::Metadata - + sp_session::SessionKeys - + sp_api::ApiExt - + sp_offchain::OffchainWorkerApi - + sp_block_builder::BlockBuilder - + fp_rpc::EthereumRuntimeRPCApi - + AuraApi, - sc_client_api::StateBackendFor, Block>: - sc_client_api::StateBackend, -{ - let cidp_client = client.clone(); - - cumulus_client_consensus_aura::equivocation_import_queue::fully_verifying_import_queue::< - AuraPair, - _, - _, - _, - _, - >( - client, - block_import, - move |parent_hash, _| { - let cidp_client = cidp_client.clone(); - async move { - let slot_duration = - sc_consensus_aura::standalone::slot_duration_at(&*cidp_client, parent_hash)?; - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = - sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - *timestamp, - slot_duration, - ); - - Ok((slot, timestamp)) - } - }, - &task_manager.spawn_essential_handle(), - config.prometheus_registry(), - telemetry_handle, - ) -} - /// Start collating with the `shell` runtime while waiting for an upgrade to an Aura compatible runtime. -fn start_aura_consensus_fallback( - client: Arc>, - backend: Arc>, - parachain_block_import: ParachainBlockImport< - Block, - FrontierBlockImport< - Block, - Arc>, - TFullClient, - >, - TFullBackend, - >, - prometheus_registry: Option<&Registry>, - telemetry: Option, - task_manager: &TaskManager, - relay_chain_interface: Arc, - transaction_pool: Arc< - sc_transaction_pool::FullPool>, - >, - sync_oracle: Arc>, - keystore: KeystorePtr, - para_id: ParaId, - collator_key: CollatorPair, - additional_config: AdditionalConfig, -) -> Result<(), sc_service::Error> -where - RuntimeApi: ConstructRuntimeApi> - + Send - + Sync - + 'static, - RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue - + sp_api::Metadata - + sp_session::SessionKeys - + sp_api::ApiExt - + sp_offchain::OffchainWorkerApi - + sp_block_builder::BlockBuilder - + fp_rpc::EthereumRuntimeRPCApi - + AuraApi - + AuraUnincludedSegmentApi - + cumulus_primitives_core::CollectCollationInfo, - sc_client_api::StateBackendFor, Block>: - sc_client_api::StateBackend, -{ - let mut proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( - task_manager.spawn_handle(), - client.clone(), - transaction_pool, - prometheus_registry, - telemetry, - ); - - proposer_factory.set_default_block_size_limit(additional_config.proposer_block_size_limit); - proposer_factory.set_soft_deadline(Percent::from_percent( - additional_config.proposer_soft_deadline_percent, - )); - - let overseer_handle = relay_chain_interface - .overseer_handle() - .map_err(|e| sc_service::Error::Application(Box::new(e)))?; - - let spawner = task_manager.spawn_handle(); - let client_ = client.clone(); - - let collation_future = Box::pin(async move { - use parity_scale_codec::Decode; - use sp_api::ApiExt; - - let client = client_.clone(); - - // Start collating with the `shell` runtime while waiting for an upgrade to an Aura - // compatible runtime. - let mut request_stream = cumulus_client_collator::relay_chain_driven::init( - collator_key.clone(), - para_id.clone(), - overseer_handle.clone(), - ) - .await; - - while let Some(request) = request_stream.next().await { - let pvd = request.persisted_validation_data().clone(); - let last_head_hash = - match ::Header::decode(&mut &pvd.parent_head.0[..]) { - Ok(header) => header.hash(), - Err(e) => { - log::error!("Could not decode the head data: {e}"); - request.complete(None); - continue; - } - }; - - // Check if we have upgraded to an Aura compatible runtime and transition if - // necessary. - if client - .runtime_api() - .has_api::>(last_head_hash) - .unwrap_or_default() - { - // Respond to this request before transitioning to Aura. - request.complete(None); - break; - } - } - - // Move to Aura consensus. - let announce_block = { - let sync_service = sync_oracle.clone(); - Arc::new(move |hash, data| sync_service.announce_block(hash, data)) - }; - - let collator_service = cumulus_client_collator::service::CollatorService::new( - client.clone(), - Arc::new(spawner), - announce_block, - client.clone(), - ); - - aura::run::(AuraParams { - create_inherent_data_providers: move |_, ()| async move { Ok(()) }, - block_import: parachain_block_import.clone(), - para_client: client.clone(), - para_backend: backend, - relay_client: relay_chain_interface.clone(), - code_hash_provider: move |block_hash| { - client - .code_at(block_hash) - .ok() - .map(|c| ValidationCode::from(c).hash()) - }, - sync_oracle: sync_oracle.clone(), - keystore, - collator_key, - para_id, - overseer_handle, - relay_chain_slot_duration: Duration::from_secs(6), - proposer: cumulus_client_consensus_proposer::Proposer::new(proposer_factory), - collator_service, - authoring_duration: Duration::from_millis(1500), - reinitialize: true, - }) - .await - }); - - task_manager - .spawn_essential_handle() - .spawn("aura", None, collation_future); - Ok(()) -} - -fn start_aura_consensus( - client: Arc>, +fn start_aura_consensus( + client: Arc, backend: Arc>, parachain_block_import: ParachainBlockImport< Block, - FrontierBlockImport< - Block, - Arc>, - TFullClient, - >, + FrontierBlockImport, FullClient>, TFullBackend, >, prometheus_registry: Option<&Registry>, telemetry: Option, task_manager: &TaskManager, relay_chain_interface: Arc, - transaction_pool: Arc< - sc_transaction_pool::FullPool>, - >, + transaction_pool: Arc>, sync_oracle: Arc>, keystore: KeystorePtr, para_id: ParaId, collator_key: CollatorPair, additional_config: AdditionalConfig, -) -> Result<(), sc_service::Error> -where - RuntimeApi: ConstructRuntimeApi> - + Send - + Sync - + 'static, - RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue - + sp_api::Metadata - + sp_session::SessionKeys - + sp_api::ApiExt - + sp_offchain::OffchainWorkerApi - + sp_block_builder::BlockBuilder - + fp_rpc::EthereumRuntimeRPCApi - + AuraApi - + AuraUnincludedSegmentApi - + cumulus_primitives_core::CollectCollationInfo, - sc_client_api::StateBackendFor, Block>: - sc_client_api::StateBackend, -{ +) -> Result<(), sc_service::Error> { let mut proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( task_manager.spawn_handle(), client.clone(), @@ -1265,17 +605,20 @@ where client.clone(), ); - let fut = aura::run::(AuraParams { + let params = AuraParams { create_inherent_data_providers: move |_, ()| async move { Ok(()) }, block_import: parachain_block_import.clone(), para_client: client.clone(), para_backend: backend, relay_client: relay_chain_interface.clone(), - code_hash_provider: move |block_hash| { - client - .code_at(block_hash) - .ok() - .map(|c| ValidationCode::from(c).hash()) + code_hash_provider: { + let client = client.clone(); + move |block_hash| { + client + .code_at(block_hash) + .ok() + .map(|c| ValidationCode::from(c).hash()) + } }, sync_oracle: sync_oracle.clone(), keystore, @@ -1285,84 +628,44 @@ where relay_chain_slot_duration: Duration::from_secs(6), proposer: cumulus_client_consensus_proposer::Proposer::new(proposer_factory), collator_service, - authoring_duration: Duration::from_millis(1500), + authoring_duration: Duration::from_millis(2000), reinitialize: false, - }); + }; + + let fut = async move { + wait_for_aura(client).await; + aura::run::(params).await + }; task_manager .spawn_essential_handle() .spawn("aura", None, fut); - Ok(()) } -/// Start a parachain node for Astar. -pub async fn start_astar_node( - parachain_config: Configuration, - polkadot_config: Configuration, - collator_options: CollatorOptions, - id: ParaId, - additional_config: AdditionalConfig, -) -> sc_service::error::Result<( - TaskManager, - Arc>, -)> { - start_node_impl::>( - parachain_config, - polkadot_config, - collator_options, - id, - additional_config.clone(), - build_import_queue, - start_aura_consensus, - ) - .await -} - -/// Start a parachain node for Shiden. -pub async fn start_shiden_node( - parachain_config: Configuration, - polkadot_config: Configuration, - collator_options: CollatorOptions, - id: ParaId, - additional_config: AdditionalConfig, -) -> sc_service::error::Result<( - TaskManager, - Arc>, -)> { - start_node_impl::>( - parachain_config, - polkadot_config, - collator_options, - id, - additional_config.clone(), - build_import_queue_fallback, - start_aura_consensus_fallback, - ) - .await -} +/// Wait for the Aura runtime API to appear on chain. +/// This is useful for chains that started out without Aura. Components that +/// are depending on Aura functionality will wait until Aura appears in the runtime. +async fn wait_for_aura(client: Arc) { + let finalized_hash = client.chain_info().finalized_hash; + if client + .runtime_api() + .has_api::>(finalized_hash) + .unwrap_or_default() + { + return; + }; -/// Start a parachain node for Shibuya. -pub async fn start_shibuya_node( - parachain_config: Configuration, - polkadot_config: Configuration, - collator_options: CollatorOptions, - id: ParaId, - additional_config: AdditionalConfig, -) -> sc_service::error::Result<( - TaskManager, - Arc>, -)> { - start_node_impl::>( - parachain_config, - polkadot_config, - collator_options, - id, - additional_config.clone(), - build_import_queue, - start_aura_consensus, - ) - .await + let mut stream = client.finality_notification_stream(); + while let Some(notification) = stream.next().await { + if client + .runtime_api() + .has_api::>(notification.hash) + .unwrap_or_default() + { + return; + } + } } /// Checks that the hardware meets the requirements and print a warning otherwise. @@ -1377,3 +680,35 @@ fn warn_if_slow_hardware(hwbench: &sc_sysinfo::HwBench) { ); } } + +/// Start a parachain node. +pub async fn start_node( + parachain_config: Configuration, + polkadot_config: Configuration, + collator_options: CollatorOptions, + para_id: ParaId, + additional_config: AdditionalConfig, +) -> sc_service::error::Result<(TaskManager, Arc)> { + match parachain_config.network.network_backend { + NetworkBackendType::Libp2p => { + start_node_impl::>( + parachain_config, + polkadot_config, + collator_options, + para_id, + additional_config, + ) + .await + } + NetworkBackendType::Litep2p => { + start_node_impl::( + parachain_config, + polkadot_config, + collator_options, + para_id, + additional_config, + ) + .await + } + } +} diff --git a/bin/collator/src/rpc.rs b/bin/collator/src/rpc.rs index dde4630bb8..f87e589de6 100644 --- a/bin/collator/src/rpc.rs +++ b/bin/collator/src/rpc.rs @@ -46,20 +46,15 @@ use sp_runtime::traits::BlakeTwo256; use std::sync::Arc; use substrate_frame_rpc_system::{System, SystemApiServer}; -#[cfg(feature = "evm-tracing")] use moonbeam_rpc_debug::{Debug, DebugServer}; -#[cfg(feature = "evm-tracing")] use moonbeam_rpc_trace::{Trace, TraceServer}; // TODO: get rid of this completely now that it's part of frontier? -#[cfg(feature = "evm-tracing")] use moonbeam_rpc_txpool::{TxPool as MoonbeamTxPool, TxPoolServer}; use astar_primitives::*; -#[cfg(feature = "evm-tracing")] pub mod tracing; -#[cfg(feature = "evm-tracing")] #[derive(Clone)] pub struct EvmTracingConfig { pub tracing_requesters: tracing::RpcRequesters, @@ -142,7 +137,6 @@ pub struct FullDeps { } /// Instantiate all RPC extensions and Tracing RPC. -#[cfg(feature = "evm-tracing")] pub fn create_full( deps: FullDeps, subscription_task_executor: SubscriptionTaskExecutor, @@ -207,45 +201,6 @@ where Ok(io) } -/// Instantiate all RPC extensions. -#[cfg(not(feature = "evm-tracing"))] -pub fn create_full( - deps: FullDeps, - subscription_task_executor: SubscriptionTaskExecutor, - pubsub_notification_sinks: Arc< - fc_mapping_sync::EthereumBlockNotificationSinks< - fc_mapping_sync::EthereumBlockNotification, - >, - >, -) -> Result, Box> -where - C: ProvideRuntimeApi - + HeaderBackend - + UsageProvider - + CallApiAt - + AuxStore - + StorageProvider - + HeaderMetadata - + BlockchainEvents - + Send - + Sync - + 'static, - C: sc_client_api::BlockBackend, - C::Api: substrate_frame_rpc_system::AccountNonceApi - + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi - + fp_rpc::ConvertTransactionRuntimeApi - + fp_rpc::EthereumRuntimeRPCApi - + BlockBuilder - + AuraApi, - P: TransactionPool + Sync + Send + 'static, - BE: Backend + 'static, - BE::State: StateBackend, - BE::Blockchain: BlockchainBackend, - A: ChainApi + 'static, -{ - create_full_rpc(deps, subscription_task_executor, pubsub_notification_sinks) -} - fn create_full_rpc( deps: FullDeps, subscription_task_executor: SubscriptionTaskExecutor, diff --git a/runtime/local/Cargo.toml b/runtime/local/Cargo.toml index f12ab053a0..80134dc292 100644 --- a/runtime/local/Cargo.toml +++ b/runtime/local/Cargo.toml @@ -262,11 +262,6 @@ try-runtime = [ "pallet-chain-extension-assets/try-runtime", "sp-runtime/try-runtime", ] -evm-tracing = [ - "moonbeam-evm-tracer", - "moonbeam-rpc-primitives-debug", - "moonbeam-rpc-primitives-txpool", -] # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. metadata-hash = ["substrate-wasm-builder?/metadata-hash"] diff --git a/runtime/local/src/lib.rs b/runtime/local/src/lib.rs index a76b1007d4..cc262965bb 100644 --- a/runtime/local/src/lib.rs +++ b/runtime/local/src/lib.rs @@ -1854,7 +1854,6 @@ impl_runtime_apis! { } } - #[cfg(feature = "evm-tracing")] impl moonbeam_rpc_primitives_debug::DebugRuntimeApi for Runtime { fn trace_transaction( extrinsics: Vec<::Extrinsic>, @@ -2007,7 +2006,6 @@ impl_runtime_apis! { } } - #[cfg(feature = "evm-tracing")] impl moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi for Runtime { fn extrinsic_filter( xts_ready: Vec<::Extrinsic>,