Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pallet_parameters. #2898

Closed
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ pallet-identity = { git = "https://github.com/moonbeam-foundation/polkadot-sdk",
pallet-message-queue = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
pallet-multisig = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
pallet-preimage = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
pallet-parameters = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
pallet-proxy = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
pallet-referenda = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
pallet-root-testing = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pallet-identity = { workspace = true }
pallet-moonbeam-orbiters = { workspace = true }
pallet-multisig = { workspace = true }
pallet-preimage = { workspace = true }
pallet-parameters = { workspace = true }
pallet-proxy = { workspace = true }
pallet-referenda = { workspace = true }
pallet-scheduler = { workspace = true }
Expand Down Expand Up @@ -99,6 +100,7 @@ std = [
"pallet-evm/std",
"pallet-migrations/std",
"pallet-parachain-staking/std",
"pallet-parameters/std",
"pallet-randomness/std",
"pallet-referenda/std",
"pallet-scheduler/std",
Expand Down Expand Up @@ -136,6 +138,7 @@ runtime-benchmarks = [
"pallet-multisig/runtime-benchmarks",
"pallet-parachain-staking/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-parameters/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-randomness/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
Expand Down
4 changes: 4 additions & 0 deletions runtime/common/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,10 @@ macro_rules! impl_runtime_apis_plus_common {
hex_literal::hex!( "0d715f2646c8f85767b5d2764bb27826"
"04a74d81251e398fd8a0a4d55023bb3f")
.to_vec().into(),
// Parameters Parameters
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters Parameters is a map, not a value.
This whitelist do nothing then, as we can whitelist only full keys

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no option to whitelist an entire storage?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, we have to edit manually this list each time we add a parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

hex_literal::hex!( "c63bdd4a39095ccf55623a6f2872bf8a"
"c63bdd4a39095ccf55623a6f2872bf8a")
.to_vec().into(),

];

Expand Down
1 change: 1 addition & 0 deletions runtime/common/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub mod pallet_moonbeam_lazy_migrations;
pub mod pallet_moonbeam_orbiters;
pub mod pallet_multisig;
pub mod pallet_parachain_staking;
pub mod pallet_parameters;
pub mod pallet_precompile_benchmarks;
pub mod pallet_preimage;
pub mod pallet_proxy;
Expand Down
60 changes: 60 additions & 0 deletions runtime/common/src/weights/pallet_parameters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2019-2022 PureStake Inc.
// This file is part of Moonbeam.

// Moonbeam 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.

// Moonbeam 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 Moonbeam. If not, see <http://www.gnu.org/licenses/>.

//! Autogenerated weights for `pallet_parameters`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-08-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `COV0706`, CPU: `AMD Ryzen 9 7950X 16-Core Processor`
//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024

// Executed Command:
// ./target/release/moonbeam
// benchmark
// pallet
// --chain=moonbase-dev
// --steps=50
// --repeat=20
// --pallet=pallet_parameters
// --extrinsic=*
// --wasm-execution=compiled
// --header=./file_header.txt
// --template=./benchmarking/frame-weight-template.hbs
// --output=./runtime/common/src/weights/

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;

/// Weights for `pallet_parameters`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_parameters::WeightInfo for WeightInfo<T> {
/// Storage: `Parameters::Parameters` (r:1 w:1)
/// Proof: `Parameters::Parameters` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`)
fn set_parameter() -> Weight {
// Proof Size summary in bytes:
// Measured: `3`
// Estimated: `3501`
// Minimum execution time: 5_480_000 picoseconds.
Weight::from_parts(5_610_000, 3501)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}
4 changes: 4 additions & 0 deletions runtime/moonbase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pallet-conviction-voting = { workspace = true }
pallet-identity = { workspace = true }
pallet-multisig = { workspace = true }
pallet-preimage = { workspace = true }
pallet-parameters = { workspace = true }
pallet-proxy = { workspace = true }
pallet-referenda = { workspace = true }
pallet-root-testing = { workspace = true }
Expand Down Expand Up @@ -274,6 +275,7 @@ std = [
"pallet-parachain-staking/std",
"pallet-precompile-benchmarks/std",
"pallet-preimage/std",
"pallet-parameters/std",
"pallet-proxy-genesis-companion/std",
"pallet-proxy/std",
"pallet-randomness/std",
Expand Down Expand Up @@ -365,6 +367,7 @@ runtime-benchmarks = [
"pallet-parachain-staking/runtime-benchmarks",
"pallet-precompile-benchmarks/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-parameters/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-randomness/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
Expand Down Expand Up @@ -406,6 +409,7 @@ try-runtime = [
"pallet-moonbeam-lazy-migrations/try-runtime",
"pallet-parachain-staking/try-runtime",
"pallet-preimage/try-runtime",
"pallet-parameters/try-runtime",
"pallet-referenda/try-runtime",
"pallet-relay-storage-roots/try-runtime",
"pallet-root-testing/try-runtime",
Expand Down
4 changes: 1 addition & 3 deletions runtime/moonbase/src/governance/referenda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
//! 3. pallet-referenda

use super::*;
use crate::currency::*;
use frame_support::traits::{EitherOf, MapSuccess};
use frame_system::EnsureRootWithSuccess;
use moonbeam_runtime_common::weights as moonbase_weights;
Expand All @@ -45,7 +44,6 @@ impl pallet_conviction_voting::Config for Runtime {

parameter_types! {
pub const AlarmInterval: BlockNumber = 1;
pub const SubmissionDeposit: Balance = 10 * UNIT * SUPPLY_FACTOR;
pub const UndecidingTimeout: BlockNumber = 21 * DAYS;
}

Expand Down Expand Up @@ -92,7 +90,7 @@ impl pallet_referenda::Config for Runtime {
type Slash = Treasury;
type Votes = pallet_conviction_voting::VotesOf<Runtime>;
type Tally = pallet_conviction_voting::TallyOf<Runtime>;
type SubmissionDeposit = SubmissionDeposit;
type SubmissionDeposit = runtime_params::dynamic_params::pallet_referenda::SubmissionDeposit;
type MaxQueued = ConstU32<100>;
type UndecidingTimeout = UndecidingTimeout;
type AlarmInterval = AlarmInterval;
Expand Down
12 changes: 12 additions & 0 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

pub mod asset_config;
pub mod governance;
pub mod runtime_params;
pub mod xcm_config;

mod migrations;
Expand Down Expand Up @@ -125,6 +126,8 @@ use xcm_config::AssetType;
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
use xcm_primitives::UnitsToWeightRatio;

use runtime_params::*;

use smallvec::smallvec;
use sp_runtime::serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -1379,6 +1382,13 @@ impl pallet_precompile_benchmarks::Config for Runtime {
type WeightInfo = moonbase_weights::pallet_precompile_benchmarks::WeightInfo<Runtime>;
}

impl pallet_parameters::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type RuntimeParameters = RuntimeParameters;
type WeightInfo = moonbase_weights::pallet_parameters::WeightInfo<Runtime>;
}

construct_runtime! {
pub enum Runtime
{
Expand Down Expand Up @@ -1441,6 +1451,7 @@ construct_runtime! {
MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event<T>} = 54,
EmergencyParaXcm: pallet_emergency_para_xcm::{Pallet, Call, Storage, Event} = 55,
EvmForeignAssets: pallet_moonbeam_foreign_assets::{Pallet, Call, Storage, Event<T>} = 56,
Parameters: pallet_parameters = 57,
}
}

Expand Down Expand Up @@ -1516,6 +1527,7 @@ mod benches {
[pallet_relay_storage_roots, RelayStorageRoots]
[pallet_precompile_benchmarks, PrecompileBenchmarks]
[pallet_moonbeam_lazy_migrations, MoonbeamLazyMigrations]
[pallet_parameters, Parameters]
);
}

Expand Down
55 changes: 55 additions & 0 deletions runtime/moonbase/src/runtime_params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2024 Moonbeam Foundation.
// This file is part of Moonbeam.

// Moonbeam 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.

// Moonbeam 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 Moonbeam. If not, see <http://www.gnu.org/licenses/>.

//! Dynamic runtime parametes.
use crate::currency::{SUPPLY_FACTOR, UNIT};
use crate::{Balance, Runtime};
use account::AccountId20;
use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params};

#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::<Runtime>)]
pub mod dynamic_params {
use super::*;

#[dynamic_pallet_params]
#[codec(index = 0)]
pub mod pallet_referenda {

#[codec(index = 0)]
pub static SubmissionDeposit: Balance = 10 * UNIT * SUPPLY_FACTOR;
}

#[dynamic_pallet_params]
#[codec(index = 1)]
pub mod xcm_executor {

#[codec(index = 0)]
/// Xcm fees will go to the treasury account
pub static XcmFeesAccount: AccountId20 = crate::Treasury::account_id();
}
}

#[cfg(feature = "runtime-benchmarks")]
impl Default for RuntimeParameters {
fn default() -> Self {
RuntimeParameters::PalletReferenda(
dynamic_params::pallet_referenda::Parameters::SubmissionDeposit(
dynamic_params::pallet_referenda::SubmissionDeposit,
Some(10 * UNIT * SUPPLY_FACTOR),
),
)
}
}
11 changes: 3 additions & 8 deletions runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use super::{
governance, AccountId, AssetId, AssetManager, Balance, Balances, DealWithFees,
EmergencyParaXcm, Erc20XcmBridge, EvmForeignAssets, MaintenanceMode, MessageQueue,
ParachainInfo, ParachainSystem, Perbill, PolkadotXcm, Runtime, RuntimeBlockWeights,
RuntimeCall, RuntimeEvent, RuntimeOrigin, Treasury, XcmpQueue,
RuntimeCall, RuntimeEvent, RuntimeOrigin, XcmpQueue,
};
use crate::OpenTechCommitteeInstance;
use crate::{runtime_params, OpenTechCommitteeInstance};
use moonbeam_runtime_common::weights as moonbase_weights;
use moonkit_xcm_primitives::AccountIdAssetIdConversion;
use sp_runtime::{
Expand Down Expand Up @@ -227,11 +227,6 @@ pub type XcmBarrier = (
>,
);

parameter_types! {
/// Xcm fees will go to the treasury account
pub XcmFeesAccount: AccountId = Treasury::account_id();
}

/// This is the struct that will handle the revenue from xcm fees
/// We do not burn anything because we want to mimic exactly what
/// the sovereign account has
Expand All @@ -246,7 +241,7 @@ pub type XcmFeesToAccount = xcm_primitives::XcmFeesToAccount<
>,
),
AccountId,
XcmFeesAccount,
runtime_params::dynamic_params::xcm_executor::XcmFeesAccount,
>;

// Our implementation of the Moonbeam Call
Expand Down
Loading