From 68b71f8de49cdb6f9126a17a8159b97dacba4b00 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:24:50 +0200 Subject: [PATCH 01/12] pallets: Add Anchors V2 pallet --- Cargo.lock | 17 + Cargo.toml | 94 +-- pallets/anchors-v2/Cargo.toml | 52 ++ pallets/anchors-v2/src/benchmarking.rs | 89 +++ pallets/anchors-v2/src/lib.rs | 287 +++++++++ pallets/anchors-v2/src/mock.rs | 64 ++ pallets/anchors-v2/src/tests.rs | 350 +++++++++++ pallets/anchors-v2/src/weights.rs | 32 + runtime/development/Cargo.toml | 565 +++++++++--------- runtime/development/src/lib.rs | 17 + runtime/development/src/weights/mod.rs | 1 + .../src/weights/pallet_anchors_v2.rs | 51 ++ 12 files changed, 1292 insertions(+), 327 deletions(-) create mode 100644 pallets/anchors-v2/Cargo.toml create mode 100644 pallets/anchors-v2/src/benchmarking.rs create mode 100644 pallets/anchors-v2/src/lib.rs create mode 100644 pallets/anchors-v2/src/mock.rs create mode 100644 pallets/anchors-v2/src/tests.rs create mode 100644 pallets/anchors-v2/src/weights.rs create mode 100644 runtime/development/src/weights/pallet_anchors_v2.rs diff --git a/Cargo.lock b/Cargo.lock index 0649571452..18559e03f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3129,6 +3129,7 @@ dependencies = [ "orml-xcm-support", "orml-xtokens", "pallet-anchors", + "pallet-anchors-v2", "pallet-aura", "pallet-authorship", "pallet-balances", @@ -7382,6 +7383,22 @@ dependencies = [ "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.2)", ] +[[package]] +name = "pallet-anchors-v2" +version = "1.0.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.2)", +] + [[package]] name = "pallet-asset-conversion" version = "10.0.0" diff --git a/Cargo.toml b/Cargo.toml index 72ca487ae2..e31443d878 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,48 +1,49 @@ [workspace] resolver = "2" members = [ - "node", - "libs/mocks", - "libs/primitives", - "libs/test-utils", - "libs/traits", - "libs/types", - "libs/utils", - "pallets/anchors", - "pallets/bridge", - "pallets/block-rewards", - "pallets/collator-allowlist", - "pallets/ethereum-transaction", - "pallets/fees", - "pallets/foreign-investments", - "pallets/interest-accrual", - "pallets/investments", - "pallets/keystore", - "pallets/liquidity-pools", - "pallets/liquidity-pools-gateway", - "pallets/liquidity-pools-gateway/axelar-gateway-precompile", - "pallets/liquidity-pools-gateway/routers", - "pallets/liquidity-rewards", - "pallets/loans", - "pallets/oracle-feed", - "pallets/oracle-collection", - "pallets/order-book", - "pallets/permissions", - "pallets/pool-fees", - "pallets/pool-system", - "pallets/pool-registry", - "pallets/restricted-tokens", - "pallets/restricted-xtokens", - "pallets/rewards", - "pallets/swaps", - "pallets/token-mux", - "pallets/transfer-allowlist", - "runtime/altair", - "runtime/centrifuge", - "runtime/development", - "runtime/common", - "runtime/integration-tests", - "runtime/integration-tests/procedural", + "node", + "libs/mocks", + "libs/primitives", + "libs/test-utils", + "libs/traits", + "libs/types", + "libs/utils", + "pallets/anchors", + "pallets/anchors-v2", + "pallets/bridge", + "pallets/block-rewards", + "pallets/collator-allowlist", + "pallets/ethereum-transaction", + "pallets/fees", + "pallets/foreign-investments", + "pallets/interest-accrual", + "pallets/investments", + "pallets/keystore", + "pallets/liquidity-pools", + "pallets/liquidity-pools-gateway", + "pallets/liquidity-pools-gateway/axelar-gateway-precompile", + "pallets/liquidity-pools-gateway/routers", + "pallets/liquidity-rewards", + "pallets/loans", + "pallets/oracle-feed", + "pallets/oracle-collection", + "pallets/order-book", + "pallets/permissions", + "pallets/pool-fees", + "pallets/pool-system", + "pallets/pool-registry", + "pallets/restricted-tokens", + "pallets/restricted-xtokens", + "pallets/rewards", + "pallets/swaps", + "pallets/token-mux", + "pallets/transfer-allowlist", + "runtime/altair", + "runtime/centrifuge", + "runtime/development", + "runtime/common", + "runtime/integration-tests", + "runtime/integration-tests/procedural", ] [workspace.package] @@ -173,7 +174,7 @@ sp-trie = { git = "https://github.com/paritytech/polkadot-sdk", default-features frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } frame-executive = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } frame-support = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, features = [ - "tuples-96", + "tuples-96", ], branch = "release-polkadot-v1.7.2" } # Check when tuples-96 can be removed frame-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } frame-system-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } @@ -219,6 +220,7 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-s axelar-gateway-precompile = { path = "pallets/liquidity-pools-gateway/axelar-gateway-precompile", default-features = false } liquidity-pools-gateway-routers = { path = "pallets/liquidity-pools-gateway/routers", default-features = false } pallet-anchors = { path = "pallets/anchors", default-features = false } +pallet-anchors-v2 = { path = "pallets/anchors-v2", default-features = false } pallet-block-rewards = { path = "pallets/block-rewards", default-features = false } pallet-bridge = { path = "pallets/bridge", default-features = false } pallet-collator-allowlist = { path = "pallets/collator-allowlist", default-features = false } @@ -281,14 +283,14 @@ pallet-remarks = { git = "https://github.com/foss3/runtime-pallet-library", bran # Moonbeam fork of polkadot-evm/frontier fp-rpc = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2" } fp-self-contained = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2", features = [ - "serde", + "serde", ] } pallet-base-fee = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2" } pallet-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2", features = [ - "forbid-evm-reentrancy", + "forbid-evm-reentrancy", ] } pallet-evm = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2", features = [ - "forbid-evm-reentrancy", + "forbid-evm-reentrancy", ] } pallet-evm-chain-id = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2" } pallet-evm-precompile-blake2 = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2" } diff --git a/pallets/anchors-v2/Cargo.toml b/pallets/anchors-v2/Cargo.toml new file mode 100644 index 0000000000..861126747e --- /dev/null +++ b/pallets/anchors-v2/Cargo.toml @@ -0,0 +1,52 @@ +[package] +name = "pallet-anchors-v2" +description = "Anchors V2 pallet for runtime" +version = "1.0.0" +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true +documentation.workspace = true + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +parity-scale-codec = { workspace = true } +scale-info = { workspace = true } + +frame-benchmarking = { workspace = true, optional = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } +sp-core = { workspace = true } + +[dev-dependencies] +pallet-balances = { workspace = true, default-features = true } +sp-core = { workspace = true, default-features = true } +sp-io = { workspace = true, default-features = true } + +[features] +default = ["std"] +std = [ + "parity-scale-codec/std", + "scale-info/std", + "frame-support/std", + "frame-system/std", + "sp-runtime/std", + "sp-std/std", + "frame-benchmarking/std", +] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "sp-runtime/try-runtime", +] diff --git a/pallets/anchors-v2/src/benchmarking.rs b/pallets/anchors-v2/src/benchmarking.rs new file mode 100644 index 0000000000..993bd76b45 --- /dev/null +++ b/pallets/anchors-v2/src/benchmarking.rs @@ -0,0 +1,89 @@ +// Copyright 2021 Centrifuge Foundation (centrifuge.io). +// This file is part of Centrifuge chain project. + +// Centrifuge 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 (see http://www.gnu.org/licenses). + +// Centrifuge 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. + +use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite}; +use frame_support::traits::Currency; +use frame_system::RawOrigin; +use parity_scale_codec::EncodeLike; +use scale_info::prelude::format; +use sp_core::H256; +use sp_runtime::traits::Hash; + +use super::*; + +benchmarks! { + where_clause { + where + T: Config, + T::AccountId: EncodeLike<::AccountId>, + } + + set_anchor { + let caller: T::AccountId = account("acc_0", 0, 0); + + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + let deposit = AnchorDeposit::::get(); + + let anchor = AnchorOf:: { + account_id: caller.clone(), + document_id, + document_version, + hash, + deposit, + }; + + let _ = T::Currency::deposit_creating(&caller.clone().into(), T::Currency::minimum_balance() + T::DefaultAnchorDeposit::get()); + let origin = RawOrigin::Signed(caller.clone()); + }: set_anchor(origin.clone(), document_id, document_version, hash) + verify { + assert_eq!(Anchors::::get((document_id, document_version), caller.clone()), Some(anchor.clone())); + assert_eq!(PersonalAnchors::::get((caller, document_id, document_version)), Some(anchor)); + } + + remove_anchor { + let caller: T::AccountId = account("acc_0", 0, 0); + + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + let deposit = AnchorDeposit::::get(); + + let anchor = AnchorOf:: { + account_id: caller.clone(), + document_id, + document_version, + hash, + deposit, + }; + + Anchors::::insert((document_id, document_version), caller.clone(), anchor.clone()); + PersonalAnchors::::insert((caller.clone(), document_id, document_version), anchor); + + let origin = RawOrigin::Signed(caller.clone()); + }: remove_anchor(origin.clone(), document_id, document_version) + verify { + assert_eq!(Anchors::::get((document_id, document_version), caller.clone()), None); + assert_eq!(PersonalAnchors::::get((caller, document_id, document_version)), None); + } + + set_deposit { + let deposit = 2 * T::DefaultAnchorDeposit::get(); + }: set_deposit(RawOrigin::Root, deposit) + verify { + assert_eq!(AnchorDeposit::::get(), 2 * T::DefaultAnchorDeposit::get()); + } +} + +impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Runtime,); diff --git a/pallets/anchors-v2/src/lib.rs b/pallets/anchors-v2/src/lib.rs new file mode 100644 index 0000000000..4e88d9a382 --- /dev/null +++ b/pallets/anchors-v2/src/lib.rs @@ -0,0 +1,287 @@ +// Copyright 2021 Centrifuge Foundation (centrifuge.io). +// This file is part of Centrifuge chain project. + +// Centrifuge 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 (see http://www.gnu.org/licenses). + +// Centrifuge 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. +#![cfg_attr(not(feature = "std"), no_std)] + +use frame_support::pallet_prelude::*; +pub use pallet::*; +use scale_info::TypeInfo; +pub use weights::*; + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; +#[cfg(test)] +mod mock; +#[cfg(test)] +mod tests; + +pub mod weights; + +#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub struct Anchor { + account_id: AccountId, + document_id: DocumentId, + document_version: DocumentVersion, + hash: Hash, + deposit: Balance, +} + +pub type AnchorOf = Anchor< + ::AccountId, + ::DocumentId, + ::DocumentVersion, + ::Hash, + ::Balance, +>; + +#[frame_support::pallet] +pub mod pallet { + use frame_support::traits::ReservableCurrency; + use frame_system::pallet_prelude::*; + use sp_runtime::{traits::AtLeast32BitUnsigned, FixedPointOperand}; + + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + type Balance: Member + + Parameter + + AtLeast32BitUnsigned + + Default + + Copy + + MaxEncodedLen + + FixedPointOperand + + From + + From + + TypeInfo + + TryInto; + + type Currency: ReservableCurrency; + + /// Default deposit that will be taken when adding an anchor. + type DefaultAnchorDeposit: Get; + + /// The type used to identify a document. + type DocumentId: Member + + Parameter + + AtLeast32BitUnsigned + + Default + + Copy + + MaxEncodedLen + + FixedPointOperand + + From + + From + + TypeInfo + + TryInto; + + /// The type used to version a document. + type DocumentVersion: Member + + Parameter + + AtLeast32BitUnsigned + + Default + + Copy + + MaxEncodedLen + + FixedPointOperand + + From + + TypeInfo + + TryInto; + + /// Origin used when setting a deposit. + type AdminOrigin: EnsureOrigin; + + /// Weight information. + type WeightInfo: WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(_); + + /// Storage for document anchors. + #[pallet::storage] + #[pallet::getter(fn get_anchor)] + pub type Anchors = StorageDoubleMap< + _, + Blake2_256, + (T::DocumentId, T::DocumentVersion), + Blake2_256, + T::AccountId, + AnchorOf, + >; + + /// Storage for document anchors specific to an account. + #[pallet::storage] + #[pallet::getter(fn get_personal_anchor)] + pub type PersonalAnchors = StorageNMap< + _, + ( + NMapKey, + NMapKey, + NMapKey, + ), + AnchorOf, + OptionQuery, + >; + + /// Stores the current deposit that will be taken when storing an anchor. + #[pallet::storage] + #[pallet::getter(fn get_anchor_deposit)] + pub type AnchorDeposit = + StorageValue<_, T::Balance, ValueQuery, T::DefaultAnchorDeposit>; + + #[pallet::event] + #[pallet::generate_deposit(pub (super) fn deposit_event)] + pub enum Event { + /// An anchor was added. + AnchorAdded { + account_id: T::AccountId, + document_id: T::DocumentId, + document_version: T::DocumentVersion, + hash: T::Hash, + deposit: T::Balance, + }, + /// An anchor was removed. + AnchorRemoved { + account_id: T::AccountId, + document_id: T::DocumentId, + document_version: T::DocumentVersion, + hash: T::Hash, + deposit: T::Balance, + }, + /// A deposit was set. + DepositSet { new_deposit: T::Balance }, + } + + #[pallet::error] + pub enum Error { + /// The anchor already exists. + AnchorAlreadyExists, + + /// The personal anchor already exists. + PersonalAnchorAlreadyExists, + + /// The anchor was not found in storage. + AnchorNotFound, + + /// The personal anchor was not found in storage. + PersonalAnchorNotFound, + } + + #[pallet::call] + impl Pallet { + /// Sets an anchor for a document ID and version. + #[pallet::weight(T::WeightInfo::set_anchor())] + #[pallet::call_index(0)] + pub fn set_anchor( + origin: OriginFor, + document_id: T::DocumentId, + document_version: T::DocumentVersion, + hash: T::Hash, + ) -> DispatchResult { + let account_id = ensure_signed(origin)?; + + // Only one anchor should be stored for a particular document ID and version. + ensure!( + Anchors::::iter_prefix_values((document_id, document_version)).count() == 0, + Error::::AnchorAlreadyExists + ); + + ensure!( + PersonalAnchors::::get((account_id.clone(), document_id, document_version)) + .is_none(), + Error::::PersonalAnchorAlreadyExists + ); + + let deposit = AnchorDeposit::::get(); + + T::Currency::reserve(&account_id, deposit)?; + + let anchor = AnchorOf:: { + account_id: account_id.clone(), + document_id, + document_version, + hash, + deposit, + }; + + Anchors::::insert( + (document_id, document_version), + account_id.clone(), + anchor.clone(), + ); + + PersonalAnchors::::insert( + (account_id.clone(), document_id, document_version), + anchor, + ); + + Self::deposit_event(Event::AnchorAdded { + account_id, + document_id, + document_version, + hash, + deposit, + }); + + Ok(()) + } + + /// Removes an anchor for a document ID and version. + #[pallet::weight(T::WeightInfo::remove_anchor())] + #[pallet::call_index(1)] + pub fn remove_anchor( + origin: OriginFor, + document_id: T::DocumentId, + document_version: T::DocumentVersion, + ) -> DispatchResult { + let account_id = ensure_signed(origin)?; + + ensure!( + PersonalAnchors::::get((account_id.clone(), document_id, document_version)) + .is_some(), + Error::::PersonalAnchorNotFound + ); + + let anchor = Anchors::::get((document_id, document_version), account_id.clone()) + .ok_or(Error::::AnchorNotFound)?; + + T::Currency::unreserve(&account_id, anchor.deposit); + + Anchors::::remove((document_id, document_version), account_id.clone()); + PersonalAnchors::::remove((account_id.clone(), document_id, document_version)); + + Self::deposit_event(Event::AnchorRemoved { + account_id, + document_id, + document_version, + hash: anchor.hash, + deposit: anchor.deposit, + }); + + Ok(()) + } + + /// Set a new anchor deposit. + #[pallet::weight(T::WeightInfo::set_deposit())] + #[pallet::call_index(2)] + pub fn set_deposit(origin: OriginFor, new_deposit: T::Balance) -> DispatchResult { + T::AdminOrigin::ensure_origin(origin)?; + + >::set(new_deposit); + + Self::deposit_event(Event::DepositSet { new_deposit }); + + Ok(()) + } + } +} diff --git a/pallets/anchors-v2/src/mock.rs b/pallets/anchors-v2/src/mock.rs new file mode 100644 index 0000000000..e4139ce3f8 --- /dev/null +++ b/pallets/anchors-v2/src/mock.rs @@ -0,0 +1,64 @@ +// Copyright 2021 Centrifuge Foundation (centrifuge.io). +// This file is part of Centrifuge chain project. + +// Centrifuge 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 (see http://www.gnu.org/licenses). + +// Centrifuge 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. + +use frame_support::{derive_impl, parameter_types, traits::EitherOfDiverse}; +use frame_system::{EnsureRoot, EnsureSigned}; +use sp_runtime::traits::ConstU128; + +use crate::{self as pallet_anchors_v2, Config}; + +pub type Balance = u128; + +pub const CURRENCY: Balance = 1_000_000_000_000_000_000; + +frame_support::construct_runtime!( + pub enum Runtime { + System: frame_system, + AnchorsV2: pallet_anchors_v2, + Balances: pallet_balances, + } +); + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] +impl frame_system::Config for Runtime { + type AccountData = pallet_balances::AccountData; + type Block = frame_system::mocking::MockBlock; +} + +#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] +impl pallet_balances::Config for Runtime { + type AccountStore = System; + type Balance = Balance; + type DustRemoval = (); + type ExistentialDeposit = ConstU128<1>; + type RuntimeHoldReason = (); +} + +parameter_types! { + pub const DefaultAnchorDeposit: Balance = 100 * CURRENCY; +} + +impl Config for Runtime { + type AdminOrigin = EnsureRoot; + type Balance = Balance; + type Currency = Balances; + type DefaultAnchorDeposit = DefaultAnchorDeposit; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); + type DocumentId = u128; + type DocumentVersion = u64; +} + +pub fn new_test_ext() -> sp_io::TestExternalities { + System::externalities() +} diff --git a/pallets/anchors-v2/src/tests.rs b/pallets/anchors-v2/src/tests.rs new file mode 100644 index 0000000000..93ec6b0696 --- /dev/null +++ b/pallets/anchors-v2/src/tests.rs @@ -0,0 +1,350 @@ +// Copyright 2021 Centrifuge Foundation (centrifuge.io). +// This file is part of Centrifuge chain project. + +// Centrifuge 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 (see http://www.gnu.org/licenses). + +// Centrifuge 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. + +use frame_support::{assert_err, assert_ok}; +use frame_system::{Account, AccountInfo}; +use pallet_balances::AccountData; +use sp_runtime::testing::H256; + +use super::*; +use crate::mock::{RuntimeEvent as MockEvent, *}; +use frame_support::dispatch::RawOrigin; +use pallet_balances::Error::InsufficientBalance; +use sp_runtime::DispatchError::BadOrigin; + +mod set_anchor { + use super::*; + + #[test] + fn success() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + let deposit = AnchorDeposit::::get(); + + let anchor = AnchorOf:: { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }; + + Balances::force_set_balance(RuntimeOrigin::root(), origin, 10000 * CURRENCY).unwrap(); + + assert_ok!(AnchorsV2::set_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + hash, + )); + assert_eq!( + Anchors::::get((document_id, document_version), origin), + Some(anchor.clone()), + "anchors should be in storage" + ); + assert_eq!( + PersonalAnchors::::get((origin, document_id, document_version)), + Some(anchor), + "personal anchors should be in storage" + ); + + event_exists(Event::::AnchorAdded { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }); + + let account_info: AccountInfo<_, AccountData> = + Account::::get(origin); + + assert_eq!( + account_info.data.reserved, deposit, + "correct amount should be reserved" + ); + }); + } + + #[test] + fn unsigned_origin() { + new_test_ext().execute_with(|| { + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + + assert_err!( + AnchorsV2::set_anchor(RawOrigin::None.into(), document_id, document_version, hash,), + BadOrigin + ); + }); + } + + #[test] + fn anchor_present() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + let deposit = AnchorDeposit::::get(); + + let anchor = AnchorOf:: { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }; + + Anchors::::insert((document_id, document_version), origin, anchor); + + assert_err!( + AnchorsV2::set_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + hash, + ), + Error::::AnchorAlreadyExists + ); + }); + } + + #[test] + fn personal_anchor_present() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + let deposit = AnchorDeposit::::get(); + + let anchor = AnchorOf:: { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }; + + PersonalAnchors::::insert((origin, document_id, document_version), anchor); + + assert_err!( + AnchorsV2::set_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + hash, + ), + Error::::PersonalAnchorAlreadyExists + ); + }); + } + + #[test] + fn insufficient_balance() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + + assert_err!( + AnchorsV2::set_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + hash, + ), + InsufficientBalance:: + ); + }); + } +} + +mod remove_anchor { + use super::*; + + #[test] + fn success() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + let deposit = AnchorDeposit::::get(); + + let anchor = AnchorOf:: { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }; + + Anchors::::insert((document_id, document_version), origin, anchor.clone()); + PersonalAnchors::::insert((origin, document_id, document_version), anchor); + + let account_info = AccountInfo::<_, AccountData> { + nonce: 0, + consumers: 0, + providers: 0, + sufficients: 0, + data: AccountData:: { + free: 0, + reserved: deposit, + frozen: 0, + flags: Default::default(), + }, + }; + + Account::::insert(origin, account_info); + + assert_ok!(AnchorsV2::remove_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + )); + + assert_eq!( + Anchors::::iter_prefix_values((document_id, document_version)).count(), + 0 + ); + assert!( + PersonalAnchors::::get((origin, document_id, document_version)).is_none() + ); + + event_exists(Event::::AnchorRemoved { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }); + + let account_info: AccountInfo<_, AccountData> = + Account::::get(origin); + + assert_eq!(account_info.data.reserved, 0); + }); + } + + #[test] + fn unsigned_origin() { + new_test_ext().execute_with(|| { + let document_id = 123; + let document_version = 456; + + assert_err!( + AnchorsV2::remove_anchor(RawOrigin::None.into(), document_id, document_version), + BadOrigin + ); + }); + } + + #[test] + fn personal_anchor_not_present() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + + assert_err!( + AnchorsV2::remove_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + ), + Error::::PersonalAnchorNotFound + ); + }); + } + + #[test] + fn anchor_not_present() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + let deposit = AnchorDeposit::::get(); + + let anchor = AnchorOf:: { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }; + + PersonalAnchors::::insert((origin, document_id, document_version), anchor); + + assert_err!( + AnchorsV2::remove_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + ), + Error::::AnchorNotFound + ); + }); + } +} + +mod set_deposit { + use super::*; + + #[test] + fn success() { + new_test_ext().execute_with(|| { + let new_deposit = 123; + + assert_ok!(AnchorsV2::set_deposit(RuntimeOrigin::root(), new_deposit)); + assert_eq!(AnchorDeposit::::get(), new_deposit); + + event_exists(Event::::DepositSet { new_deposit }); + }) + } + + #[test] + fn bad_origin() { + new_test_ext().execute_with(|| { + let new_deposit = 123; + assert_err!( + AnchorsV2::set_deposit(RuntimeOrigin::signed(1), new_deposit), + BadOrigin + ); + }) + } +} + +fn event_exists>(e: E) { + let actual: Vec = frame_system::Pallet::::events() + .iter() + .map(|e| e.event.clone()) + .collect(); + + let e: MockEvent = e.into(); + let mut exists = false; + for evt in actual { + if evt == e { + exists = true; + break; + } + } + assert!(exists); +} diff --git a/pallets/anchors-v2/src/weights.rs b/pallets/anchors-v2/src/weights.rs new file mode 100644 index 0000000000..ebff3564b9 --- /dev/null +++ b/pallets/anchors-v2/src/weights.rs @@ -0,0 +1,32 @@ +// Copyright 2021 Centrifuge Foundation (centrifuge.io). +// This file is part of Centrifuge chain project. + +// Centrifuge 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 (see http://www.gnu.org/licenses). + +// Centrifuge 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. + +use frame_support::weights::Weight; + +pub trait WeightInfo { + fn set_anchor() -> Weight; + fn remove_anchor() -> Weight; + fn set_deposit() -> Weight; +} + +impl WeightInfo for () { + fn set_anchor() -> Weight { + Weight::zero() + } + fn remove_anchor() -> Weight { + Weight::zero() + } + fn set_deposit() -> Weight { + Weight::zero() + } +} diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index 440ee5309c..58a3d8065d 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -81,6 +81,7 @@ orml-tokens = { workspace = true } orml-xcm = { workspace = true } orml-xtokens = { workspace = true } pallet-anchors = { workspace = true } +pallet-anchors-v2 = { workspace = true } pallet-aura = { workspace = true } pallet-authorship = { workspace = true } pallet-balances = { workspace = true } @@ -145,299 +146,301 @@ substrate-wasm-builder = { workspace = true } default = ["std"] std = [ - "parity-scale-codec/std", - "hex/std", - "log/std", - "scale-info/std", - "serde/std", - # Substrate related - "sp-api/std", - "sp-runtime/std", - "sp-block-builder/std", - "sp-consensus-aura/std", - "sp-core/std", - "sp-genesis-builder/std", - "sp-inherents/std", - "sp-io/std", - "sp-offchain/std", - "sp-session/std", - "sp-std/std", - "sp-transaction-pool/std", - "sp-version/std", - "sp-staking/std", - "frame-support/std", - "frame-system/std", - "frame-system-rpc-runtime-api/std", - "frame-executive/std", - "frame-try-runtime?/std", - "frame-system-benchmarking?/std", - "frame-benchmarking?/std", - "cumulus-primitives-core/std", - "cumulus-primitives-timestamp/std", - "cumulus-primitives-utility/std", - "cumulus-pallet-session-benchmarking?/std", - "staging-xcm/std", - "staging-xcm-builder/std", - "staging-xcm-executor/std", - "xcm-primitives/std", - "orml-traits/std", - "orml-xcm-support/std", - "fp-rpc/std", - "fp-self-contained/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "polkadot-runtime-common/std", - "polkadot-parachain-primitives/std", - # Locals - "cfg-primitives/std", - "cfg-traits/std", - "cfg-types/std", - "runtime-common/std", - "liquidity-pools-gateway-routers/std", - # Pallet list - "axelar-gateway-precompile/std", - "chainbridge/std", - "cumulus-pallet-aura-ext/std", - "cumulus-pallet-dmp-queue/std", - "cumulus-pallet-parachain-system/std", - "cumulus-pallet-xcm/std", - "cumulus-pallet-xcmp-queue/std", - "orml-asset-registry/std", - "orml-tokens/std", - "orml-xcm/std", - "orml-xtokens/std", - "pallet-anchors/std", - "pallet-aura/std", - "pallet-authorship/std", - "pallet-balances/std", - "pallet-base-fee/std", - "pallet-block-rewards/std", - "pallet-bridge/std", - "pallet-collator-allowlist/std", - "pallet-collator-selection/std", - "pallet-collective/std", - "pallet-democracy/std", - "pallet-elections-phragmen/std", - "pallet-ethereum/std", - "pallet-ethereum-transaction/std", - "pallet-evm/std", - "pallet-evm-chain-id/std", - "pallet-fees/std", - "pallet-foreign-investments/std", - "pallet-identity/std", - "pallet-interest-accrual/std", - "pallet-investments/std", - "pallet-keystore/std", - "pallet-liquidity-pools/std", - "pallet-liquidity-pools-gateway/std", - "pallet-liquidity-rewards/std", - "pallet-loans/std", - "pallet-membership/std", - "pallet-multisig/std", - "pallet-oracle-collection/std", - "pallet-oracle-feed/std", - "pallet-order-book/std", - "pallet-permissions/std", - "pallet-pool-fees/std", - "pallet-pool-registry/std", - "pallet-pool-system/std", - "pallet-preimage/std", - "pallet-proxy/std", - "pallet-remarks/std", - "pallet-restricted-tokens/std", - "pallet-restricted-xtokens/std", - "pallet-rewards/std", - "pallet-scheduler/std", - "pallet-session/std", - "pallet-sudo/std", - "pallet-swaps/std", - "pallet-timestamp/std", - "pallet-token-mux/std", - "pallet-transaction-payment/std", - "pallet-transfer-allowlist/std", - "pallet-treasury/std", - "pallet-uniques/std", - "pallet-utility/std", - "pallet-vesting/std", - "pallet-xcm/std", - "pallet-xcm-transactor/std", - "pallet-message-queue/std", - "staging-parachain-info/std", + "parity-scale-codec/std", + "hex/std", + "log/std", + "scale-info/std", + "serde/std", + # Substrate related + "sp-api/std", + "sp-runtime/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-core/std", + "sp-genesis-builder/std", + "sp-inherents/std", + "sp-io/std", + "sp-offchain/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "sp-staking/std", + "frame-support/std", + "frame-system/std", + "frame-system-rpc-runtime-api/std", + "frame-executive/std", + "frame-try-runtime?/std", + "frame-system-benchmarking?/std", + "frame-benchmarking?/std", + "cumulus-primitives-core/std", + "cumulus-primitives-timestamp/std", + "cumulus-primitives-utility/std", + "cumulus-pallet-session-benchmarking?/std", + "staging-xcm/std", + "staging-xcm-builder/std", + "staging-xcm-executor/std", + "xcm-primitives/std", + "orml-traits/std", + "orml-xcm-support/std", + "fp-rpc/std", + "fp-self-contained/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "polkadot-runtime-common/std", + "polkadot-parachain-primitives/std", + # Locals + "cfg-primitives/std", + "cfg-traits/std", + "cfg-types/std", + "runtime-common/std", + "liquidity-pools-gateway-routers/std", + # Pallet list + "axelar-gateway-precompile/std", + "chainbridge/std", + "cumulus-pallet-aura-ext/std", + "cumulus-pallet-dmp-queue/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "orml-asset-registry/std", + "orml-tokens/std", + "orml-xcm/std", + "orml-xtokens/std", + "pallet-anchors/std", + "pallet-anchors-v2/std", + "pallet-aura/std", + "pallet-authorship/std", + "pallet-balances/std", + "pallet-base-fee/std", + "pallet-block-rewards/std", + "pallet-bridge/std", + "pallet-collator-allowlist/std", + "pallet-collator-selection/std", + "pallet-collective/std", + "pallet-democracy/std", + "pallet-elections-phragmen/std", + "pallet-ethereum/std", + "pallet-ethereum-transaction/std", + "pallet-evm/std", + "pallet-evm-chain-id/std", + "pallet-fees/std", + "pallet-foreign-investments/std", + "pallet-identity/std", + "pallet-interest-accrual/std", + "pallet-investments/std", + "pallet-keystore/std", + "pallet-liquidity-pools/std", + "pallet-liquidity-pools-gateway/std", + "pallet-liquidity-rewards/std", + "pallet-loans/std", + "pallet-membership/std", + "pallet-multisig/std", + "pallet-oracle-collection/std", + "pallet-oracle-feed/std", + "pallet-order-book/std", + "pallet-permissions/std", + "pallet-pool-fees/std", + "pallet-pool-registry/std", + "pallet-pool-system/std", + "pallet-preimage/std", + "pallet-proxy/std", + "pallet-remarks/std", + "pallet-restricted-tokens/std", + "pallet-restricted-xtokens/std", + "pallet-rewards/std", + "pallet-scheduler/std", + "pallet-session/std", + "pallet-sudo/std", + "pallet-swaps/std", + "pallet-timestamp/std", + "pallet-token-mux/std", + "pallet-transaction-payment/std", + "pallet-transfer-allowlist/std", + "pallet-treasury/std", + "pallet-uniques/std", + "pallet-utility/std", + "pallet-vesting/std", + "pallet-xcm/std", + "pallet-xcm-transactor/std", + "pallet-message-queue/std", + "staging-parachain-info/std", ] runtime-benchmarks = [ - # Enabling optional - "frame-system-benchmarking/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", - "cumulus-pallet-session-benchmarking/runtime-benchmarks", - # Substrate related - "sp-runtime/runtime-benchmarks", - "sp-staking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "staging-xcm-builder/runtime-benchmarks", - "staging-xcm-executor/runtime-benchmarks", - "xcm-primitives/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", - "polkadot-parachain-primitives/runtime-benchmarks", - # Locals - "cfg-primitives/runtime-benchmarks", - "cfg-traits/runtime-benchmarks", - "cfg-types/runtime-benchmarks", - "runtime-common/runtime-benchmarks", - "liquidity-pools-gateway-routers/runtime-benchmarks", - # Pallet list - "axelar-gateway-precompile/runtime-benchmarks", - "chainbridge/runtime-benchmarks", - "cumulus-pallet-parachain-system/runtime-benchmarks", - "cumulus-pallet-xcmp-queue/runtime-benchmarks", - "orml-asset-registry/runtime-benchmarks", - "orml-tokens/runtime-benchmarks", - "orml-xtokens/runtime-benchmarks", - "pallet-anchors/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-block-rewards/runtime-benchmarks", - "pallet-bridge/runtime-benchmarks", - "pallet-collator-allowlist/runtime-benchmarks", - "pallet-collator-selection/runtime-benchmarks", - "pallet-collective/runtime-benchmarks", - "pallet-democracy/runtime-benchmarks", - "pallet-elections-phragmen/runtime-benchmarks", - "pallet-ethereum/runtime-benchmarks", - "pallet-ethereum-transaction/runtime-benchmarks", - "pallet-evm/runtime-benchmarks", - "pallet-fees/runtime-benchmarks", - "pallet-foreign-investments/runtime-benchmarks", - "pallet-identity/runtime-benchmarks", - "pallet-interest-accrual/runtime-benchmarks", - "pallet-investments/runtime-benchmarks", - "pallet-keystore/runtime-benchmarks", - "pallet-liquidity-pools/runtime-benchmarks", - "pallet-liquidity-pools-gateway/runtime-benchmarks", - "pallet-liquidity-rewards/runtime-benchmarks", - "pallet-loans/runtime-benchmarks", - "pallet-membership/runtime-benchmarks", - "pallet-multisig/runtime-benchmarks", - "pallet-oracle-collection/runtime-benchmarks", - "pallet-oracle-feed/runtime-benchmarks", - "pallet-order-book/runtime-benchmarks", - "pallet-permissions/runtime-benchmarks", - "pallet-pool-fees/runtime-benchmarks", - "pallet-pool-registry/runtime-benchmarks", - "pallet-pool-system/runtime-benchmarks", - "pallet-preimage/runtime-benchmarks", - "pallet-proxy/runtime-benchmarks", - "pallet-remarks/runtime-benchmarks", - "pallet-restricted-tokens/runtime-benchmarks", - "pallet-restricted-xtokens/runtime-benchmarks", - "pallet-rewards/runtime-benchmarks", - "pallet-scheduler/runtime-benchmarks", - "pallet-sudo/runtime-benchmarks", - "pallet-swaps/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "pallet-token-mux/runtime-benchmarks", - "pallet-transfer-allowlist/runtime-benchmarks", - "pallet-treasury/runtime-benchmarks", - "pallet-uniques/runtime-benchmarks", - "pallet-utility/runtime-benchmarks", - "pallet-vesting/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", - "pallet-xcm-transactor/runtime-benchmarks", - "pallet-message-queue/runtime-benchmarks", + # Enabling optional + "frame-system-benchmarking/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "cumulus-pallet-session-benchmarking/runtime-benchmarks", + # Substrate related + "sp-runtime/runtime-benchmarks", + "sp-staking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "staging-xcm-builder/runtime-benchmarks", + "staging-xcm-executor/runtime-benchmarks", + "xcm-primitives/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", + # Locals + "cfg-primitives/runtime-benchmarks", + "cfg-traits/runtime-benchmarks", + "cfg-types/runtime-benchmarks", + "runtime-common/runtime-benchmarks", + "liquidity-pools-gateway-routers/runtime-benchmarks", + # Pallet list + "axelar-gateway-precompile/runtime-benchmarks", + "chainbridge/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "orml-asset-registry/runtime-benchmarks", + "orml-tokens/runtime-benchmarks", + "orml-xtokens/runtime-benchmarks", + "pallet-anchors/runtime-benchmarks", + "pallet-anchors-v2/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-block-rewards/runtime-benchmarks", + "pallet-bridge/runtime-benchmarks", + "pallet-collator-allowlist/runtime-benchmarks", + "pallet-collator-selection/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "pallet-democracy/runtime-benchmarks", + "pallet-elections-phragmen/runtime-benchmarks", + "pallet-ethereum/runtime-benchmarks", + "pallet-ethereum-transaction/runtime-benchmarks", + "pallet-evm/runtime-benchmarks", + "pallet-fees/runtime-benchmarks", + "pallet-foreign-investments/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-interest-accrual/runtime-benchmarks", + "pallet-investments/runtime-benchmarks", + "pallet-keystore/runtime-benchmarks", + "pallet-liquidity-pools/runtime-benchmarks", + "pallet-liquidity-pools-gateway/runtime-benchmarks", + "pallet-liquidity-rewards/runtime-benchmarks", + "pallet-loans/runtime-benchmarks", + "pallet-membership/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-oracle-collection/runtime-benchmarks", + "pallet-oracle-feed/runtime-benchmarks", + "pallet-order-book/runtime-benchmarks", + "pallet-permissions/runtime-benchmarks", + "pallet-pool-fees/runtime-benchmarks", + "pallet-pool-registry/runtime-benchmarks", + "pallet-pool-system/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-remarks/runtime-benchmarks", + "pallet-restricted-tokens/runtime-benchmarks", + "pallet-restricted-xtokens/runtime-benchmarks", + "pallet-rewards/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-swaps/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-token-mux/runtime-benchmarks", + "pallet-transfer-allowlist/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", + "pallet-uniques/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "pallet-vesting/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "pallet-xcm-transactor/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", ] try-runtime = [ - # Enabling optional - "frame-try-runtime/try-runtime", - # Substrate related - "sp-runtime/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "frame-executive/try-runtime", - "fp-self-contained/try-runtime", - "polkadot-runtime-common/try-runtime", - # Locals - "cfg-primitives/try-runtime", - "cfg-traits/try-runtime", - "cfg-types/try-runtime", - "runtime-common/try-runtime", - "liquidity-pools-gateway-routers/try-runtime", - # Pallet list - "axelar-gateway-precompile/try-runtime", - "chainbridge/try-runtime", - "cumulus-pallet-aura-ext/try-runtime", - "cumulus-pallet-dmp-queue/try-runtime", - "cumulus-pallet-parachain-system/try-runtime", - "cumulus-pallet-xcm/try-runtime", - "cumulus-pallet-xcmp-queue/try-runtime", - "orml-asset-registry/try-runtime", - "orml-tokens/try-runtime", - "orml-xcm/try-runtime", - "orml-xtokens/try-runtime", - "pallet-anchors/try-runtime", - "pallet-aura/try-runtime", - "pallet-authorship/try-runtime", - "pallet-balances/try-runtime", - "pallet-base-fee/try-runtime", - "pallet-block-rewards/try-runtime", - "pallet-bridge/try-runtime", - "pallet-collator-allowlist/try-runtime", - "pallet-collator-selection/try-runtime", - "pallet-collective/try-runtime", - "pallet-democracy/try-runtime", - "pallet-elections-phragmen/try-runtime", - "pallet-ethereum/try-runtime", - "pallet-ethereum-transaction/try-runtime", - "pallet-evm/try-runtime", - "pallet-evm-chain-id/try-runtime", - "pallet-fees/try-runtime", - "pallet-foreign-investments/try-runtime", - "pallet-identity/try-runtime", - "pallet-interest-accrual/try-runtime", - "pallet-investments/try-runtime", - "pallet-keystore/try-runtime", - "pallet-liquidity-pools/try-runtime", - "pallet-liquidity-pools-gateway/try-runtime", - "pallet-liquidity-rewards/try-runtime", - "pallet-loans/try-runtime", - "pallet-membership/try-runtime", - "pallet-multisig/try-runtime", - "pallet-oracle-collection/try-runtime", - "pallet-oracle-feed/try-runtime", - "pallet-order-book/try-runtime", - "pallet-permissions/try-runtime", - "pallet-pool-fees/try-runtime", - "pallet-pool-registry/try-runtime", - "pallet-pool-system/try-runtime", - "pallet-preimage/try-runtime", - "pallet-proxy/try-runtime", - "pallet-remarks/try-runtime", - "pallet-restricted-tokens/try-runtime", - "pallet-restricted-xtokens/try-runtime", - "pallet-rewards/try-runtime", - "pallet-scheduler/try-runtime", - "pallet-session/try-runtime", - "pallet-sudo/try-runtime", - "pallet-swaps/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-token-mux/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-transfer-allowlist/try-runtime", - "pallet-treasury/try-runtime", - "pallet-uniques/try-runtime", - "pallet-utility/try-runtime", - "pallet-vesting/try-runtime", - "pallet-xcm/try-runtime", - "pallet-xcm-transactor/try-runtime", - "pallet-message-queue/try-runtime", - "staging-parachain-info/try-runtime", + # Enabling optional + "frame-try-runtime/try-runtime", + # Substrate related + "sp-runtime/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "frame-executive/try-runtime", + "fp-self-contained/try-runtime", + "polkadot-runtime-common/try-runtime", + # Locals + "cfg-primitives/try-runtime", + "cfg-traits/try-runtime", + "cfg-types/try-runtime", + "runtime-common/try-runtime", + "liquidity-pools-gateway-routers/try-runtime", + # Pallet list + "axelar-gateway-precompile/try-runtime", + "chainbridge/try-runtime", + "cumulus-pallet-aura-ext/try-runtime", + "cumulus-pallet-dmp-queue/try-runtime", + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", + "orml-asset-registry/try-runtime", + "orml-tokens/try-runtime", + "orml-xcm/try-runtime", + "orml-xtokens/try-runtime", + "pallet-anchors/try-runtime", + "pallet-aura/try-runtime", + "pallet-authorship/try-runtime", + "pallet-balances/try-runtime", + "pallet-base-fee/try-runtime", + "pallet-block-rewards/try-runtime", + "pallet-bridge/try-runtime", + "pallet-collator-allowlist/try-runtime", + "pallet-collator-selection/try-runtime", + "pallet-collective/try-runtime", + "pallet-democracy/try-runtime", + "pallet-elections-phragmen/try-runtime", + "pallet-ethereum/try-runtime", + "pallet-ethereum-transaction/try-runtime", + "pallet-evm/try-runtime", + "pallet-evm-chain-id/try-runtime", + "pallet-fees/try-runtime", + "pallet-foreign-investments/try-runtime", + "pallet-identity/try-runtime", + "pallet-interest-accrual/try-runtime", + "pallet-investments/try-runtime", + "pallet-keystore/try-runtime", + "pallet-liquidity-pools/try-runtime", + "pallet-liquidity-pools-gateway/try-runtime", + "pallet-liquidity-rewards/try-runtime", + "pallet-loans/try-runtime", + "pallet-membership/try-runtime", + "pallet-multisig/try-runtime", + "pallet-oracle-collection/try-runtime", + "pallet-oracle-feed/try-runtime", + "pallet-order-book/try-runtime", + "pallet-permissions/try-runtime", + "pallet-pool-fees/try-runtime", + "pallet-pool-registry/try-runtime", + "pallet-pool-system/try-runtime", + "pallet-preimage/try-runtime", + "pallet-proxy/try-runtime", + "pallet-remarks/try-runtime", + "pallet-restricted-tokens/try-runtime", + "pallet-restricted-xtokens/try-runtime", + "pallet-rewards/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-session/try-runtime", + "pallet-sudo/try-runtime", + "pallet-swaps/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-token-mux/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-transfer-allowlist/try-runtime", + "pallet-treasury/try-runtime", + "pallet-uniques/try-runtime", + "pallet-utility/try-runtime", + "pallet-vesting/try-runtime", + "pallet-xcm/try-runtime", + "pallet-xcm-transactor/try-runtime", + "pallet-message-queue/try-runtime", + "staging-parachain-info/try-runtime", ] # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. on-chain-release-build = [ - "sp-api/disable-logging", - "runtime-common/on-chain-release-build", + "sp-api/disable-logging", + "runtime-common/on-chain-release-build", ] # Used by integration testing diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index cc8d52cc88..58c611518e 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -1643,6 +1643,21 @@ impl pallet_keystore::pallet::Config for Runtime { type WeightInfo = weights::pallet_keystore::WeightInfo; } +parameter_types! { + pub const DefaultAnchorDeposit: Balance = 100 * CFG; +} + +impl pallet_anchors_v2::pallet::Config for Runtime { + type AdminOrigin = EnsureRootOr; + type Balance = Balance; + type Currency = Balances; + type DefaultAnchorDeposit = DefaultAnchorDeposit; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = weights::pallet_anchors_v2::WeightInfo; + type DocumentId = u128; + type DocumentVersion = u64; +} + parameter_types! { pub const MaxOutstandingCollects: u32 = 10; } @@ -2127,6 +2142,7 @@ construct_runtime!( ForeignInvestments: pallet_foreign_investments::{Pallet, Storage, Event} = 117, OraclePriceFeed: pallet_oracle_feed::{Pallet, Call, Storage, Event} = 118, OraclePriceCollection: pallet_oracle_collection::{Pallet, Call, Storage, Event} = 119, + AnchorsV2: pallet_anchors_v2::{Pallet, Call, Storage, Event} = 130, // XCM XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 120, @@ -2831,6 +2847,7 @@ mod benches { [pallet_preimage, Preimage] [pallet_fees, Fees] [pallet_anchors, Anchor] + [pallet_anchors_v2, AnchorsV2] [pallet_block_rewards, BlockRewards] [pallet_collator_allowlist, CollatorAllowlist] [pallet_collator_selection, CollatorSelection] diff --git a/runtime/development/src/weights/mod.rs b/runtime/development/src/weights/mod.rs index 659c89486d..857944649e 100644 --- a/runtime/development/src/weights/mod.rs +++ b/runtime/development/src/weights/mod.rs @@ -12,6 +12,7 @@ pub mod cumulus_pallet_xcmp_queue; pub mod frame_system; pub mod pallet_anchors; +pub mod pallet_anchors_v2; pub mod pallet_balances; pub mod pallet_block_rewards; pub mod pallet_collator_allowlist; diff --git a/runtime/development/src/weights/pallet_anchors_v2.rs b/runtime/development/src/weights/pallet_anchors_v2.rs new file mode 100644 index 0000000000..0fe663c15d --- /dev/null +++ b/runtime/development/src/weights/pallet_anchors_v2.rs @@ -0,0 +1,51 @@ + +//! Autogenerated weights for `pallet_anchors_v2` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-06-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner`, CPU: `AMD EPYC 7763 64-Core Processor` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("centrifuge-local")`, DB CACHE: 1024 + +// Executed Command: +// target/release/centrifuge-chain +// benchmark +// pallet +// --chain=centrifuge-local +// --steps=50 +// --repeat=20 +// --pallet=pallet_anchors_v2 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=/tmp/runtime/centrifuge/src/weights/pallet_keystore.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_anchors_v2`. +pub struct WeightInfo(PhantomData); +impl pallet_anchors_v2::WeightInfo for WeightInfo { + fn set_anchor() -> Weight { + Weight::from_parts(7_645_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + + fn remove_anchor() -> Weight { + Weight::from_parts(7_645_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + + fn set_deposit() -> Weight { + Weight::from_parts(7_645_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} From 0266be84f441c3de914ba5eccfa041efaddab6d9 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Tue, 18 Jun 2024 14:43:56 +0200 Subject: [PATCH 02/12] taplo: Fix --- Cargo.toml | 94 +++--- pallets/anchors-v2/Cargo.toml | 30 +- runtime/development/Cargo.toml | 566 ++++++++++++++++----------------- 3 files changed, 345 insertions(+), 345 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e31443d878..abc49e02e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,49 +1,49 @@ [workspace] resolver = "2" members = [ - "node", - "libs/mocks", - "libs/primitives", - "libs/test-utils", - "libs/traits", - "libs/types", - "libs/utils", - "pallets/anchors", - "pallets/anchors-v2", - "pallets/bridge", - "pallets/block-rewards", - "pallets/collator-allowlist", - "pallets/ethereum-transaction", - "pallets/fees", - "pallets/foreign-investments", - "pallets/interest-accrual", - "pallets/investments", - "pallets/keystore", - "pallets/liquidity-pools", - "pallets/liquidity-pools-gateway", - "pallets/liquidity-pools-gateway/axelar-gateway-precompile", - "pallets/liquidity-pools-gateway/routers", - "pallets/liquidity-rewards", - "pallets/loans", - "pallets/oracle-feed", - "pallets/oracle-collection", - "pallets/order-book", - "pallets/permissions", - "pallets/pool-fees", - "pallets/pool-system", - "pallets/pool-registry", - "pallets/restricted-tokens", - "pallets/restricted-xtokens", - "pallets/rewards", - "pallets/swaps", - "pallets/token-mux", - "pallets/transfer-allowlist", - "runtime/altair", - "runtime/centrifuge", - "runtime/development", - "runtime/common", - "runtime/integration-tests", - "runtime/integration-tests/procedural", + "node", + "libs/mocks", + "libs/primitives", + "libs/test-utils", + "libs/traits", + "libs/types", + "libs/utils", + "pallets/anchors", + "pallets/anchors-v2", + "pallets/bridge", + "pallets/block-rewards", + "pallets/collator-allowlist", + "pallets/ethereum-transaction", + "pallets/fees", + "pallets/foreign-investments", + "pallets/interest-accrual", + "pallets/investments", + "pallets/keystore", + "pallets/liquidity-pools", + "pallets/liquidity-pools-gateway", + "pallets/liquidity-pools-gateway/axelar-gateway-precompile", + "pallets/liquidity-pools-gateway/routers", + "pallets/liquidity-rewards", + "pallets/loans", + "pallets/oracle-feed", + "pallets/oracle-collection", + "pallets/order-book", + "pallets/permissions", + "pallets/pool-fees", + "pallets/pool-system", + "pallets/pool-registry", + "pallets/restricted-tokens", + "pallets/restricted-xtokens", + "pallets/rewards", + "pallets/swaps", + "pallets/token-mux", + "pallets/transfer-allowlist", + "runtime/altair", + "runtime/centrifuge", + "runtime/development", + "runtime/common", + "runtime/integration-tests", + "runtime/integration-tests/procedural", ] [workspace.package] @@ -174,7 +174,7 @@ sp-trie = { git = "https://github.com/paritytech/polkadot-sdk", default-features frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } frame-executive = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } frame-support = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, features = [ - "tuples-96", + "tuples-96", ], branch = "release-polkadot-v1.7.2" } # Check when tuples-96 can be removed frame-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } frame-system-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } @@ -283,14 +283,14 @@ pallet-remarks = { git = "https://github.com/foss3/runtime-pallet-library", bran # Moonbeam fork of polkadot-evm/frontier fp-rpc = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2" } fp-self-contained = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2", features = [ - "serde", + "serde", ] } pallet-base-fee = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2" } pallet-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2", features = [ - "forbid-evm-reentrancy", + "forbid-evm-reentrancy", ] } pallet-evm = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2", features = [ - "forbid-evm-reentrancy", + "forbid-evm-reentrancy", ] } pallet-evm-chain-id = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2" } pallet-evm-precompile-blake2 = { git = "https://github.com/moonbeam-foundation/frontier", default-features = false, branch = "moonbeam-polkadot-v1.7.2" } diff --git a/pallets/anchors-v2/Cargo.toml b/pallets/anchors-v2/Cargo.toml index 861126747e..c259105cb3 100644 --- a/pallets/anchors-v2/Cargo.toml +++ b/pallets/anchors-v2/Cargo.toml @@ -19,9 +19,9 @@ scale-info = { workspace = true } frame-benchmarking = { workspace = true, optional = true } frame-support = { workspace = true } frame-system = { workspace = true } +sp-core = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } -sp-core = { workspace = true } [dev-dependencies] pallet-balances = { workspace = true, default-features = true } @@ -31,22 +31,22 @@ sp-io = { workspace = true, default-features = true } [features] default = ["std"] std = [ - "parity-scale-codec/std", - "scale-info/std", - "frame-support/std", - "frame-system/std", - "sp-runtime/std", - "sp-std/std", - "frame-benchmarking/std", + "parity-scale-codec/std", + "scale-info/std", + "frame-support/std", + "frame-system/std", + "sp-runtime/std", + "sp-std/std", + "frame-benchmarking/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "sp-runtime/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "sp-runtime/try-runtime", ] diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index 58a3d8065d..712344bc86 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -146,301 +146,301 @@ substrate-wasm-builder = { workspace = true } default = ["std"] std = [ - "parity-scale-codec/std", - "hex/std", - "log/std", - "scale-info/std", - "serde/std", - # Substrate related - "sp-api/std", - "sp-runtime/std", - "sp-block-builder/std", - "sp-consensus-aura/std", - "sp-core/std", - "sp-genesis-builder/std", - "sp-inherents/std", - "sp-io/std", - "sp-offchain/std", - "sp-session/std", - "sp-std/std", - "sp-transaction-pool/std", - "sp-version/std", - "sp-staking/std", - "frame-support/std", - "frame-system/std", - "frame-system-rpc-runtime-api/std", - "frame-executive/std", - "frame-try-runtime?/std", - "frame-system-benchmarking?/std", - "frame-benchmarking?/std", - "cumulus-primitives-core/std", - "cumulus-primitives-timestamp/std", - "cumulus-primitives-utility/std", - "cumulus-pallet-session-benchmarking?/std", - "staging-xcm/std", - "staging-xcm-builder/std", - "staging-xcm-executor/std", - "xcm-primitives/std", - "orml-traits/std", - "orml-xcm-support/std", - "fp-rpc/std", - "fp-self-contained/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "polkadot-runtime-common/std", - "polkadot-parachain-primitives/std", - # Locals - "cfg-primitives/std", - "cfg-traits/std", - "cfg-types/std", - "runtime-common/std", - "liquidity-pools-gateway-routers/std", - # Pallet list - "axelar-gateway-precompile/std", - "chainbridge/std", - "cumulus-pallet-aura-ext/std", - "cumulus-pallet-dmp-queue/std", - "cumulus-pallet-parachain-system/std", - "cumulus-pallet-xcm/std", - "cumulus-pallet-xcmp-queue/std", - "orml-asset-registry/std", - "orml-tokens/std", - "orml-xcm/std", - "orml-xtokens/std", - "pallet-anchors/std", - "pallet-anchors-v2/std", - "pallet-aura/std", - "pallet-authorship/std", - "pallet-balances/std", - "pallet-base-fee/std", - "pallet-block-rewards/std", - "pallet-bridge/std", - "pallet-collator-allowlist/std", - "pallet-collator-selection/std", - "pallet-collective/std", - "pallet-democracy/std", - "pallet-elections-phragmen/std", - "pallet-ethereum/std", - "pallet-ethereum-transaction/std", - "pallet-evm/std", - "pallet-evm-chain-id/std", - "pallet-fees/std", - "pallet-foreign-investments/std", - "pallet-identity/std", - "pallet-interest-accrual/std", - "pallet-investments/std", - "pallet-keystore/std", - "pallet-liquidity-pools/std", - "pallet-liquidity-pools-gateway/std", - "pallet-liquidity-rewards/std", - "pallet-loans/std", - "pallet-membership/std", - "pallet-multisig/std", - "pallet-oracle-collection/std", - "pallet-oracle-feed/std", - "pallet-order-book/std", - "pallet-permissions/std", - "pallet-pool-fees/std", - "pallet-pool-registry/std", - "pallet-pool-system/std", - "pallet-preimage/std", - "pallet-proxy/std", - "pallet-remarks/std", - "pallet-restricted-tokens/std", - "pallet-restricted-xtokens/std", - "pallet-rewards/std", - "pallet-scheduler/std", - "pallet-session/std", - "pallet-sudo/std", - "pallet-swaps/std", - "pallet-timestamp/std", - "pallet-token-mux/std", - "pallet-transaction-payment/std", - "pallet-transfer-allowlist/std", - "pallet-treasury/std", - "pallet-uniques/std", - "pallet-utility/std", - "pallet-vesting/std", - "pallet-xcm/std", - "pallet-xcm-transactor/std", - "pallet-message-queue/std", - "staging-parachain-info/std", + "parity-scale-codec/std", + "hex/std", + "log/std", + "scale-info/std", + "serde/std", + # Substrate related + "sp-api/std", + "sp-runtime/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-core/std", + "sp-genesis-builder/std", + "sp-inherents/std", + "sp-io/std", + "sp-offchain/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "sp-staking/std", + "frame-support/std", + "frame-system/std", + "frame-system-rpc-runtime-api/std", + "frame-executive/std", + "frame-try-runtime?/std", + "frame-system-benchmarking?/std", + "frame-benchmarking?/std", + "cumulus-primitives-core/std", + "cumulus-primitives-timestamp/std", + "cumulus-primitives-utility/std", + "cumulus-pallet-session-benchmarking?/std", + "staging-xcm/std", + "staging-xcm-builder/std", + "staging-xcm-executor/std", + "xcm-primitives/std", + "orml-traits/std", + "orml-xcm-support/std", + "fp-rpc/std", + "fp-self-contained/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "polkadot-runtime-common/std", + "polkadot-parachain-primitives/std", + # Locals + "cfg-primitives/std", + "cfg-traits/std", + "cfg-types/std", + "runtime-common/std", + "liquidity-pools-gateway-routers/std", + # Pallet list + "axelar-gateway-precompile/std", + "chainbridge/std", + "cumulus-pallet-aura-ext/std", + "cumulus-pallet-dmp-queue/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "orml-asset-registry/std", + "orml-tokens/std", + "orml-xcm/std", + "orml-xtokens/std", + "pallet-anchors/std", + "pallet-anchors-v2/std", + "pallet-aura/std", + "pallet-authorship/std", + "pallet-balances/std", + "pallet-base-fee/std", + "pallet-block-rewards/std", + "pallet-bridge/std", + "pallet-collator-allowlist/std", + "pallet-collator-selection/std", + "pallet-collective/std", + "pallet-democracy/std", + "pallet-elections-phragmen/std", + "pallet-ethereum/std", + "pallet-ethereum-transaction/std", + "pallet-evm/std", + "pallet-evm-chain-id/std", + "pallet-fees/std", + "pallet-foreign-investments/std", + "pallet-identity/std", + "pallet-interest-accrual/std", + "pallet-investments/std", + "pallet-keystore/std", + "pallet-liquidity-pools/std", + "pallet-liquidity-pools-gateway/std", + "pallet-liquidity-rewards/std", + "pallet-loans/std", + "pallet-membership/std", + "pallet-multisig/std", + "pallet-oracle-collection/std", + "pallet-oracle-feed/std", + "pallet-order-book/std", + "pallet-permissions/std", + "pallet-pool-fees/std", + "pallet-pool-registry/std", + "pallet-pool-system/std", + "pallet-preimage/std", + "pallet-proxy/std", + "pallet-remarks/std", + "pallet-restricted-tokens/std", + "pallet-restricted-xtokens/std", + "pallet-rewards/std", + "pallet-scheduler/std", + "pallet-session/std", + "pallet-sudo/std", + "pallet-swaps/std", + "pallet-timestamp/std", + "pallet-token-mux/std", + "pallet-transaction-payment/std", + "pallet-transfer-allowlist/std", + "pallet-treasury/std", + "pallet-uniques/std", + "pallet-utility/std", + "pallet-vesting/std", + "pallet-xcm/std", + "pallet-xcm-transactor/std", + "pallet-message-queue/std", + "staging-parachain-info/std", ] runtime-benchmarks = [ - # Enabling optional - "frame-system-benchmarking/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", - "cumulus-pallet-session-benchmarking/runtime-benchmarks", - # Substrate related - "sp-runtime/runtime-benchmarks", - "sp-staking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "staging-xcm-builder/runtime-benchmarks", - "staging-xcm-executor/runtime-benchmarks", - "xcm-primitives/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", - "polkadot-parachain-primitives/runtime-benchmarks", - # Locals - "cfg-primitives/runtime-benchmarks", - "cfg-traits/runtime-benchmarks", - "cfg-types/runtime-benchmarks", - "runtime-common/runtime-benchmarks", - "liquidity-pools-gateway-routers/runtime-benchmarks", - # Pallet list - "axelar-gateway-precompile/runtime-benchmarks", - "chainbridge/runtime-benchmarks", - "cumulus-pallet-parachain-system/runtime-benchmarks", - "cumulus-pallet-xcmp-queue/runtime-benchmarks", - "orml-asset-registry/runtime-benchmarks", - "orml-tokens/runtime-benchmarks", - "orml-xtokens/runtime-benchmarks", - "pallet-anchors/runtime-benchmarks", - "pallet-anchors-v2/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-block-rewards/runtime-benchmarks", - "pallet-bridge/runtime-benchmarks", - "pallet-collator-allowlist/runtime-benchmarks", - "pallet-collator-selection/runtime-benchmarks", - "pallet-collective/runtime-benchmarks", - "pallet-democracy/runtime-benchmarks", - "pallet-elections-phragmen/runtime-benchmarks", - "pallet-ethereum/runtime-benchmarks", - "pallet-ethereum-transaction/runtime-benchmarks", - "pallet-evm/runtime-benchmarks", - "pallet-fees/runtime-benchmarks", - "pallet-foreign-investments/runtime-benchmarks", - "pallet-identity/runtime-benchmarks", - "pallet-interest-accrual/runtime-benchmarks", - "pallet-investments/runtime-benchmarks", - "pallet-keystore/runtime-benchmarks", - "pallet-liquidity-pools/runtime-benchmarks", - "pallet-liquidity-pools-gateway/runtime-benchmarks", - "pallet-liquidity-rewards/runtime-benchmarks", - "pallet-loans/runtime-benchmarks", - "pallet-membership/runtime-benchmarks", - "pallet-multisig/runtime-benchmarks", - "pallet-oracle-collection/runtime-benchmarks", - "pallet-oracle-feed/runtime-benchmarks", - "pallet-order-book/runtime-benchmarks", - "pallet-permissions/runtime-benchmarks", - "pallet-pool-fees/runtime-benchmarks", - "pallet-pool-registry/runtime-benchmarks", - "pallet-pool-system/runtime-benchmarks", - "pallet-preimage/runtime-benchmarks", - "pallet-proxy/runtime-benchmarks", - "pallet-remarks/runtime-benchmarks", - "pallet-restricted-tokens/runtime-benchmarks", - "pallet-restricted-xtokens/runtime-benchmarks", - "pallet-rewards/runtime-benchmarks", - "pallet-scheduler/runtime-benchmarks", - "pallet-sudo/runtime-benchmarks", - "pallet-swaps/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "pallet-token-mux/runtime-benchmarks", - "pallet-transfer-allowlist/runtime-benchmarks", - "pallet-treasury/runtime-benchmarks", - "pallet-uniques/runtime-benchmarks", - "pallet-utility/runtime-benchmarks", - "pallet-vesting/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", - "pallet-xcm-transactor/runtime-benchmarks", - "pallet-message-queue/runtime-benchmarks", + # Enabling optional + "frame-system-benchmarking/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "cumulus-pallet-session-benchmarking/runtime-benchmarks", + # Substrate related + "sp-runtime/runtime-benchmarks", + "sp-staking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "staging-xcm-builder/runtime-benchmarks", + "staging-xcm-executor/runtime-benchmarks", + "xcm-primitives/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", + # Locals + "cfg-primitives/runtime-benchmarks", + "cfg-traits/runtime-benchmarks", + "cfg-types/runtime-benchmarks", + "runtime-common/runtime-benchmarks", + "liquidity-pools-gateway-routers/runtime-benchmarks", + # Pallet list + "axelar-gateway-precompile/runtime-benchmarks", + "chainbridge/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "orml-asset-registry/runtime-benchmarks", + "orml-tokens/runtime-benchmarks", + "orml-xtokens/runtime-benchmarks", + "pallet-anchors/runtime-benchmarks", + "pallet-anchors-v2/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-block-rewards/runtime-benchmarks", + "pallet-bridge/runtime-benchmarks", + "pallet-collator-allowlist/runtime-benchmarks", + "pallet-collator-selection/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "pallet-democracy/runtime-benchmarks", + "pallet-elections-phragmen/runtime-benchmarks", + "pallet-ethereum/runtime-benchmarks", + "pallet-ethereum-transaction/runtime-benchmarks", + "pallet-evm/runtime-benchmarks", + "pallet-fees/runtime-benchmarks", + "pallet-foreign-investments/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-interest-accrual/runtime-benchmarks", + "pallet-investments/runtime-benchmarks", + "pallet-keystore/runtime-benchmarks", + "pallet-liquidity-pools/runtime-benchmarks", + "pallet-liquidity-pools-gateway/runtime-benchmarks", + "pallet-liquidity-rewards/runtime-benchmarks", + "pallet-loans/runtime-benchmarks", + "pallet-membership/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-oracle-collection/runtime-benchmarks", + "pallet-oracle-feed/runtime-benchmarks", + "pallet-order-book/runtime-benchmarks", + "pallet-permissions/runtime-benchmarks", + "pallet-pool-fees/runtime-benchmarks", + "pallet-pool-registry/runtime-benchmarks", + "pallet-pool-system/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-remarks/runtime-benchmarks", + "pallet-restricted-tokens/runtime-benchmarks", + "pallet-restricted-xtokens/runtime-benchmarks", + "pallet-rewards/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-swaps/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-token-mux/runtime-benchmarks", + "pallet-transfer-allowlist/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", + "pallet-uniques/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "pallet-vesting/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "pallet-xcm-transactor/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", ] try-runtime = [ - # Enabling optional - "frame-try-runtime/try-runtime", - # Substrate related - "sp-runtime/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "frame-executive/try-runtime", - "fp-self-contained/try-runtime", - "polkadot-runtime-common/try-runtime", - # Locals - "cfg-primitives/try-runtime", - "cfg-traits/try-runtime", - "cfg-types/try-runtime", - "runtime-common/try-runtime", - "liquidity-pools-gateway-routers/try-runtime", - # Pallet list - "axelar-gateway-precompile/try-runtime", - "chainbridge/try-runtime", - "cumulus-pallet-aura-ext/try-runtime", - "cumulus-pallet-dmp-queue/try-runtime", - "cumulus-pallet-parachain-system/try-runtime", - "cumulus-pallet-xcm/try-runtime", - "cumulus-pallet-xcmp-queue/try-runtime", - "orml-asset-registry/try-runtime", - "orml-tokens/try-runtime", - "orml-xcm/try-runtime", - "orml-xtokens/try-runtime", - "pallet-anchors/try-runtime", - "pallet-aura/try-runtime", - "pallet-authorship/try-runtime", - "pallet-balances/try-runtime", - "pallet-base-fee/try-runtime", - "pallet-block-rewards/try-runtime", - "pallet-bridge/try-runtime", - "pallet-collator-allowlist/try-runtime", - "pallet-collator-selection/try-runtime", - "pallet-collective/try-runtime", - "pallet-democracy/try-runtime", - "pallet-elections-phragmen/try-runtime", - "pallet-ethereum/try-runtime", - "pallet-ethereum-transaction/try-runtime", - "pallet-evm/try-runtime", - "pallet-evm-chain-id/try-runtime", - "pallet-fees/try-runtime", - "pallet-foreign-investments/try-runtime", - "pallet-identity/try-runtime", - "pallet-interest-accrual/try-runtime", - "pallet-investments/try-runtime", - "pallet-keystore/try-runtime", - "pallet-liquidity-pools/try-runtime", - "pallet-liquidity-pools-gateway/try-runtime", - "pallet-liquidity-rewards/try-runtime", - "pallet-loans/try-runtime", - "pallet-membership/try-runtime", - "pallet-multisig/try-runtime", - "pallet-oracle-collection/try-runtime", - "pallet-oracle-feed/try-runtime", - "pallet-order-book/try-runtime", - "pallet-permissions/try-runtime", - "pallet-pool-fees/try-runtime", - "pallet-pool-registry/try-runtime", - "pallet-pool-system/try-runtime", - "pallet-preimage/try-runtime", - "pallet-proxy/try-runtime", - "pallet-remarks/try-runtime", - "pallet-restricted-tokens/try-runtime", - "pallet-restricted-xtokens/try-runtime", - "pallet-rewards/try-runtime", - "pallet-scheduler/try-runtime", - "pallet-session/try-runtime", - "pallet-sudo/try-runtime", - "pallet-swaps/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-token-mux/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-transfer-allowlist/try-runtime", - "pallet-treasury/try-runtime", - "pallet-uniques/try-runtime", - "pallet-utility/try-runtime", - "pallet-vesting/try-runtime", - "pallet-xcm/try-runtime", - "pallet-xcm-transactor/try-runtime", - "pallet-message-queue/try-runtime", - "staging-parachain-info/try-runtime", + # Enabling optional + "frame-try-runtime/try-runtime", + # Substrate related + "sp-runtime/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "frame-executive/try-runtime", + "fp-self-contained/try-runtime", + "polkadot-runtime-common/try-runtime", + # Locals + "cfg-primitives/try-runtime", + "cfg-traits/try-runtime", + "cfg-types/try-runtime", + "runtime-common/try-runtime", + "liquidity-pools-gateway-routers/try-runtime", + # Pallet list + "axelar-gateway-precompile/try-runtime", + "chainbridge/try-runtime", + "cumulus-pallet-aura-ext/try-runtime", + "cumulus-pallet-dmp-queue/try-runtime", + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", + "orml-asset-registry/try-runtime", + "orml-tokens/try-runtime", + "orml-xcm/try-runtime", + "orml-xtokens/try-runtime", + "pallet-anchors/try-runtime", + "pallet-aura/try-runtime", + "pallet-authorship/try-runtime", + "pallet-balances/try-runtime", + "pallet-base-fee/try-runtime", + "pallet-block-rewards/try-runtime", + "pallet-bridge/try-runtime", + "pallet-collator-allowlist/try-runtime", + "pallet-collator-selection/try-runtime", + "pallet-collective/try-runtime", + "pallet-democracy/try-runtime", + "pallet-elections-phragmen/try-runtime", + "pallet-ethereum/try-runtime", + "pallet-ethereum-transaction/try-runtime", + "pallet-evm/try-runtime", + "pallet-evm-chain-id/try-runtime", + "pallet-fees/try-runtime", + "pallet-foreign-investments/try-runtime", + "pallet-identity/try-runtime", + "pallet-interest-accrual/try-runtime", + "pallet-investments/try-runtime", + "pallet-keystore/try-runtime", + "pallet-liquidity-pools/try-runtime", + "pallet-liquidity-pools-gateway/try-runtime", + "pallet-liquidity-rewards/try-runtime", + "pallet-loans/try-runtime", + "pallet-membership/try-runtime", + "pallet-multisig/try-runtime", + "pallet-oracle-collection/try-runtime", + "pallet-oracle-feed/try-runtime", + "pallet-order-book/try-runtime", + "pallet-permissions/try-runtime", + "pallet-pool-fees/try-runtime", + "pallet-pool-registry/try-runtime", + "pallet-pool-system/try-runtime", + "pallet-preimage/try-runtime", + "pallet-proxy/try-runtime", + "pallet-remarks/try-runtime", + "pallet-restricted-tokens/try-runtime", + "pallet-restricted-xtokens/try-runtime", + "pallet-rewards/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-session/try-runtime", + "pallet-sudo/try-runtime", + "pallet-swaps/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-token-mux/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-transfer-allowlist/try-runtime", + "pallet-treasury/try-runtime", + "pallet-uniques/try-runtime", + "pallet-utility/try-runtime", + "pallet-vesting/try-runtime", + "pallet-xcm/try-runtime", + "pallet-xcm-transactor/try-runtime", + "pallet-message-queue/try-runtime", + "staging-parachain-info/try-runtime", ] # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. on-chain-release-build = [ - "sp-api/disable-logging", - "runtime-common/on-chain-release-build", + "sp-api/disable-logging", + "runtime-common/on-chain-release-build", ] # Used by integration testing From 7f7153d27c9d5bcf677d77f9e1c5deecd780c605 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:01:33 +0200 Subject: [PATCH 03/12] pallet: Fix imports --- pallets/anchors-v2/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/anchors-v2/src/lib.rs b/pallets/anchors-v2/src/lib.rs index 4e88d9a382..d62ed91e5e 100644 --- a/pallets/anchors-v2/src/lib.rs +++ b/pallets/anchors-v2/src/lib.rs @@ -13,9 +13,10 @@ #![cfg_attr(not(feature = "std"), no_std)] use frame_support::pallet_prelude::*; -pub use pallet::*; +use frame_support::traits::ReservableCurrency; +use frame_system::pallet_prelude::*; use scale_info::TypeInfo; -pub use weights::*; +use sp_runtime::{traits::AtLeast32BitUnsigned, FixedPointOperand}; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; @@ -26,6 +27,9 @@ mod tests; pub mod weights; +pub use pallet::*; +pub use weights::*; + #[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct Anchor { account_id: AccountId, @@ -45,10 +49,6 @@ pub type AnchorOf = Anchor< #[frame_support::pallet] pub mod pallet { - use frame_support::traits::ReservableCurrency; - use frame_system::pallet_prelude::*; - use sp_runtime::{traits::AtLeast32BitUnsigned, FixedPointOperand}; - use super::*; #[pallet::config] From 354701eb972b246d4bbfc205f64400ff345e6263 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:30:44 +0200 Subject: [PATCH 04/12] pallet: Use benchmarking v2, drop AnchorOf --- pallets/anchors-v2/src/benchmarking.rs | 74 ++++++++++++++------------ pallets/anchors-v2/src/lib.rs | 43 +++++---------- pallets/anchors-v2/src/mock.rs | 4 +- pallets/anchors-v2/src/tests.rs | 48 ++++++----------- pallets/anchors-v2/src/weights.rs | 4 +- runtime/development/src/lib.rs | 2 + 6 files changed, 75 insertions(+), 100 deletions(-) diff --git a/pallets/anchors-v2/src/benchmarking.rs b/pallets/anchors-v2/src/benchmarking.rs index 993bd76b45..977dee1081 100644 --- a/pallets/anchors-v2/src/benchmarking.rs +++ b/pallets/anchors-v2/src/benchmarking.rs @@ -11,56 +11,56 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite}; +use frame_benchmarking::{account, impl_benchmark_test_suite, v2::*}; use frame_support::traits::Currency; use frame_system::RawOrigin; use parity_scale_codec::EncodeLike; -use scale_info::prelude::format; use sp_core::H256; -use sp_runtime::traits::Hash; use super::*; -benchmarks! { - where_clause { +#[benchmarks( where T: Config, T::AccountId: EncodeLike<::AccountId>, - } +)] +mod benchmarks { + use super::*; - set_anchor { + #[benchmark] + fn set_anchor() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("acc_0", 0, 0); let document_id = 123; let document_version = 456; - let hash = H256::random(); - let deposit = AnchorDeposit::::get(); + let hash = H256::from_low_u64_be(1); - let anchor = AnchorOf:: { - account_id: caller.clone(), + let _ = T::Currency::deposit_creating( + &caller.clone().into(), + T::Currency::minimum_balance() + T::DefaultAnchorDeposit::get(), + ); + + #[extrinsic_call] + set_anchor( + RawOrigin::Signed(caller), document_id, document_version, hash, - deposit, - }; + ); - let _ = T::Currency::deposit_creating(&caller.clone().into(), T::Currency::minimum_balance() + T::DefaultAnchorDeposit::get()); - let origin = RawOrigin::Signed(caller.clone()); - }: set_anchor(origin.clone(), document_id, document_version, hash) - verify { - assert_eq!(Anchors::::get((document_id, document_version), caller.clone()), Some(anchor.clone())); - assert_eq!(PersonalAnchors::::get((caller, document_id, document_version)), Some(anchor)); + Ok(()) } - remove_anchor { + #[benchmark] + fn remove_anchor() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("acc_0", 0, 0); let document_id = 123; let document_version = 456; - let hash = H256::random(); + let hash = H256::from_low_u64_be(1); let deposit = AnchorDeposit::::get(); - let anchor = AnchorOf:: { + let anchor = Anchor:: { account_id: caller.clone(), document_id, document_version, @@ -68,22 +68,28 @@ benchmarks! { deposit, }; - Anchors::::insert((document_id, document_version), caller.clone(), anchor.clone()); + Anchors::::insert( + (document_id, document_version), + caller.clone(), + anchor.clone(), + ); PersonalAnchors::::insert((caller.clone(), document_id, document_version), anchor); - let origin = RawOrigin::Signed(caller.clone()); - }: remove_anchor(origin.clone(), document_id, document_version) - verify { - assert_eq!(Anchors::::get((document_id, document_version), caller.clone()), None); - assert_eq!(PersonalAnchors::::get((caller, document_id, document_version)), None); + #[extrinsic_call] + remove_anchor(RawOrigin::Signed(caller), document_id, document_version); + + Ok(()) } - set_deposit { + #[benchmark] + fn set_deposit_value() -> Result<(), BenchmarkError> { let deposit = 2 * T::DefaultAnchorDeposit::get(); - }: set_deposit(RawOrigin::Root, deposit) - verify { - assert_eq!(AnchorDeposit::::get(), 2 * T::DefaultAnchorDeposit::get()); + + #[extrinsic_call] + set_deposit_value(RawOrigin::Root, deposit); + + Ok(()) } -} -impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Runtime,); + impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Runtime); +} diff --git a/pallets/anchors-v2/src/lib.rs b/pallets/anchors-v2/src/lib.rs index d62ed91e5e..6f2deb6aed 100644 --- a/pallets/anchors-v2/src/lib.rs +++ b/pallets/anchors-v2/src/lib.rs @@ -31,22 +31,15 @@ pub use pallet::*; pub use weights::*; #[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] -pub struct Anchor { - account_id: AccountId, - document_id: DocumentId, - document_version: DocumentVersion, - hash: Hash, - deposit: Balance, +#[scale_info(skip_type_params(T))] +pub struct Anchor { + account_id: T::AccountId, + document_id: T::DocumentId, + document_version: T::DocumentVersion, + hash: T::Hash, + deposit: T::Balance, } -pub type AnchorOf = Anchor< - ::AccountId, - ::DocumentId, - ::DocumentVersion, - ::Hash, - ::Balance, ->; - #[frame_support::pallet] pub mod pallet { use super::*; @@ -55,17 +48,7 @@ pub mod pallet { pub trait Config: frame_system::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type Balance: Member - + Parameter - + AtLeast32BitUnsigned - + Default - + Copy - + MaxEncodedLen - + FixedPointOperand - + From - + From - + TypeInfo - + TryInto; + type Balance: frame_support::traits::tokens::Balance; type Currency: ReservableCurrency; @@ -116,7 +99,7 @@ pub mod pallet { (T::DocumentId, T::DocumentVersion), Blake2_256, T::AccountId, - AnchorOf, + Anchor, >; /// Storage for document anchors specific to an account. @@ -129,7 +112,7 @@ pub mod pallet { NMapKey, NMapKey, ), - AnchorOf, + Anchor, OptionQuery, >; @@ -206,7 +189,7 @@ pub mod pallet { T::Currency::reserve(&account_id, deposit)?; - let anchor = AnchorOf:: { + let anchor = Anchor:: { account_id: account_id.clone(), document_id, document_version, @@ -272,9 +255,9 @@ pub mod pallet { } /// Set a new anchor deposit. - #[pallet::weight(T::WeightInfo::set_deposit())] + #[pallet::weight(T::WeightInfo::set_deposit_value())] #[pallet::call_index(2)] - pub fn set_deposit(origin: OriginFor, new_deposit: T::Balance) -> DispatchResult { + pub fn set_deposit_value(origin: OriginFor, new_deposit: T::Balance) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; >::set(new_deposit); diff --git a/pallets/anchors-v2/src/mock.rs b/pallets/anchors-v2/src/mock.rs index e4139ce3f8..db4a92bf6b 100644 --- a/pallets/anchors-v2/src/mock.rs +++ b/pallets/anchors-v2/src/mock.rs @@ -11,8 +11,8 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -use frame_support::{derive_impl, parameter_types, traits::EitherOfDiverse}; -use frame_system::{EnsureRoot, EnsureSigned}; +use frame_support::{derive_impl, parameter_types}; +use frame_system::EnsureRoot; use sp_runtime::traits::ConstU128; use crate::{self as pallet_anchors_v2, Config}; diff --git a/pallets/anchors-v2/src/tests.rs b/pallets/anchors-v2/src/tests.rs index 93ec6b0696..868f62f6db 100644 --- a/pallets/anchors-v2/src/tests.rs +++ b/pallets/anchors-v2/src/tests.rs @@ -12,8 +12,6 @@ // GNU General Public License for more details. use frame_support::{assert_err, assert_ok}; -use frame_system::{Account, AccountInfo}; -use pallet_balances::AccountData; use sp_runtime::testing::H256; use super::*; @@ -34,7 +32,7 @@ mod set_anchor { let hash = H256::random(); let deposit = AnchorDeposit::::get(); - let anchor = AnchorOf:: { + let anchor = Anchor:: { account_id: origin, document_id, document_version, @@ -42,7 +40,7 @@ mod set_anchor { deposit, }; - Balances::force_set_balance(RuntimeOrigin::root(), origin, 10000 * CURRENCY).unwrap(); + Balances::force_set_balance(RuntimeOrigin::root(), origin, deposit * 2).unwrap(); assert_ok!(AnchorsV2::set_anchor( RuntimeOrigin::signed(origin), @@ -69,11 +67,9 @@ mod set_anchor { deposit, }); - let account_info: AccountInfo<_, AccountData> = - Account::::get(origin); - assert_eq!( - account_info.data.reserved, deposit, + Balances::reserved_balance(&origin), + deposit, "correct amount should be reserved" ); }); @@ -102,7 +98,7 @@ mod set_anchor { let hash = H256::random(); let deposit = AnchorDeposit::::get(); - let anchor = AnchorOf:: { + let anchor = Anchor:: { account_id: origin, document_id, document_version, @@ -133,7 +129,7 @@ mod set_anchor { let hash = H256::random(); let deposit = AnchorDeposit::::get(); - let anchor = AnchorOf:: { + let anchor = Anchor:: { account_id: origin, document_id, document_version, @@ -188,7 +184,7 @@ mod remove_anchor { let hash = H256::random(); let deposit = AnchorDeposit::::get(); - let anchor = AnchorOf:: { + let anchor = Anchor:: { account_id: origin, document_id, document_version, @@ -199,20 +195,8 @@ mod remove_anchor { Anchors::::insert((document_id, document_version), origin, anchor.clone()); PersonalAnchors::::insert((origin, document_id, document_version), anchor); - let account_info = AccountInfo::<_, AccountData> { - nonce: 0, - consumers: 0, - providers: 0, - sufficients: 0, - data: AccountData:: { - free: 0, - reserved: deposit, - frozen: 0, - flags: Default::default(), - }, - }; - - Account::::insert(origin, account_info); + Balances::force_set_balance(RuntimeOrigin::root(), origin, deposit * 2).unwrap(); + assert_ok!(Balances::reserve(&origin, deposit)); assert_ok!(AnchorsV2::remove_anchor( RuntimeOrigin::signed(origin), @@ -236,10 +220,7 @@ mod remove_anchor { deposit, }); - let account_info: AccountInfo<_, AccountData> = - Account::::get(origin); - - assert_eq!(account_info.data.reserved, 0); + assert_eq!(Balances::reserved_balance(&origin), 0); }); } @@ -283,7 +264,7 @@ mod remove_anchor { let hash = H256::random(); let deposit = AnchorDeposit::::get(); - let anchor = AnchorOf:: { + let anchor = Anchor:: { account_id: origin, document_id, document_version, @@ -313,7 +294,10 @@ mod set_deposit { new_test_ext().execute_with(|| { let new_deposit = 123; - assert_ok!(AnchorsV2::set_deposit(RuntimeOrigin::root(), new_deposit)); + assert_ok!(AnchorsV2::set_deposit_value( + RuntimeOrigin::root(), + new_deposit + )); assert_eq!(AnchorDeposit::::get(), new_deposit); event_exists(Event::::DepositSet { new_deposit }); @@ -325,7 +309,7 @@ mod set_deposit { new_test_ext().execute_with(|| { let new_deposit = 123; assert_err!( - AnchorsV2::set_deposit(RuntimeOrigin::signed(1), new_deposit), + AnchorsV2::set_deposit_value(RuntimeOrigin::signed(1), new_deposit), BadOrigin ); }) diff --git a/pallets/anchors-v2/src/weights.rs b/pallets/anchors-v2/src/weights.rs index ebff3564b9..215c0be0b8 100644 --- a/pallets/anchors-v2/src/weights.rs +++ b/pallets/anchors-v2/src/weights.rs @@ -16,7 +16,7 @@ use frame_support::weights::Weight; pub trait WeightInfo { fn set_anchor() -> Weight; fn remove_anchor() -> Weight; - fn set_deposit() -> Weight; + fn set_deposit_value() -> Weight; } impl WeightInfo for () { @@ -26,7 +26,7 @@ impl WeightInfo for () { fn remove_anchor() -> Weight { Weight::zero() } - fn set_deposit() -> Weight { + fn set_deposit_value() -> Weight { Weight::zero() } } diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 58c611518e..d22be31b28 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -2142,6 +2142,8 @@ construct_runtime!( ForeignInvestments: pallet_foreign_investments::{Pallet, Storage, Event} = 117, OraclePriceFeed: pallet_oracle_feed::{Pallet, Call, Storage, Event} = 118, OraclePriceCollection: pallet_oracle_collection::{Pallet, Call, Storage, Event} = 119, + + // our pallets part 2 AnchorsV2: pallet_anchors_v2::{Pallet, Call, Storage, Event} = 130, // XCM From d3ded71c85a328e05f47f5be6f1ffe37d49dfe2d Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:35:25 +0200 Subject: [PATCH 05/12] pallet: Drop associated types for document id and version --- pallets/anchors-v2/src/benchmarking.rs | 2 +- pallets/anchors-v2/src/lib.rs | 60 ++++++-------------------- pallets/anchors-v2/src/mock.rs | 2 - 3 files changed, 15 insertions(+), 49 deletions(-) diff --git a/pallets/anchors-v2/src/benchmarking.rs b/pallets/anchors-v2/src/benchmarking.rs index 977dee1081..04faf740a1 100644 --- a/pallets/anchors-v2/src/benchmarking.rs +++ b/pallets/anchors-v2/src/benchmarking.rs @@ -21,7 +21,7 @@ use super::*; #[benchmarks( where - T: Config, + T: Config, T::AccountId: EncodeLike<::AccountId>, )] mod benchmarks { diff --git a/pallets/anchors-v2/src/lib.rs b/pallets/anchors-v2/src/lib.rs index 6f2deb6aed..211345448a 100644 --- a/pallets/anchors-v2/src/lib.rs +++ b/pallets/anchors-v2/src/lib.rs @@ -16,7 +16,6 @@ use frame_support::pallet_prelude::*; use frame_support::traits::ReservableCurrency; use frame_system::pallet_prelude::*; use scale_info::TypeInfo; -use sp_runtime::{traits::AtLeast32BitUnsigned, FixedPointOperand}; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; @@ -34,8 +33,8 @@ pub use weights::*; #[scale_info(skip_type_params(T))] pub struct Anchor { account_id: T::AccountId, - document_id: T::DocumentId, - document_version: T::DocumentVersion, + document_id: u128, + document_version: u64, hash: T::Hash, deposit: T::Balance, } @@ -55,31 +54,6 @@ pub mod pallet { /// Default deposit that will be taken when adding an anchor. type DefaultAnchorDeposit: Get; - /// The type used to identify a document. - type DocumentId: Member - + Parameter - + AtLeast32BitUnsigned - + Default - + Copy - + MaxEncodedLen - + FixedPointOperand - + From - + From - + TypeInfo - + TryInto; - - /// The type used to version a document. - type DocumentVersion: Member - + Parameter - + AtLeast32BitUnsigned - + Default - + Copy - + MaxEncodedLen - + FixedPointOperand - + From - + TypeInfo - + TryInto; - /// Origin used when setting a deposit. type AdminOrigin: EnsureOrigin; @@ -93,14 +67,8 @@ pub mod pallet { /// Storage for document anchors. #[pallet::storage] #[pallet::getter(fn get_anchor)] - pub type Anchors = StorageDoubleMap< - _, - Blake2_256, - (T::DocumentId, T::DocumentVersion), - Blake2_256, - T::AccountId, - Anchor, - >; + pub type Anchors = + StorageDoubleMap<_, Blake2_256, (u128, u64), Blake2_256, T::AccountId, Anchor>; /// Storage for document anchors specific to an account. #[pallet::storage] @@ -109,8 +77,8 @@ pub mod pallet { _, ( NMapKey, - NMapKey, - NMapKey, + NMapKey, + NMapKey, ), Anchor, OptionQuery, @@ -128,16 +96,16 @@ pub mod pallet { /// An anchor was added. AnchorAdded { account_id: T::AccountId, - document_id: T::DocumentId, - document_version: T::DocumentVersion, + document_id: u128, + document_version: u64, hash: T::Hash, deposit: T::Balance, }, /// An anchor was removed. AnchorRemoved { account_id: T::AccountId, - document_id: T::DocumentId, - document_version: T::DocumentVersion, + document_id: u128, + document_version: u64, hash: T::Hash, deposit: T::Balance, }, @@ -167,8 +135,8 @@ pub mod pallet { #[pallet::call_index(0)] pub fn set_anchor( origin: OriginFor, - document_id: T::DocumentId, - document_version: T::DocumentVersion, + document_id: u128, + document_version: u64, hash: T::Hash, ) -> DispatchResult { let account_id = ensure_signed(origin)?; @@ -224,8 +192,8 @@ pub mod pallet { #[pallet::call_index(1)] pub fn remove_anchor( origin: OriginFor, - document_id: T::DocumentId, - document_version: T::DocumentVersion, + document_id: u128, + document_version: u64, ) -> DispatchResult { let account_id = ensure_signed(origin)?; diff --git a/pallets/anchors-v2/src/mock.rs b/pallets/anchors-v2/src/mock.rs index db4a92bf6b..c23fbc0428 100644 --- a/pallets/anchors-v2/src/mock.rs +++ b/pallets/anchors-v2/src/mock.rs @@ -55,8 +55,6 @@ impl Config for Runtime { type DefaultAnchorDeposit = DefaultAnchorDeposit; type RuntimeEvent = RuntimeEvent; type WeightInfo = (); - type DocumentId = u128; - type DocumentVersion = u64; } pub fn new_test_ext() -> sp_io::TestExternalities { From 3510e990008f8c551a3c26be998a352a5bf9387f Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Thu, 20 Jun 2024 21:12:25 +0200 Subject: [PATCH 06/12] pallet: Fix and add more tests --- pallets/anchors-v2/src/benchmarking.rs | 13 ++- pallets/anchors-v2/src/lib.rs | 105 +++++++++++++++++------ pallets/anchors-v2/src/mock.rs | 1 + pallets/anchors-v2/src/tests.rs | 114 +++++++++++++++++-------- 4 files changed, 162 insertions(+), 71 deletions(-) diff --git a/pallets/anchors-v2/src/benchmarking.rs b/pallets/anchors-v2/src/benchmarking.rs index 04faf740a1..b97763454f 100644 --- a/pallets/anchors-v2/src/benchmarking.rs +++ b/pallets/anchors-v2/src/benchmarking.rs @@ -21,7 +21,7 @@ use super::*; #[benchmarks( where - T: Config, + T: Config, T::AccountId: EncodeLike<::AccountId>, )] mod benchmarks { @@ -59,8 +59,10 @@ mod benchmarks { let document_version = 456; let hash = H256::from_low_u64_be(1); let deposit = AnchorDeposit::::get(); + let anchor_id = 1; let anchor = Anchor:: { + anchor_id, account_id: caller.clone(), document_id, document_version, @@ -68,12 +70,9 @@ mod benchmarks { deposit, }; - Anchors::::insert( - (document_id, document_version), - caller.clone(), - anchor.clone(), - ); - PersonalAnchors::::insert((caller.clone(), document_id, document_version), anchor); + Anchors::::insert(anchor_id, anchor.clone()); + DocumentAnchors::::insert((document_id, document_version), anchor_id); + PersonalAnchors::::insert(caller.clone(), (document_id, document_version), anchor_id); #[extrinsic_call] remove_anchor(RawOrigin::Signed(caller), document_id, document_version); diff --git a/pallets/anchors-v2/src/lib.rs b/pallets/anchors-v2/src/lib.rs index 211345448a..32280cbdcf 100644 --- a/pallets/anchors-v2/src/lib.rs +++ b/pallets/anchors-v2/src/lib.rs @@ -16,6 +16,7 @@ use frame_support::pallet_prelude::*; use frame_support::traits::ReservableCurrency; use frame_system::pallet_prelude::*; use scale_info::TypeInfo; +use sp_runtime::traits::{AtLeast32BitUnsigned, EnsureAdd}; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; @@ -29,12 +30,19 @@ pub mod weights; pub use pallet::*; pub use weights::*; +/// Document ID type. +pub type DocumentId = u128; + +/// Document version type. +pub type DocumentVersion = u64; + #[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] #[scale_info(skip_type_params(T))] pub struct Anchor { + anchor_id: T::AnchorIdNonce, account_id: T::AccountId, - document_id: u128, - document_version: u64, + document_id: DocumentId, + document_version: DocumentVersion, hash: T::Hash, deposit: T::Balance, } @@ -42,6 +50,7 @@ pub struct Anchor { #[frame_support::pallet] pub mod pallet { use super::*; + use sp_runtime::traits::{EnsureAddAssign, One}; #[pallet::config] pub trait Config: frame_system::Config { @@ -57,6 +66,17 @@ pub mod pallet { /// Origin used when setting a deposit. type AdminOrigin: EnsureOrigin; + /// Type used for AnchorId. AnchorIdNonce ensures each + /// Anchor is unique. AnchorIdNonce is incremented with each new anchor. + type AnchorIdNonce: Parameter + + Member + + AtLeast32BitUnsigned + + Default + + Copy + + EnsureAdd + + MaybeSerializeDeserialize + + MaxEncodedLen; + /// Weight information. type WeightInfo: WeightInfo; } @@ -64,24 +84,31 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(_); - /// Storage for document anchors. + /// Stores AnchorIdNonce and ensure that each anchor has an unique ID. + #[pallet::storage] + pub type AnchorIdNonceStore = StorageValue<_, T::AnchorIdNonce, ValueQuery>; + + /// Storage for anchors. #[pallet::storage] #[pallet::getter(fn get_anchor)] - pub type Anchors = - StorageDoubleMap<_, Blake2_256, (u128, u64), Blake2_256, T::AccountId, Anchor>; + pub type Anchors = StorageMap<_, Blake2_256, T::AnchorIdNonce, Anchor>; + + /// Storage for document anchors. + #[pallet::storage] + #[pallet::getter(fn get_document_anchor)] + pub type DocumentAnchors = + StorageMap<_, Blake2_256, (DocumentId, DocumentVersion), T::AnchorIdNonce>; /// Storage for document anchors specific to an account. #[pallet::storage] #[pallet::getter(fn get_personal_anchor)] - pub type PersonalAnchors = StorageNMap< + pub type PersonalAnchors = StorageDoubleMap< _, - ( - NMapKey, - NMapKey, - NMapKey, - ), - Anchor, - OptionQuery, + Blake2_256, + T::AccountId, + Blake2_256, + (DocumentId, DocumentVersion), + T::AnchorIdNonce, >; /// Stores the current deposit that will be taken when storing an anchor. @@ -95,6 +122,7 @@ pub mod pallet { pub enum Event { /// An anchor was added. AnchorAdded { + anchor_id: T::AnchorIdNonce, account_id: T::AccountId, document_id: u128, document_version: u64, @@ -103,6 +131,7 @@ pub mod pallet { }, /// An anchor was removed. AnchorRemoved { + anchor_id: T::AnchorIdNonce, account_id: T::AccountId, document_id: u128, document_version: u64, @@ -118,12 +147,18 @@ pub mod pallet { /// The anchor already exists. AnchorAlreadyExists, + /// The document anchor already exists. + DocumentAnchorAlreadyExists, + /// The personal anchor already exists. PersonalAnchorAlreadyExists, /// The anchor was not found in storage. AnchorNotFound, + /// The document anchor was not found in storage. + DocumentAnchorNotFound, + /// The personal anchor was not found in storage. PersonalAnchorNotFound, } @@ -141,14 +176,23 @@ pub mod pallet { ) -> DispatchResult { let account_id = ensure_signed(origin)?; - // Only one anchor should be stored for a particular document ID and version. + let anchor_id = AnchorIdNonceStore::::try_mutate(|n| { + n.ensure_add_assign(One::one())?; + Ok::<_, DispatchError>(*n) + })?; + ensure!( - Anchors::::iter_prefix_values((document_id, document_version)).count() == 0, + Anchors::::get(anchor_id).is_none(), Error::::AnchorAlreadyExists ); + // Only one anchor should be stored for a particular document ID and version. + ensure!( + DocumentAnchors::::get((document_id, document_version)).is_none(), + Error::::DocumentAnchorAlreadyExists + ); ensure!( - PersonalAnchors::::get((account_id.clone(), document_id, document_version)) + PersonalAnchors::::get(account_id.clone(), (document_id, document_version)) .is_none(), Error::::PersonalAnchorAlreadyExists ); @@ -158,6 +202,7 @@ pub mod pallet { T::Currency::reserve(&account_id, deposit)?; let anchor = Anchor:: { + anchor_id, account_id: account_id.clone(), document_id, document_version, @@ -165,18 +210,18 @@ pub mod pallet { deposit, }; - Anchors::::insert( - (document_id, document_version), - account_id.clone(), - anchor.clone(), - ); + Anchors::::insert(anchor_id, anchor); + + DocumentAnchors::::insert((document_id, document_version), anchor_id); PersonalAnchors::::insert( - (account_id.clone(), document_id, document_version), - anchor, + account_id.clone(), + (document_id, document_version), + anchor_id, ); Self::deposit_event(Event::AnchorAdded { + anchor_id, account_id, document_id, document_version, @@ -198,20 +243,24 @@ pub mod pallet { let account_id = ensure_signed(origin)?; ensure!( - PersonalAnchors::::get((account_id.clone(), document_id, document_version)) + PersonalAnchors::::get(account_id.clone(), (document_id, document_version)) .is_some(), Error::::PersonalAnchorNotFound ); - let anchor = Anchors::::get((document_id, document_version), account_id.clone()) - .ok_or(Error::::AnchorNotFound)?; + let anchor_id = DocumentAnchors::::get((document_id, document_version)) + .ok_or(Error::::DocumentAnchorNotFound)?; + + let anchor = Anchors::::get(anchor_id).ok_or(Error::::AnchorNotFound)?; T::Currency::unreserve(&account_id, anchor.deposit); - Anchors::::remove((document_id, document_version), account_id.clone()); - PersonalAnchors::::remove((account_id.clone(), document_id, document_version)); + Anchors::::remove(anchor_id); + DocumentAnchors::::remove((document_id, document_version)); + PersonalAnchors::::remove(account_id.clone(), (document_id, document_version)); Self::deposit_event(Event::AnchorRemoved { + anchor_id, account_id, document_id, document_version, diff --git a/pallets/anchors-v2/src/mock.rs b/pallets/anchors-v2/src/mock.rs index c23fbc0428..9b95829f84 100644 --- a/pallets/anchors-v2/src/mock.rs +++ b/pallets/anchors-v2/src/mock.rs @@ -55,6 +55,7 @@ impl Config for Runtime { type DefaultAnchorDeposit = DefaultAnchorDeposit; type RuntimeEvent = RuntimeEvent; type WeightInfo = (); + type AnchorIdNonce = u128; } pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/pallets/anchors-v2/src/tests.rs b/pallets/anchors-v2/src/tests.rs index 868f62f6db..3949583cfd 100644 --- a/pallets/anchors-v2/src/tests.rs +++ b/pallets/anchors-v2/src/tests.rs @@ -31,8 +31,10 @@ mod set_anchor { let document_version = 456; let hash = H256::random(); let deposit = AnchorDeposit::::get(); + let anchor_id = 1; let anchor = Anchor:: { + anchor_id, account_id: origin, document_id, document_version, @@ -48,18 +50,25 @@ mod set_anchor { document_version, hash, )); + assert_eq!( - Anchors::::get((document_id, document_version), origin), + Anchors::::get(anchor_id), Some(anchor.clone()), - "anchors should be in storage" + "anchor should be in storage" + ); + assert_eq!( + DocumentAnchors::::get((document_id, document_version)), + Some(anchor_id), + "document anchor should be in storage" ); assert_eq!( - PersonalAnchors::::get((origin, document_id, document_version)), - Some(anchor), - "personal anchors should be in storage" + PersonalAnchors::::get(origin, (document_id, document_version)), + Some(anchor_id), + "personal anchor should be in storage" ); event_exists(Event::::AnchorAdded { + anchor_id, account_id: origin, document_id, document_version, @@ -97,8 +106,10 @@ mod set_anchor { let document_version = 456; let hash = H256::random(); let deposit = AnchorDeposit::::get(); + let anchor_id = 1; let anchor = Anchor:: { + anchor_id, account_id: origin, document_id, document_version, @@ -106,7 +117,7 @@ mod set_anchor { deposit, }; - Anchors::::insert((document_id, document_version), origin, anchor); + Anchors::::insert(anchor_id, anchor); assert_err!( AnchorsV2::set_anchor( @@ -121,23 +132,38 @@ mod set_anchor { } #[test] - fn personal_anchor_present() { + fn document_anchor_present() { new_test_ext().execute_with(|| { let origin: u64 = 1; let document_id = 123; let document_version = 456; let hash = H256::random(); - let deposit = AnchorDeposit::::get(); + let anchor_id = 1; - let anchor = Anchor:: { - account_id: origin, - document_id, - document_version, - hash, - deposit, - }; + DocumentAnchors::::insert((document_id, document_version), anchor_id); + + assert_err!( + AnchorsV2::set_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + hash, + ), + Error::::DocumentAnchorAlreadyExists + ); + }); + } + + #[test] + fn personal_anchor_present() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + let anchor_id = 1; - PersonalAnchors::::insert((origin, document_id, document_version), anchor); + PersonalAnchors::::insert(origin, (document_id, document_version), anchor_id); assert_err!( AnchorsV2::set_anchor( @@ -183,8 +209,10 @@ mod remove_anchor { let document_version = 456; let hash = H256::random(); let deposit = AnchorDeposit::::get(); + let anchor_id = 1; let anchor = Anchor:: { + anchor_id, account_id: origin, document_id, document_version, @@ -192,8 +220,9 @@ mod remove_anchor { deposit, }; - Anchors::::insert((document_id, document_version), origin, anchor.clone()); - PersonalAnchors::::insert((origin, document_id, document_version), anchor); + Anchors::::insert(anchor_id, anchor); + DocumentAnchors::::insert((document_id, document_version), anchor_id); + PersonalAnchors::::insert(origin, (document_id, document_version), anchor_id); Balances::force_set_balance(RuntimeOrigin::root(), origin, deposit * 2).unwrap(); assert_ok!(Balances::reserve(&origin, deposit)); @@ -204,15 +233,14 @@ mod remove_anchor { document_version, )); - assert_eq!( - Anchors::::iter_prefix_values((document_id, document_version)).count(), - 0 - ); + assert!(Anchors::::get(anchor_id).is_none(),); + assert!(DocumentAnchors::::get((document_id, document_version)).is_none()); assert!( - PersonalAnchors::::get((origin, document_id, document_version)).is_none() + PersonalAnchors::::get(origin, (document_id, document_version)).is_none() ); event_exists(Event::::AnchorRemoved { + anchor_id, account_id: origin, document_id, document_version, @@ -238,7 +266,7 @@ mod remove_anchor { } #[test] - fn personal_anchor_not_present() { + fn personal_anchor_not_found() { new_test_ext().execute_with(|| { let origin: u64 = 1; let document_id = 123; @@ -256,23 +284,36 @@ mod remove_anchor { } #[test] - fn anchor_not_present() { + fn document_anchor_not_found() { new_test_ext().execute_with(|| { let origin: u64 = 1; let document_id = 123; let document_version = 456; - let hash = H256::random(); - let deposit = AnchorDeposit::::get(); + let anchor_id = 1; - let anchor = Anchor:: { - account_id: origin, - document_id, - document_version, - hash, - deposit, - }; + PersonalAnchors::::insert(origin, (document_id, document_version), anchor_id); + + assert_err!( + AnchorsV2::remove_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + ), + Error::::DocumentAnchorNotFound + ); + }); + } - PersonalAnchors::::insert((origin, document_id, document_version), anchor); + #[test] + fn anchor_not_found() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let anchor_id = 1; + + PersonalAnchors::::insert(origin, (document_id, document_version), anchor_id); + DocumentAnchors::::insert((document_id, document_version), anchor_id); assert_err!( AnchorsV2::remove_anchor( @@ -292,7 +333,8 @@ mod set_deposit { #[test] fn success() { new_test_ext().execute_with(|| { - let new_deposit = 123; + let deposit = AnchorDeposit::::get(); + let new_deposit = deposit * 2; assert_ok!(AnchorsV2::set_deposit_value( RuntimeOrigin::root(), From 7f3e4670743ab19cda09958c08afa7e5a9acb6d0 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Thu, 20 Jun 2024 21:15:42 +0200 Subject: [PATCH 07/12] docs: Add Anchors V2 pallet to README. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 66258e0772..93e4959484 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ Centrifuge is the infrastructure that facilitates the decentralized financing of On top of the [Substrate FRAME](https://docs.substrate.io/reference/frame-pallets/) framework, Centrifuge Chain is composed of custom pallets which can be found inside the `pallets` folder. The following list gives a brief overview, and links to the corresponding documentation: - [**anchors**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/anchors) ([docs](https://reference.centrifuge.io/pallet_anchors/index.html)): Storing hashes of documents on-chain. The documents are stored in the Private Off-chain Data (POD) node network. +- +- [**anchors-v2**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/anchors-v2) ([docs](https://reference.centrifuge.io/pallet_anchors_v2/index.html)): Second version of the pallet used to store document hashes on-chain. - [**block-rewards**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/block-rewards) ([docs](https://reference.centrifuge.io/pallet_block_rewards/index.html)): Provides means of configuring and distributing block rewards to collators as well as the annual treasury inflation. From 96bcc0ef5faeee7fc6ad35145317e85a8108d27a Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Thu, 20 Jun 2024 21:22:03 +0200 Subject: [PATCH 08/12] runtime: Add nonce type, fix weight impl. --- runtime/development/src/lib.rs | 3 +-- runtime/development/src/weights/pallet_anchors_v2.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index d22be31b28..69d6b9ead2 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -1654,8 +1654,7 @@ impl pallet_anchors_v2::pallet::Config for Runtime { type DefaultAnchorDeposit = DefaultAnchorDeposit; type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_anchors_v2::WeightInfo; - type DocumentId = u128; - type DocumentVersion = u64; + type AnchorIdNonce = u128; } parameter_types! { diff --git a/runtime/development/src/weights/pallet_anchors_v2.rs b/runtime/development/src/weights/pallet_anchors_v2.rs index 0fe663c15d..78afe2dd5e 100644 --- a/runtime/development/src/weights/pallet_anchors_v2.rs +++ b/runtime/development/src/weights/pallet_anchors_v2.rs @@ -43,7 +43,7 @@ impl pallet_anchors_v2::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().writes(1)) } - fn set_deposit() -> Weight { + fn set_deposit_value() -> Weight { Weight::from_parts(7_645_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) From 3b0ac0c081195ee2435e7538097307f47a298a86 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Thu, 20 Jun 2024 21:26:27 +0200 Subject: [PATCH 09/12] pallet: Move import --- pallets/anchors-v2/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/anchors-v2/src/lib.rs b/pallets/anchors-v2/src/lib.rs index 32280cbdcf..a699bf56f2 100644 --- a/pallets/anchors-v2/src/lib.rs +++ b/pallets/anchors-v2/src/lib.rs @@ -17,6 +17,7 @@ use frame_support::traits::ReservableCurrency; use frame_system::pallet_prelude::*; use scale_info::TypeInfo; use sp_runtime::traits::{AtLeast32BitUnsigned, EnsureAdd}; +use sp_runtime::traits::{EnsureAddAssign, One}; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; @@ -50,7 +51,6 @@ pub struct Anchor { #[frame_support::pallet] pub mod pallet { use super::*; - use sp_runtime::traits::{EnsureAddAssign, One}; #[pallet::config] pub trait Config: frame_system::Config { From aaa370113438810301dbfdab5c05e45cb9f1576c Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Thu, 20 Jun 2024 21:51:56 +0200 Subject: [PATCH 10/12] pallet: Remove AnchorIdNonce --- pallets/anchors-v2/src/benchmarking.rs | 9 +-- pallets/anchors-v2/src/lib.rs | 81 +++++------------------- pallets/anchors-v2/src/mock.rs | 1 - pallets/anchors-v2/src/tests.rs | 87 ++++---------------------- runtime/development/src/lib.rs | 1 - 5 files changed, 30 insertions(+), 149 deletions(-) diff --git a/pallets/anchors-v2/src/benchmarking.rs b/pallets/anchors-v2/src/benchmarking.rs index b97763454f..af9eea12ff 100644 --- a/pallets/anchors-v2/src/benchmarking.rs +++ b/pallets/anchors-v2/src/benchmarking.rs @@ -21,7 +21,7 @@ use super::*; #[benchmarks( where - T: Config, + T: Config, T::AccountId: EncodeLike<::AccountId>, )] mod benchmarks { @@ -59,10 +59,8 @@ mod benchmarks { let document_version = 456; let hash = H256::from_low_u64_be(1); let deposit = AnchorDeposit::::get(); - let anchor_id = 1; let anchor = Anchor:: { - anchor_id, account_id: caller.clone(), document_id, document_version, @@ -70,9 +68,8 @@ mod benchmarks { deposit, }; - Anchors::::insert(anchor_id, anchor.clone()); - DocumentAnchors::::insert((document_id, document_version), anchor_id); - PersonalAnchors::::insert(caller.clone(), (document_id, document_version), anchor_id); + Anchors::::insert((document_id, document_version), anchor); + PersonalAnchors::::insert(caller.clone(), (document_id, document_version), ()); #[extrinsic_call] remove_anchor(RawOrigin::Signed(caller), document_id, document_version); diff --git a/pallets/anchors-v2/src/lib.rs b/pallets/anchors-v2/src/lib.rs index a699bf56f2..d698f4c966 100644 --- a/pallets/anchors-v2/src/lib.rs +++ b/pallets/anchors-v2/src/lib.rs @@ -16,8 +16,9 @@ use frame_support::pallet_prelude::*; use frame_support::traits::ReservableCurrency; use frame_system::pallet_prelude::*; use scale_info::TypeInfo; -use sp_runtime::traits::{AtLeast32BitUnsigned, EnsureAdd}; -use sp_runtime::traits::{EnsureAddAssign, One}; + +pub use pallet::*; +pub use weights::*; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; @@ -28,9 +29,6 @@ mod tests; pub mod weights; -pub use pallet::*; -pub use weights::*; - /// Document ID type. pub type DocumentId = u128; @@ -40,7 +38,6 @@ pub type DocumentVersion = u64; #[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] #[scale_info(skip_type_params(T))] pub struct Anchor { - anchor_id: T::AnchorIdNonce, account_id: T::AccountId, document_id: DocumentId, document_version: DocumentVersion, @@ -66,17 +63,6 @@ pub mod pallet { /// Origin used when setting a deposit. type AdminOrigin: EnsureOrigin; - /// Type used for AnchorId. AnchorIdNonce ensures each - /// Anchor is unique. AnchorIdNonce is incremented with each new anchor. - type AnchorIdNonce: Parameter - + Member - + AtLeast32BitUnsigned - + Default - + Copy - + EnsureAdd - + MaybeSerializeDeserialize - + MaxEncodedLen; - /// Weight information. type WeightInfo: WeightInfo; } @@ -84,20 +70,11 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(_); - /// Stores AnchorIdNonce and ensure that each anchor has an unique ID. - #[pallet::storage] - pub type AnchorIdNonceStore = StorageValue<_, T::AnchorIdNonce, ValueQuery>; - - /// Storage for anchors. - #[pallet::storage] - #[pallet::getter(fn get_anchor)] - pub type Anchors = StorageMap<_, Blake2_256, T::AnchorIdNonce, Anchor>; - /// Storage for document anchors. #[pallet::storage] - #[pallet::getter(fn get_document_anchor)] - pub type DocumentAnchors = - StorageMap<_, Blake2_256, (DocumentId, DocumentVersion), T::AnchorIdNonce>; + #[pallet::getter(fn get_anchor)] + pub type Anchors = + StorageMap<_, Blake2_256, (DocumentId, DocumentVersion), Anchor>; /// Storage for document anchors specific to an account. #[pallet::storage] @@ -108,7 +85,7 @@ pub mod pallet { T::AccountId, Blake2_256, (DocumentId, DocumentVersion), - T::AnchorIdNonce, + (), >; /// Stores the current deposit that will be taken when storing an anchor. @@ -122,7 +99,6 @@ pub mod pallet { pub enum Event { /// An anchor was added. AnchorAdded { - anchor_id: T::AnchorIdNonce, account_id: T::AccountId, document_id: u128, document_version: u64, @@ -131,7 +107,6 @@ pub mod pallet { }, /// An anchor was removed. AnchorRemoved { - anchor_id: T::AnchorIdNonce, account_id: T::AccountId, document_id: u128, document_version: u64, @@ -147,18 +122,12 @@ pub mod pallet { /// The anchor already exists. AnchorAlreadyExists, - /// The document anchor already exists. - DocumentAnchorAlreadyExists, - /// The personal anchor already exists. PersonalAnchorAlreadyExists, /// The anchor was not found in storage. AnchorNotFound, - /// The document anchor was not found in storage. - DocumentAnchorNotFound, - /// The personal anchor was not found in storage. PersonalAnchorNotFound, } @@ -176,20 +145,10 @@ pub mod pallet { ) -> DispatchResult { let account_id = ensure_signed(origin)?; - let anchor_id = AnchorIdNonceStore::::try_mutate(|n| { - n.ensure_add_assign(One::one())?; - Ok::<_, DispatchError>(*n) - })?; - - ensure!( - Anchors::::get(anchor_id).is_none(), - Error::::AnchorAlreadyExists - ); - // Only one anchor should be stored for a particular document ID and version. ensure!( - DocumentAnchors::::get((document_id, document_version)).is_none(), - Error::::DocumentAnchorAlreadyExists + Anchors::::get((document_id, document_version)).is_none(), + Error::::AnchorAlreadyExists ); ensure!( PersonalAnchors::::get(account_id.clone(), (document_id, document_version)) @@ -202,7 +161,6 @@ pub mod pallet { T::Currency::reserve(&account_id, deposit)?; let anchor = Anchor:: { - anchor_id, account_id: account_id.clone(), document_id, document_version, @@ -210,18 +168,11 @@ pub mod pallet { deposit, }; - Anchors::::insert(anchor_id, anchor); + Anchors::::insert((document_id, document_version), anchor); - DocumentAnchors::::insert((document_id, document_version), anchor_id); - - PersonalAnchors::::insert( - account_id.clone(), - (document_id, document_version), - anchor_id, - ); + PersonalAnchors::::insert(account_id.clone(), (document_id, document_version), ()); Self::deposit_event(Event::AnchorAdded { - anchor_id, account_id, document_id, document_version, @@ -248,19 +199,15 @@ pub mod pallet { Error::::PersonalAnchorNotFound ); - let anchor_id = DocumentAnchors::::get((document_id, document_version)) - .ok_or(Error::::DocumentAnchorNotFound)?; - - let anchor = Anchors::::get(anchor_id).ok_or(Error::::AnchorNotFound)?; + let anchor = Anchors::::get((document_id, document_version)) + .ok_or(Error::::AnchorNotFound)?; T::Currency::unreserve(&account_id, anchor.deposit); - Anchors::::remove(anchor_id); - DocumentAnchors::::remove((document_id, document_version)); + Anchors::::remove((document_id, document_version)); PersonalAnchors::::remove(account_id.clone(), (document_id, document_version)); Self::deposit_event(Event::AnchorRemoved { - anchor_id, account_id, document_id, document_version, diff --git a/pallets/anchors-v2/src/mock.rs b/pallets/anchors-v2/src/mock.rs index 9b95829f84..c23fbc0428 100644 --- a/pallets/anchors-v2/src/mock.rs +++ b/pallets/anchors-v2/src/mock.rs @@ -55,7 +55,6 @@ impl Config for Runtime { type DefaultAnchorDeposit = DefaultAnchorDeposit; type RuntimeEvent = RuntimeEvent; type WeightInfo = (); - type AnchorIdNonce = u128; } pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/pallets/anchors-v2/src/tests.rs b/pallets/anchors-v2/src/tests.rs index 3949583cfd..b658c3547c 100644 --- a/pallets/anchors-v2/src/tests.rs +++ b/pallets/anchors-v2/src/tests.rs @@ -12,13 +12,14 @@ // GNU General Public License for more details. use frame_support::{assert_err, assert_ok}; -use sp_runtime::testing::H256; - -use super::*; -use crate::mock::{RuntimeEvent as MockEvent, *}; use frame_support::dispatch::RawOrigin; use pallet_balances::Error::InsufficientBalance; use sp_runtime::DispatchError::BadOrigin; +use sp_runtime::testing::H256; + +use crate::mock::{*, RuntimeEvent as MockEvent}; + +use super::*; mod set_anchor { use super::*; @@ -31,10 +32,8 @@ mod set_anchor { let document_version = 456; let hash = H256::random(); let deposit = AnchorDeposit::::get(); - let anchor_id = 1; let anchor = Anchor:: { - anchor_id, account_id: origin, document_id, document_version, @@ -52,23 +51,17 @@ mod set_anchor { )); assert_eq!( - Anchors::::get(anchor_id), + Anchors::::get((document_id, document_version)), Some(anchor.clone()), "anchor should be in storage" ); - assert_eq!( - DocumentAnchors::::get((document_id, document_version)), - Some(anchor_id), - "document anchor should be in storage" - ); assert_eq!( PersonalAnchors::::get(origin, (document_id, document_version)), - Some(anchor_id), + Some(()), "personal anchor should be in storage" ); event_exists(Event::::AnchorAdded { - anchor_id, account_id: origin, document_id, document_version, @@ -106,10 +99,8 @@ mod set_anchor { let document_version = 456; let hash = H256::random(); let deposit = AnchorDeposit::::get(); - let anchor_id = 1; let anchor = Anchor:: { - anchor_id, account_id: origin, document_id, document_version, @@ -117,7 +108,7 @@ mod set_anchor { deposit, }; - Anchors::::insert(anchor_id, anchor); + Anchors::::insert((document_id, document_version), anchor); assert_err!( AnchorsV2::set_anchor( @@ -131,29 +122,6 @@ mod set_anchor { }); } - #[test] - fn document_anchor_present() { - new_test_ext().execute_with(|| { - let origin: u64 = 1; - let document_id = 123; - let document_version = 456; - let hash = H256::random(); - let anchor_id = 1; - - DocumentAnchors::::insert((document_id, document_version), anchor_id); - - assert_err!( - AnchorsV2::set_anchor( - RuntimeOrigin::signed(origin), - document_id, - document_version, - hash, - ), - Error::::DocumentAnchorAlreadyExists - ); - }); - } - #[test] fn personal_anchor_present() { new_test_ext().execute_with(|| { @@ -161,9 +129,8 @@ mod set_anchor { let document_id = 123; let document_version = 456; let hash = H256::random(); - let anchor_id = 1; - PersonalAnchors::::insert(origin, (document_id, document_version), anchor_id); + PersonalAnchors::::insert(origin, (document_id, document_version), ()); assert_err!( AnchorsV2::set_anchor( @@ -209,10 +176,8 @@ mod remove_anchor { let document_version = 456; let hash = H256::random(); let deposit = AnchorDeposit::::get(); - let anchor_id = 1; let anchor = Anchor:: { - anchor_id, account_id: origin, document_id, document_version, @@ -220,9 +185,8 @@ mod remove_anchor { deposit, }; - Anchors::::insert(anchor_id, anchor); - DocumentAnchors::::insert((document_id, document_version), anchor_id); - PersonalAnchors::::insert(origin, (document_id, document_version), anchor_id); + Anchors::::insert((document_id, document_version), anchor); + PersonalAnchors::::insert(origin, (document_id, document_version), ()); Balances::force_set_balance(RuntimeOrigin::root(), origin, deposit * 2).unwrap(); assert_ok!(Balances::reserve(&origin, deposit)); @@ -233,14 +197,12 @@ mod remove_anchor { document_version, )); - assert!(Anchors::::get(anchor_id).is_none(),); - assert!(DocumentAnchors::::get((document_id, document_version)).is_none()); + assert!(Anchors::::get((document_id, document_version)).is_none()); assert!( PersonalAnchors::::get(origin, (document_id, document_version)).is_none() ); event_exists(Event::::AnchorRemoved { - anchor_id, account_id: origin, document_id, document_version, @@ -283,37 +245,14 @@ mod remove_anchor { }); } - #[test] - fn document_anchor_not_found() { - new_test_ext().execute_with(|| { - let origin: u64 = 1; - let document_id = 123; - let document_version = 456; - let anchor_id = 1; - - PersonalAnchors::::insert(origin, (document_id, document_version), anchor_id); - - assert_err!( - AnchorsV2::remove_anchor( - RuntimeOrigin::signed(origin), - document_id, - document_version, - ), - Error::::DocumentAnchorNotFound - ); - }); - } - #[test] fn anchor_not_found() { new_test_ext().execute_with(|| { let origin: u64 = 1; let document_id = 123; let document_version = 456; - let anchor_id = 1; - PersonalAnchors::::insert(origin, (document_id, document_version), anchor_id); - DocumentAnchors::::insert((document_id, document_version), anchor_id); + PersonalAnchors::::insert(origin, (document_id, document_version), ()); assert_err!( AnchorsV2::remove_anchor( diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 69d6b9ead2..00bddcbde6 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -1654,7 +1654,6 @@ impl pallet_anchors_v2::pallet::Config for Runtime { type DefaultAnchorDeposit = DefaultAnchorDeposit; type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_anchors_v2::WeightInfo; - type AnchorIdNonce = u128; } parameter_types! { From 01f23f7fa314951c8ef274742205db3eb5a78d7b Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Thu, 20 Jun 2024 22:13:06 +0200 Subject: [PATCH 11/12] fmt: Fix --- pallets/anchors-v2/src/lib.rs | 6 ++--- pallets/anchors-v2/src/tests.rs | 9 +++---- pallets/anchors-v2/src/weights.rs | 2 ++ pallets/pool-system/src/pool_types.rs | 3 +-- pallets/pool-system/src/tranches.rs | 1 - runtime/common/src/lib.rs | 26 +++++++++---------- .../src/generic/cases/liquidity_pools.rs | 21 +++++++-------- 7 files changed, 30 insertions(+), 38 deletions(-) diff --git a/pallets/anchors-v2/src/lib.rs b/pallets/anchors-v2/src/lib.rs index d698f4c966..d1fe005044 100644 --- a/pallets/anchors-v2/src/lib.rs +++ b/pallets/anchors-v2/src/lib.rs @@ -12,12 +12,10 @@ // GNU General Public License for more details. #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::pallet_prelude::*; -use frame_support::traits::ReservableCurrency; +use frame_support::{pallet_prelude::*, traits::ReservableCurrency}; use frame_system::pallet_prelude::*; -use scale_info::TypeInfo; - pub use pallet::*; +use scale_info::TypeInfo; pub use weights::*; #[cfg(feature = "runtime-benchmarks")] diff --git a/pallets/anchors-v2/src/tests.rs b/pallets/anchors-v2/src/tests.rs index b658c3547c..23c03c736a 100644 --- a/pallets/anchors-v2/src/tests.rs +++ b/pallets/anchors-v2/src/tests.rs @@ -11,15 +11,12 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -use frame_support::{assert_err, assert_ok}; -use frame_support::dispatch::RawOrigin; +use frame_support::{assert_err, assert_ok, dispatch::RawOrigin}; use pallet_balances::Error::InsufficientBalance; -use sp_runtime::DispatchError::BadOrigin; -use sp_runtime::testing::H256; - -use crate::mock::{*, RuntimeEvent as MockEvent}; +use sp_runtime::{testing::H256, DispatchError::BadOrigin}; use super::*; +use crate::mock::{RuntimeEvent as MockEvent, *}; mod set_anchor { use super::*; diff --git a/pallets/anchors-v2/src/weights.rs b/pallets/anchors-v2/src/weights.rs index 215c0be0b8..796a57e9fb 100644 --- a/pallets/anchors-v2/src/weights.rs +++ b/pallets/anchors-v2/src/weights.rs @@ -23,9 +23,11 @@ impl WeightInfo for () { fn set_anchor() -> Weight { Weight::zero() } + fn remove_anchor() -> Weight { Weight::zero() } + fn set_deposit_value() -> Weight { Weight::zero() } diff --git a/pallets/pool-system/src/pool_types.rs b/pallets/pool-system/src/pool_types.rs index d2a5a4551c..0594d15ab2 100644 --- a/pallets/pool-system/src/pool_types.rs +++ b/pallets/pool-system/src/pool_types.rs @@ -12,6 +12,7 @@ use cfg_traits::Seconds; use cfg_types::{epoch::EpochState, pools::TrancheMetadata}; +pub use changes::PoolChangeProposal; use frame_support::{ dispatch::DispatchResult, pallet_prelude::{DispatchError, RuntimeDebug}, @@ -419,5 +420,3 @@ pub mod changes { pub change: ChangeProposal, } } - -pub use changes::PoolChangeProposal; diff --git a/pallets/pool-system/src/tranches.rs b/pallets/pool-system/src/tranches.rs index afa0a5ebbf..9b7011ca13 100644 --- a/pallets/pool-system/src/tranches.rs +++ b/pallets/pool-system/src/tranches.rs @@ -1724,7 +1724,6 @@ pub mod test { } mod tranche { - use super::*; #[test] diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 56aae05d43..29dd4bd01c 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -15,19 +15,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub mod account_conversion; -pub mod apis; -pub mod changes; -pub mod evm; -pub mod fees; -pub mod gateway; -pub mod migrations; -pub mod oracle; -pub mod pool; -pub mod remarks; -pub mod transfer_filter; -pub mod xcm; - use cfg_primitives::Balance; use cfg_types::{ fee_keys::FeeKey, @@ -44,6 +31,19 @@ use sp_runtime::{ }; use sp_std::marker::PhantomData; +pub mod account_conversion; +pub mod apis; +pub mod changes; +pub mod evm; +pub mod fees; +pub mod gateway; +pub mod migrations; +pub mod oracle; +pub mod pool; +pub mod remarks; +pub mod transfer_filter; +pub mod xcm; + pub mod instances { /// The rewards associated to block rewards pub type BlockRewards = pallet_rewards::Instance1; diff --git a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs index 860c1468e4..9383cede21 100644 --- a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs @@ -65,6 +65,7 @@ use staging_xcm::{ }, VersionedAsset, VersionedAssets, VersionedLocation, }; +use utils::*; use crate::{ generic::{ @@ -211,9 +212,9 @@ pub mod utils { } } -use utils::*; - mod development { + use utils::*; + use super::*; pub const GLMR_CURRENCY_ID: CurrencyId = CurrencyId::ForeignAsset(4); @@ -798,8 +799,6 @@ mod development { } } - use utils::*; - mod add_allow_upgrade { use cfg_types::tokens::LiquidityPoolsWrappedToken; @@ -4528,6 +4527,8 @@ mod development { } mod ethereum_xcm { + use utils::*; + use super::*; mod utils { @@ -4667,8 +4668,6 @@ mod development { } } - use utils::*; - const TEST_DOMAIN: Domain = Domain::EVM(1); #[test_runtimes([development])] @@ -4873,11 +4872,12 @@ mod development { mod altair { use altair_runtime::{xcm::CurrencyIdConvert, PoolPalletIndex}; - - pub const KSM_ASSET_ID: CurrencyId = CurrencyId::ForeignAsset(1000); + use utils::*; use super::*; + pub const KSM_ASSET_ID: CurrencyId = CurrencyId::ForeignAsset(1000); + mod utils { use super::*; @@ -4949,8 +4949,6 @@ mod altair { } } - use utils::*; - mod transfers { use super::*; @@ -5845,6 +5843,7 @@ mod altair { mod centrifuge { use centrifuge_runtime::xcm::CurrencyIdConvert; + use utils::*; use super::*; @@ -6120,8 +6119,6 @@ mod centrifuge { } } - use utils::*; - mod asset_registry { use super::*; From bf3d2e4d5addee270ac3ec9698d033b0b3e9613b Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:54:09 +0200 Subject: [PATCH 12/12] runtime: Add missing feature, remove extra import --- pallets/pool-system/src/mock.rs | 1 - runtime/development/Cargo.toml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/pool-system/src/mock.rs b/pallets/pool-system/src/mock.rs index da4ec270df..a385b59856 100644 --- a/pallets/pool-system/src/mock.rs +++ b/pallets/pool-system/src/mock.rs @@ -393,7 +393,6 @@ impl EnsureOriginWithArg for All { #[cfg(feature = "runtime-benchmarks")] fn try_successful_origin(_: &PoolId) -> Result { - use frame_support::dispatch::RawOrigin; Ok(RawOrigin::Root.into()) } } diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index 712344bc86..e5c4c4989e 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -377,6 +377,7 @@ try-runtime = [ "orml-xcm/try-runtime", "orml-xtokens/try-runtime", "pallet-anchors/try-runtime", + "pallet-anchors-v2/try-runtime", "pallet-aura/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime",