From 17e00b527b63d6deeb9adcf960a3716029f4f9a2 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:34:10 +0100 Subject: [PATCH] remarks: Add remarks pallet (#1659) * remarks: Add remarks pallet * development: Add weights for remarks pallet * centrifuge: Add weights for remarks pallet --- Cargo.lock | 16 +++++++ Cargo.toml | 3 +- runtime/centrifuge/Cargo.toml | 4 ++ runtime/centrifuge/src/lib.rs | 16 +++++++ runtime/centrifuge/src/weights/mod.rs | 1 + .../centrifuge/src/weights/pallet_remarks.rs | 46 +++++++++++++++++++ runtime/common/src/lib.rs | 1 + runtime/common/src/remarks.rs | 39 ++++++++++++++++ runtime/development/Cargo.toml | 4 ++ runtime/development/src/lib.rs | 20 +++++++- runtime/development/src/weights/mod.rs | 1 + .../development/src/weights/pallet_remarks.rs | 46 +++++++++++++++++++ 12 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 runtime/centrifuge/src/weights/pallet_remarks.rs create mode 100644 runtime/common/src/remarks.rs create mode 100644 runtime/development/src/weights/pallet_remarks.rs diff --git a/Cargo.lock b/Cargo.lock index 90956be429..2acd855272 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1205,6 +1205,7 @@ dependencies = [ "pallet-pool-system", "pallet-preimage", "pallet-proxy", + "pallet-remarks", "pallet-restricted-tokens", "pallet-restricted-xtokens", "pallet-rewards", @@ -2812,6 +2813,7 @@ dependencies = [ "pallet-pool-system", "pallet-preimage", "pallet-proxy", + "pallet-remarks", "pallet-restricted-tokens", "pallet-restricted-xtokens", "pallet-rewards", @@ -8425,6 +8427,20 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-remarks" +version = "0.0.1" +source = "git+https://github.com/foss3/runtime-pallet-library?branch=polkadot-v0.9.43#4c6aa68ce21729b835e56b8aaf1b76040a4cf189" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec 3.6.5", + "scale-info", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-restricted-tokens" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index fc6eb1b9e9..9a1f31776c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -243,6 +243,7 @@ chainbridge = { git = "https://github.com/centrifuge/chainbridge-substrate.git", # Foss3 mock-builder = { git = "https://github.com/foss3/runtime-pallet-library", branch = "polkadot-v0.9.43" } +pallet-remarks = { git = "https://github.com/foss3/runtime-pallet-library", branch = "polkadot-v0.9.43", default-features = false } # Centrifuge pallets axelar-gateway-precompile = { path = "pallets/liquidity-pools-gateway/axelar-gateway-precompile", default-features = false } @@ -285,7 +286,7 @@ cfg-types = { path = "libs/types", default-features = false } cfg-utils = { path = "libs/utils", default-features = false } cfg-mocks = { path = "libs/mocks", default-features = false } -# Centrifuge uuntimes +# Centrifuge runtimes runtime-common = { path = "runtime/common", default-features = false } development-runtime = { path = "runtime/development", default-features = false } altair-runtime = { path = "runtime/altair", default-features = false } diff --git a/runtime/centrifuge/Cargo.toml b/runtime/centrifuge/Cargo.toml index a2acc5558b..190c4c8397 100644 --- a/runtime/centrifuge/Cargo.toml +++ b/runtime/centrifuge/Cargo.toml @@ -123,6 +123,7 @@ pallet-pool-registry = { workspace = true } pallet-pool-system = { workspace = true } pallet-preimage = { workspace = true } pallet-proxy = { workspace = true } +pallet-remarks = { workspace = true } pallet-restricted-tokens = { workspace = true } pallet-restricted-xtokens = { workspace = true } pallet-rewards = { workspace = true } @@ -252,6 +253,7 @@ 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", @@ -339,6 +341,7 @@ 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", @@ -427,6 +430,7 @@ 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", diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index 0190b95f22..e81951aa8a 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -1836,6 +1836,19 @@ impl pallet_transfer_allowlist::Config for Runtime { type WeightInfo = weights::pallet_transfer_allowlist::WeightInfo; } +parameter_types! { + pub const MaxRemarksPerCall: u32 = 10; +} + +impl pallet_remarks::Config for Runtime { + type MaxRemarksPerCall = MaxRemarksPerCall; + type Remark = runtime_common::remarks::Remark; + type RemarkDispatchHandler = pallet_remarks::NoopRemarkDispatchHandler; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = weights::pallet_remarks::WeightInfo; +} + // Frame Order in this block dictates the index of each one in the metadata // Any addition should be done at the bottom // Any deletion affects the following frames during runtime upgrades @@ -1899,6 +1912,7 @@ construct_runtime!( TransferAllowList: pallet_transfer_allowlist::{Pallet, Call, Storage, Event} = 110, OraclePriceFeed: pallet_oracle_feed::{Pallet, Call, Storage, Event} = 111, OraclePriceCollection: pallet_oracle_collection::{Pallet, Call, Storage, Event} = 112, + Remarks: pallet_remarks::{Pallet, Call, Event} = 113, // XCM XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 120, @@ -2513,6 +2527,7 @@ impl_runtime_apis! { list_benchmark!(list, extra, pallet_transfer_allowlist, TransferAllowList); list_benchmark!(list, extra, pallet_oracle_feed, OraclePriceFeed); list_benchmark!(list, extra, pallet_oracle_collection, OraclePriceCollection); + list_benchmark!(list, extra, pallet_remarks, Remarks); let storage_info = AllPalletsWithSystem::storage_info(); @@ -2590,6 +2605,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_transfer_allowlist, TransferAllowList); add_benchmark!(params, batches, pallet_oracle_feed, OraclePriceFeed); add_benchmark!(params, batches, pallet_oracle_collection, OraclePriceCollection); + add_benchmark!(params, batches, pallet_remarks, Remarks); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/centrifuge/src/weights/mod.rs b/runtime/centrifuge/src/weights/mod.rs index cffb3664ed..338d459ee1 100644 --- a/runtime/centrifuge/src/weights/mod.rs +++ b/runtime/centrifuge/src/weights/mod.rs @@ -38,6 +38,7 @@ pub mod pallet_pool_registry; pub mod pallet_pool_system; pub mod pallet_preimage; pub mod pallet_proxy; +pub mod pallet_remarks; pub mod pallet_restricted_tokens; pub mod pallet_scheduler; pub mod pallet_session; diff --git a/runtime/centrifuge/src/weights/pallet_remarks.rs b/runtime/centrifuge/src/weights/pallet_remarks.rs new file mode 100644 index 0000000000..1c7b5b85b9 --- /dev/null +++ b/runtime/centrifuge/src/weights/pallet_remarks.rs @@ -0,0 +1,46 @@ + +//! Autogenerated weights for `pallet_remarks` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2024-01-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner`, CPU: `AMD EPYC 7763 64-Core Processor` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("centrifuge-dev"), DB CACHE: 1024 + +// Executed Command: +// target/release/centrifuge-chain +// benchmark +// pallet +// --chain=centrifuge-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_remarks +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=/tmp/runtime/centrifuge/src/weights/pallet_remarks.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_remarks`. +pub struct WeightInfo(PhantomData); +impl pallet_remarks::WeightInfo for WeightInfo { + /// The range of component `n` is `[1, 10]`. + fn remark(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 16_792_000 picoseconds. + Weight::from_parts(17_287_221, 0) + .saturating_add(Weight::from_parts(0, 0)) + // Standard Error: 2_915 + .saturating_add(Weight::from_parts(145_247, 0).saturating_mul(n.into())) + } +} diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 51e6d84b87..7715d1567c 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -23,6 +23,7 @@ pub mod fees; pub mod gateway; pub mod migrations; pub mod oracle; +pub mod remarks; pub mod transfer_filter; pub mod xcm; diff --git a/runtime/common/src/remarks.rs b/runtime/common/src/remarks.rs new file mode 100644 index 0000000000..1a8a6f5cd7 --- /dev/null +++ b/runtime/common/src/remarks.rs @@ -0,0 +1,39 @@ +// Copyright 2023 Centrifuge Foundation (centrifuge.io). +// +// This file is part of the 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 cfg_primitives::LoanId; +use frame_support::{dispatch::TypeInfo, parameter_types, BoundedVec}; +use sp_runtime::codec::{Decode, Encode}; +use sp_std::vec; + +parameter_types! { + pub const IpfsHashLength: u32 = 64; + pub const MaxNamedRemark: u32 = 1024; +} + +#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode, TypeInfo)] +pub enum Remark { + /// IPFS hash + IpfsHash(BoundedVec), + + /// UTF-8 encoded string + Named(BoundedVec), + + /// Association with a loan + Loan(LoanId), +} + +impl Default for Remark { + fn default() -> Self { + Remark::Named(BoundedVec::try_from(vec![]).unwrap()) + } +} diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index 4e230ebeac..aed868e6e7 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -122,6 +122,7 @@ pallet-pool-registry = { workspace = true } pallet-pool-system = { workspace = true } pallet-preimage = { workspace = true } pallet-proxy = { workspace = true } +pallet-remarks = { workspace = true } pallet-restricted-tokens = { workspace = true } pallet-restricted-xtokens = { workspace = true } pallet-rewards = { workspace = true } @@ -250,6 +251,7 @@ 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", @@ -338,6 +340,7 @@ 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", @@ -426,6 +429,7 @@ 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", diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index b0eb967ff2..83f26e8eec 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -1819,6 +1819,19 @@ impl pallet_order_book::Config for Runtime { type Weights = weights::pallet_order_book::WeightInfo; } +parameter_types! { + pub const MaxRemarksPerCall: u32 = 10; +} + +impl pallet_remarks::Config for Runtime { + type MaxRemarksPerCall = MaxRemarksPerCall; + type Remark = Remark; + type RemarkDispatchHandler = pallet_remarks::NoopRemarkDispatchHandler; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = weights::pallet_remarks::WeightInfo; +} + // Frame Order in this block dictates the index of each one in the metadata // Any addition should be done at the bottom // Any deletion affects the following frames during runtime upgrades @@ -1918,6 +1931,9 @@ construct_runtime!( Migration: pallet_migration_manager::{Pallet, Call, Storage, Event} = 199, // admin stuff Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event} = 200, + + // our pallets part 2 + Remarks: pallet_remarks::{Pallet, Call, Event} = 251, } ); @@ -2076,7 +2092,7 @@ mod __runtime_api_use { #[cfg(not(feature = "disable-runtime-api"))] use __runtime_api_use::*; -use runtime_common::transfer_filter::PreNativeTransfer; +use runtime_common::{remarks::Remark, transfer_filter::PreNativeTransfer}; #[cfg(not(feature = "disable-runtime-api"))] impl_runtime_apis! { @@ -2608,6 +2624,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_xcm, PolkadotXcm); add_benchmark!(params, batches, pallet_oracle_feed, OraclePriceFeed); add_benchmark!(params, batches, pallet_oracle_collection, OraclePriceCollection); + add_benchmark!(params, batches, pallet_remarks, Remarks); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) @@ -2667,6 +2684,7 @@ impl_runtime_apis! { list_benchmark!(list, extra, pallet_xcm, PolkadotXcm); list_benchmark!(list, extra, pallet_oracle_feed, OraclePriceFeed); list_benchmark!(list, extra, pallet_oracle_collection, OraclePriceCollection); + list_benchmark!(list, extra, pallet_remarks, Remarks); let storage_info = AllPalletsWithSystem::storage_info(); diff --git a/runtime/development/src/weights/mod.rs b/runtime/development/src/weights/mod.rs index 35dfe0dd1d..af5fd9ed8b 100644 --- a/runtime/development/src/weights/mod.rs +++ b/runtime/development/src/weights/mod.rs @@ -38,6 +38,7 @@ pub mod pallet_pool_registry; pub mod pallet_pool_system; pub mod pallet_preimage; pub mod pallet_proxy; +pub mod pallet_remarks; pub mod pallet_restricted_tokens; pub mod pallet_scheduler; pub mod pallet_session; diff --git a/runtime/development/src/weights/pallet_remarks.rs b/runtime/development/src/weights/pallet_remarks.rs new file mode 100644 index 0000000000..2bdbe1a041 --- /dev/null +++ b/runtime/development/src/weights/pallet_remarks.rs @@ -0,0 +1,46 @@ + +//! Autogenerated weights for `pallet_remarks` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2024-01-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner`, CPU: `AMD EPYC 7763 64-Core Processor` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("development-local"), DB CACHE: 1024 + +// Executed Command: +// target/release/centrifuge-chain +// benchmark +// pallet +// --chain=development-local +// --steps=50 +// --repeat=20 +// --pallet=pallet_remarks +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=/tmp/runtime/development/src/weights/pallet_remarks.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_remarks`. +pub struct WeightInfo(PhantomData); +impl pallet_remarks::WeightInfo for WeightInfo { + /// The range of component `n` is `[1, 10]`. + fn remark(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 16_390_000 picoseconds. + Weight::from_parts(16_943_014, 0) + .saturating_add(Weight::from_parts(0, 0)) + // Standard Error: 3_395 + .saturating_add(Weight::from_parts(155_924, 0).saturating_mul(n.into())) + } +}