From 3f0dc87c1b1f47d61a8b99bda8440c895d081389 Mon Sep 17 00:00:00 2001 From: Nicolas Fernandez Date: Tue, 28 Nov 2023 18:51:47 +0100 Subject: [PATCH 1/3] Configure payments pallet in the Kreivo runtime --- Cargo.lock | 26 ++ Cargo.toml | 4 +- pallets/payments/Cargo.toml | 2 + pallets/payments/src/benchmarking.rs | 36 ++- pallets/payments/src/lib.rs | 21 +- pallets/payments/src/mock.rs | 2 + pallets/payments/src/tests.rs | 62 +++- pallets/payments/src/weights.rs | 335 ++++++++++++++++++-- runtime/kreivo/Cargo.toml | 50 +-- runtime/kreivo/src/impls.rs | 19 +- runtime/kreivo/src/lib.rs | 139 +++++++- runtime/kreivo/src/payments.rs | 84 +++++ runtime/kusama-runtime-constants/src/lib.rs | 2 - 13 files changed, 699 insertions(+), 83 deletions(-) create mode 100644 runtime/kreivo/src/payments.rs diff --git a/Cargo.lock b/Cargo.lock index 4629bebc..08d27696 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4643,7 +4643,10 @@ dependencies = [ "pallet-collator-selection", "pallet-message-queue", "pallet-multisig", + "pallet-payments", + "pallet-preimage", "pallet-proxy", + "pallet-scheduler", "pallet-session", "pallet-sudo", "pallet-timestamp", @@ -6848,6 +6851,29 @@ dependencies = [ "sp-std 8.0.0 (git+https://github.com/virto-network/polkadot-sdk?branch=release-virto-v1.5.0)", ] +[[package]] +name = "pallet-payments" +version = "0.1.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-assets", + "pallet-balances", + "pallet-preimage", + "pallet-scheduler", + "pallet-sudo", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-std 8.0.0 (git+https://github.com/virto-network/polkadot-sdk?branch=release-virto-v1.5.0)", +] + [[package]] name = "pallet-preimage" version = "4.0.0-dev" diff --git a/Cargo.toml b/Cargo.toml index 9947bd27..46f9c6e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ members = [ "node", "runtime/kreivo", - "common" + "common", ] exclude = ["xcm-emulator"] @@ -48,10 +48,10 @@ smallvec = "1.11" kreivo-runtime = { path = "runtime/kreivo" } jsonrpsee = { version = "0.16.2"} - # Virto Pallets pallet-asset-registry = { default-features = false, path = "pallets/asset-registry" } pallet-burner = { default-features = false, path = "pallets/burner" } +pallet-payments = { default-features = false, path = "pallets/payments" } runtime-common = { default-features = false, path = "runtime/common" } kusama-runtime-constants = { default-features = false, path = "runtime/kusama-runtime-constants" } diff --git a/pallets/payments/Cargo.toml b/pallets/payments/Cargo.toml index aaf4467d..3163c9df 100644 --- a/pallets/payments/Cargo.toml +++ b/pallets/payments/Cargo.toml @@ -20,6 +20,7 @@ sp-io = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } frame-benchmarking = { workspace = true, optional = true } +log = { workspace = true } [dev-dependencies] serde = { workspace = true } @@ -30,6 +31,7 @@ sp-keystore = { workspace = true } pallet-preimage = { workspace = true } pallet-scheduler= { workspace = true } + [features] default = ["std"] runtime-benchmarks = [ diff --git a/pallets/payments/src/benchmarking.rs b/pallets/payments/src/benchmarking.rs index 22dde6bb..2b4ab429 100644 --- a/pallets/payments/src/benchmarking.rs +++ b/pallets/payments/src/benchmarking.rs @@ -11,7 +11,9 @@ use frame_support::{ }; use frame_system::RawOrigin; +use log; use sp_runtime::Percent; +use sp_std::vec; // Compare `generic_event` to the last emitted event. fn assert_last_event(generic_event: ::RuntimeEvent) { @@ -31,11 +33,10 @@ fn create_and_mint_asset( sender: &T::AccountId, beneficiary: &T::AccountId, asset: &AssetIdOf, - amount: &BalanceOf, ) -> Result<(), BenchmarkError> { T::BenchmarkHelper::create_asset(asset.clone(), sender.clone(), true, >::from(1u32)); - T::Assets::mint_into(asset.clone(), &sender, >::from(100000u32))?; - T::Assets::mint_into(asset.clone(), &beneficiary, >::from(100000u32))?; + T::Assets::mint_into(asset.clone(), &sender, >::from(10000000u32))?; + T::Assets::mint_into(asset.clone(), &beneficiary, >::from(10000000u32))?; Ok(()) } @@ -55,9 +56,10 @@ fn create_payment( BenchmarkError, > { let (sender, beneficiary, sender_lookup, beneficiary_lookup) = create_accounts::(); - create_and_mint_asset::(&sender, &beneficiary, &asset, &>::from(100000u32))?; + create_and_mint_asset::(&sender, &beneficiary, &asset)?; let payment_id: T::PaymentId = Payments::::next_payment_id()?; + log::info!("payment_id: {:?}", payment_id); let payment_detail = Payments::::create_payment( &sender, @@ -72,6 +74,8 @@ fn create_payment( // reserve funds for payment Payments::::reserve_payment_amount(&sender, &beneficiary, payment_detail)?; + log::info!("reserve_payment_amount executed"); + // TODO: check storage items Ok((payment_id, sender, beneficiary, sender_lookup, beneficiary_lookup)) @@ -88,8 +92,8 @@ mod benchmarks { fn pay(q: Linear<1, { T::MaxRemarkLength::get() }>) -> Result<(), BenchmarkError> { let (sender, beneficiary, _, beneficiary_lookup) = create_accounts::(); let asset: AssetIdOf = >::zero(); - create_and_mint_asset::(&sender, &beneficiary, &asset, &>::from(100000u32))?; - let amount = >::from(50_u32); + create_and_mint_asset::(&sender, &beneficiary, &asset)?; + let amount = >::from(100000_u32); let remark: Option> = if q == 0 { None @@ -121,10 +125,12 @@ mod benchmarks { #[benchmark] fn release() -> Result<(), BenchmarkError> { - let amount = >::from(50_u32); + let amount = >::from(100000_u32); let asset = >::zero(); let (payment_id, sender, beneficiary, _, beneficiary_lookup) = create_payment::(&amount, &asset, None)?; + log::info!("beneficiary_lookup: {:?}", beneficiary_lookup); + #[extrinsic_call] _(RawOrigin::Signed(sender.clone()), beneficiary_lookup, payment_id); @@ -134,7 +140,7 @@ mod benchmarks { #[benchmark] fn cancel() -> Result<(), BenchmarkError> { - let amount = >::from(50_u32); + let amount = >::from(100000_u32); let asset = >::zero(); let (payment_id, sender, beneficiary, sender_lookup, _beneficiary_lookup) = create_payment::(&amount, &asset, None)?; @@ -148,7 +154,7 @@ mod benchmarks { #[benchmark] fn request_refund() -> Result<(), BenchmarkError> { - let amount = >::from(50_u32); + let amount = >::from(100000_u32); let asset = >::zero(); let (payment_id, sender, beneficiary, _sender_lookup, beneficiary_lookup) = create_payment::(&amount, &asset, None)?; @@ -172,7 +178,7 @@ mod benchmarks { #[benchmark] fn dispute_refund() -> Result<(), BenchmarkError> { - let amount = >::from(50_u32); + let amount = >::from(100000_u32); let asset = >::zero(); let (payment_id, sender, beneficiary, sender_lookup, beneficiary_lookup) = create_payment::(&amount, &asset, None)?; @@ -193,7 +199,7 @@ mod benchmarks { #[benchmark] fn resolve_dispute() -> Result<(), BenchmarkError> { - let amount = >::from(50_u32); + let amount = >::from(100000_u32); let asset = >::zero(); let (payment_id, sender, beneficiary, sender_lookup, beneficiary_lookup) = create_payment::(&amount, &asset, None)?; @@ -234,8 +240,8 @@ mod benchmarks { fn request_payment() -> Result<(), BenchmarkError> { let (sender, beneficiary, sender_lookup, _beneficiary_lookup) = create_accounts::(); let asset: AssetIdOf = >::zero(); - create_and_mint_asset::(&sender, &beneficiary, &asset, &>::from(100000u32))?; - let amount = >::from(50_u32); + create_and_mint_asset::(&sender, &beneficiary, &asset)?; + let amount = >::from(100000_u32); #[extrinsic_call] _(RawOrigin::Signed(beneficiary.clone()), sender_lookup, asset, amount); @@ -248,8 +254,8 @@ mod benchmarks { fn accept_and_pay() -> Result<(), BenchmarkError> { let (sender, beneficiary, sender_lookup, beneficiary_lookup) = create_accounts::(); let asset: AssetIdOf = >::zero(); - create_and_mint_asset::(&sender, &beneficiary, &asset, &>::from(100000u32))?; - let amount = >::from(50_u32); + create_and_mint_asset::(&sender, &beneficiary, &asset)?; + let amount = >::from(100000_u32); let payment_id: T::PaymentId = Payments::::next_payment_id()?; assert!(Payments::::request_payment( diff --git a/pallets/payments/src/lib.rs b/pallets/payments/src/lib.rs index 5d7e2975..4dcbfd82 100644 --- a/pallets/payments/src/lib.rs +++ b/pallets/payments/src/lib.rs @@ -91,7 +91,6 @@ pub mod pallet { + MaybeSerializeDeserialize + sp_std::fmt::Debug + Default - + From + TypeInfo + MaxEncodedLen; @@ -117,6 +116,9 @@ pub mod pallet { /// The overarching hold reason. type RuntimeHoldReason: From; + /// Weight information for extrinsics in this pallet. + type WeightInfo: WeightInfo; + #[pallet::constant] type PalletId: Get; @@ -270,7 +272,7 @@ pub mod pallet { /// custom logic and trigger alternate payment flows. the specified /// amount. #[pallet::call_index(0)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(::WeightInfo::pay(remark.as_ref().map(|x| x.len() as u32).unwrap_or(0)))] pub fn pay( origin: OriginFor, beneficiary: AccountIdLookupOf, @@ -308,7 +310,7 @@ pub mod pallet { /// Release any created payment, this will transfer the reserved amount /// from the creator of the payment to the assigned recipient #[pallet::call_index(1)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(::WeightInfo::release())] pub fn release( origin: OriginFor, beneficiary: AccountIdLookupOf, @@ -332,7 +334,7 @@ pub mod pallet { /// back to creator of the payment. This extrinsic can only be called by /// the recipient of the payment #[pallet::call_index(2)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(::WeightInfo::cancel())] pub fn cancel( origin: OriginFor, sender: AccountIdLookupOf, @@ -371,7 +373,7 @@ pub mod pallet { /// the funds after a configured amount of time that the reveiver has to /// react and opose the request #[pallet::call_index(3)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(::WeightInfo::request_refund())] pub fn request_refund( origin: OriginFor, beneficiary: AccountIdLookupOf, @@ -430,7 +432,7 @@ pub mod pallet { /// payment to a NeedsReview state The assigned resolver account can /// then change the state of the payment after review. #[pallet::call_index(4)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(::WeightInfo::dispute_refund())] pub fn dispute_refund( origin: OriginFor, sender: AccountIdLookupOf, @@ -471,7 +473,7 @@ pub mod pallet { } #[pallet::call_index(5)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(::WeightInfo::resolve_dispute())] pub fn resolve_dispute( origin: OriginFor, sender: AccountIdLookupOf, @@ -500,7 +502,7 @@ pub mod pallet { // PaymentRequested State and can only be modified by the `accept_and_pay` // extrinsic. #[pallet::call_index(6)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(::WeightInfo::request_payment())] pub fn request_payment( origin: OriginFor, sender: AccountIdLookupOf, @@ -526,7 +528,7 @@ pub mod pallet { } #[pallet::call_index(7)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(::WeightInfo::accept_and_pay())] pub fn accept_and_pay( origin: OriginFor, beneficiary: AccountIdLookupOf, @@ -707,6 +709,7 @@ impl Pallet { .map_err(|_| Error::::ReleaseFailed)?; Self::try_transfer_fees(sender, payment, fee_sender_recipients, is_dispute)?; + Self::try_transfer_fees(beneficiary, payment, fee_beneficiary_recipients, is_dispute)?; if let Some((dispute_result, resolver)) = maybe_dispute { diff --git a/pallets/payments/src/mock.rs b/pallets/payments/src/mock.rs index c5378d7f..c391c8e4 100644 --- a/pallets/payments/src/mock.rs +++ b/pallets/payments/src/mock.rs @@ -107,6 +107,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeFreezeReason = RuntimeFreezeReason; } impl pallet_assets::Config for Test { @@ -254,6 +255,7 @@ impl pallet_payments::Config for Test { type Preimages = (); type CancelBufferBlockLength = ConstU64<10>; type PalletsOrigin = OriginCaller; + type WeightInfo = (); #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = BenchmarkHelper; } diff --git a/pallets/payments/src/tests.rs b/pallets/payments/src/tests.rs index dc5046cb..cb34bc28 100644 --- a/pallets/payments/src/tests.rs +++ b/pallets/payments/src/tests.rs @@ -4,9 +4,10 @@ use crate::{ types::{PaymentDetail, PaymentState}, Payment as PaymentStore, }; -use frame_support::{assert_ok, traits::fungibles}; +use frame_support::{assert_ok, traits::fungibles, weights::constants::WEIGHT_REF_TIME_PER_NANOS}; +use weights::SubstrateWeight; -use sp_runtime::BoundedVec; +use sp_runtime::{BoundedVec, Perbill}; fn build_payment() -> Fees { let remark: BoundedVec = BoundedVec::truncate_from(b"remark".to_vec()); @@ -533,3 +534,60 @@ fn request_payment() { ); }) } + +#[test] +fn weights() { + use crate::weights::WeightInfo; + use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}; + // max block: 0.5s compute with 12s average block time + const MAX_BLOCK_REF_TIME: u64 = WEIGHT_REF_TIME_PER_SECOND.saturating_div(2); // https://github.com/paritytech/cumulus/blob/98e68bd54257b4039a5d5b734816f4a1b7c83a9d/parachain-template/runtime/src/lib.rs#L221 + const MAX_BLOCK_POV_SIZE: u64 = 5 * 1024 * 1024; // https://github.com/paritytech/polkadot/blob/ba1f65493d91d4ab1787af2fd6fe880f1da90586/primitives/src/v4/mod.rs#L384 + const MAX_BLOCK_WEIGHT: Weight = Weight::from_parts(MAX_BLOCK_REF_TIME, MAX_BLOCK_POV_SIZE); + // max extrinsics: 75% of block + const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); // https://github.com/paritytech/cumulus/blob/d20c4283fe85df0c1ef8cb7c9eb7c09abbcbfa31/parachain-template/runtime/src/lib.rs#L218 + let max_total_extrinsics = MAX_BLOCK_WEIGHT * NORMAL_DISPATCH_RATIO; + // max extrinsic: max total extrinsics less average on_initialize ratio and less + // base extrinsic weight + const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5); // https://github.com/paritytech/cumulus/blob/d20c4283fe85df0c1ef8cb7c9eb7c09abbcbfa31/parachain-template/runtime/src/lib.rs#L214 + const BASE_EXTRINSIC: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000), 0); // https://github.com/paritytech/cumulus/blob/d20c4283fe85df0c1ef8cb7c9eb7c09abbcbfa31/parachain-template/runtime/src/weights/extrinsic_weights.rs#L26 + let max_extrinsic_weight = max_total_extrinsics + .saturating_sub(MAX_BLOCK_WEIGHT * AVERAGE_ON_INITIALIZE_RATIO) + .saturating_sub(BASE_EXTRINSIC); + assert_eq!(max_extrinsic_weight, Weight::from_parts(349_875_000_000, 3_670_016)); + + println!("max block weight: {MAX_BLOCK_WEIGHT}"); + println!("max total extrinsics weight: {max_total_extrinsics}"); + println!("max extrinsic weight: {max_extrinsic_weight}\n"); + + let mut total = Weight::zero(); + for (function, weight) in vec![ + // Examples: call available weight functions with various parameters (as applicable) to gauge weight usage in + // comparison to limits + ("pay (20)", SubstrateWeight::::pay(20_u32)), + ("release", SubstrateWeight::::release()), + ("cancel", SubstrateWeight::::cancel()), + ("request_refund", SubstrateWeight::::request_refund()), + ("dispute_refund", SubstrateWeight::::dispute_refund()), + ("resolve_dispute", SubstrateWeight::::resolve_dispute()), + ("request_payment", SubstrateWeight::::request_payment()), + ("accept_and_pay", SubstrateWeight::::accept_and_pay()), + ] { + println!("{function}: {weight:?}",); + println!( + "\tpercentage of max extrinsic weight: {:.2}% (ref_time), {:.2}% (proof_size)", + (weight.ref_time() as f64 / max_extrinsic_weight.ref_time() as f64) * 100.0, + (weight.proof_size() as f64 / max_extrinsic_weight.proof_size() as f64) * 100.0, + ); + println!( + "\tmax tx per block: {} (ref_time), {} (proof_size)", + max_extrinsic_weight.ref_time() / weight.ref_time(), + max_extrinsic_weight.proof_size() / weight.proof_size() + ); + assert!(weight.all_lt(max_extrinsic_weight)); + + total += weight; + } + + // output total weight, useful for evaluating net weight changes when optimising + println!("\ntotal weight: {total:?}"); +} diff --git a/pallets/payments/src/weights.rs b/pallets/payments/src/weights.rs index 47da9b4e..f4e8c6fb 100644 --- a/pallets/payments/src/weights.rs +++ b/pallets/payments/src/weights.rs @@ -1,26 +1,30 @@ -//! Autogenerated weights for pallet_burner +//! Autogenerated weights for pallet_payments //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-05-29, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 28.0.0 +//! DATE: 2023-11-29, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: ``, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kreivo-rococo-local"), DB CACHE: 1024 +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("kreivo"), DB CACHE: 1024 // Executed Command: // ./target/release/virto-node // benchmark // pallet -// --chain=kreivo-rococo-local -// --steps=50 -// --repeat=20 -// --pallet=pallet_burner -// --extrinsic=* -// --execution=wasm +// --chain +// kreivo // --wasm-execution=compiled -// --heap-pages=4096 -// --output=./pallets/burner/src/weights.rs -// --template=templates/frame-weight-template.hbs +// --pallet +// pallet_payments +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --template=./templates/frame-weight-template.hbs +// --output +// pallets/payments/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -30,30 +34,309 @@ use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; -/// Weight functions needed for pallet_burner. +/// Weight functions needed for pallet_payments. pub trait WeightInfo { - fn burn_asset() -> Weight; + fn pay(q: u32, ) -> Weight; + fn release() -> Weight; + fn cancel() -> Weight; + fn request_refund() -> Weight; + fn dispute_refund() -> Weight; + fn resolve_dispute() -> Weight; + fn request_payment() -> Weight; + fn accept_and_pay() -> Weight; } -/// Weights for pallet_burner using the Substrate node and recommended hardware. +/// Weights for pallet_payments using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - fn burn_asset() -> Weight { + /// Storage: `Payments::LastId` (r:1 w:0) + /// Proof: `Payments::LastId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Holds` (r:2 w:2) + /// Proof: `Assets::Holds` (`max_values`: None, `max_size`: Some(969), added: 3444, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:2 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// The range of component `q` is `[1, 50]`. + fn pay(q: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 19_000_000 picoseconds. - Weight::from_parts(20_000_000, 0) + // Measured: `472` + // Estimated: `8524` + // Minimum execution time: 76_000_000 picoseconds. + Weight::from_parts(77_728_000, 8524) + // Standard Error: 2_460 + .saturating_add(Weight::from_parts(1_411, 0).saturating_mul(q.into())) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:3 w:3) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Assets::Holds` (r:2 w:2) + /// Proof: `Assets::Holds` (`max_values`: None, `max_size`: Some(969), added: 3444, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn release() -> Weight { + // Proof Size summary in bytes: + // Measured: `1063` + // Estimated: `8817` + // Minimum execution time: 136_000_000 picoseconds. + Weight::from_parts(137_000_000, 8817) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:2 w:2) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Assets::Holds` (r:2 w:2) + /// Proof: `Assets::Holds` (`max_values`: None, `max_size`: Some(969), added: 3444, mode: `MaxEncodedLen`) + fn cancel() -> Weight { + // Proof Size summary in bytes: + // Measured: `960` + // Estimated: `8524` + // Minimum execution time: 100_000_000 picoseconds. + Weight::from_parts(101_000_000, 8524) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Lookup` (r:1 w:1) + /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn request_refund() -> Weight { + // Proof Size summary in bytes: + // Measured: `291` + // Estimated: `159279` + // Minimum execution time: 30_000_000 picoseconds. + Weight::from_parts(31_000_000, 159279) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Holds` (r:1 w:1) + /// Proof: `Assets::Holds` (`max_values`: None, `max_size`: Some(969), added: 3444, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:1 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Lookup` (r:1 w:1) + /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn dispute_refund() -> Weight { + // Proof Size summary in bytes: + // Measured: `1091` + // Estimated: `159279` + // Minimum execution time: 69_000_000 picoseconds. + Weight::from_parts(70_000_000, 159279) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:3 w:3) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Assets::Holds` (r:2 w:2) + /// Proof: `Assets::Holds` (`max_values`: None, `max_size`: Some(969), added: 3444, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn resolve_dispute() -> Weight { + // Proof Size summary in bytes: + // Measured: `1063` + // Estimated: `8817` + // Minimum execution time: 195_000_000 picoseconds. + Weight::from_parts(196_000_000, 8817) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) + } + /// Storage: `Payments::LastId` (r:1 w:0) + /// Proof: `Payments::LastId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + fn request_payment() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `8524` + // Minimum execution time: 14_000_000 picoseconds. + Weight::from_parts(15_000_000, 8524) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:3 w:3) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn accept_and_pay() -> Weight { + // Proof Size summary in bytes: + // Measured: `856` + // Estimated: `8817` + // Minimum execution time: 120_000_000 picoseconds. + Weight::from_parts(121_000_000, 8817) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - fn burn_asset() -> Weight { + /// Storage: `Payments::LastId` (r:1 w:0) + /// Proof: `Payments::LastId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Holds` (r:2 w:2) + /// Proof: `Assets::Holds` (`max_values`: None, `max_size`: Some(969), added: 3444, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:2 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// The range of component `q` is `[1, 50]`. + fn pay(q: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `472` + // Estimated: `8524` + // Minimum execution time: 76_000_000 picoseconds. + Weight::from_parts(77_728_000, 8524) + // Standard Error: 2_460 + .saturating_add(Weight::from_parts(1_411, 0).saturating_mul(q.into())) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:3 w:3) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Assets::Holds` (r:2 w:2) + /// Proof: `Assets::Holds` (`max_values`: None, `max_size`: Some(969), added: 3444, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn release() -> Weight { + // Proof Size summary in bytes: + // Measured: `1063` + // Estimated: `8817` + // Minimum execution time: 136_000_000 picoseconds. + Weight::from_parts(137_000_000, 8817) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(8_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:2 w:2) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Assets::Holds` (r:2 w:2) + /// Proof: `Assets::Holds` (`max_values`: None, `max_size`: Some(969), added: 3444, mode: `MaxEncodedLen`) + fn cancel() -> Weight { + // Proof Size summary in bytes: + // Measured: `960` + // Estimated: `8524` + // Minimum execution time: 100_000_000 picoseconds. + Weight::from_parts(101_000_000, 8524) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Lookup` (r:1 w:1) + /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn request_refund() -> Weight { + // Proof Size summary in bytes: + // Measured: `291` + // Estimated: `159279` + // Minimum execution time: 30_000_000 picoseconds. + Weight::from_parts(31_000_000, 159279) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Holds` (r:1 w:1) + /// Proof: `Assets::Holds` (`max_values`: None, `max_size`: Some(969), added: 3444, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:1 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Lookup` (r:1 w:1) + /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn dispute_refund() -> Weight { + // Proof Size summary in bytes: + // Measured: `1091` + // Estimated: `159279` + // Minimum execution time: 69_000_000 picoseconds. + Weight::from_parts(70_000_000, 159279) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:3 w:3) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Assets::Holds` (r:2 w:2) + /// Proof: `Assets::Holds` (`max_values`: None, `max_size`: Some(969), added: 3444, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn resolve_dispute() -> Weight { + // Proof Size summary in bytes: + // Measured: `1063` + // Estimated: `8817` + // Minimum execution time: 195_000_000 picoseconds. + Weight::from_parts(196_000_000, 8817) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(8_u64)) + } + /// Storage: `Payments::LastId` (r:1 w:0) + /// Proof: `Payments::LastId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + fn request_payment() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `8524` + // Minimum execution time: 14_000_000 picoseconds. + Weight::from_parts(15_000_000, 8524) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Payments::Payment` (r:1 w:1) + /// Proof: `Payments::Payment` (`max_values`: None, `max_size`: Some(5059), added: 7534, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:3 w:3) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn accept_and_pay() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 19_000_000 picoseconds. - Weight::from_parts(20_000_000, 0) + // Measured: `856` + // Estimated: `8817` + // Minimum execution time: 120_000_000 picoseconds. + Weight::from_parts(121_000_000, 8817) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } } diff --git a/runtime/kreivo/Cargo.toml b/runtime/kreivo/Cargo.toml index 0000f870..81f43939 100644 --- a/runtime/kreivo/Cargo.toml +++ b/runtime/kreivo/Cargo.toml @@ -24,6 +24,8 @@ smallvec = { workspace = true } # Local pallet-asset-registry ={ workspace = true } pallet-burner = { workspace = true } +pallet-payments = { workspace = true } + runtime-common = { workspace = true } # Substrate @@ -42,7 +44,9 @@ pallet-authorship = { workspace = true } pallet-balances = { workspace = true } pallet-multisig = { workspace = true } pallet-utility = { workspace = true } +pallet-preimage = { workspace = true } pallet-proxy = { workspace = true } +pallet-scheduler = { workspace = true } pallet-session = { workspace = true } pallet-sudo = { workspace = true } pallet-timestamp = { workspace = true } @@ -94,9 +98,6 @@ default = [ "std", ] std = [ - "parity-scale-codec/std", - "log/std", - "scale-info/std", "assets-common/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", @@ -105,21 +106,24 @@ std = [ "cumulus-primitives-core/std", "cumulus-primitives-timestamp/std", "cumulus-primitives-utility/std", - "parachains-common/std", "frame-executive/std", "frame-support/std", "frame-system-rpc-runtime-api/std", "frame-system/std", - "pallet-assets/std", - "pallet-asset-tx-payment/std", + "log/std", "pallet-asset-registry/std", + "pallet-asset-tx-payment/std", + "pallet-assets/std", "pallet-aura/std", "pallet-authorship/std", "pallet-balances/std", "pallet-burner/std", "pallet-collator-selection/std", + "pallet-message-queue/std", "pallet-multisig/std", + "pallet-preimage/std", "pallet-proxy/std", + "pallet-scheduler/std", "pallet-session/std", "pallet-sudo/std", "pallet-timestamp/std", @@ -129,10 +133,12 @@ std = [ "pallet-utility/std", "pallet-xcm/std", "parachain-info/std", + "parachains-common/std", + "parity-scale-codec/std", "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", - "pallet-message-queue/std", "runtime-common/std", + "scale-info/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", @@ -152,28 +158,31 @@ std = [ ] runtime-benchmarks = [ - "hex-literal", + "assets-common/runtime-benchmarks", + "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-xcmp-queue/runtime-benchmarks", "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", - "pallet-assets/runtime-benchmarks", + "hex-literal", "pallet-asset-registry/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", + "pallet-burner/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-payments/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-treasury/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", - "pallet-burner/runtime-benchmarks", - "pallet-multisig/runtime-benchmarks", "pallet-utility/runtime-benchmarks", - "pallet-proxy/runtime-benchmarks", + "pallet-xcm-benchmarks/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", - "cumulus-pallet-session-benchmarking/runtime-benchmarks", - "cumulus-pallet-xcmp-queue/runtime-benchmarks", - "assets-common/runtime-benchmarks", - "pallet-xcm-benchmarks/runtime-benchmarks", ] try-runtime = [ @@ -184,20 +193,21 @@ try-runtime = [ "frame-executive/try-runtime", "frame-system/try-runtime", "frame-try-runtime/try-runtime", - "pallet-assets/try-runtime", "pallet-asset-registry/try-runtime", + "pallet-assets/try-runtime", "pallet-aura/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", "pallet-multisig/try-runtime", - "pallet-utility/try-runtime", + "pallet-payments/try-runtime", + "pallet-proxy/try-runtime", "pallet-session/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-treasury/try-runtime", + "pallet-utility/try-runtime", "pallet-xcm/try-runtime", - "pallet-proxy/try-runtime", "parachain-info/try-runtime", ] diff --git a/runtime/kreivo/src/impls.rs b/runtime/kreivo/src/impls.rs index ce400b04..90db0619 100644 --- a/runtime/kreivo/src/impls.rs +++ b/runtime/kreivo/src/impls.rs @@ -17,7 +17,8 @@ //! Taken from polkadot/runtime/common (at a21cd64) and adapted for parachains. use super::*; -use frame_support::traits::{Contains, Currency, InstanceFilter}; +use core::cmp::Ordering; +use frame_support::traits::{Contains, Currency, InstanceFilter, PrivilegeCmp}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use sp_runtime::RuntimeDebug; @@ -134,3 +135,19 @@ impl InstanceFilter for ProxyType { } } } + +/// Used to compare the privilege of an origin inside the scheduler. +pub struct EqualOrGreatestRootCmp; + +impl PrivilegeCmp for EqualOrGreatestRootCmp { + fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option { + if left == right { + return Some(Ordering::Equal); + } + match (left, right) { + // Root is greater than anything. + (OriginCaller::system(frame_system::RawOrigin::Root), _) => Some(Ordering::Greater), + _ => None, + } + } +} diff --git a/runtime/kreivo/src/lib.rs b/runtime/kreivo/src/lib.rs index ca22d9cb..a6cb6547 100644 --- a/runtime/kreivo/src/lib.rs +++ b/runtime/kreivo/src/lib.rs @@ -22,7 +22,7 @@ pub use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto, IdentityLookup}, transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, MultiAddress, Perbill, Percent, Permill, + AccountId32, ApplyExtrinsicResult, MultiAddress, Perbill, Percent, Permill, }; use sp_std::prelude::*; #[cfg(feature = "std")] @@ -33,13 +33,15 @@ use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, genesis_builder_helper::{build_config, create_default_config}, - parameter_types, + ord_parameter_types, parameter_types, traits::{ + fungible::HoldConsideration, tokens::{PayFromAccount, UnityAssetBalanceConversion}, - AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, TransformOrigin, + AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, LinearStoragePrice, + TransformOrigin, }, weights::{constants::RocksDbWeight, ConstantMultiplier, Weight}, - PalletId, + BoundedVec, PalletId, }; pub use frame_system::Call as SystemCall; @@ -60,11 +62,17 @@ pub use polkadot_runtime_common::{prod_or_fast, BlockHashCount, SlowAdjustingFee pub use weights::{BlockExecutionWeight, ExtrinsicBaseWeight}; +pub mod payments; + // XCM Imports use xcm::latest::prelude::BodyId; pub use constants::{currency::*, fee::WeightToFee}; -pub use impls::ProxyType; + +use pallet_payments::types::*; + +pub use impls::{EqualOrGreatestRootCmp, ProxyType, RuntimeBlackListedCalls}; + pub use parachains_common::{ opaque, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MINUTES, NORMAL_DISPATCH_RATIO, SLOT_DURATION, @@ -172,9 +180,14 @@ construct_runtime!( Multisig: pallet_multisig = 42, Utility: pallet_utility = 43, Proxy: pallet_proxy = 44, + Scheduler: pallet_scheduler = 45, + Preimage: pallet_preimage = 46, // Governance Treasury: pallet_treasury = 50, + + // Virto Tooling + Payments: pallet_payments = 60, } ); @@ -267,7 +280,7 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type MaxReserves = ConstU32<50>; type ReserveIdentifier = [u8; 8]; - type RuntimeHoldReason = (); + type RuntimeHoldReason = RuntimeHoldReason; type FreezeIdentifier = (); type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; @@ -566,6 +579,119 @@ impl pallet_proxy::Config for Runtime { type AnnouncementDepositFactor = AnnouncementDepositFactor; } +parameter_types! { + pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block; +} + +#[cfg(not(feature = "runtime-benchmarks"))] +parameter_types! { + pub const MaxScheduledPerBlock: u32 = 50; +} + +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub const MaxScheduledPerBlock: u32 = 200; +} + +impl pallet_scheduler::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type PalletsOrigin = OriginCaller; + type RuntimeCall = RuntimeCall; + type MaximumWeight = MaximumSchedulerWeight; + type ScheduleOrigin = EnsureRoot; + type MaxScheduledPerBlock = MaxScheduledPerBlock; + type WeightInfo = pallet_scheduler::weights::SubstrateWeight; + type OriginPrivilegeCmp = EqualOrGreatestRootCmp; + type Preimages = Preimage; +} + +parameter_types! { + pub const PreimageBaseDeposit: Balance = deposit(2, 64); + pub const PreimageByteDeposit: Balance = deposit(0, 1); + pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage); +} + +impl pallet_preimage::Config for Runtime { + type WeightInfo = pallet_preimage::weights::SubstrateWeight; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type ManagerOrigin = EnsureRoot; + type Consideration = HoldConsideration< + AccountId, + Balances, + PreimageHoldReason, + LinearStoragePrice, + >; +} + +parameter_types! { + pub const MaxRemarkLength: u8 = 50; + pub const IncentivePercentage: Percent = Percent::from_percent(INCENTIVE_PERCENTAGE); + pub const PaymentPalletId: PalletId = PalletId(*b"payments"); + +} + +ord_parameter_types! { + pub const RootAccount: AccountId32 = AccountId32::new( + [ + 123,149,48,25,6,91,67,66,164,241,252,246,43,232,243,232,60,141,21,48,59,103,79,215,25,30,89,143,105,158,118,79 + ]); +} + +pub type PaymentId = u32; + +#[cfg(feature = "runtime-benchmarks")] +pub struct BenchmarkHelper; +#[cfg(feature = "runtime-benchmarks")] +impl super::BenchmarkHelper for BenchmarkHelper { + fn create_asset(id: AssetId, admin: AccountId, is_sufficient: bool, min_balance: Balance) { + >::create( + id, + admin, + is_sufficient, + min_balance, + ) + .unwrap(); + } +} + +pub struct KreivoFeeHandler; + +const MANDATORY_FEE: bool = true; +pub const SYSTEM_FEE: u8 = 1; +pub const SYSTEM_FEE_PERCENTAGE: Percent = Percent::from_percent(SYSTEM_FEE); +pub const INCENTIVE_PERCENTAGE: u8 = 10; + +impl FeeHandler for KreivoFeeHandler { + fn apply_fees( + _asset: &AssetIdOf, + _sender: &AccountId, + _beneficiary: &AccountId, + amount: &Balance, + _remark: Option<&[u8]>, + ) -> Fees { + let sender_fee: Vec<(AccountId, Balance, bool)> = vec![( + RootAccount::get(), + SYSTEM_FEE_PERCENTAGE.mul_floor(*amount), + MANDATORY_FEE, + )]; + let beneficiary_fee: Vec<(AccountId, Balance, bool)> = vec![( + RootAccount::get(), + SYSTEM_FEE_PERCENTAGE.mul_floor(*amount), + MANDATORY_FEE, + )]; + + let sender_pays: FeeDetails = BoundedVec::try_from(sender_fee).unwrap(); + let beneficiary_pays: FeeDetails = BoundedVec::try_from(beneficiary_fee).unwrap(); + + Fees { + sender_pays, + beneficiary_pays, + } + } +} + #[cfg(feature = "runtime-benchmarks")] pub struct AssetRegistryBenchmarkHelper; #[cfg(feature = "runtime-benchmarks")] @@ -618,6 +744,7 @@ mod benches { [pallet_assets, Assets] [pallet_proxy, Proxy] [pallet_asset_registry, AssetRegistry] + [pallet_payments, Payments] // XCM // NOTE: Make sure you point to the individual modules below. [pallet_xcm_benchmarks::fungible, XcmBalances] diff --git a/runtime/kreivo/src/payments.rs b/runtime/kreivo/src/payments.rs new file mode 100644 index 00000000..7dc272a8 --- /dev/null +++ b/runtime/kreivo/src/payments.rs @@ -0,0 +1,84 @@ +use super::*; + +parameter_types! { + pub const MaxRemarkLength: u8 = 50; + pub const IncentivePercentage: Percent = Percent::from_percent(INCENTIVE_PERCENTAGE); + pub const PaymentPalletId: PalletId = PalletId(*b"payments"); + +} + +pub type PaymentId = u32; + +#[cfg(feature = "runtime-benchmarks")] +pub struct BenchmarkHelper; +#[cfg(feature = "runtime-benchmarks")] +impl pallet_payments::BenchmarkHelper for BenchmarkHelper { + fn create_asset(id: AssetIdForTrustBackedAssets, admin: AccountId, is_sufficient: bool, min_balance: Balance) { + >::create( + id, + admin, + is_sufficient, + min_balance, + ) + .unwrap(); + } +} + +pub struct KreivoFeeHandler; + +const MANDATORY_FEE: bool = true; +pub const SYSTEM_FEE: u8 = 1; +pub const SYSTEM_FEE_PERCENTAGE: Percent = Percent::from_percent(SYSTEM_FEE); +pub const INCENTIVE_PERCENTAGE: u8 = 10; + +impl FeeHandler for KreivoFeeHandler { + fn apply_fees( + _asset: &AssetIdOf, + _sender: &AccountId, + _beneficiary: &AccountId, + amount: &Balance, + _remark: Option<&[u8]>, + ) -> Fees { + let sender_fee: Vec<(AccountId, Balance, bool)> = vec![( + TreasuryAccount::get(), + SYSTEM_FEE_PERCENTAGE.mul_floor(*amount), + MANDATORY_FEE, + )]; + let beneficiary_fee: Vec<(AccountId, Balance, bool)> = vec![( + TreasuryAccount::get(), + SYSTEM_FEE_PERCENTAGE.mul_floor(*amount), + MANDATORY_FEE, + )]; + + let sender_pays: FeeDetails = BoundedVec::try_from(sender_fee).unwrap(); + let beneficiary_pays: FeeDetails = BoundedVec::try_from(beneficiary_fee).unwrap(); + + Fees { + sender_pays, + beneficiary_pays, + } + } +} + +impl pallet_payments::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Assets = Assets; + type AssetsBalance = Balance; + type PaymentId = PaymentId; + type FeeHandler = KreivoFeeHandler; + type IncentivePercentage = IncentivePercentage; + type MaxRemarkLength = MaxRemarkLength; + type DisputeResolver = frame_system::EnsureRootWithSuccess; + type PalletId = PaymentPalletId; + type RuntimeHoldReason = RuntimeHoldReason; + type MaxDiscounts = ConstU32<10>; + type MaxFees = ConstU32<50>; + type RuntimeCall = RuntimeCall; + type Scheduler = Scheduler; + type Preimages = Preimage; + type CancelBufferBlockLength = ConstU32<14400>; // 2 days + type PalletsOrigin = OriginCaller; + type WeightInfo = pallet_payments::weights::SubstrateWeight; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = BenchmarkHelper; +} diff --git a/runtime/kusama-runtime-constants/src/lib.rs b/runtime/kusama-runtime-constants/src/lib.rs index 32315d7e..ac51c5c7 100644 --- a/runtime/kusama-runtime-constants/src/lib.rs +++ b/runtime/kusama-runtime-constants/src/lib.rs @@ -24,7 +24,6 @@ pub mod currency { /// The existential deposit. pub const EXISTENTIAL_DEPOSIT: Balance = CENTS; - pub const UNITS: Balance = 1_000_000_000_000; pub const QUID: Balance = UNITS / 30; pub const CENTS: Balance = QUID / 100; @@ -43,7 +42,6 @@ pub mod time { pub const MILLISECS_PER_BLOCK: Moment = 6000; pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; pub const EPOCH_DURATION_IN_SLOTS: BlockNumber = prod_or_fast!(HOURS, MINUTES); - // These time units are defined in number of blocks. pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); pub const HOURS: BlockNumber = MINUTES * 60; From 169033953e321c8fe184f4a2011aa062af37acf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Mon, 15 Jan 2024 12:25:10 -0500 Subject: [PATCH 2/3] fix(cargo): missing 'signal' feature on 'nix' dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 46f9c6e6..cea42afe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -193,7 +193,7 @@ pallet-xcm-benchmarks = { default-features = false, git = "https://github.com/vi # Dev dependencies assert_cmd = "2.0" -nix = "0.27.1" +nix = { version = "0.27.1", features = ["signal"] } tempfile = "3.7" tokio = { version = "1.32.0", features = ["macros", "time", "parking_lot"] } wait-timeout = "0.2" From 48a26daf9aea7bdab0a530c2bf86fc71925c215e Mon Sep 17 00:00:00 2001 From: Daniel Olano Date: Tue, 16 Jan 2024 11:09:17 +0100 Subject: [PATCH 3/3] Fix integrity tests --- runtime/kreivo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/kreivo/src/lib.rs b/runtime/kreivo/src/lib.rs index a6cb6547..439edd42 100644 --- a/runtime/kreivo/src/lib.rs +++ b/runtime/kreivo/src/lib.rs @@ -282,7 +282,7 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type RuntimeHoldReason = RuntimeHoldReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; + type MaxHolds = ConstU32<2>; type MaxFreezes = ConstU32<0>; type RuntimeFreezeReason = RuntimeFreezeReason; }