From d6313a11080c0d235be1fc0237e21e3f9470cb28 Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Wed, 17 Apr 2024 14:16:05 +0200 Subject: [PATCH 1/2] CI workflow improvements (#81) * CI worflow improvements * fixes * cleanup * cancel previous * fix * ... * fix * Delete .github/workflows/cancel.yml * efficiency * fix * setup fix * fix * fixes * revert the basic CI * tarpaulin * revert cache version * fix * fixes * Update coverage.yml * syntax fyx * Update action.yml * switch to stable * rust-src --- .github/actions/setup/action.yml | 1 + .github/workflows/basic.yml | 6 +++- .github/workflows/benchmarks.yml | 4 +++ .github/workflows/coverage.yml | 49 ++++++++++++++++++++++++++++++ .github/workflows/dependencies.yml | 10 +++--- .github/workflows/smoke.yml | 21 +++++++------ .github/workflows/tests.yml | 4 +++ .github/workflows/try_runtime.yml | 4 +++ rust-toolchain.toml | 2 +- 9 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index e27d0e4e..3a3adbff 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -15,5 +15,6 @@ runs: rustup component add clippy --toolchain nightly-x86_64-unknown-linux-gnu rustup component add rustfmt --toolchain nightly rustup target add wasm32-unknown-unknown --toolchain nightly + rustup component add rust-src rustup show shell: bash diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index 8ea03c4c..4f14f7ee 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -12,6 +12,10 @@ on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: fmt: @@ -50,7 +54,7 @@ jobs: run: echo "CARGO_NET_GIT_FETCH_WITH_CLI=true" >> $GITHUB_ENV - name: Cargo clippy - run: cargo +nightly clippy -- -D warnings + run: cargo clippy -- -D warnings - name: Check Code run: cargo check diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 152cc4da..4fb8f2c3 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -3,6 +3,10 @@ name: Benchmarks on: workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: benchmark: runs-on: ubuntu-22.04 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..4ace915a --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,49 @@ +name: Test coverage + +on: + # Triggers the workflow on push or pull request events but only for the main branch + pull_request: + branches: + - main + push: + branches: + - main + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + TARPAULIN_VERSION: 0.27.3 + +jobs: + coverage: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 + - uses: ./.github/actions/setup + + - name: Setup SSH + uses: webfactory/ssh-agent@v0.5.3 + with: + ssh-private-key: ${{ secrets.GH_TOKEN }} + + - name: Use Git CLI for Cargo + run: echo "CARGO_NET_GIT_FETCH_WITH_CLI=true" >> $GITHUB_ENV + + - name: Run cargo-tarpaulin + run: | + wget https://github.com/xd009642/tarpaulin/releases/download/${{ env.TARPAULIN_VERSION }}/cargo-tarpaulin-x86_64-unknown-linux-musl.tar.gz + tar -zxvf cargo-tarpaulin-x86_64-unknown-linux-musl.tar.gz -C $HOME/.cargo/bin + cargo tarpaulin --workspace \ + -e regionx-node regionx-runtime \ + --exclude-files **/mock.rs **/weights/* \ + --out xml + + - uses: codecov/codecov-action@v4.0.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: RegionX-Labs/RegionX-Node diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml index 3fddfbba..a0804e63 100644 --- a/.github/workflows/dependencies.yml +++ b/.github/workflows/dependencies.yml @@ -10,6 +10,10 @@ on: - main workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: check-dependencies: runs-on: ubuntu-latest @@ -18,11 +22,7 @@ jobs: - uses: ./.github/actions/setup - name: Install Rust - run: | - rustup show - rustup toolchain install nightly - cargo install --git https://github.com/paritytech/psvm psvm - + run: cargo install --git https://github.com/paritytech/psvm psvm - name: Check Dependency Versions run: | chmod +x ./scripts/check-dependency-versions.sh diff --git a/.github/workflows/smoke.yml b/.github/workflows/smoke.yml index 9e5a4b45..16a38d63 100644 --- a/.github/workflows/smoke.yml +++ b/.github/workflows/smoke.yml @@ -4,17 +4,23 @@ name: Smoke tests on: workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: smoke: runs-on: ubuntu-latest steps: - name: Checkout Repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 + - uses: ./.github/actions/setup + - name: Zombienet setup run: | wget https://github.com/paritytech/zombienet/releases/download/v1.3.100/zombienet-linux-x64 @@ -26,16 +32,11 @@ jobs: - name: Pull Docker Image run: docker pull szegoo/regionx-node:latest - - - name: Create Container - id: create-container - run: | - container_id=$(docker create szegoo/regionx-node:latest) - echo "::set-output name=container_id::$container_id" - - name: Copy Executable from Container + - name: Compile regionx-node run: | - docker cp ${{ steps.create-container.outputs.container_id }}:/usr/bin/regionx-node . - + cargo build --release + cp ./target/release/regionx-node . + - name: Run smoke test 0001 run: ./zombienet-linux-x64 -p native test ./zombienet_tests/0001-smoke-test.zndsl diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e11242d8..0d051094 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,6 +3,10 @@ name: Tests on: workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: test: runs-on: ubuntu-22.04 diff --git a/.github/workflows/try_runtime.yml b/.github/workflows/try_runtime.yml index edfecbd2..c336aaed 100644 --- a/.github/workflows/try_runtime.yml +++ b/.github/workflows/try_runtime.yml @@ -3,6 +3,10 @@ name: Try-runtime on: workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: try-runtime: runs-on: ubuntu-22.04 diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 465c14b3..9ba3bc0e 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly" +channel = "stable" components = [ "rustfmt", "clippy" ] targets = [ "wasm32-unknown-unknown"] profile = "minimal" From 47bb08351a4559eb2d18bbbf986b127876e956bb Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:35:54 +0200 Subject: [PATCH 2/2] Add utility pallets (#86) * add utility pallet * add multisig * add proxy * fmt * Update runtime/regionx/src/lib.rs Co-authored-by: cuteolaf * Update runtime/regionx/src/lib.rs Co-authored-by: cuteolaf * Update runtime/regionx/src/lib.rs Co-authored-by: cuteolaf --------- Co-authored-by: cuteolaf --- Cargo.lock | 3 ++ Cargo.toml | 3 ++ runtime/regionx/Cargo.toml | 12 ++++++ runtime/regionx/src/impls.rs | 47 ++++++++++++++++++++++- runtime/regionx/src/lib.rs | 72 +++++++++++++++++++++++++++++++++--- 5 files changed, 129 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aee179dd..c0d31cbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9336,11 +9336,14 @@ dependencies = [ "pallet-collator-selection", "pallet-ismp", "pallet-message-queue", + "pallet-multisig", + "pallet-proxy", "pallet-session", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", + "pallet-utility", "pallet-xcm", "parachains-common", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index 7ece8be2..cda66da2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,9 @@ pallet-timestamp = { version = "27.0.0", default-features = false } pallet-transaction-payment = { version = "28.0.0", default-features = false } pallet-transaction-payment-rpc-runtime-api = { version = "28.0.0", default-features = false } pallet-message-queue = { version = "31.0.0", default-features = false } +pallet-multisig = { version = "28.0.0", default-features = false } +pallet-proxy = { version = "28.0.0", default-features = false } +pallet-utility = { version = "28.0.0", default-features = false } sp-api = { version = "26.0.0", default-features = false } sp-blockchain = { version = "28.0.0", default-features = false } sp-io = { version = "30.0.0", default-features = false } diff --git a/runtime/regionx/Cargo.toml b/runtime/regionx/Cargo.toml index 54f90845..583bd00c 100644 --- a/runtime/regionx/Cargo.toml +++ b/runtime/regionx/Cargo.toml @@ -46,11 +46,14 @@ pallet-aura = { workspace = true } pallet-authorship = { workspace = true } pallet-balances = { workspace = true } pallet-message-queue = { workspace = true } +pallet-multisig = { workspace = true } +pallet-proxy = { workspace = true } pallet-session = { workspace = true } pallet-sudo = { workspace = true } pallet-timestamp = { workspace = true } pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } +pallet-utility = { workspace = true } sp-api = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } @@ -119,8 +122,11 @@ std = [ "pallet-collator-selection/std", "pallet-message-queue/std", "regionx-primitives/std", + "pallet-multisig/std", + "pallet-proxy/std", "pallet-session/std", "pallet-sudo/std", + "pallet-utility/std", "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", @@ -164,7 +170,10 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", @@ -194,8 +203,11 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", "pallet-message-queue/try-runtime", + "pallet-multisig/try-runtime", + "pallet-proxy/try-runtime", "pallet-session/try-runtime", "pallet-sudo/try-runtime", + "pallet-utility/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-xcm/try-runtime", diff --git a/runtime/regionx/src/impls.rs b/runtime/regionx/src/impls.rs index 55f0edca..a9ef7f6b 100644 --- a/runtime/regionx/src/impls.rs +++ b/runtime/regionx/src/impls.rs @@ -1,9 +1,10 @@ -use crate::{AssetId, Runtime}; +use crate::{AssetId, Runtime, RuntimeCall}; +use frame_support::traits::InstanceFilter; use orml_asset_registry::DefaultAssetMetadata; use orml_traits::asset_registry::AssetProcessor; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; -use sp_runtime::DispatchError; +use sp_runtime::{DispatchError, RuntimeDebug}; #[derive( Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen, @@ -28,3 +29,45 @@ impl AssetProcessor> for CustomAssetProce Ok(()) } } + +/// The type used to represent the kinds of proxying allowed. +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + Encode, + Decode, + RuntimeDebug, + MaxEncodedLen, + scale_info::TypeInfo, +)] +pub enum ProxyType { + /// Fully permissioned proxy. Can execute any call on behalf of _proxied_. + Any, + /// Can execute any call that does not transfer funds or assets. + NonTransfer, + /// Proxy with the ability to reject time-delay proxy announcements. + CancelProxy, + // TODO: add more proxies in future related to coretime trading. +} + +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} + +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => + !matches!(c, RuntimeCall::Balances { .. } | RuntimeCall::Assets { .. }), + ProxyType::CancelProxy => + matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })), + } + } +} diff --git a/runtime/regionx/src/lib.rs b/runtime/regionx/src/lib.rs index e052bf7b..390293ab 100644 --- a/runtime/regionx/src/lib.rs +++ b/runtime/regionx/src/lib.rs @@ -553,6 +553,58 @@ impl pallet_collator_selection::Config for Runtime { type WeightInfo = (); } +impl pallet_utility::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type PalletsOrigin = OriginCaller; + type WeightInfo = pallet_utility::weights::SubstrateWeight; +} + +parameter_types! { + // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. + pub const DepositBase: Balance = deposit(1, 88); + // Additional storage item size of 32 bytes. + pub const DepositFactor: Balance = deposit(0, 32); + pub const MaxSignatories: u32 = 100; +} + +impl pallet_multisig::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type DepositBase = DepositBase; + type DepositFactor = DepositFactor; + type MaxSignatories = MaxSignatories; + type WeightInfo = pallet_multisig::weights::SubstrateWeight; +} + +parameter_types! { + // One storage item; key size 32, value size 8; . + pub const ProxyDepositBase: Balance = deposit(1, 40); + // Additional storage item size of 33 bytes. + pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const MaxProxies: u16 = 32; + // One storage item; key size 32, value size 16 + pub const AnnouncementDepositBase: Balance = deposit(1, 48); + pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const MaxPending: u16 = 32; +} + +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type ProxyType = ProxyType; + type ProxyDepositBase = ProxyDepositBase; + type ProxyDepositFactor = ProxyDepositFactor; + type MaxProxies = MaxProxies; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; + type MaxPending = MaxPending; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = AnnouncementDepositBase; + type AnnouncementDepositFactor = AnnouncementDepositFactor; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime @@ -579,15 +631,20 @@ construct_runtime!( Aura: pallet_aura = 33, AuraExt: cumulus_pallet_aura_ext = 34, + // Handy utilities + Utility: pallet_utility = 40, + Multisig: pallet_multisig = 41, + Proxy: pallet_proxy = 42, + // XCM helpers. - XcmpQueue: cumulus_pallet_xcmp_queue = 40, - PolkadotXcm: pallet_xcm = 41, - CumulusXcm: cumulus_pallet_xcm = 42, - MessageQueue: pallet_message_queue = 43, + XcmpQueue: cumulus_pallet_xcmp_queue = 50, + PolkadotXcm: pallet_xcm = 51, + CumulusXcm: cumulus_pallet_xcm = 52, + MessageQueue: pallet_message_queue = 53, // ISMP - Ismp: pallet_ismp = 50, - IsmpParachain: ismp_parachain = 51, + Ismp: pallet_ismp = 60, + IsmpParachain: ismp_parachain = 61, } ); @@ -598,6 +655,9 @@ mod benches { [pallet_assets, Assets] [pallet_balances, Balances] [pallet_session, SessionBench::] + [pallet_multisig, Multisig] + [pallet_proxy, Proxy] + [pallet_timestamp, Utility] [pallet_timestamp, Timestamp] [pallet_sudo, Sudo] [pallet_collator_selection, CollatorSelection]