From cc612a22ce43eba3a091bef97a7a7813d4db1994 Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Fri, 2 Feb 2024 16:22:46 +0100 Subject: [PATCH] migration: remove claims pallet (#1707) * chore: remove claims pallet from centrifuge runtime * chore: remove claims pallet from dev runtime * chore: remove claims pallet entirely * chore: apply suggestions from review --- Cargo.lock | 22 -- Cargo.toml | 2 - README.md | 2 - libs/types/src/ids.rs | 1 - pallets/claims/Cargo.toml | 57 ---- pallets/claims/README.md | 92 ------ pallets/claims/src/lib.rs | 424 -------------------------- pallets/claims/src/mock.rs | 203 ------------ pallets/claims/src/tests.rs | 322 ------------------- pallets/claims/src/weights.rs | 37 --- runtime/altair/Cargo.toml | 4 - runtime/altair/src/migrations.rs | 8 +- runtime/centrifuge/Cargo.toml | 4 - runtime/centrifuge/src/lib.rs | 21 +- runtime/centrifuge/src/migrations.rs | 8 +- runtime/common/Cargo.toml | 4 - runtime/common/src/migrations/mod.rs | 1 - runtime/common/src/migrations/nuke.rs | 78 ++++- runtime/development/Cargo.toml | 4 - runtime/development/src/lib.rs | 19 +- runtime/integration-tests/Cargo.toml | 1 - 21 files changed, 89 insertions(+), 1225 deletions(-) delete mode 100644 pallets/claims/Cargo.toml delete mode 100644 pallets/claims/README.md delete mode 100644 pallets/claims/src/lib.rs delete mode 100644 pallets/claims/src/mock.rs delete mode 100644 pallets/claims/src/tests.rs delete mode 100644 pallets/claims/src/weights.rs diff --git a/Cargo.lock b/Cargo.lock index e496ee9ba2..371efe3447 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -159,7 +159,6 @@ dependencies = [ "pallet-base-fee", "pallet-block-rewards", "pallet-bridge", - "pallet-claims", "pallet-collator-allowlist", "pallet-collator-selection", "pallet-collective", @@ -1039,7 +1038,6 @@ dependencies = [ "pallet-base-fee", "pallet-block-rewards", "pallet-bridge", - "pallet-claims", "pallet-collator-allowlist", "pallet-collator-selection", "pallet-collective", @@ -2495,7 +2493,6 @@ dependencies = [ "pallet-base-fee", "pallet-block-rewards", "pallet-bridge", - "pallet-claims", "pallet-collator-allowlist", "pallet-collator-selection", "pallet-collective", @@ -6846,23 +6843,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-claims" -version = "2.0.0" -dependencies = [ - "cfg-primitives", - "cfg-types", - "frame-support", - "frame-system", - "pallet-balances", - "parity-scale-codec 3.6.9", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-collator-allowlist" version = "2.0.0" @@ -10901,7 +10881,6 @@ dependencies = [ "pallet-base-fee", "pallet-block-rewards", "pallet-bridge", - "pallet-claims", "pallet-collator-allowlist", "pallet-collator-selection", "pallet-collective", @@ -11024,7 +11003,6 @@ dependencies = [ "pallet-base-fee", "pallet-block-rewards", "pallet-bridge", - "pallet-claims", "pallet-collator-allowlist", "pallet-collator-selection", "pallet-collective", diff --git a/Cargo.toml b/Cargo.toml index cb71501695..61fa62acbf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ members = [ "pallets/anchors", "pallets/bridge", "pallets/block-rewards", - "pallets/claims", "pallets/collator-allowlist", "pallets/crowdloan-claim", "pallets/crowdloan-reward", @@ -253,7 +252,6 @@ liquidity-pools-gateway-routers = { path = "pallets/liquidity-pools-gateway/rout pallet-anchors = { path = "pallets/anchors", default-features = false } pallet-block-rewards = { path = "pallets/block-rewards", default-features = false } pallet-bridge = { path = "pallets/bridge", default-features = false } -pallet-claims = { path = "pallets/claims", default-features = false } pallet-collator-allowlist = { path = "pallets/collator-allowlist", default-features = false } pallet-crowdloan-claim = { path = "pallets/crowdloan-claim", default-features = false } pallet-crowdloan-reward = { path = "pallets/crowdloan-reward", default-features = false } diff --git a/README.md b/README.md index 5c08872fd6..962754d79a 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,6 @@ On top of the [Substrate FRAME](https://docs.substrate.io/reference/frame-pallet - [**bridge**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/bridge) ([docs](https://reference.centrifuge.io/pallet_bridge/index.html)): Connecting [ChainBridge](https://github.com/centrifuge/chainbridge-substrate) to transfer tokens to and from Ethereum. -- [**claims**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/claims) ([docs](https://reference.centrifuge.io/pallet_claims/index.html)): Processing claims of liquidity rewards acquired through Tinlake investments. - - [**collator-allowlist**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/collator-allowlist) ([docs](https://reference.centrifuge.io/pallet_collator_allowlist/index.html)): Tracking active collators, and allows the root account to manage this list. - [**crowdloan-claim**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/crowdloan-claim) ([docs](https://reference.centrifuge.io/pallet_crowdloan_claim/index.html)): Claiming user rewards for their crowdloan funding support. diff --git a/libs/types/src/ids.rs b/libs/types/src/ids.rs index 3e620d6913..0c8a9f0553 100644 --- a/libs/types/src/ids.rs +++ b/libs/types/src/ids.rs @@ -28,7 +28,6 @@ impl TypeId for InvestmentAccount { // Pallet-Ids that define pallets accounts pub const POOLS_PALLET_ID: PalletId = PalletId(*b"roc/pool"); pub const CHAIN_BRIDGE_PALLET_ID: PalletId = PalletId(*b"chnbrdge"); -pub const CLAIMS_PALLET_ID: PalletId = PalletId(*b"p/claims"); pub const CROWDLOAN_REWARD_PALLET_ID: PalletId = PalletId(*b"cc/rewrd"); pub const CROWDLOAN_CLAIM_PALLET_ID: PalletId = PalletId(*b"cc/claim"); pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry"); diff --git a/pallets/claims/Cargo.toml b/pallets/claims/Cargo.toml deleted file mode 100644 index f83d621385..0000000000 --- a/pallets/claims/Cargo.toml +++ /dev/null @@ -1,57 +0,0 @@ -[package] -name = "pallet-claims" -description = "Pallet for processing token claims for Tinlake investments." -authors = ["The Centrifugians Tribe"] -edition = "2021" -homepage = "https://centrifuge.io" -license = "LGPL-3.0" -repository = "https://github.com/centrifuge/centrifuge-chain" -version = "2.0.0" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } -pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } -parity-scale-codec = { version = "3.0.0", features = ["derive"], default-features = false } -scale-info = { version = "2.3.0", default-features = false, features = ["derive"] } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } - -[dev-dependencies] -cfg-primitives = { path = "../../libs/primitives", default_features = true } -cfg-types = { path = "../../libs/types", default_features = true } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } - -[features] -default = ["std"] -std = [ - "parity-scale-codec/std", - "scale-info/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "sp-std/std", - "sp-core/std", - "sp-runtime/std", -] - -try-runtime = [ - "cfg-primitives/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "pallet-balances/try-runtime", - "sp-runtime/try-runtime", -] -runtime-benchmarks = [ - "cfg-primitives/runtime-benchmarks", - "cfg-types/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", -] diff --git a/pallets/claims/README.md b/pallets/claims/README.md deleted file mode 100644 index 5977c8555b..0000000000 --- a/pallets/claims/README.md +++ /dev/null @@ -1,92 +0,0 @@ -# Claims Pallet - - - -- [Claims Pallet](#claims-pallet) - - [Overview](#overview) - - [Pallet Usage](#pallet-usage) - - [Add the Pallet to your Runtime](#add-the-pallet-to-your-runtime) - - [Configure the Pallet](#configure-the-pallet) - - [Pallet Documentation](#pallet-documentation) - - - -## Overview - -This Centrifuge Chain pallet provides functionalities for processing claims of tokens acquired -through [Tinlake](https://tinlake.centrifuge.io/) investments. - -This pallet is built on Substrate [FRAME v2](https://substrate.dev/docs/en/knowledgebase/runtime/frame) -library. - -## Pallet Usage - -### Add the Pallet to your Runtime - -In order to add this pallet to your runtime, you should add the following lines -to your parachain's main `Cargo.toml` file: - -```toml -# -- snip -- - -[dependencies] - -pallet-claims = { branch = "master", git = "https://github.com/centrifuge/centrifuge-chain.git", default-features = false } - -# -- snip -- - -[features] -std = [ - # -- snip -- - 'pallet-claims/std', # <-- Add this line -] -``` - -### Configure the Pallet - -Now that the pallet is added to your runtime, the latter must be configured -for your runtime (in `[runtime_path]/lib.rs` file): - -```rust - -node_primitives::Balance - -// Centrifuge chain token definition -pub(crate) const MICRO_CFG: Balance = 1_000_000_000_000; // 10−6 0.000001 -pub(crate) const MILLI_CFG: Balance = 1_000 * MICRO_CFG; // 10−3 0.001 -pub(crate) const CENTI_CFG: Balance = 10 * MILLI_CFG; // 10−2 0.01 -pub(crate) const CFG: Balance = 100 * CENTI_CFG; - -// Parameterize claims pallet -parameter_types! { - pub const ClaimsPalletId: PalletId = PalletId(*b"claims"); - pub const One: u64 = 1; - pub const Longevity: u32 = 64; - pub const MinimalPayoutAmount: node_primitives::Balance = 5 * CFG; -} - -// Implement claims pallet configuration trait for the mock runtime -impl pallet_claims::Config for MyRuntime { - type Event = (); - type PalletId = ClaimsPalletId; - type AdminOrigin = EnsureSignedBy; - type Currency = Balances; - type WeightInfo = (); -} - -construct_runtime! { - … - - Claims: pallet_claims::{Pallet, Call, Config, Storage, Event}, -} -``` - -## Pallet Documentation - -You can see this pallet's reference documentation with the following command: - -```sh -$ cargo doc --package pallet-claims --open -``` - -The table of contents for this markdown file is automatically generated using the [`auto-markdown-toc`](https://marketplace.visualstudio.com/items?itemName=huntertran.auto-markdown-toc) extension for Visual StudioCode. diff --git a/pallets/claims/src/lib.rs b/pallets/claims/src/lib.rs deleted file mode 100644 index e87776d98e..0000000000 --- a/pallets/claims/src/lib.rs +++ /dev/null @@ -1,424 +0,0 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Centrifuge (centrifuge.io) parachain. - -// Cumulus 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. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -//! # Claims processing pallet -//! -//! This pallet implement a reward claim mechanism with vesting, for -//! rewarding tokens (CFG or others) awarded through [Tinlake](https://tinlake.centrifuge.io) -//! investments. -//! -//! ## Overview -//! This pallet is used for processing reward payout claims from investors who -//! invested in [Tinlake](https://tinlake.centrifuge.io) pools. -//! -//! ## Terminology -//! CFG is the native token of Centrifuge chain. -//! -//! ## Usage -//! -//! ## Interface -//! -//! ### Supported Origins -//! Valid origin is an administrator or root. -//! -//! ### Dispatchable Functions -//! -//! Callable functions (or extrinsics), also considered as transactions, -//! materialize the pallet contract. Here's the callable functions implemented -//! in this module: -//! -//! - `claim` - Claims tokens awarded through tinlake investments. -//! - `set_upload_account` - Admin function that sets the allowed upload account -//! to add root hashes. -//! - `store_root_hash` - Stores root hash for correspondent claim merkle tree -//! run. -//! -//! ### Public Functions -//! - `sorted_hash_of` - Build a sorted hash of two given hash values. -//! -//! ## Genesis Configuration -//! The pallet is parameterized and configured via [`parameter_types`](https://docs.rs/frame-support/2.0.0-rc1/frame_support/macro.parameter_types.html) macro, at the time the runtime is built -//! by means of the [`construct_runtime`](https://substrate.dev/rustdocs/v3.0.0/frame_support/macro.construct_runtime.html) macro. -//! -//! ## Dependencies -//! This pallet is tightly coupled to: -//! - Substrate FRAME's [balances pallet](https://github.com/paritytech/substrate/tree/master/frame/balances). -//! -//! ## References -//! - [Substrate FRAME v2 attribute macros](https://crates.parity.io/frame_support/attr.pallet.html). -//! -//! ## Credits -//! The Centrifugians Tribe - -// Ensure we're `no_std` when compiling for WebAssembly. -#![cfg_attr(not(feature = "std"), no_std)] - -// ---------------------------------------------------------------------------- -// Imports and dependencies -// ---------------------------------------------------------------------------- - -// Mock runtime and unit test cases -#[cfg(test)] -mod mock; - -#[cfg(test)] -mod tests; - -// Extrinsics weight information -mod weights; - -// Runtime, system and frame primitives -use frame_support::{ - dispatch::DispatchResult, - traits::{Currency, EnsureOrigin, ExistenceRequirement::KeepAlive, Get}, - PalletId, -}; -use frame_system::ensure_root; -// Re-export in crate namespace (for runtime construction) -pub use pallet::*; -use sp_core::Encode; -use sp_runtime::{ - sp_std::vec::Vec, - traits::{AccountIdConversion, CheckedSub, Hash}, -}; -pub use weights::WeightInfo; - -// ---------------------------------------------------------------------------- -// Pallet module -// ---------------------------------------------------------------------------- - -// Rad claim pallet module -// -// The name of the pallet is provided by `construct_runtime` and is used as -// the unique identifier for the pallet's storage. It is not defined in the -// pallet itself. -#[frame_support::pallet] -pub mod pallet { - - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - - use super::*; - - // Rad claim pallet type declaration. - // - // This structure is a placeholder for traits and functions implementation - // for the pallet. - #[pallet::pallet] - pub struct Pallet(_); - - // ------------------------------------------------------------------------ - // Pallet configuration - // ------------------------------------------------------------------------ - - /// Claims pallet's configuration trait. - /// - /// Associated types and constants are declared in this trait. If the pallet - /// depends on other super-traits, the latter must be added to this trait, - /// such as, in this case, [`frame_system::Config`] and - /// [`pallet_balances::Config`] super-traits. Note that - /// [`frame_system::Config`] must always be included. - #[pallet::config] - pub trait Config: frame_system::Config + pallet_balances::Config { - /// Ensure that origin of a transaction is an administrator. - type AdminOrigin: EnsureOrigin; - - /// Expected currency of the reward claim. - type Currency: Currency; - - /// Associated type for Event enum - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// Minimal amount that can be claimed for a reward payout. - /// - /// This constant is set via [`parameter_types`](https://substrate.dev/docs/en/knowledgebase/runtime/macros#parameter_types) - /// macro when configuring a runtime. - #[pallet::constant] - type MinimalPayoutAmount: Get; - - /// Constant configuration parameter to store the module identifier for - /// the pallet. - /// - /// The module identifier may be of the form - /// ```PalletId(*b"rd/claim")``` and set using the [`parameter_types`](https://substrate.dev/docs/en/knowledgebase/runtime/macros#parameter_types) - // macro in the [`runtime/lib.rs`] file. - #[pallet::constant] - type PalletId: Get; - - /// Weight information for extrinsics in this pallet - type WeightInfo: WeightInfo; - } - - // ------------------------------------------------------------------------ - // Pallet events - // ------------------------------------------------------------------------ - - // The macro generates event metadata and derive Clone, Debug, Eq, PartialEq and - // Codec - #[pallet::event] - // The macro generates a function on Pallet to deposit an event - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// Event triggered after a reward claim is successfully processed - Claimed { - account_id: T::AccountId, - amount: ::Balance, - }, - - /// Event triggered when the root hash is stored - RootHashStored { - root_hash: ::Hash, - }, - } - - // ------------------------------------------------------------------------ - // Pallet storage items - // ------------------------------------------------------------------------ - - /// Total claimed amounts for all accounts. - #[pallet::storage] - #[pallet::getter(fn get_claimed_amount)] - pub(super) type ClaimedAmounts = - StorageMap<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>; - - /// Root hash that correspond to lists of reward claim amounts per account. - #[pallet::storage] - #[pallet::getter(fn get_root_hash)] - pub(super) type RootHash = StorageValue<_, T::Hash, OptionQuery>; - - /// Account that is allowed to upload new root hashes. - #[pallet::storage] - #[pallet::getter(fn get_upload_account)] - pub(super) type UploadAccount = StorageValue<_, T::AccountId, OptionQuery>; - - // ------------------------------------------------------------------------ - // Pallet errors - // ------------------------------------------------------------------------ - - #[pallet::error] - pub enum Error { - /// Amount being claimed is less than the available amount stored. - InsufficientBalance, - - /// The combination of account id, amount, and proofs vector in a claim - /// was invalid. - InvalidProofs, - - /// Protected operation, must be performed by admin - MustBeAdmin, - - /// The payout amount attempting to be claimed is less than the minimum - /// allowed by [`Config::MinimalPayoutAmount`]. - UnderMinPayout, - } - - // ------------------------------------------------------------------------ - // Pallet dispatchable functions - // ------------------------------------------------------------------------ - - // Declare Call struct and implement dispatchable (or callable) functions. - // - // Dispatchable functions are transactions modifying the state of the chain. - // They are also called extrinsics are constitute the pallet's public interface. - // Note that each parameter used in functions must implement `Clone`, `Debug`, - // `Eq`, `PartialEq` and `Codec` traits. - #[pallet::call] - impl Pallet { - /// Claims tokens awarded through Tinlake investments. - /// - /// # - /// - Based on hashes length - /// # - #[pallet::weight(::WeightInfo::claim(sorted_hashes.len()))] - #[pallet::call_index(0)] - pub fn claim( - origin: OriginFor, - account_id: T::AccountId, - amount: T::Balance, - sorted_hashes: Vec, - ) -> DispatchResultWithPostInfo { - ensure_signed(origin)?; - - ensure!( - Self::verify_proofs(&account_id, &amount, &sorted_hashes), - Error::::InvalidProofs - ); - - let claimed = Self::get_claimed_amount(&account_id); - - // Payout = amount - claimed - let payout = amount - .checked_sub(&claimed) - .ok_or(Error::::InsufficientBalance)?; - - // Payout must not be less than the minimum allowed - ensure!( - payout >= T::MinimalPayoutAmount::get(), - Error::::UnderMinPayout - ); - - let source = Self::account_id(); - - // Transfer payout amount - as Currency<_>>::transfer( - &source, - &account_id, - payout, - KeepAlive, - )?; - - // Set account balance to amount - ClaimedAmounts::::insert(account_id.clone(), amount); - - Self::deposit_event(Event::Claimed { account_id, amount }); - - Ok(().into()) - } - - /// Admin function that sets the allowed upload account to add root - /// hashes Controlled by custom origin or root - /// - /// # - /// - Based on origin check and write op - /// # - #[pallet::weight(::WeightInfo::set_upload_account())] - #[pallet::call_index(1)] - pub fn set_upload_account( - origin: OriginFor, - account_id: T::AccountId, - ) -> DispatchResultWithPostInfo { - Self::can_update_upload_account(origin)?; - - >::put(account_id); - - Ok(().into()) - } - - /// Stores root hash for correspondent claim Merkle tree run - /// - /// # - /// - Based on origin check and write op - /// # - #[pallet::weight(::WeightInfo::store_root_hash())] - #[pallet::call_index(2)] - pub fn store_root_hash( - origin: OriginFor, - root_hash: T::Hash, - ) -> DispatchResultWithPostInfo { - let who = ensure_signed(origin)?; - - ensure!( - Self::get_upload_account() == Some(who), - Error::::MustBeAdmin - ); - - >::put(root_hash); - - Self::deposit_event(Event::RootHashStored { root_hash }); - - Ok(().into()) - } - } -} - -// ---------------------------------------------------------------------------- -// Pallet implementation block -// ---------------------------------------------------------------------------- - -// Claims pallet implementation block. -// -// This main implementation block contains two categories of functions, namely: -// - Public functions: These are functions that are `pub` and generally fall -// into inspector functions that do not write to storage and operation -// functions that do. -// - Private functions: These are private helpers or utilities that cannot be -// called from other pallets. -impl Pallet { - /// Return the account identifier of the claims pallet. - /// - /// This actually does computation. If you need to keep using it, then make - /// sure you cache the value and only call this once. - pub fn account_id() -> T::AccountId { - T::PalletId::get().into_account_truncating() - } - - /// Build a sorted hash of two given hash values. - /// - /// Hash a:b if a < b, else b:a. Uses the runtime module's hasher. - pub fn sorted_hash_of(a: &T::Hash, b: &T::Hash) -> T::Hash { - let mut h: Vec = Vec::with_capacity(64); - if a < b { - h.extend_from_slice(a.as_ref()); - h.extend_from_slice(b.as_ref()); - } else { - h.extend_from_slice(b.as_ref()); - h.extend_from_slice(a.as_ref()); - } - - T::Hashing::hash(&h) - } - - /// Returns true if the given origin can update the upload account - fn can_update_upload_account(origin: T::RuntimeOrigin) -> DispatchResult { - T::AdminOrigin::try_origin(origin) - .map(|_| ()) - .or_else(ensure_root)?; - - Ok(()) - } - - // Verifies lexicographically-sorted proofs. - // - // This function essentially proceeds as follows, in order to verify proofs: - // 1. A leaf hash is first built, namely `Hash(account_id + amount)`, with the - // account and the amount 2. The leaf is then passed to iterator as the first - // accumulative value to the 'sorted_hash_of' function 3. Then 'sorted_hash_of' - // function hashes both 'hash1' and 'hash2' together, and the order depends on - // which one is "bigger". - // This approach avoids having an extra byte that tells if the hash is left - // or right so they can be concatenated accordingly before hashing - // 4. And finally, it checks that the resulting root hash matches with the one - // stored - fn verify_proofs( - account_id: &T::AccountId, - amount: &T::Balance, - sorted_hashes: &Vec, - ) -> bool { - // Number of proofs should practically never be >30. Checking this - // blocks abuse. - if sorted_hashes.len() > 30 { - return false; - } - - // Concat account id : amount - let mut v: Vec = account_id.encode(); - v.extend(amount.encode()); - - // Generate root hash - let leaf_hash = T::Hashing::hash(&v); - let mut root_hash = sorted_hashes - .iter() - .fold(leaf_hash, |acc, hash| Self::sorted_hash_of(&acc, hash)); - - // Initial runs might only have trees of single leaves, - // in this case leaf_hash is as well root_hash - if sorted_hashes.is_empty() { - root_hash = leaf_hash; - } - - Self::get_root_hash() == Some(root_hash) - } -} diff --git a/pallets/claims/src/mock.rs b/pallets/claims/src/mock.rs deleted file mode 100644 index 4d877ae0d0..0000000000 --- a/pallets/claims/src/mock.rs +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Centrifuge (centrifuge.io) parachain. - -// Cumulus 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. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -//! Claims pallet testing environment and utilities -//! -//! The main components implemented in this mock module is a mock runtime, -//! some helper functions and the definition of some constants. - -// ---------------------------------------------------------------------------- -// Imports and dependencies -// ---------------------------------------------------------------------------- - -use cfg_primitives::Balance; -use frame_support::{ - parameter_types, - traits::{Everything, SortedMembers}, - PalletId, -}; -use frame_system::EnsureSignedBy; -pub use pallet_balances as balances; -use sp_core::{ConstU32, H256}; -use sp_io::TestExternalities; -use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, IdentityLookup}, - transaction_validity::TransactionPriority, -}; - -use crate::{self as pallet_claims, Config}; - -// ---------------------------------------------------------------------------- -// Types and constants declaration -// ---------------------------------------------------------------------------- - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; - -// Radial token definition -// -// This avoids circular dependency on the runtime crate. Though for testing -// we do not care about real CFG token "value", it helps understanding and -// reading the testing code. -pub(crate) const MICRO_CFG: Balance = 1_000_000_000_000; // 10−6 0.000001 -pub(crate) const MILLI_CFG: Balance = 1_000 * MICRO_CFG; // 10−3 0.001 -pub(crate) const CENTI_CFG: Balance = 10 * MILLI_CFG; // 10−2 0.01 -pub(crate) const CFG: Balance = 100 * CENTI_CFG; - -pub(crate) const ADMIN: u64 = 0x1; -pub(crate) const USER_A: u64 = 0x2; - -// USER_B does not have existential balance -pub(crate) const USER_B: u64 = 0x3; - -pub(crate) const ENDOWED_BALANCE: u128 = 10000 * CFG; - -// ---------------------------------------------------------------------------- -// Mock runtime configuration -// ---------------------------------------------------------------------------- - -// Build mock runtime -frame_support::construct_runtime!( - pub enum Runtime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - Balances: pallet_balances::{Pallet, Call, Config, Storage, Event}, - Claims: pallet_claims::{Pallet, Call, Storage, Event}, - } -); - -// Parameterize FRAME system pallet -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - -// Implement FRAME system pallet configuration trait for the mock runtime -impl frame_system::Config for Runtime { - type AccountData = balances::AccountData; - type AccountId = u64; - type BaseCallFilter = Everything; - type BlockHashCount = BlockHashCount; - type BlockLength = (); - type BlockNumber = u64; - type BlockWeights = (); - type DbWeight = (); - type Hash = H256; - type Hashing = BlakeTwo256; - type Header = Header; - type Index = u64; - type Lookup = IdentityLookup; - type MaxConsumers = frame_support::traits::ConstU32<16>; - type OnKilledAccount = (); - type OnNewAccount = (); - type OnSetCode = (); - type PalletInfo = PalletInfo; - type RuntimeCall = RuntimeCall; - type RuntimeEvent = RuntimeEvent; - type RuntimeOrigin = RuntimeOrigin; - type SS58Prefix = (); - type SystemWeightInfo = (); - type Version = (); -} - -// Parameterize FRAME balances pallet -parameter_types! { - pub const ExistentialDeposit: u64 = 1; -} - -// Implement FRAME balances pallet configuration trait for the mock runtime -impl pallet_balances::Config for Runtime { - type AccountStore = System; - type Balance = Balance; - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type FreezeIdentifier = (); - type HoldIdentifier = (); - type MaxFreezes = ConstU32<50>; - type MaxHolds = ConstU32<50>; - type MaxLocks = ConstU32<50>; - type MaxReserves = ConstU32<50>; - type ReserveIdentifier = [u8; 8]; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); -} - -// Parameterize claims pallet -parameter_types! { - pub const ClaimsPalletId: PalletId = cfg_types::ids::CLAIMS_PALLET_ID; - pub const One: u64 = 1; - pub const Longevity: u32 = 64; - pub const UnsignedPriority: TransactionPriority = TransactionPriority::max_value(); - pub const MinimalPayoutAmount: Balance = 5 * CFG; -} - -impl SortedMembers for One { - fn sorted_members() -> Vec { - vec![1] - } -} - -// Implement claims pallet configuration trait for the mock runtime -impl Config for Runtime { - type AdminOrigin = EnsureSignedBy; - type Currency = Balances; - type MinimalPayoutAmount = MinimalPayoutAmount; - type PalletId = ClaimsPalletId; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); -} - -// ---------------------------------------------------------------------------- -// Runtime externalities -// ---------------------------------------------------------------------------- - -// Runtime externalities builder type declaraction. -// -// This type is mainly used for mocking storage in tests. It is the type alias -// for an in-memory, hashmap-based externalities implementation. -pub struct TestExternalitiesBuilder {} - -// Default trait implementation for test externalities builder -impl Default for TestExternalitiesBuilder { - fn default() -> Self { - Self {} - } -} - -impl TestExternalitiesBuilder { - // Build a genesis storage key/value store - pub(crate) fn build(self) -> TestExternalities { - let mut storage = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); - - // pre-fill balances - pallet_balances::GenesisConfig:: { - balances: vec![ - (ADMIN, ENDOWED_BALANCE), - (USER_A, 1), - (Claims::account_id(), ENDOWED_BALANCE), - ], - } - .assimilate_storage(&mut storage) - .unwrap(); - - TestExternalities::new(storage) - } -} diff --git a/pallets/claims/src/tests.rs b/pallets/claims/src/tests.rs deleted file mode 100644 index b8e860f031..0000000000 --- a/pallets/claims/src/tests.rs +++ /dev/null @@ -1,322 +0,0 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Centrifuge (centrifuge.io) parachain. - -// Cumulus 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. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -//! Rad claims pallet's unit test cases - -// ---------------------------------------------------------------------------- -// Imports and dependencies -// ---------------------------------------------------------------------------- - -use frame_support::{assert_noop, assert_ok}; -use sp_core::H256; -use sp_runtime::{ - traits::{BadOrigin, Hash}, - TokenError, -}; - -use crate::{mock::*, *}; - -// ---------------------------------------------------------------------------- -// Test unit cases -// ---------------------------------------------------------------------------- - -#[test] -fn can_upload_account() { - TestExternalitiesBuilder::default() - .build() - .execute_with(|| { - assert_noop!( - Claims::can_update_upload_account(RuntimeOrigin::signed(USER_A)), - BadOrigin - ); - assert_ok!(Claims::can_update_upload_account(RuntimeOrigin::signed( - ADMIN - ))); - }); -} - -#[test] -fn verify_proofs() { - TestExternalitiesBuilder::default() - .build() - .execute_with(|| { - let amount: u128 = 100 * CFG; - let sorted_hashes_long: [H256; 31] = [ - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - [0; 32].into(), - ]; - - // Abuse DDoS attach check - assert_eq!( - Claims::verify_proofs(&USER_B, &amount, &sorted_hashes_long.to_vec()), - false - ); - - // Wrong sorted hashes for merkle tree - let one_sorted_hashes: [H256; 1] = [[0; 32].into()]; - assert_eq!( - Claims::verify_proofs(&USER_B, &amount, &one_sorted_hashes.to_vec()), - false - ); - - let mut v: Vec = USER_B.encode(); - v.extend(amount.encode()); - - // Single-leaf tree - assert_ok!(Claims::set_upload_account( - RuntimeOrigin::signed(ADMIN), - ADMIN - )); - let leaf_hash = ::Hashing::hash(&v); - assert_ok!(Claims::store_root_hash( - RuntimeOrigin::signed(ADMIN), - leaf_hash - )); - assert_eq!(Claims::verify_proofs(&USER_B, &amount, &[].to_vec()), true); - - // Two-leaf tree - let root_hash = Claims::sorted_hash_of(&leaf_hash, &one_sorted_hashes[0]); - assert_ok!(Claims::store_root_hash( - RuntimeOrigin::signed(ADMIN), - root_hash - )); - assert_eq!( - Claims::verify_proofs(&USER_B, &amount, &one_sorted_hashes.to_vec()), - true - ); - - // 10-leaf tree - let leaf_hash_0: H256 = [0; 32].into(); - let leaf_hash_1: H256 = [1; 32].into(); - let leaf_hash_2: H256 = leaf_hash; - let leaf_hash_3: H256 = [3; 32].into(); - let leaf_hash_4: H256 = [4; 32].into(); - let leaf_hash_5: H256 = [5; 32].into(); - let leaf_hash_6: H256 = [6; 32].into(); - let leaf_hash_7: H256 = [7; 32].into(); - let leaf_hash_8: H256 = [8; 32].into(); - let leaf_hash_9: H256 = [9; 32].into(); - let node_0 = Claims::sorted_hash_of(&leaf_hash_0, &leaf_hash_1); - let node_1 = Claims::sorted_hash_of(&leaf_hash_2, &leaf_hash_3); - let node_2 = Claims::sorted_hash_of(&leaf_hash_4, &leaf_hash_5); - let node_3 = Claims::sorted_hash_of(&leaf_hash_6, &leaf_hash_7); - let node_4 = Claims::sorted_hash_of(&leaf_hash_8, &leaf_hash_9); - let node_00 = Claims::sorted_hash_of(&node_0, &node_1); - let node_01 = Claims::sorted_hash_of(&node_2, &node_3); - let node_000 = Claims::sorted_hash_of(&node_00, &node_01); - let node_root = Claims::sorted_hash_of(&node_000, &node_4); - - let four_sorted_hashes: [H256; 4] = [ - leaf_hash_3.into(), - node_0.into(), - node_01.into(), - node_4.into(), - ]; - assert_ok!(Claims::store_root_hash( - RuntimeOrigin::signed(ADMIN), - node_root - )); - assert_eq!( - Claims::verify_proofs(&USER_B, &amount, &four_sorted_hashes.to_vec()), - true - ); - }); -} - -#[test] -fn set_upload_account() { - TestExternalitiesBuilder::default() - .build() - .execute_with(|| { - assert_eq!(Claims::get_upload_account(), None); - assert_noop!( - Claims::set_upload_account(RuntimeOrigin::signed(USER_A), USER_A), - BadOrigin - ); - assert_ok!(Claims::set_upload_account( - RuntimeOrigin::signed(ADMIN), - USER_A - )); - assert_eq!(Claims::get_upload_account(), Some(USER_A)); - }); -} - -#[test] -fn store_root_hash() { - TestExternalitiesBuilder::default() - .build() - .execute_with(|| { - assert_eq!(Claims::get_upload_account(), None); - // USER_A not allowed to upload hash - let root_hash = ::Hashing::hash(&[0; 32]); - assert_noop!( - Claims::store_root_hash(RuntimeOrigin::signed(USER_A), root_hash), - Error::::MustBeAdmin - ); - // Adding ADMIN as allowed upload account - assert_ok!(Claims::set_upload_account( - RuntimeOrigin::signed(ADMIN), - ADMIN - )); - assert_eq!(Claims::get_upload_account(), Some(ADMIN)); - assert_ok!(Claims::store_root_hash( - RuntimeOrigin::signed(ADMIN), - root_hash - )); - assert_eq!(Claims::get_root_hash(), Some(root_hash)); - }); -} - -fn pre_calculate_single_root( - account_id: &::AccountId, - amount: &::Balance, - other_hash: &::Hash, -) -> H256 { - let mut v: Vec = account_id.encode(); - v.extend(amount.encode()); - let leaf_hash = ::Hashing::hash(&v); - - Claims::sorted_hash_of(&leaf_hash, other_hash) -} - -#[test] -fn claim() { - TestExternalitiesBuilder::default() - .build() - .execute_with(|| { - let amount: u128 = 100 * CFG; - // Random sorted hashes - let one_sorted_hashes: [H256; 1] = [[0; 32].into()]; - - // proof validation error - roothash not stored - assert_noop!( - Claims::claim( - RuntimeOrigin::signed(0), - USER_B, - amount, - one_sorted_hashes.to_vec() - ), - Error::::InvalidProofs - ); - - // Set valid proofs - assert_ok!(Claims::set_upload_account( - RuntimeOrigin::signed(ADMIN), - ADMIN - )); - - let short_root_hash = - pre_calculate_single_root(&USER_B, &(4 * CFG), &one_sorted_hashes[0]); - assert_ok!(Claims::store_root_hash( - RuntimeOrigin::signed(ADMIN), - short_root_hash - )); - - // Minimum payout not met - assert_noop!( - Claims::claim( - RuntimeOrigin::signed(0), - USER_B, - 4 * CFG, - one_sorted_hashes.to_vec() - ), - Error::::UnderMinPayout - ); - - let long_root_hash = - pre_calculate_single_root(&USER_B, &(10001 * CFG), &one_sorted_hashes[0]); - assert_ok!(Claims::store_root_hash( - RuntimeOrigin::signed(ADMIN), - long_root_hash - )); - - // Claims Module Account does not have enough balance - assert_noop!( - Claims::claim( - RuntimeOrigin::signed(0), - USER_B, - 10001 * CFG, - one_sorted_hashes.to_vec() - ), - TokenError::FundsUnavailable - ); - - // Ok - let ok_root_hash = pre_calculate_single_root(&USER_B, &amount, &one_sorted_hashes[0]); - assert_ok!(Claims::store_root_hash( - RuntimeOrigin::signed(ADMIN), - ok_root_hash - )); - - let account_balance = >::free_balance(USER_B); - assert_ok!(Claims::claim( - RuntimeOrigin::signed(0), - USER_B, - amount, - one_sorted_hashes.to_vec() - )); - assert_eq!(Claims::get_claimed_amount(USER_B), amount); - let account_new_balance = >::free_balance(USER_B); - assert_eq!(account_new_balance, account_balance + amount); - - // Knowing that account has a balance of 100, trying to claim 50 will fail - // Since balance logic is accumulative - let past_root_hash = - pre_calculate_single_root(&USER_B, &(50 * CFG), &one_sorted_hashes[0]); - assert_ok!(Claims::store_root_hash( - RuntimeOrigin::signed(ADMIN), - past_root_hash - )); - assert_noop!( - Claims::claim( - RuntimeOrigin::signed(0), - USER_B, - 50 * CFG, - one_sorted_hashes.to_vec() - ), - Error::::InsufficientBalance - ); - }); -} diff --git a/pallets/claims/src/weights.rs b/pallets/claims/src/weights.rs deleted file mode 100644 index b0e3b8da7e..0000000000 --- a/pallets/claims/src/weights.rs +++ /dev/null @@ -1,37 +0,0 @@ -// 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::{constants::RocksDbWeight, Weight}; - -pub trait WeightInfo { - fn claim(hashes_length: usize) -> Weight; - fn set_upload_account() -> Weight; - fn store_root_hash() -> Weight; -} - -impl WeightInfo for () { - fn claim(hashes_length: usize) -> Weight { - Weight::from_parts(195_000_000, 0).saturating_add( - Weight::from_parts(hashes_length.saturating_mul(1_000_000) as u64, 0) - + RocksDbWeight::get().reads_writes(2, 2), - ) - } - - fn set_upload_account() -> Weight { - Weight::from_parts(190_000_000, 0) - } - - fn store_root_hash() -> Weight { - Weight::from_parts(185_000_000, 0) - } -} diff --git a/runtime/altair/Cargo.toml b/runtime/altair/Cargo.toml index 02a148130e..f56073a4b5 100644 --- a/runtime/altair/Cargo.toml +++ b/runtime/altair/Cargo.toml @@ -88,7 +88,6 @@ pallet-balances = { workspace = true } pallet-base-fee = { workspace = true } pallet-block-rewards = { workspace = true } pallet-bridge = { workspace = true } -pallet-claims = { workspace = true } pallet-collator-allowlist = { workspace = true } pallet-collator-selection = { workspace = true } pallet-collective = { workspace = true } @@ -219,7 +218,6 @@ std = [ "pallet-base-fee/std", "pallet-block-rewards/std", "pallet-bridge/std", - "pallet-claims/std", "pallet-collator-allowlist/std", "pallet-collator-selection/std", "pallet-collective/std", @@ -310,7 +308,6 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-block-rewards/runtime-benchmarks", "pallet-bridge/runtime-benchmarks", - "pallet-claims/runtime-benchmarks", "pallet-collator-allowlist/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", @@ -399,7 +396,6 @@ try-runtime = [ "pallet-base-fee/try-runtime", "pallet-block-rewards/try-runtime", "pallet-bridge/try-runtime", - "pallet-claims/try-runtime", "pallet-collator-allowlist/try-runtime", "pallet-collator-selection/try-runtime", "pallet-collective/try-runtime", diff --git a/runtime/altair/src/migrations.rs b/runtime/altair/src/migrations.rs index 7b7b485c11..a8436898ad 100644 --- a/runtime/altair/src/migrations.rs +++ b/runtime/altair/src/migrations.rs @@ -17,13 +17,13 @@ pub type UpgradeAltair1034 = ( // FIXME: This migration fails to decode 4 entries against Altair // orml_tokens_migration::CurrencyIdRefactorMigration, // At minimum, bumps storage version from 1 to 2 - runtime_common::migrations::nuke::Migration, + runtime_common::migrations::nuke::ResetPallet, // At minimum, bumps storage version from 0 to 3 - runtime_common::migrations::nuke::Migration, + runtime_common::migrations::nuke::ResetPallet, // At minimum, bumps storage version from 0 to 1 - runtime_common::migrations::nuke::Migration, + runtime_common::migrations::nuke::ResetPallet, // At minimum, bumps storage version from 0 to 1 - runtime_common::migrations::nuke::Migration, + runtime_common::migrations::nuke::ResetPallet, // Funds pallet_rewards::Instance2 account with existential deposit pallet_rewards::migrations::new_instance::FundExistentialDeposit< crate::Runtime, diff --git a/runtime/centrifuge/Cargo.toml b/runtime/centrifuge/Cargo.toml index 314a3d8a47..be757e21b0 100644 --- a/runtime/centrifuge/Cargo.toml +++ b/runtime/centrifuge/Cargo.toml @@ -88,7 +88,6 @@ pallet-balances = { workspace = true } pallet-base-fee = { workspace = true } pallet-block-rewards = { workspace = true } pallet-bridge = { workspace = true } -pallet-claims = { workspace = true } pallet-collator-allowlist = { workspace = true } pallet-collator-selection = { workspace = true } pallet-collective = { workspace = true } @@ -219,7 +218,6 @@ std = [ "pallet-base-fee/std", "pallet-block-rewards/std", "pallet-bridge/std", - "pallet-claims/std", "pallet-collator-allowlist/std", "pallet-collator-selection/std", "pallet-collective/std", @@ -309,7 +307,6 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-block-rewards/runtime-benchmarks", "pallet-bridge/runtime-benchmarks", - "pallet-claims/runtime-benchmarks", "pallet-collator-allowlist/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", @@ -398,7 +395,6 @@ try-runtime = [ "pallet-base-fee/try-runtime", "pallet-block-rewards/try-runtime", "pallet-bridge/try-runtime", - "pallet-claims/try-runtime", "pallet-collator-allowlist/try-runtime", "pallet-collator-selection/try-runtime", "pallet-collective/try-runtime", diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index 2c1ee3a190..03a7c27df6 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -1139,25 +1139,6 @@ impl chainbridge::Config for Runtime { type WeightInfo = (); } -// Parameterize claims pallet -parameter_types! { - pub const ClaimsPalletId: PalletId = cfg_types::ids::CLAIMS_PALLET_ID; - pub const MinimalPayoutAmount: Balance = 5 * CFG; -} - -// Implement claims pallet configuration trait for the mock runtime -impl pallet_claims::Config for Runtime { - type AdminOrigin = EnsureRootOr; - type Currency = Balances; - type MinimalPayoutAmount = MinimalPayoutAmount; - type PalletId = ClaimsPalletId; - type RuntimeEvent = RuntimeEvent; - // NOTE: No benchmarks available. - // BUT will be deprecated once Tinlake - // is wind down. - type WeightInfo = (); -} - // Parameterize crowdloan reward pallet configuration parameter_types! { pub const CrowdloanRewardPalletId: PalletId = cfg_types::ids::CROWDLOAN_REWARD_PALLET_ID; @@ -1916,7 +1897,7 @@ construct_runtime!( // our pallets Fees: pallet_fees::{Pallet, Call, Storage, Config, Event} = 90, Anchor: pallet_anchors::{Pallet, Call, Storage} = 91, - Claims: pallet_claims::{Pallet, Call, Storage, Event} = 92, + // Removed: Claims = 92 Nfts: pallet_nft::{Pallet, Call, Event} = 93, Bridge: pallet_bridge::{Pallet, Call, Storage, Config, Event} = 94, Migration: pallet_migration_manager::{Pallet, Call, Storage, Event} = 95, diff --git a/runtime/centrifuge/src/migrations.rs b/runtime/centrifuge/src/migrations.rs index f6fa50f3b3..8806931305 100644 --- a/runtime/centrifuge/src/migrations.rs +++ b/runtime/centrifuge/src/migrations.rs @@ -10,6 +10,10 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +frame_support::parameter_types! { + pub const ClaimsPalletName: &'static str = "Claims"; +} + pub type UpgradeCentrifuge1025 = ( // Burns tokens from other domains that are falsly not burned when they were transferred back // to their domain @@ -17,7 +21,9 @@ pub type UpgradeCentrifuge1025 = ( runtime_common::migrations::epoch_execution::Migration, // Migrates the currency used in `pallet-transfer-allowlist` from our global currency to a // special filter currency enum - runtime_common::migrations::transfer_allowlist_currency::Migration, + runtime_common::migrations::transfer_allowlist_currency::Migration, + // Removes tinlake reward claims pallet + runtime_common::migrations::nuke::KillPallet, ); // Copyright 2021 Centrifuge Foundation (centrifuge.io). diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index a57a3ceb90..ee854036ca 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -66,7 +66,6 @@ pallet-balances = { workspace = true } pallet-base-fee = { workspace = true } pallet-block-rewards = { workspace = true } pallet-bridge = { workspace = true } -pallet-claims = { workspace = true } pallet-collator-allowlist = { workspace = true } pallet-collator-selection = { workspace = true } pallet-collective = { workspace = true } @@ -205,7 +204,6 @@ std = [ "pallet-base-fee/std", "pallet-block-rewards/std", "pallet-bridge/std", - "pallet-claims/std", "pallet-collator-allowlist/std", "pallet-collator-selection/std", "pallet-collective/std", @@ -288,7 +286,6 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-block-rewards/runtime-benchmarks", "pallet-bridge/runtime-benchmarks", - "pallet-claims/runtime-benchmarks", "pallet-collator-allowlist/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", @@ -366,7 +363,6 @@ try-runtime = [ "pallet-base-fee/try-runtime", "pallet-block-rewards/try-runtime", "pallet-bridge/try-runtime", - "pallet-claims/try-runtime", "pallet-collator-allowlist/try-runtime", "pallet-collator-selection/try-runtime", "pallet-collective/try-runtime", diff --git a/runtime/common/src/migrations/mod.rs b/runtime/common/src/migrations/mod.rs index 7e72e1f5c7..43b15631c1 100644 --- a/runtime/common/src/migrations/mod.rs +++ b/runtime/common/src/migrations/mod.rs @@ -17,5 +17,4 @@ pub mod epoch_execution; pub mod nuke; pub mod orml_tokens; pub mod precompile_account_codes; - pub mod transfer_allowlist_currency; diff --git a/runtime/common/src/migrations/nuke.rs b/runtime/common/src/migrations/nuke.rs index 04956b5af6..360091a422 100644 --- a/runtime/common/src/migrations/nuke.rs +++ b/runtime/common/src/migrations/nuke.rs @@ -24,6 +24,80 @@ use sp_runtime::DispatchError; #[cfg(feature = "try-runtime")] use sp_std::vec::Vec; +/// This upgrade nukes all storage from the pallet individually. +/// +/// If the pallet shall be kept, please use [ResetPallet] instead because +/// here we neither check nor reset the corresponding storage version. +pub struct KillPallet(sp_std::marker::PhantomData<(PalletName, DbWeight)>); + +impl OnRuntimeUpgrade for KillPallet +where + PalletName: Get<&'static str>, + DbWeight: Get, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, DispatchError> { + if !unhashed::contains_prefixed_key(&sp_io::hashing::twox_128(PalletName::get().as_bytes())) + { + log::info!( + "Clear pallet {:?}: Pallet prefix doesn't exist, storage is empty already", + PalletName::get(), + ) + } + + Ok(Vec::new()) + } + + fn on_runtime_upgrade() -> Weight { + log::info!( + "Clear pallet {:?}: nuking pallet prefix...", + PalletName::get() + ); + + let result = unhashed::clear_prefix( + &sp_io::hashing::twox_128(PalletName::get().as_bytes()), + None, + None, + ); + match result.maybe_cursor { + None => log::info!( + "Clear pallet {:?}: storage cleared successful", + PalletName::get() + ), + Some(_) => { + // TODO: Should we loop over maybe_cursor as a new prefix? + // By now, returning error. + log::error!( + "Clear pallet {:?}: storage not totally cleared", + PalletName::get() + ) + } + } + + log::info!( + "Clear pallet {:?}: iteration result. backend: {} unique: {} loops: {}", + PalletName::get(), + result.backend, + result.unique, + result.loops, + ); + + DbWeight::get().writes(result.unique.into()) + DbWeight::get().reads(result.loops.into()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_: Vec) -> Result<(), DispatchError> { + ensure!( + !unhashed::contains_prefixed_key(&sp_io::hashing::twox_128( + PalletName::get().as_bytes() + )), + "Pallet prefix still exists!" + ); + + Ok(()) + } +} + /// This upgrade nukes all storages from the pallet individually. /// This upgrade is only executed if pallet version has changed. /// @@ -31,12 +105,12 @@ use sp_std::vec::Vec; /// you must specify the ON_CHAIN_VERSION, /// which represent the expected previous on-chain version when the upgrade is /// done. If these numbers mismatch, the upgrade will not take effect. -pub struct Migration( +pub struct ResetPallet( sp_std::marker::PhantomData<(Pallet, DbWeight)>, ); impl OnRuntimeUpgrade - for Migration + for ResetPallet where Pallet: GetStorageVersion + PalletInfoAccess, DbWeight: Get, diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index ed10c5ccb5..cb1890c7ed 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -87,7 +87,6 @@ pallet-balances = { workspace = true } pallet-base-fee = { workspace = true } pallet-block-rewards = { workspace = true } pallet-bridge = { workspace = true } -pallet-claims = { workspace = true } pallet-collator-allowlist = { workspace = true } pallet-collator-selection = { workspace = true } pallet-collective = { workspace = true } @@ -217,7 +216,6 @@ std = [ "pallet-base-fee/std", "pallet-block-rewards/std", "pallet-bridge/std", - "pallet-claims/std", "pallet-collator-allowlist/std", "pallet-collator-selection/std", "pallet-collective/std", @@ -308,7 +306,6 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-block-rewards/runtime-benchmarks", "pallet-bridge/runtime-benchmarks", - "pallet-claims/runtime-benchmarks", "pallet-collator-allowlist/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", @@ -397,7 +394,6 @@ try-runtime = [ "pallet-base-fee/try-runtime", "pallet-block-rewards/try-runtime", "pallet-bridge/try-runtime", - "pallet-claims/try-runtime", "pallet-collator-allowlist/try-runtime", "pallet-collator-selection/try-runtime", "pallet-collective/try-runtime", diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index bec8991818..dd24810cd5 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -489,7 +489,6 @@ impl InstanceFilter for ProxyType { RuntimeCall::Preimage(..) | RuntimeCall::Fees(..) | RuntimeCall::Anchor(..) | - RuntimeCall::Claims(..) | RuntimeCall::CrowdloanClaim(..) | RuntimeCall::CrowdloanReward(..) | RuntimeCall::PoolSystem(..) | @@ -1003,22 +1002,6 @@ impl pallet_collator_allowlist::Config for Runtime { type WeightInfo = weights::pallet_collator_allowlist::WeightInfo; } -// Parameterize claims pallet -parameter_types! { - pub const ClaimsPalletId: PalletId = cfg_types::ids::CLAIMS_PALLET_ID; - pub const MinimalPayoutAmount: Balance = 5 * CFG; -} - -// Implement claims pallet configuration trait for the centrifuge runtime -impl pallet_claims::Config for Runtime { - type AdminOrigin = EnsureRootOr; - type Currency = Tokens; - type MinimalPayoutAmount = MinimalPayoutAmount; - type PalletId = ClaimsPalletId; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); -} - // Pool config parameters parameter_types! { pub const PoolPalletId: frame_support::PalletId = cfg_types::ids::POOLS_PALLET_ID; @@ -1900,7 +1883,7 @@ construct_runtime!( // our pallets part 1 Fees: pallet_fees::{Pallet, Call, Storage, Config, Event} = 90, Anchor: pallet_anchors::{Pallet, Call, Storage} = 91, - Claims: pallet_claims::{Pallet, Call, Storage, Event} = 92, + // Removed: Claims = 92 CrowdloanClaim: pallet_crowdloan_claim::{Pallet, Call, Storage, Event} = 93, CrowdloanReward: pallet_crowdloan_reward::{Pallet, Call, Storage, Event} = 94, PoolSystem: pallet_pool_system::{Pallet, Call, Storage, Event} = 95, diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index d0d38ee4b3..393efce545 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -101,7 +101,6 @@ pallet-balances = { workspace = true, features = ["std"] } pallet-base-fee = { workspace = true, features = ["std"] } pallet-block-rewards = { workspace = true, features = ["std"] } pallet-bridge = { workspace = true, features = ["std"] } -pallet-claims = { workspace = true, features = ["std"] } pallet-collator-allowlist = { workspace = true, features = ["std"] } pallet-collator-selection = { workspace = true, features = ["std"] } pallet-collective = { workspace = true, features = ["std"] }