Skip to content

Commit

Permalink
remarks: Add remarks pallet (#1659)
Browse files Browse the repository at this point in the history
* remarks: Add remarks pallet

* development: Add weights for remarks pallet

* centrifuge: Add weights for remarks pallet
  • Loading branch information
cdamian authored Jan 4, 2024
1 parent ba8a1b2 commit 17e00b5
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down
4 changes: 4 additions & 0 deletions runtime/centrifuge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,19 @@ impl pallet_transfer_allowlist::Config for Runtime {
type WeightInfo = weights::pallet_transfer_allowlist::WeightInfo<Runtime>;
}

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<Runtime>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_remarks::WeightInfo<Runtime>;
}

// 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
Expand Down Expand Up @@ -1899,6 +1912,7 @@ construct_runtime!(
TransferAllowList: pallet_transfer_allowlist::{Pallet, Call, Storage, Event<T>} = 110,
OraclePriceFeed: pallet_oracle_feed::{Pallet, Call, Storage, Event<T>} = 111,
OraclePriceCollection: pallet_oracle_collection::{Pallet, Call, Storage, Event<T>} = 112,
Remarks: pallet_remarks::{Pallet, Call, Event<T>} = 113,

// XCM
XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 120,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions runtime/centrifuge/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 46 additions & 0 deletions runtime/centrifuge/src/weights/pallet_remarks.rs
Original file line number Diff line number Diff line change
@@ -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<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_remarks::WeightInfo for WeightInfo<T> {
/// 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()))
}
}
1 change: 1 addition & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
39 changes: 39 additions & 0 deletions runtime/common/src/remarks.rs
Original file line number Diff line number Diff line change
@@ -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<u8, IpfsHashLength>),

/// UTF-8 encoded string
Named(BoundedVec<u8, MaxNamedRemark>),

/// Association with a loan
Loan(LoanId),
}

impl Default for Remark {
fn default() -> Self {
Remark::Named(BoundedVec::try_from(vec![]).unwrap())
}
}
4 changes: 4 additions & 0 deletions runtime/development/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
20 changes: 19 additions & 1 deletion runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,19 @@ impl pallet_order_book::Config for Runtime {
type Weights = weights::pallet_order_book::WeightInfo<Runtime>;
}

parameter_types! {
pub const MaxRemarksPerCall: u32 = 10;
}

impl pallet_remarks::Config for Runtime {
type MaxRemarksPerCall = MaxRemarksPerCall;
type Remark = Remark;
type RemarkDispatchHandler = pallet_remarks::NoopRemarkDispatchHandler<Runtime>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_remarks::WeightInfo<Runtime>;
}

// 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
Expand Down Expand Up @@ -1918,6 +1931,9 @@ construct_runtime!(
Migration: pallet_migration_manager::{Pallet, Call, Storage, Event<T>} = 199,
// admin stuff
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 200,

// our pallets part 2
Remarks: pallet_remarks::{Pallet, Call, Event<T>} = 251,
}
);

Expand Down Expand Up @@ -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! {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions runtime/development/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 46 additions & 0 deletions runtime/development/src/weights/pallet_remarks.rs
Original file line number Diff line number Diff line change
@@ -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<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_remarks::WeightInfo for WeightInfo<T> {
/// 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()))
}
}

0 comments on commit 17e00b5

Please sign in to comment.