From b769fe5a96c3a23df7ec0edcf13a0b2e48cadac2 Mon Sep 17 00:00:00 2001 From: Gabriel Facco de Arruda Date: Fri, 10 Nov 2023 11:11:36 -0300 Subject: [PATCH 1/6] feat: InvArch - Added vesting pallet --- invarch/Cargo.lock | 15 ++++++++ invarch/runtime/Cargo.toml | 4 +-- invarch/runtime/src/balances.rs | 62 +++++++++++++++++++++++++++++++++ invarch/runtime/src/lib.rs | 27 +++----------- 4 files changed, 83 insertions(+), 25 deletions(-) create mode 100644 invarch/runtime/src/balances.rs diff --git a/invarch/Cargo.lock b/invarch/Cargo.lock index 0a395bc7..02aa6a96 100644 --- a/invarch/Cargo.lock +++ b/invarch/Cargo.lock @@ -3955,6 +3955,7 @@ dependencies = [ "frame-try-runtime", "hex-literal 0.3.4", "log", + "orml-vesting", "orml-xcm", "pallet-aura", "pallet-authorship", @@ -5706,6 +5707,20 @@ dependencies = [ "num-traits", ] +[[package]] +name = "orml-vesting" +version = "0.4.1-dev" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.43#28a2e6f0df9540d91db4018c7ecebb8bfc217a2a" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "orml-xcm" version = "0.4.1-dev" diff --git a/invarch/runtime/Cargo.toml b/invarch/runtime/Cargo.toml index 3fa880cf..a2f75aae 100644 --- a/invarch/runtime/Cargo.toml +++ b/invarch/runtime/Cargo.toml @@ -15,7 +15,7 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", bran [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -hex-literal = { version = "0.3.4", optional = true } +hex-literal = { version = "0.3.4" } log = { version = "0.4.17", default-features = false } scale-info = { version = "2.3.1", default-features = false, features = ["derive"] } smallvec = "1.10.0" @@ -51,6 +51,7 @@ sp-version = { git = "https://github.com/paritytech/substrate", default-features # ORML orml-xcm = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.43" } +orml-vesting = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.43" } # Polkadot pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.43" } @@ -123,7 +124,6 @@ std = [ ] runtime-benchmarks = [ - "hex-literal", "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", diff --git a/invarch/runtime/src/balances.rs b/invarch/runtime/src/balances.rs new file mode 100644 index 00000000..6035381d --- /dev/null +++ b/invarch/runtime/src/balances.rs @@ -0,0 +1,62 @@ +use crate::{ + AccountId, Balance, Balances, Runtime, RuntimeEvent, System, EXISTENTIAL_DEPOSIT, UNIT, +}; +use frame_support::{pallet_prelude::ConstU32, parameter_types, traits::SortedMembers}; +use frame_system::EnsureSignedBy; +use sp_std::vec::Vec; + +parameter_types! { + pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = ConstU32<50>; + /// The type for recording an account's balance. + type Balance = Balance; + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = pallet_balances::weights::SubstrateWeight; + type MaxReserves = ConstU32<50>; + type ReserveIdentifier = [u8; 8]; + + type MaxHolds = ConstU32<1>; + type FreezeIdentifier = (); + type MaxFreezes = (); + type HoldIdentifier = [u8; 8]; +} + +parameter_types! { + pub const MinVestedTransfer: Balance = UNIT; + pub const MaxVestingSchedules: u32 = 50u32; +} + +pub struct InvArchAccounts; +impl SortedMembers for InvArchAccounts { + fn sorted_members() -> Vec { + [ + // InvArch/Tinkernet Root Account (i53Pqi67ocj66W81cJNrUvjjoM3RcAsGhXVTzREs5BRfwLnd7) + hex_literal::hex!["f430c3461d19cded0bb3195af29d2b0379a96836c714ceb8e64d3f10902cec55"] + .into(), + // InvArch/Tinkernet Rewards Account (i4zTcKHr38MbSUrhFLVKHG5iULhYttBVrqVon2rv6iWcxQwQQ) + hex_literal::hex!["725bf57f1243bf4b06e911a79eb954d1fe1003f697ef5db9640e64d6e30f9a42"] + .into(), + ] + .to_vec() + } +} + +pub type EnsureInvArchAccount = EnsureSignedBy; + +impl orml_vesting::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type MinVestedTransfer = MinVestedTransfer; + type VestedTransferOrigin = EnsureInvArchAccount; + type WeightInfo = (); + type MaxVestingSchedules = MaxVestingSchedules; + // Relay chain block number provider (6 seconds) + type BlockNumberProvider = cumulus_pallet_parachain_system::RelaychainDataProvider; +} diff --git a/invarch/runtime/src/lib.rs b/invarch/runtime/src/lib.rs index 2859ab68..73a55bd6 100644 --- a/invarch/runtime/src/lib.rs +++ b/invarch/runtime/src/lib.rs @@ -6,9 +6,12 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +pub mod balances; mod weights; pub mod xcm_config; +pub use balances::*; + use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use smallvec::smallvec; use sp_api::impl_runtime_apis; @@ -318,29 +321,6 @@ impl pallet_authorship::Config for Runtime { type EventHandler = (CollatorSelection,); } -parameter_types! { - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; -} - -impl pallet_balances::Config for Runtime { - type MaxLocks = ConstU32<50>; - /// The type for recording an account's balance. - type Balance = Balance; - /// The ubiquitous event type. - type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = pallet_balances::weights::SubstrateWeight; - type MaxReserves = ConstU32<50>; - type ReserveIdentifier = [u8; 8]; - - type MaxHolds = ConstU32<1>; - type FreezeIdentifier = (); - type MaxFreezes = (); - type HoldIdentifier = [u8; 8]; -} - parameter_types! { /// Relay Chain `TransactionByteFee` / 10 pub const TransactionByteFee: Balance = 10 * MICROUNIT; @@ -453,6 +433,7 @@ construct_runtime!( // Monetary stuff. Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 10, TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event} = 11, + Vesting: orml_vesting::{Pallet, Call, Storage, Event} = 12, // Collator support. The order of these 4 are important and shall not change. Authorship: pallet_authorship::{Pallet, Storage} = 20, From bfb3d7e8d958207a7c73edb55dd985f66c6d48f7 Mon Sep 17 00:00:00 2001 From: Gabriel Facco de Arruda Date: Fri, 10 Nov 2023 11:59:03 -0300 Subject: [PATCH 2/6] feat: InvArch - treasury + DealWithFees --- invarch/Cargo.lock | 1 + invarch/runtime/Cargo.toml | 1 + invarch/runtime/src/balances.rs | 102 +++++++++++++++++++++++++++++++- invarch/runtime/src/lib.rs | 54 ++--------------- 4 files changed, 106 insertions(+), 52 deletions(-) diff --git a/invarch/Cargo.lock b/invarch/Cargo.lock index 02aa6a96..d09db718 100644 --- a/invarch/Cargo.lock +++ b/invarch/Cargo.lock @@ -3966,6 +3966,7 @@ dependencies = [ "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", "pallet-xcm", "parachain-info", "parity-scale-codec", diff --git a/invarch/runtime/Cargo.toml b/invarch/runtime/Cargo.toml index a2f75aae..5ec264f3 100644 --- a/invarch/runtime/Cargo.toml +++ b/invarch/runtime/Cargo.toml @@ -37,6 +37,7 @@ pallet-sudo = { git = "https://github.com/paritytech/substrate", default-feature pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } +pallet-treasury = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } diff --git a/invarch/runtime/src/balances.rs b/invarch/runtime/src/balances.rs index 6035381d..16b3dbeb 100644 --- a/invarch/runtime/src/balances.rs +++ b/invarch/runtime/src/balances.rs @@ -1,8 +1,19 @@ use crate::{ - AccountId, Balance, Balances, Runtime, RuntimeEvent, System, EXISTENTIAL_DEPOSIT, UNIT, + AccountId, Balance, Balances, BlockNumber, ExtrinsicBaseWeight, Runtime, RuntimeEvent, System, + Treasury, DAYS, EXISTENTIAL_DEPOSIT, MICROUNIT, MILLIUNIT, UNIT, }; -use frame_support::{pallet_prelude::ConstU32, parameter_types, traits::SortedMembers}; -use frame_system::EnsureSignedBy; +use frame_support::{ + pallet_prelude::ConstU32, + parameter_types, + traits::{Currency, Imbalance, OnUnbalanced, SortedMembers}, + weights::{ + ConstantMultiplier, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, + }, + PalletId, +}; +use frame_system::{EnsureRoot, EnsureSignedBy}; +use polkadot_runtime_common::SlowAdjustingFeeUpdate; +use sp_runtime::{traits::AccountIdConversion, Perbill, Permill}; use sp_std::vec::Vec; parameter_types! { @@ -28,6 +39,63 @@ impl pallet_balances::Config for Runtime { type HoldIdentifier = [u8; 8]; } +parameter_types! { + // Relay Chain `TransactionByteFee` / 10 + pub const TransactionByteFee: Balance = 10 * MICROUNIT; + pub const OperationalFeeMultiplier: u8 = 5; +} + +pub struct WeightToFee; +impl WeightToFeePolynomial for WeightToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + let p = MILLIUNIT; + let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); + smallvec::smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } +} + +type NegativeImbalance = >::NegativeImbalance; + +pub struct ToCollatorPot; +impl OnUnbalanced for ToCollatorPot { + fn on_nonzero_unbalanced(amount: NegativeImbalance) { + let collator_pot = + ::PotId::get().into_account_truncating(); + Balances::resolve_creating(&collator_pot, amount); + } +} + +pub struct DealWithFees; +impl OnUnbalanced for DealWithFees { + fn on_unbalanceds(mut fees_then_tips: impl Iterator) { + if let Some(mut fees) = fees_then_tips.next() { + if let Some(tips) = fees_then_tips.next() { + tips.merge_into(&mut fees); + } + + let (to_treasury, to_collators) = fees.ration(50, 50); + + ToCollatorPot::on_unbalanced(to_collators); + Treasury::on_unbalanced(to_treasury) + } + } +} + +impl pallet_transaction_payment::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter; + type WeightToFee = WeightToFee; + type LengthToFee = ConstantMultiplier; + type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; + type OperationalFeeMultiplier = OperationalFeeMultiplier; +} + parameter_types! { pub const MinVestedTransfer: Balance = UNIT; pub const MaxVestingSchedules: u32 = 50u32; @@ -60,3 +128,31 @@ impl orml_vesting::Config for Runtime { // Relay chain block number provider (6 seconds) type BlockNumberProvider = cumulus_pallet_parachain_system::RelaychainDataProvider; } + +parameter_types! { + pub const ProposalBond: Permill = Permill::from_percent(1); + pub const ProposalBondMinimum: Balance = 100 * UNIT; + pub const SpendPeriod: BlockNumber = 30 * DAYS; + pub const Burn: Permill = Permill::from_percent(1); + pub const TreasuryPalletId: PalletId = PalletId(*b"ia/trsry"); + pub const MaxApprovals: u32 = 100; +} + +impl pallet_treasury::Config for Runtime { + type PalletId = TreasuryPalletId; + type Currency = Balances; + type ApproveOrigin = EnsureRoot; + type RejectOrigin = EnsureRoot; + type RuntimeEvent = RuntimeEvent; + type OnSlash = (); + type ProposalBond = ProposalBond; + type ProposalBondMinimum = ProposalBondMinimum; + type SpendPeriod = SpendPeriod; + type Burn = (); + type BurnDestination = (); + type SpendFunds = (); + type WeightInfo = pallet_treasury::weights::SubstrateWeight; + type MaxApprovals = MaxApprovals; + type ProposalBondMaximum = (); + type SpendOrigin = frame_support::traits::NeverEnsureOrigin; +} diff --git a/invarch/runtime/src/lib.rs b/invarch/runtime/src/lib.rs index 73a55bd6..e1e2c935 100644 --- a/invarch/runtime/src/lib.rs +++ b/invarch/runtime/src/lib.rs @@ -13,7 +13,6 @@ pub mod xcm_config; pub use balances::*; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; -use smallvec::smallvec; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -32,11 +31,8 @@ use frame_support::{ construct_runtime, dispatch::DispatchClass, parameter_types, - traits::{ConstU32, ConstU64, ConstU8, Everything}, - weights::{ - constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient, - WeightToFeeCoefficients, WeightToFeePolynomial, - }, + traits::{ConstU32, ConstU64, Everything}, + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, PalletId, }; use frame_system::{ @@ -50,7 +46,7 @@ pub use sp_runtime::{MultiAddress, Perbill, Permill}; pub use sp_runtime::BuildStorage; // Polkadot imports -use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; +use polkadot_runtime_common::BlockHashCount; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; @@ -116,33 +112,6 @@ pub type Executive = frame_executive::Executive< AllPalletsWithSystem, >; -/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the -/// node's balance type. -/// -/// This should typically create a mapping between the following ranges: -/// - `[0, MAXIMUM_BLOCK_WEIGHT]` -/// - `[Balance::min, Balance::max]` -/// -/// Yet, it can be used for any other sort of change to weight-fee. Some examples being: -/// - Setting it to `0` will essentially disable the weight fee. -/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. -pub struct WeightToFee; -impl WeightToFeePolynomial for WeightToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // in Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1 MILLIUNIT: - // in our template, we map to 1/10 of that, or 1/10 MILLIUNIT - let p = MILLIUNIT / 10; - let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } -} - /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats /// of data like extrinsics, allowing for them to continue syncing the network through upgrades @@ -321,20 +290,6 @@ impl pallet_authorship::Config for Runtime { type EventHandler = (CollatorSelection,); } -parameter_types! { - /// Relay Chain `TransactionByteFee` / 10 - pub const TransactionByteFee: Balance = 10 * MICROUNIT; -} - -impl pallet_transaction_payment::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter; - type WeightToFee = WeightToFee; - type LengthToFee = ConstantMultiplier; - type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; - type OperationalFeeMultiplier = ConstU8<5>; -} - parameter_types! { pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); @@ -433,7 +388,8 @@ construct_runtime!( // Monetary stuff. Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 10, TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event} = 11, - Vesting: orml_vesting::{Pallet, Call, Storage, Event} = 12, + Treasury: pallet_treasury::{Pallet, Call, Storage, Event} = 12, + Vesting: orml_vesting::{Pallet, Call, Storage, Event} = 13, // Collator support. The order of these 4 are important and shall not change. Authorship: pallet_authorship::{Pallet, Storage} = 20, From 6092be3b32473b955ddd5791c5e0797a1f5a5558 Mon Sep 17 00:00:00 2001 From: Gabriel Facco de Arruda Date: Sat, 11 Nov 2023 13:45:41 -0300 Subject: [PATCH 3/6] feat: InvArch - pallets utility and identity --- invarch/Cargo.lock | 2 ++ invarch/runtime/Cargo.toml | 2 ++ invarch/runtime/src/lib.rs | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/invarch/Cargo.lock b/invarch/Cargo.lock index d09db718..53bd806a 100644 --- a/invarch/Cargo.lock +++ b/invarch/Cargo.lock @@ -3961,12 +3961,14 @@ dependencies = [ "pallet-authorship", "pallet-balances", "pallet-collator-selection", + "pallet-identity", "pallet-session", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-treasury", + "pallet-utility", "pallet-xcm", "parachain-info", "parity-scale-codec", diff --git a/invarch/runtime/Cargo.toml b/invarch/runtime/Cargo.toml index 5ec264f3..224852d3 100644 --- a/invarch/runtime/Cargo.toml +++ b/invarch/runtime/Cargo.toml @@ -32,12 +32,14 @@ frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-f pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } pallet-authorship = { 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" } +pallet-identity = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } pallet-treasury = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } +pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } diff --git a/invarch/runtime/src/lib.rs b/invarch/runtime/src/lib.rs index e1e2c935..04ba766b 100644 --- a/invarch/runtime/src/lib.rs +++ b/invarch/runtime/src/lib.rs @@ -369,6 +369,37 @@ impl pallet_sudo::Config for Runtime { type WeightInfo = pallet_sudo::weights::SubstrateWeight; } +impl pallet_utility::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type PalletsOrigin = OriginCaller; + type WeightInfo = pallet_utility::weights::SubstrateWeight; +} + +parameter_types! { + pub BasicDeposit: Balance = 5 * UNIT; + pub FieldDeposit: Balance = 2 * UNIT; + pub const MaxAdditionalFields: u32 = 5; + pub const MaxRegistrars: u32 = 10; + pub const MaxSubAccounts: u32 = 10; + pub SubAccountDeposit: Balance = 5 * UNIT; +} + +impl pallet_identity::Config for Runtime { + type BasicDeposit = BasicDeposit; + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type FieldDeposit = FieldDeposit; + type ForceOrigin = EnsureRoot; + type MaxAdditionalFields = MaxAdditionalFields; + type MaxRegistrars = MaxRegistrars; + type MaxSubAccounts = MaxSubAccounts; + type RegistrarOrigin = EnsureRoot; + type Slashed = Treasury; + type SubAccountDeposit = SubAccountDeposit; + type WeightInfo = pallet_identity::weights::SubstrateWeight; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -384,6 +415,7 @@ construct_runtime!( Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 2, ParachainInfo: parachain_info::{Pallet, Storage, Config} = 3, Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event} = 4, + Utility: pallet_utility::{Pallet, Call, Event} = 5, // Monetary stuff. Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 10, @@ -405,6 +437,9 @@ construct_runtime!( DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 33, OrmlXcm: orml_xcm = 34, + // Extra + Identity: pallet_identity::{Pallet, Call, Storage, Event} = 40, + } ); From 1102e859b675ee80f8a4706a6ea21304f4aa3761 Mon Sep 17 00:00:00 2001 From: Gabriel Facco de Arruda Date: Sat, 11 Nov 2023 19:36:26 -0300 Subject: [PATCH 4/6] chore: InvArch - bump spec version --- invarch/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/invarch/runtime/src/lib.rs b/invarch/runtime/src/lib.rs index 04ba766b..671aee6d 100644 --- a/invarch/runtime/src/lib.rs +++ b/invarch/runtime/src/lib.rs @@ -140,7 +140,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("invarch"), impl_name: create_runtime_str!("invarch"), authoring_version: 1, - spec_version: 2, + spec_version: 3, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 8781e9c21f086629cd99627e45fb217e3276dd84 Mon Sep 17 00:00:00 2001 From: Gabriel Facco de Arruda Date: Sun, 12 Nov 2023 11:59:39 -0300 Subject: [PATCH 5/6] feat: InvArch - Added pallet-tx-pause --- Makefile | 8 + invarch/Cargo.lock | 19 ++ invarch/pallet-tx-pause/Cargo.toml | 67 +++++++ invarch/pallet-tx-pause/src/lib.rs | 241 +++++++++++++++++++++++++ invarch/pallet-tx-pause/src/weights.rs | 107 +++++++++++ invarch/runtime/Cargo.toml | 3 + invarch/runtime/src/lib.rs | 64 ++++--- 7 files changed, 485 insertions(+), 24 deletions(-) create mode 100644 invarch/pallet-tx-pause/Cargo.toml create mode 100644 invarch/pallet-tx-pause/src/lib.rs create mode 100644 invarch/pallet-tx-pause/src/weights.rs diff --git a/Makefile b/Makefile index d617434b..a1edd943 100644 --- a/Makefile +++ b/Makefile @@ -54,3 +54,11 @@ run-tinkernet-solo-bob: cd tinkernet && ./target/release/tinkernet-collator --chain solo-dev --bob --tmp --listen-addr /ip4/0.0.0.0/tcp/54102/ws --rpc-cors=all --discover-local --collator --bootnodes /ip4/127.0.0.1/tcp/53102/ws/p2p/12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2 run-tinkernet-solo: ; printf "run-tinkernet-solo-alice\nrun-tinkernet-solo-bob" | parallel -u make + +run-invarch-solo-alice: + cd invarch && ./target/release/invarch-collator --chain solo-dev --alice --tmp --listen-addr /ip4/0.0.0.0/tcp/53102/ws --rpc-cors=all --discover-local --collator --node-key c12b6d18942f5ee8528c8e2baf4e147b5c5c18710926ea492d09cbd9f6c9f82a + +run-invarch-solo-bob: + cd invarch && ./target/release/invarch-collator --chain solo-dev --bob --tmp --listen-addr /ip4/0.0.0.0/tcp/54102/ws --rpc-cors=all --discover-local --collator --bootnodes /ip4/127.0.0.1/tcp/53102/ws/p2p/12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2 + +run-invarch-solo: ; printf "run-invarch-solo-alice\nrun-invarch-solo-bob" | parallel -u make diff --git a/invarch/Cargo.lock b/invarch/Cargo.lock index 53bd806a..243f0d84 100644 --- a/invarch/Cargo.lock +++ b/invarch/Cargo.lock @@ -3968,6 +3968,7 @@ dependencies = [ "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-treasury", + "pallet-tx-pause", "pallet-utility", "pallet-xcm", "parachain-info", @@ -6672,6 +6673,24 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-tx-pause" +version = "4.0.0-dev" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-balances", + "pallet-proxy", + "pallet-utility", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-utility" version = "4.0.0-dev" diff --git a/invarch/pallet-tx-pause/Cargo.toml b/invarch/pallet-tx-pause/Cargo.toml new file mode 100644 index 00000000..4518e986 --- /dev/null +++ b/invarch/pallet-tx-pause/Cargo.toml @@ -0,0 +1,67 @@ +[package] +name = "pallet-tx-pause" +version = "4.0.0-dev" +authors = ["Parity Technologies "] +edition = "2021" +license = "Apache-2.0" +homepage = "https://substrate.io" +repository = "https://github.com/paritytech/substrate/" +description = "FRAME transaction pause pallet" +readme = "README.md" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } +scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } + +frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.43" } +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" } +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" } +pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.43" } +pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.43" } +pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.43" } + +[dev-dependencies] +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +pallet-proxy = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } + +[features] +default = [ "std" ] +std = [ + "codec/std", + "frame-benchmarking/std", + "frame-support/std", + "frame-system/std", + "pallet-balances?/std", + "pallet-proxy?/std", + "pallet-utility?/std", + "scale-info/std", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", +] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-balances?/try-runtime", + "pallet-proxy?/try-runtime", + "pallet-utility?/try-runtime", + "sp-runtime/try-runtime", +] diff --git a/invarch/pallet-tx-pause/src/lib.rs b/invarch/pallet-tx-pause/src/lib.rs new file mode 100644 index 00000000..2a391788 --- /dev/null +++ b/invarch/pallet-tx-pause/src/lib.rs @@ -0,0 +1,241 @@ +// This file is part of Substrate. + +// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#![cfg_attr(not(feature = "std"), no_std)] +#![deny(rustdoc::broken_intra_doc_links)] + +pub mod weights; + +use frame_support::{ + dispatch::GetDispatchInfo, + pallet_prelude::*, + traits::{CallMetadata, Contains, GetCallMetadata, IsSubType, IsType}, + DefaultNoBound, +}; +use frame_system::pallet_prelude::*; +use sp_runtime::{traits::Dispatchable, DispatchResult}; +use sp_std::{convert::TryInto, prelude::*}; + +pub use pallet::*; +pub use weights::*; + +/// The stringy name of a pallet from [`GetCallMetadata`] for [`Config::RuntimeCall`] variants. +pub type PalletNameOf = BoundedVec::MaxNameLen>; + +/// The stringy name of a call (within a pallet) from [`GetCallMetadata`] for +/// [`Config::RuntimeCall`] variants. +pub type PalletCallNameOf = BoundedVec::MaxNameLen>; + +/// A fully specified pallet ([`PalletNameOf`]) and optional call ([`PalletCallNameOf`]) +/// to partially or fully specify an item a variant of a [`Config::RuntimeCall`]. +pub type RuntimeCallNameOf = (PalletNameOf, PalletCallNameOf); + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::pallet] + pub struct Pallet(PhantomData); + + #[pallet::config] + pub trait Config: frame_system::Config { + /// The overarching event type. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + /// The overarching call type. + type RuntimeCall: Parameter + + Dispatchable + + GetDispatchInfo + + GetCallMetadata + + From> + + IsSubType> + + IsType<::RuntimeCall>; + + /// The only origin that can pause calls. + type PauseOrigin: EnsureOrigin; + + /// The only origin that can un-pause calls. + type UnpauseOrigin: EnsureOrigin; + + /// Contains all calls that cannot be paused. + /// + /// The `TxMode` pallet cannot pause its own calls, and does not need to be explicitly + /// added here. + type WhitelistedCalls: Contains>; + + /// Maximum length for pallet name and call name SCALE encoded string names. + /// + /// TOO LONG NAMES WILL BE TREATED AS PAUSED. + #[pallet::constant] + type MaxNameLen: Get; + + // Weight information for extrinsics in this pallet. + type WeightInfo: WeightInfo; + } + + /// The set of calls that are explicitly paused. + #[pallet::storage] + pub type PausedCalls = + StorageMap<_, Blake2_128Concat, RuntimeCallNameOf, (), OptionQuery>; + + #[pallet::error] + pub enum Error { + /// The call is paused. + IsPaused, + + /// The call is unpaused. + IsUnpaused, + + /// The call is whitelisted and cannot be paused. + Unpausable, + + // The pallet or call does not exist in the runtime. + NotFound, + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + /// This pallet, or a specific call is now paused. + CallPaused { full_name: RuntimeCallNameOf }, + /// This pallet, or a specific call is now unpaused. + CallUnpaused { full_name: RuntimeCallNameOf }, + } + + /// Configure the initial state of this pallet in the genesis block. + #[pallet::genesis_config] + #[derive(DefaultNoBound)] + pub struct GenesisConfig { + /// Initially paused calls. + pub paused: Vec>, + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + for call in &self.paused { + Pallet::::ensure_can_pause(&call).expect("Genesis data is known good; qed"); + PausedCalls::::insert(&call, ()); + } + } + } + + #[pallet::call] + impl Pallet { + /// Pause a call. + /// + /// Can only be called by [`Config::PauseOrigin`]. + /// Emits an [`Event::CallPaused`] event on success. + #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::pause())] + pub fn pause(origin: OriginFor, full_name: RuntimeCallNameOf) -> DispatchResult { + T::PauseOrigin::ensure_origin(origin)?; + + Self::do_pause(full_name).map_err(Into::into) + } + + /// Un-pause a call. + /// + /// Can only be called by [`Config::UnpauseOrigin`]. + /// Emits an [`Event::CallUnpaused`] event on success. + #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::unpause())] + pub fn unpause(origin: OriginFor, ident: RuntimeCallNameOf) -> DispatchResult { + T::UnpauseOrigin::ensure_origin(origin)?; + + Self::do_unpause(ident).map_err(Into::into) + } + } +} + +impl Pallet { + pub(crate) fn do_pause(ident: RuntimeCallNameOf) -> Result<(), Error> { + Self::ensure_can_pause(&ident)?; + PausedCalls::::insert(&ident, ()); + Self::deposit_event(Event::CallPaused { full_name: ident }); + + Ok(()) + } + + pub(crate) fn do_unpause(ident: RuntimeCallNameOf) -> Result<(), Error> { + Self::ensure_can_unpause(&ident)?; + PausedCalls::::remove(&ident); + Self::deposit_event(Event::CallUnpaused { full_name: ident }); + + Ok(()) + } + + /// Return whether this call is paused. + pub fn is_paused(full_name: &RuntimeCallNameOf) -> bool { + if T::WhitelistedCalls::contains(full_name) { + return false; + } + + >::contains_key(full_name) + } + + /// Same as [`Self::is_paused`] but for inputs unbound by max-encoded-len. + pub fn is_paused_unbound(pallet: Vec, call: Vec) -> bool { + let pallet = PalletNameOf::::try_from(pallet); + let call = PalletCallNameOf::::try_from(call); + + match (pallet, call) { + (Ok(pallet), Ok(call)) => Self::is_paused(&(pallet, call)), + _ => true, + } + } + + /// Ensure that this call can be paused. + pub fn ensure_can_pause(full_name: &RuntimeCallNameOf) -> Result<(), Error> { + // SAFETY: The `TxPause` pallet can never pause itself. + if full_name.0.as_ref() == ::name().as_bytes().to_vec() { + return Err(Error::::Unpausable); + } + + if T::WhitelistedCalls::contains(&full_name) { + return Err(Error::::Unpausable); + } + if Self::is_paused(&full_name) { + return Err(Error::::IsPaused); + } + Ok(()) + } + + /// Ensure that this call can be un-paused. + pub fn ensure_can_unpause(full_name: &RuntimeCallNameOf) -> Result<(), Error> { + if Self::is_paused(&full_name) { + // SAFETY: Everything that is paused, can be un-paused. + Ok(()) + } else { + Err(Error::IsUnpaused) + } + } +} + +impl Contains<::RuntimeCall> for Pallet +where + ::RuntimeCall: GetCallMetadata, +{ + /// Return whether the call is allowed to be dispatched. + fn contains(call: &::RuntimeCall) -> bool { + let CallMetadata { + pallet_name, + function_name, + } = call.get_call_metadata(); + !Pallet::::is_paused_unbound(pallet_name.into(), function_name.into()) + } +} diff --git a/invarch/pallet-tx-pause/src/weights.rs b/invarch/pallet-tx-pause/src/weights.rs new file mode 100644 index 00000000..b733e64b --- /dev/null +++ b/invarch/pallet-tx-pause/src/weights.rs @@ -0,0 +1,107 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Autogenerated weights for `pallet_tx_pause` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-08-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-aahe6cbd-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` + +// Executed Command: +// target/production/substrate-node +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/substrate/.git/.artifacts/bench.json +// --pallet=pallet_tx_pause +// --chain=dev +// --header=./HEADER-APACHE2 +// --output=./frame/tx-pause/src/weights.rs +// --template=./.maintain/frame-weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for `pallet_tx_pause`. +pub trait WeightInfo { + fn pause() -> Weight; + fn unpause() -> Weight; +} + +/// Weights for `pallet_tx_pause` using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: `TxPause::PausedCalls` (r:1 w:1) + /// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`) + fn pause() -> Weight { + // Proof Size summary in bytes: + // Measured: `3` + // Estimated: `3997` + // Minimum execution time: 15_096_000 picoseconds. + Weight::from_parts(15_437_000, 3997) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `TxPause::PausedCalls` (r:1 w:1) + /// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`) + fn unpause() -> Weight { + // Proof Size summary in bytes: + // Measured: `565` + // Estimated: `3997` + // Minimum execution time: 21_546_000 picoseconds. + Weight::from_parts(22_178_000, 3997) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} + +// For backwards compatibility and tests. +impl WeightInfo for () { + /// Storage: `TxPause::PausedCalls` (r:1 w:1) + /// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`) + fn pause() -> Weight { + // Proof Size summary in bytes: + // Measured: `3` + // Estimated: `3997` + // Minimum execution time: 15_096_000 picoseconds. + Weight::from_parts(15_437_000, 3997) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `TxPause::PausedCalls` (r:1 w:1) + /// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`) + fn unpause() -> Weight { + // Proof Size summary in bytes: + // Measured: `565` + // Estimated: `3997` + // Minimum execution time: 21_546_000 picoseconds. + Weight::from_parts(22_178_000, 3997) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } +} diff --git a/invarch/runtime/Cargo.toml b/invarch/runtime/Cargo.toml index 224852d3..16387d17 100644 --- a/invarch/runtime/Cargo.toml +++ b/invarch/runtime/Cargo.toml @@ -52,6 +52,9 @@ sp-std = { git = "https://github.com/paritytech/substrate", default-features = f sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } +## Local tx-pause pallet as it wasn't available at the time of v0.9.43 +pallet-tx-pause = { path = "../pallet-tx-pause", default-features = false } + # ORML orml-xcm = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.43" } orml-vesting = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.43" } diff --git a/invarch/runtime/src/lib.rs b/invarch/runtime/src/lib.rs index 671aee6d..6917bd9e 100644 --- a/invarch/runtime/src/lib.rs +++ b/invarch/runtime/src/lib.rs @@ -6,32 +6,12 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -pub mod balances; -mod weights; -pub mod xcm_config; - -pub use balances::*; - use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; -use sp_api::impl_runtime_apis; -use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; -use sp_runtime::{ - create_runtime_str, generic, impl_opaque_keys, - traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, Verify}, - transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, MultiSignature, -}; - -use sp_std::prelude::*; -#[cfg(feature = "std")] -use sp_version::NativeVersion; -use sp_version::RuntimeVersion; - use frame_support::{ construct_runtime, dispatch::DispatchClass, parameter_types, - traits::{ConstU32, ConstU64, Everything}, + traits::{ConstU32, ConstU64, Contains, Everything, InsideBoth}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, PalletId, }; @@ -39,15 +19,30 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, }; +use polkadot_runtime_common::BlockHashCount; +use sp_api::impl_runtime_apis; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; +use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; +use sp_runtime::{ + create_runtime_str, generic, impl_opaque_keys, + traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, Verify}, + transaction_validity::{TransactionSource, TransactionValidity}, + ApplyExtrinsicResult, MultiSignature, +}; pub use sp_runtime::{MultiAddress, Perbill, Permill}; +use sp_std::prelude::*; +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::RuntimeVersion; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; -// Polkadot imports -use polkadot_runtime_common::BlockHashCount; +pub mod balances; +mod weights; +pub mod xcm_config; +use balances::*; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. @@ -263,7 +258,7 @@ impl frame_system::Config for Runtime { /// The weight of database operations that the runtime can invoke. type DbWeight = RocksDbWeight; /// The basic call filter to use in dispatchable. - type BaseCallFilter = Everything; + type BaseCallFilter = InsideBoth; /// Weight information for the extrinsics of this pallet. type SystemWeightInfo = (); /// Block & extrinsics weights: base values and limits. @@ -400,6 +395,26 @@ impl pallet_identity::Config for Runtime { type WeightInfo = pallet_identity::weights::SubstrateWeight; } +pub struct TxPauseWhitelistedCalls; +impl Contains> for TxPauseWhitelistedCalls { + fn contains(full_name: &pallet_tx_pause::RuntimeCallNameOf) -> bool { + match (full_name.0.as_slice(), full_name.1.as_slice()) { + (b"Sudo", _) => true, + _ => false, + } + } +} + +impl pallet_tx_pause::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MaxNameLen = ConstU32<50>; + type PauseOrigin = EnsureRoot; + type UnpauseOrigin = EnsureRoot; + type RuntimeCall = RuntimeCall; + type WeightInfo = pallet_tx_pause::weights::SubstrateWeight; + type WhitelistedCalls = TxPauseWhitelistedCalls; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -416,6 +431,7 @@ construct_runtime!( ParachainInfo: parachain_info::{Pallet, Storage, Config} = 3, Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event} = 4, Utility: pallet_utility::{Pallet, Call, Event} = 5, + TxPause: pallet_tx_pause::{Pallet, Call, Storage, Event} = 6, // Monetary stuff. Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 10, From df85c4269a8df5db62a151a4f1a68e9062c6f9bf Mon Sep 17 00:00:00 2001 From: Gabriel Facco de Arruda Date: Sun, 12 Nov 2023 13:04:52 -0300 Subject: [PATCH 6/6] chore: InvArch - clippy cleanup --- invarch/pallet-tx-pause/src/lib.rs | 10 +++++----- invarch/runtime/src/lib.rs | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/invarch/pallet-tx-pause/src/lib.rs b/invarch/pallet-tx-pause/src/lib.rs index 2a391788..16ef0c66 100644 --- a/invarch/pallet-tx-pause/src/lib.rs +++ b/invarch/pallet-tx-pause/src/lib.rs @@ -128,8 +128,8 @@ pub mod pallet { impl GenesisBuild for GenesisConfig { fn build(&self) { for call in &self.paused { - Pallet::::ensure_can_pause(&call).expect("Genesis data is known good; qed"); - PausedCalls::::insert(&call, ()); + Pallet::::ensure_can_pause(call).expect("Genesis data is known good; qed"); + PausedCalls::::insert(call, ()); } } } @@ -206,10 +206,10 @@ impl Pallet { return Err(Error::::Unpausable); } - if T::WhitelistedCalls::contains(&full_name) { + if T::WhitelistedCalls::contains(full_name) { return Err(Error::::Unpausable); } - if Self::is_paused(&full_name) { + if Self::is_paused(full_name) { return Err(Error::::IsPaused); } Ok(()) @@ -217,7 +217,7 @@ impl Pallet { /// Ensure that this call can be un-paused. pub fn ensure_can_unpause(full_name: &RuntimeCallNameOf) -> Result<(), Error> { - if Self::is_paused(&full_name) { + if Self::is_paused(full_name) { // SAFETY: Everything that is paused, can be un-paused. Ok(()) } else { diff --git a/invarch/runtime/src/lib.rs b/invarch/runtime/src/lib.rs index 6917bd9e..90b3f049 100644 --- a/invarch/runtime/src/lib.rs +++ b/invarch/runtime/src/lib.rs @@ -398,10 +398,10 @@ impl pallet_identity::Config for Runtime { pub struct TxPauseWhitelistedCalls; impl Contains> for TxPauseWhitelistedCalls { fn contains(full_name: &pallet_tx_pause::RuntimeCallNameOf) -> bool { - match (full_name.0.as_slice(), full_name.1.as_slice()) { - (b"Sudo", _) => true, - _ => false, - } + matches!( + (full_name.0.as_slice(), full_name.1.as_slice()), + (b"Sudo", _) + ) } }