From 85b653c371bb15b1a887042a06964768923651f0 Mon Sep 17 00:00:00 2001 From: Doordashcon Date: Sat, 27 Jul 2024 13:31:14 +0100 Subject: [PATCH 01/15] bump_offchain task --- substrate/frame/salary/Cargo.toml | 1 + substrate/frame/salary/src/lib.rs | 63 +++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/substrate/frame/salary/Cargo.toml b/substrate/frame/salary/Cargo.toml index 9121f59ff462..ca61da5d0001 100644 --- a/substrate/frame/salary/Cargo.toml +++ b/substrate/frame/salary/Cargo.toml @@ -57,3 +57,4 @@ try-runtime = [ "pallet-ranked-collective?/try-runtime", "sp-runtime/try-runtime", ] +experimental = ["frame-support/experimental", "frame-system/experimental"] diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs index efb4f5d3c542..dcdfcb828422 100644 --- a/substrate/frame/salary/src/lib.rs +++ b/substrate/frame/salary/src/lib.rs @@ -21,7 +21,7 @@ use codec::{Decode, Encode, MaxEncodedLen}; use core::marker::PhantomData; -use scale_info::TypeInfo; +use scale_info::{TypeInfo, prelude::vec}; use sp_arithmetic::traits::{Saturating, Zero}; use sp_runtime::{Perbill, RuntimeDebug}; @@ -35,6 +35,9 @@ use frame_support::{ }, }; +#[cfg(feature = "experimental")] +const LOG_TARGET: &str = "pallet-salary-tasks"; + #[cfg(test)] mod tests; @@ -89,13 +92,22 @@ pub struct ClaimantStatus { pub mod pallet { use super::*; use frame_support::{dispatch::Pays, pallet_prelude::*}; - use frame_system::pallet_prelude::*; + use frame_system::{ + offchain::SendTransactionTypes, + pallet_prelude::{BlockNumberFor, *}, + }; #[pallet::pallet] pub struct Pallet(PhantomData<(T, I)>); #[pallet::config] - pub trait Config: frame_system::Config { + pub trait Config: + SendTransactionTypes> + frame_system::Config + { + type RuntimeTask: frame_support::traits::Task + + IsType<::RuntimeTask> + + From>; + /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; @@ -382,6 +394,51 @@ pub mod pallet { } } + #[pallet::tasks_experimental] + impl, I: 'static> Pallet { + #[pallet::task_list(vec![].into_iter())] + #[pallet::task_condition(|| { + let now = frame_system::Pallet::::block_number(); + let cycle_period = Pallet::::cycle_period(); + let mut status = Status::::get().unwrap(); + status.cycle_start.saturating_accrue(cycle_period); + now >= status.cycle_start + })] + #[pallet::task_weight(T::DbWeight::get().reads(1))] + #[pallet::task_index(0)] + pub fn bump_offchain() -> DispatchResult { + let mut status = Status::::get().ok_or(Error::::NotStarted)?; + status.cycle_index.saturating_inc(); + status.budget = T::Budget::get(); + status.total_registrations = Zero::zero(); + status.total_unregistered_paid = Zero::zero(); + Status::::put(&status); + + Pallet::deposit_event(Event::::CycleStarted { index: status.cycle_index }); + Ok(()) + } + } + + #[pallet::hooks] + impl, I: 'static> Hooks> for Pallet { + #[cfg(feature = "experimental")] + fn offchain_worker(_block_number: BlockNumberFor) { + // Create a valid task + let task = Task::::BumpOffchain {}; + let runtime_task = >::RuntimeTask::from(task); + let call = frame_system::Call::::do_task { task: runtime_task.into() }; + + // Submit the task as an unsigned transaction + let res = SubmitTransaction::>::submit_unsigned_transaction( + call.into(), + ); + match res { + Ok(_) => log::info!(target: LOG_TARGET, "Submitted the task."), + Err(e) => log::error!(target: LOG_TARGET, "Error submitting task: {:?}", e), + } + } + } + impl, I: 'static> Pallet { pub fn status() -> Option> { Status::::get() From 3ee2ad4e30982ecda22728252b4ddfda57f5acf0 Mon Sep 17 00:00:00 2001 From: Doordashcon Date: Wed, 21 Aug 2024 01:39:32 +0100 Subject: [PATCH 02/15] add SendTransactionTypes Config in Tests --- substrate/bin/node/runtime/src/lib.rs | 1 + substrate/frame/salary/src/tests/integration.rs | 13 +++++++++++-- substrate/frame/salary/src/tests/unit.rs | 14 +++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index fd8597563a02..ba51cbdc5e4f 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1849,6 +1849,7 @@ impl GetSalary for SalaryForRank { } impl pallet_salary::Config for Runtime { + type RuntimeTask = RuntimeTask; type WeightInfo = (); type RuntimeEvent = RuntimeEvent; type Paymaster = PayFromAccount; diff --git a/substrate/frame/salary/src/tests/integration.rs b/substrate/frame/salary/src/tests/integration.rs index 69f218943ade..219adb39872e 100644 --- a/substrate/frame/salary/src/tests/integration.rs +++ b/substrate/frame/salary/src/tests/integration.rs @@ -26,8 +26,7 @@ use frame_support::{ use pallet_ranked_collective::{EnsureRanked, Geometric, TallyOf, Votes}; use sp_core::{ConstU16, Get}; use sp_runtime::{ - traits::{Convert, ReduceBy, ReplaceWithDefault}, - BuildStorage, DispatchError, + testing::TestXt, traits::{Convert, ReduceBy, ReplaceWithDefault}, BuildStorage, DispatchError }; use crate as pallet_salary; @@ -36,6 +35,8 @@ use crate::*; type Rank = u16; type Block = frame_system::mocking::MockBlock; +pub type Extrinsic = TestXt; + frame_support::construct_runtime!( pub enum Test { @@ -55,6 +56,13 @@ impl frame_system::Config for Test { type Block = Block; } +impl frame_system::offchain::SendTransactionTypes for Test +where + RuntimeCall: From, +{ + type OverarchingCall = RuntimeCall; + type Extrinsic = Extrinsic; +} pub struct TestPolls; impl Polling> for TestPolls { type Index = u8; @@ -132,6 +140,7 @@ parameter_types! { } impl Config for Test { + type RuntimeTask = RuntimeTask; type WeightInfo = (); type RuntimeEvent = RuntimeEvent; type Paymaster = TestPay; diff --git a/substrate/frame/salary/src/tests/unit.rs b/substrate/frame/salary/src/tests/unit.rs index db1c8b947ef5..8848df29fd35 100644 --- a/substrate/frame/salary/src/tests/unit.rs +++ b/substrate/frame/salary/src/tests/unit.rs @@ -26,13 +26,15 @@ use frame_support::{ parameter_types, traits::{tokens::ConvertRank, ConstU64}, }; -use sp_runtime::{traits::Identity, BuildStorage, DispatchResult}; +use sp_runtime::{testing::TestXt, traits::Identity, BuildStorage, DispatchResult}; use crate as pallet_salary; use crate::*; type Block = frame_system::mocking::MockBlock; +pub type Extrinsic = TestXt; + frame_support::construct_runtime!( pub enum Test { @@ -41,6 +43,15 @@ frame_support::construct_runtime!( } ); +impl frame_system::offchain::SendTransactionTypes for Test +where + RuntimeCall: From, +{ + type OverarchingCall = RuntimeCall; + type Extrinsic = Extrinsic; +} + + parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1_000_000, 0)); @@ -146,6 +157,7 @@ parameter_types! { } impl Config for Test { + type RuntimeTask = RuntimeTask; type WeightInfo = (); type RuntimeEvent = RuntimeEvent; type Paymaster = TestPay; From 1ca440d3f7edaef91203f1a97c25ada14ea43f68 Mon Sep 17 00:00:00 2001 From: Doordashcon Date: Wed, 30 Oct 2024 15:06:41 -0700 Subject: [PATCH 03/15] hacking the execution pattern --- substrate/frame/salary/src/lib.rs | 20 +- .../frame/salary/src/tests/integration.rs | 14 +- substrate/frame/salary/src/tests/unit.rs | 178 +++++++++++++++++- 3 files changed, 197 insertions(+), 15 deletions(-) diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs index dcdfcb828422..ff1fcdc16490 100644 --- a/substrate/frame/salary/src/lib.rs +++ b/substrate/frame/salary/src/lib.rs @@ -24,6 +24,9 @@ use core::marker::PhantomData; use scale_info::{TypeInfo, prelude::vec}; use sp_arithmetic::traits::{Saturating, Zero}; use sp_runtime::{Perbill, RuntimeDebug}; +use frame_system::offchain::CreateInherent; +#[cfg(feature = "experimental")] +use frame_system::offchain::SubmitTransaction; use frame_support::{ defensive, @@ -92,17 +95,13 @@ pub struct ClaimantStatus { pub mod pallet { use super::*; use frame_support::{dispatch::Pays, pallet_prelude::*}; - use frame_system::{ - offchain::SendTransactionTypes, - pallet_prelude::{BlockNumberFor, *}, - }; + use frame_system::pallet_prelude::{BlockNumberFor, *}; #[pallet::pallet] pub struct Pallet(PhantomData<(T, I)>); #[pallet::config] - pub trait Config: - SendTransactionTypes> + frame_system::Config + pub trait Config: CreateInherent> + frame_system::Config { type RuntimeTask: frame_support::traits::Task + IsType<::RuntimeTask> @@ -409,6 +408,7 @@ pub mod pallet { pub fn bump_offchain() -> DispatchResult { let mut status = Status::::get().ok_or(Error::::NotStarted)?; status.cycle_index.saturating_inc(); + status.cycle_start = frame_system::Pallet::::block_number(); status.budget = T::Budget::get(); status.total_registrations = Zero::zero(); status.total_unregistered_paid = Zero::zero(); @@ -429,14 +429,16 @@ pub mod pallet { let call = frame_system::Call::::do_task { task: runtime_task.into() }; // Submit the task as an unsigned transaction - let res = SubmitTransaction::>::submit_unsigned_transaction( - call.into(), - ); + let xt = >>::create_inherent(call.into()); + let res = SubmitTransaction::>::submit_transaction(xt); match res { Ok(_) => log::info!(target: LOG_TARGET, "Submitted the task."), Err(e) => log::error!(target: LOG_TARGET, "Error submitting task: {:?}", e), } } + + #[cfg(not(feature = "experimental"))] + fn offchain_worker(_block_number: BlockNumberFor) {} } impl, I: 'static> Pallet { diff --git a/substrate/frame/salary/src/tests/integration.rs b/substrate/frame/salary/src/tests/integration.rs index 219adb39872e..de70daf13037 100644 --- a/substrate/frame/salary/src/tests/integration.rs +++ b/substrate/frame/salary/src/tests/integration.rs @@ -56,13 +56,23 @@ impl frame_system::Config for Test { type Block = Block; } -impl frame_system::offchain::SendTransactionTypes for Test +impl frame_system::offchain::CreateTransactionBase for Test where RuntimeCall: From, { - type OverarchingCall = RuntimeCall; + type RuntimeCall = RuntimeCall; type Extrinsic = Extrinsic; } + +impl frame_system::offchain::CreateInherent for Test +where + RuntimeCall: From, +{ + fn create_inherent(call: Self::RuntimeCall) -> Self::Extrinsic { + Extrinsic::new_bare(call) + } +} + pub struct TestPolls; impl Polling> for TestPolls { type Index = u8; diff --git a/substrate/frame/salary/src/tests/unit.rs b/substrate/frame/salary/src/tests/unit.rs index 8848df29fd35..0b22d04c0aa7 100644 --- a/substrate/frame/salary/src/tests/unit.rs +++ b/substrate/frame/salary/src/tests/unit.rs @@ -27,10 +27,11 @@ use frame_support::{ traits::{tokens::ConvertRank, ConstU64}, }; use sp_runtime::{testing::TestXt, traits::Identity, BuildStorage, DispatchResult}; - +//#[cfg(feature = "experimental")] +//use sp_core::offchain::{testing, OffchainWorkerExt, TransactionPoolExt}; +use frame_support::traits::Task; use crate as pallet_salary; use crate::*; - type Block = frame_system::mocking::MockBlock; pub type Extrinsic = TestXt; @@ -43,14 +44,23 @@ frame_support::construct_runtime!( } ); -impl frame_system::offchain::SendTransactionTypes for Test +impl frame_system::offchain::CreateTransactionBase for Test where RuntimeCall: From, { - type OverarchingCall = RuntimeCall; + type RuntimeCall = RuntimeCall; type Extrinsic = Extrinsic; } +impl frame_system::offchain::CreateInherent for Test +where + RuntimeCall: From, +{ + fn create_inherent(call: Self::RuntimeCall) -> Self::Extrinsic { + Extrinsic::new_bare(call) + } +} + parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = @@ -176,7 +186,11 @@ pub fn new_test_ext() -> sp_io::TestExternalities { } fn next_block() { + //#[cfg(feature = "experimental")] + //use frame_support::traits::Hooks; System::set_block_number(System::block_number() + 1); + //#[cfg(feature = "experimental")] + //Salary::offchain_worker(System::block_number()); } #[allow(dead_code)] @@ -627,3 +641,159 @@ fn other_mixed_bankruptcy_fails_gracefully() { assert_eq!(paid(3), 6); }); } + +#[test] +fn task_enumerate_works() { + new_test_ext().execute_with(|| { + assert_eq!(crate::pallet::Task::::iter().collect::>().len(), 0); + }); +} + +#[test] +fn runtime_task_enumerate_works_via_frame_system_config() { + new_test_ext().execute_with(|| { + assert_eq!( + ::RuntimeTask::iter().collect::>().len(), + 0 + ); + }); +} + +#[test] +fn runtime_task_enumerate_works_via_pallet_config() { + new_test_ext().execute_with(|| { + assert_eq!( + ::RuntimeTask::iter() + .collect::>() + .len(), + 0 + ); + }); +} + +#[test] +fn task_index_works_at_pallet_level() { + new_test_ext().execute_with(|| { + assert_eq!(crate::pallet::Task::::BumpOffchain { }.task_index(), 0); + }); +} + +#[test] +fn task_index_works_at_runtime_level() { + new_test_ext().execute_with(|| { + assert_eq!( + ::RuntimeTask::Salary(crate::pallet::Task::< + Test, + >::BumpOffchain {}).task_index(), + 0 + ); + }); +} + +#[cfg(feature = "experimental")] +#[test] +fn task_execution_works() { + new_test_ext().execute_with(|| { + set_rank(1, 1); + assert_ok!(Salary::init(RuntimeOrigin::signed(1))); + + let task = + ::RuntimeTask::Salary(crate::pallet::Task::< + Test, + >::BumpOffchain {}); + assert_eq!( + Salary::status(), + Some(StatusType { + cycle_index: 0, + cycle_start: 1, + budget: 10, + total_registrations: 0, + total_unregistered_paid: 0, + }) + ); + run_to(5); + assert_ok!(System::do_task(RuntimeOrigin::signed(1), task.clone(),)); + assert_eq!( + Salary::status(), + Some(StatusType { + cycle_index: 1, + cycle_start: 5, + budget: 10, + total_registrations: 0, + total_unregistered_paid: 0, + }) + ); + System::assert_last_event(frame_system::Event::::TaskCompleted { task }.into()); + + }); +} + +#[cfg(feature = "experimental")] +#[test] +fn task_execution_fails_for_invalid_task() { + new_test_ext().execute_with(|| { + set_rank(1, 1); + assert_ok!(Salary::init(RuntimeOrigin::signed(1))); + assert_eq!( + Salary::status(), + Some(StatusType { + cycle_index: 0, + cycle_start: 1, + budget: 10, + total_registrations: 0, + total_unregistered_paid: 0, + }) + ); + assert_noop!( + System::do_task( + RuntimeOrigin::signed(1), + ::RuntimeTask::Salary( + crate::pallet::Task::::BumpOffchain { } + ), + ), + frame_system::Error::::InvalidTask + ); + }); +} + + +/* +#[cfg(feature = "experimental")] +#[test] +fn task_with_offchain_worker() { + let (offchain, _offchain_state) = testing::TestOffchainExt::new(); + let (pool, pool_state) = testing::TestTransactionPoolExt::new(); + + let mut t = sp_io::TestExternalities::default(); + t.register_extension(OffchainWorkerExt::new(offchain)); + t.register_extension(TransactionPoolExt::new(pool)); + + t.execute_with(|| { + set_rank(1, 1); + assert_ok!(Salary::init(RuntimeOrigin::signed(1))); + // assert!(pool_state.read().transactions.is_empty()); + + + + run_to(2); + let tx = pool_state.write().transactions.pop().unwrap(); + // assert_ok!(Salary::init(RuntimeOrigin::signed(1))); + // assert!(pool_state.read().transactions.is_empty()); + run_to(6); + let tux = pool_state.write().transactions.pop().unwrap(); + let tx = Extrinsic::decode(&mut &*tx).unwrap(); + assert_eq!( + Salary::status(), + Some(StatusType { + cycle_index: 0, + cycle_start: 5, + budget: 10, + total_registrations: 0, + total_unregistered_paid: 0, + }) + ); + use sp_runtime::traits::ExtrinsicLike; + assert!(tx.is_bare()); + }); +} +*/ \ No newline at end of file From dbcabbdb41361ec2b407fb89a1a9a35e4bd27128 Mon Sep 17 00:00:00 2001 From: Doordashcon Date: Thu, 31 Oct 2024 04:35:08 -0700 Subject: [PATCH 04/15] needed tests --- substrate/frame/salary/src/tests/unit.rs | 48 ------------------------ 1 file changed, 48 deletions(-) diff --git a/substrate/frame/salary/src/tests/unit.rs b/substrate/frame/salary/src/tests/unit.rs index 0b22d04c0aa7..9c91f2f57540 100644 --- a/substrate/frame/salary/src/tests/unit.rs +++ b/substrate/frame/salary/src/tests/unit.rs @@ -27,8 +27,6 @@ use frame_support::{ traits::{tokens::ConvertRank, ConstU64}, }; use sp_runtime::{testing::TestXt, traits::Identity, BuildStorage, DispatchResult}; -//#[cfg(feature = "experimental")] -//use sp_core::offchain::{testing, OffchainWorkerExt, TransactionPoolExt}; use frame_support::traits::Task; use crate as pallet_salary; use crate::*; @@ -186,11 +184,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { } fn next_block() { - //#[cfg(feature = "experimental")] - //use frame_support::traits::Hooks; System::set_block_number(System::block_number() + 1); - //#[cfg(feature = "experimental")] - //Salary::offchain_worker(System::block_number()); } #[allow(dead_code)] @@ -755,45 +749,3 @@ fn task_execution_fails_for_invalid_task() { ); }); } - - -/* -#[cfg(feature = "experimental")] -#[test] -fn task_with_offchain_worker() { - let (offchain, _offchain_state) = testing::TestOffchainExt::new(); - let (pool, pool_state) = testing::TestTransactionPoolExt::new(); - - let mut t = sp_io::TestExternalities::default(); - t.register_extension(OffchainWorkerExt::new(offchain)); - t.register_extension(TransactionPoolExt::new(pool)); - - t.execute_with(|| { - set_rank(1, 1); - assert_ok!(Salary::init(RuntimeOrigin::signed(1))); - // assert!(pool_state.read().transactions.is_empty()); - - - - run_to(2); - let tx = pool_state.write().transactions.pop().unwrap(); - // assert_ok!(Salary::init(RuntimeOrigin::signed(1))); - // assert!(pool_state.read().transactions.is_empty()); - run_to(6); - let tux = pool_state.write().transactions.pop().unwrap(); - let tx = Extrinsic::decode(&mut &*tx).unwrap(); - assert_eq!( - Salary::status(), - Some(StatusType { - cycle_index: 0, - cycle_start: 5, - budget: 10, - total_registrations: 0, - total_unregistered_paid: 0, - }) - ); - use sp_runtime::traits::ExtrinsicLike; - assert!(tx.is_bare()); - }); -} -*/ \ No newline at end of file From 55700e772e686de45197402146189920819b8658 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Thu, 7 Nov 2024 13:50:52 -0800 Subject: [PATCH 05/15] collectives::pallet_salary --- Cargo.lock | 1 + .../collectives-westend/Cargo.toml | 5 + .../collectives-westend/src/ambassador/mod.rs | 1 + .../collectives-westend/src/fellowship/mod.rs | 1 + .../collectives-westend/src/lib.rs | 228 +++++++++++++++++- 5 files changed, 234 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5bc51b7840ec..6339df5c7e90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3207,6 +3207,7 @@ dependencies = [ "cumulus-primitives-utility", "frame-benchmarking", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml index e03fc934ceaf..8359c3f888e6 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml @@ -24,6 +24,7 @@ frame-system = { workspace = true } frame-system-benchmarking = { optional = true, workspace = true } frame-system-rpc-runtime-api = { workspace = true } frame-try-runtime = { optional = true, workspace = true } +frame-metadata-hash-extension = { workspace = true } pallet-asset-rate = { workspace = true } pallet-alliance = { workspace = true } pallet-aura = { workspace = true } @@ -247,6 +248,10 @@ std = [ "xcm/std", ] +experimental = [ + "pallet-salary/experimental", +] + # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs index a052a9d3800c..f4aa654706a4 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs @@ -246,6 +246,7 @@ pub type AmbassadorSalaryPaymaster = PayOverXcm< >; impl pallet_salary::Config for Runtime { + type RuntimeTask = ::RuntimeTask; type WeightInfo = weights::pallet_salary_ambassador_salary::WeightInfo; type RuntimeEvent = RuntimeEvent; diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs index 942e0c294dd0..9ea012f5c160 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs @@ -236,6 +236,7 @@ pub type FellowshipSalaryPaymaster = PayOverXcm< >; impl pallet_salary::Config for Runtime { + type RuntimeTask = ::RuntimeTask; type WeightInfo = weights::pallet_salary_fellowship_salary::WeightInfo; type RuntimeEvent = RuntimeEvent; diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 8cb2e42cb31b..8897ebae9c38 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -66,6 +66,9 @@ use sp_runtime::{ use sp_version::NativeVersion; use sp_version::RuntimeVersion; +/// FRAME signed extension for verifying the metadata hash. +pub use frame_metadata_hash_extension; + use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId}; use frame_support::{ @@ -91,7 +94,7 @@ use parachains_common::{ AccountId, AuraId, Balance, BlockNumber, Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO, }; -use sp_runtime::RuntimeDebug; +use sp_runtime::{RuntimeDebug, traits::{Verify, SaturatedConversion}}; use testnet_parachains_constants::westend::{ account::*, consensus::*, currency::*, fee::WeightToFee, time::*, }; @@ -170,6 +173,94 @@ parameter_types! { pub const SS58Prefix: u8 = 42; } +pub type SignedPayload = generic::SignedPayload; + +impl frame_system::offchain::SigningTypes for Runtime { + type Public = ::Signer; + type Signature = Signature; +} + +impl frame_system::offchain::CreateTransactionBase for Runtime +where + RuntimeCall: From, +{ + type RuntimeCall = RuntimeCall; + type Extrinsic = UncheckedExtrinsic; +} + +impl frame_system::offchain::CreateTransaction for Runtime +where + RuntimeCall: From, +{ + type Extension = TxExtension; + + fn create_transaction(call: RuntimeCall, extension: TxExtension) -> UncheckedExtrinsic { + UncheckedExtrinsic::new_transaction(call, extension) + } +} + +/// Submits a transaction with the node's public and signature type. Adheres to the signed extension +/// format of the chain. +impl frame_system::offchain::CreateSignedTransaction for Runtime +where + RuntimeCall: From, +{ + fn create_signed_transaction< + C: frame_system::offchain::AppCrypto, + >( + call: RuntimeCall, + public: ::Signer, + account: AccountId, + nonce: ::Nonce, + ) -> Option { + use sp_runtime::traits::StaticLookup; + // take the biggest period possible. + let period = + BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64; + + let current_block = System::block_number() + .saturated_into::() + // The `System::block_number` is initialized with `n+1`, + // so the actual block number is `n`. + .saturating_sub(1); + let tip = 0; + let tx_ext: TxExtension = ( + frame_system::CheckNonZeroSender::::new(), + frame_system::CheckSpecVersion::::new(), + frame_system::CheckTxVersion::::new(), + frame_system::CheckGenesis::::new(), + frame_system::CheckMortality::::from(generic::Era::mortal( + period, + current_block, + )), + frame_system::CheckNonce::::from(nonce), + frame_system::CheckWeight::::new(), + pallet_transaction_payment::ChargeTransactionPayment::::from(tip), + frame_metadata_hash_extension::CheckMetadataHash::::new(true), + ) + .into(); + let raw_payload = SignedPayload::new(call, tx_ext) + .map_err(|e| { + log::warn!("Unable to create signed payload: {:?}", e); + }) + .ok()?; + let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?; + let (call, tx_ext, _) = raw_payload.deconstruct(); + let address = ::Lookup::unlookup(account); + let transaction = UncheckedExtrinsic::new_signed(call, address, signature, tx_ext); + Some(transaction) + } +} + +impl frame_system::offchain::CreateInherent for Runtime +where + RuntimeCall: From, +{ + fn create_inherent(call: RuntimeCall) -> UncheckedExtrinsic { + UncheckedExtrinsic::new_bare(call) + } +} + // Configure FRAME pallets to include in runtime. #[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig)] impl frame_system::Config for Runtime { @@ -724,6 +815,138 @@ construct_runtime!( } ); +/* +#[frame_support::runtime(legacy_ordering)] +mod runtime { + + // The main runtime types. + #[runtime::runtime] + #[runtime::derive( + RuntimeCall, + RuntimeEvent, + RuntimeError, + RuntimeOrigin, + RuntimeFreezeReason, + RuntimeHoldReason, + RuntimeSlashReason, + RuntimeLockId, + RuntimeTask + )] + pub struct Runtime; + + #[runtime::pallet_index(0)] + pub type System = frame_system; + + #[runtime::pallet_index(1)] + pub type ParachainSystem = cumulus_pallet_parachain_system; + + #[runtime::pallet_index(2)] + pub type Timestamp = pallet_timestamp; + + #[runtime::pallet_index(3)] + pub type ParachainInfo = parachain_info; + + #[runtime::pallet_index(10)] + pub type Balances = pallet_balances; + + #[runtime::pallet_index(10)] + pub type TransactionPayment = pallet_transaction_payment; + + #[runtime::pallet_index(11)] + pub type TransactionPayment = pallet_transaction_payment; + + #[runtime::pallet_index(20)] + pub type Authorship = pallet_authorship; + + #[runtime::pallet_index(21)] + pub type CollatorSelection = pallet_collator_selection; + + #[runtime::pallet_index(22)] + pub type Session = pallet_session; + + #[runtime::pallet_index(23)] + pub type Aura = pallet_aura; + + #[runtime::pallet_index(24)] + pub type AuraExt = cumulus_pallet_aura_ext; + + #[runtime::pallet_index(30)] + pub type XcmpQueue: cumulus_pallet_xcmp_queue; + + #[runtime::pallet_index(31)] + pub type PolkadotXcm = pallet_xcm; + + #[runtime::pallet_index(32)] + pub type CumulusXcm = cumulus_pallet_xcm; + + #[runtime::pallet_index(34)] + pub type MessageQueue = pallet_message_queue; + + #[runtime::pallet_index(40)] + pub type Utility = pallet_utility; + + #[runtime::pallet_index(41)] + pub type Multisig = pallet_multisig; + + #[runtime::pallet_index(42)] + pub type Proxy = pallet_proxy; + + #[runtime::pallet_index(43)] + pub type Preimage = pallet_preimage; + + #[runtime::pallet_index(44)] + pub type Scheduler = pallet_scheduler; + + #[runtime::pallet_index(45)] + pub type AssetRate = pallet_asset_rate; + + #[runtime::pallet_index(50)] + pub type Alliance = pallet_alliance; + + #[runtime::pallet_index(51)] + pub type AllianceMotion = pallet_collective; + + #[runtime::pallet_index(60)] + pub type FellowshipCollective = pallet_ranked_collective; + + #[runtime::pallet_index(61)] + pub type FellowshipReferenda = pallet_referend; + + #[runtime::pallet_index(62)] + pub type FellowshipOrigins = pallet_fellowship_origins; + + #[runtime::pallet_index(63)] + pub type FellowshipCore = pallet_core_fellowship; + + #[runtime::pallet_index(64)] + pub type FellowshipSalary = pallet_salary; + + #[runtime::pallet_index(65)] + pub type FellowshipTreasury = pallet_treasury; + + #[runtime::pallet_index(70)] + pub type AmbassadorCollective = pallet_ranked_collective; + + #[runtime::pallet_index(71)] + pub type AmbassadorReferenda = pallet_referenda; + + #[runtime::pallet_index(72)] + pub type AmbassadorOrigins = pallet_ambassador_origins; + + #[runtime::pallet_index(73)] + pub type AmbassadorCore = pallet_core_fellowship; + + #[runtime::pallet_index(74)] + pub type AmbassadorSalary = pallet_salary; + + #[runtime::pallet_index(75)] + pub type AmbassadorContent = pallet_collective_content; + + #[runtime::pallet_index(80)] + pub type StateTrieMigration = pallet_state_trie_migration; +} +*/ + /// The address format for describing accounts. pub type Address = sp_runtime::MultiAddress; /// Block type as expected by this runtime. @@ -741,7 +964,8 @@ pub type TxExtension = ( frame_system::CheckEra, frame_system::CheckNonce, frame_system::CheckWeight, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, + pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, ); /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = From 13b3e975fbd09269dbe020439b93d862cbc584f3 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Thu, 7 Nov 2024 14:54:26 -0800 Subject: [PATCH 06/15] pallet-salary/experimental, umbrella --- .../collectives-westend/src/lib.rs | 132 ------------------ umbrella/Cargo.toml | 1 + 2 files changed, 1 insertion(+), 132 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 2e14b472f1db..ef3071aeeed4 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -815,138 +815,6 @@ construct_runtime!( } ); -/* -#[frame_support::runtime(legacy_ordering)] -mod runtime { - - // The main runtime types. - #[runtime::runtime] - #[runtime::derive( - RuntimeCall, - RuntimeEvent, - RuntimeError, - RuntimeOrigin, - RuntimeFreezeReason, - RuntimeHoldReason, - RuntimeSlashReason, - RuntimeLockId, - RuntimeTask - )] - pub struct Runtime; - - #[runtime::pallet_index(0)] - pub type System = frame_system; - - #[runtime::pallet_index(1)] - pub type ParachainSystem = cumulus_pallet_parachain_system; - - #[runtime::pallet_index(2)] - pub type Timestamp = pallet_timestamp; - - #[runtime::pallet_index(3)] - pub type ParachainInfo = parachain_info; - - #[runtime::pallet_index(10)] - pub type Balances = pallet_balances; - - #[runtime::pallet_index(10)] - pub type TransactionPayment = pallet_transaction_payment; - - #[runtime::pallet_index(11)] - pub type TransactionPayment = pallet_transaction_payment; - - #[runtime::pallet_index(20)] - pub type Authorship = pallet_authorship; - - #[runtime::pallet_index(21)] - pub type CollatorSelection = pallet_collator_selection; - - #[runtime::pallet_index(22)] - pub type Session = pallet_session; - - #[runtime::pallet_index(23)] - pub type Aura = pallet_aura; - - #[runtime::pallet_index(24)] - pub type AuraExt = cumulus_pallet_aura_ext; - - #[runtime::pallet_index(30)] - pub type XcmpQueue: cumulus_pallet_xcmp_queue; - - #[runtime::pallet_index(31)] - pub type PolkadotXcm = pallet_xcm; - - #[runtime::pallet_index(32)] - pub type CumulusXcm = cumulus_pallet_xcm; - - #[runtime::pallet_index(34)] - pub type MessageQueue = pallet_message_queue; - - #[runtime::pallet_index(40)] - pub type Utility = pallet_utility; - - #[runtime::pallet_index(41)] - pub type Multisig = pallet_multisig; - - #[runtime::pallet_index(42)] - pub type Proxy = pallet_proxy; - - #[runtime::pallet_index(43)] - pub type Preimage = pallet_preimage; - - #[runtime::pallet_index(44)] - pub type Scheduler = pallet_scheduler; - - #[runtime::pallet_index(45)] - pub type AssetRate = pallet_asset_rate; - - #[runtime::pallet_index(50)] - pub type Alliance = pallet_alliance; - - #[runtime::pallet_index(51)] - pub type AllianceMotion = pallet_collective; - - #[runtime::pallet_index(60)] - pub type FellowshipCollective = pallet_ranked_collective; - - #[runtime::pallet_index(61)] - pub type FellowshipReferenda = pallet_referend; - - #[runtime::pallet_index(62)] - pub type FellowshipOrigins = pallet_fellowship_origins; - - #[runtime::pallet_index(63)] - pub type FellowshipCore = pallet_core_fellowship; - - #[runtime::pallet_index(64)] - pub type FellowshipSalary = pallet_salary; - - #[runtime::pallet_index(65)] - pub type FellowshipTreasury = pallet_treasury; - - #[runtime::pallet_index(70)] - pub type AmbassadorCollective = pallet_ranked_collective; - - #[runtime::pallet_index(71)] - pub type AmbassadorReferenda = pallet_referenda; - - #[runtime::pallet_index(72)] - pub type AmbassadorOrigins = pallet_ambassador_origins; - - #[runtime::pallet_index(73)] - pub type AmbassadorCore = pallet_core_fellowship; - - #[runtime::pallet_index(74)] - pub type AmbassadorSalary = pallet_salary; - - #[runtime::pallet_index(75)] - pub type AmbassadorContent = pallet_collective_content; - - #[runtime::pallet_index(80)] - pub type StateTrieMigration = pallet_state_trie_migration; -} -*/ - /// The address format for describing accounts. pub type Address = sp_runtime::MultiAddress; /// Block type as expected by this runtime. diff --git a/umbrella/Cargo.toml b/umbrella/Cargo.toml index 7f50658c4e16..085332abf8b8 100644 --- a/umbrella/Cargo.toml +++ b/umbrella/Cargo.toml @@ -531,6 +531,7 @@ experimental = [ "frame-support-procedural?/experimental", "frame-support?/experimental", "frame-system?/experimental", + "pallet-salary?/experimental", "polkadot-sdk-frame?/experimental", ] with-tracing = [ From 91f42d22089959d2ae27b5aef49b5789b6422baf Mon Sep 17 00:00:00 2001 From: doordashcon Date: Fri, 8 Nov 2024 09:09:24 -0800 Subject: [PATCH 07/15] xcm-builder support --- polkadot/xcm/xcm-builder/Cargo.toml | 6 ++++++ .../xcm/xcm-builder/src/tests/pay/mock.rs | 21 ++++++++++++++++++- .../xcm/xcm-builder/src/tests/pay/salary.rs | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/polkadot/xcm/xcm-builder/Cargo.toml b/polkadot/xcm/xcm-builder/Cargo.toml index eaa115740f3e..6ddfe22b9134 100644 --- a/polkadot/xcm/xcm-builder/Cargo.toml +++ b/polkadot/xcm/xcm-builder/Cargo.toml @@ -75,3 +75,9 @@ std = [ "xcm-executor/std", "xcm/std", ] + +experimental = [ + "frame-support/experimental", + "frame-system/experimental", + "pallet-salary/experimental", +] diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs index 26ea226313f0..e9c0bb870b82 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs @@ -26,7 +26,7 @@ use frame_support::{ }; use frame_system::{EnsureRoot, EnsureSigned}; use polkadot_primitives::{AccountIndex, BlakeTwo256, Signature}; -use sp_runtime::{generic, traits::MaybeEquivalence, AccountId32, BuildStorage}; +use sp_runtime::{generic, traits::MaybeEquivalence, AccountId32, BuildStorage, testing::TestXt}; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; pub type TxExtension = ( @@ -47,6 +47,8 @@ pub type Block = generic::Block; pub type BlockNumber = u32; pub type AccountId = AccountId32; +pub type Extrinsic = TestXt; + construct_runtime!( pub enum Test { System: frame_system, @@ -57,6 +59,23 @@ construct_runtime!( } ); +impl frame_system::offchain::CreateTransactionBase for Test +where + RuntimeCall: From, +{ + type RuntimeCall = RuntimeCall; + type Extrinsic = Extrinsic; +} + +impl frame_system::offchain::CreateInherent for Test +where + RuntimeCall: From, +{ + fn create_inherent(call: Self::RuntimeCall) -> Self::Extrinsic { + Extrinsic::new_bare(call) + } +} + #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { type Block = Block; diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs index 6a2945c6a9b9..08613ddad1a5 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs @@ -105,6 +105,7 @@ impl GetSalary for FixedSalary { } impl pallet_salary::Config for Test { + type RuntimeTask = ::RuntimeTask; type WeightInfo = (); type RuntimeEvent = RuntimeEvent; type Paymaster = SalaryPayOverXcm; From 650e6bbd611c6c6545bc0f5648492f8c99c17ee3 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 12 Nov 2024 04:34:47 -0800 Subject: [PATCH 08/15] add benchmarks --- .../pallet_salary_ambassador_salary.rs | 12 +++++++++ .../pallet_salary_fellowship_salary.rs | 12 +++++++++ prdoc/pr_5163.prdoc | 17 +++++++++++++ substrate/frame/salary/src/benchmarking.rs | 16 ++++++++++++ substrate/frame/salary/src/lib.rs | 2 +- substrate/frame/salary/src/weights.rs | 25 +++++++++++++++++++ 6 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 prdoc/pr_5163.prdoc diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_salary_ambassador_salary.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_salary_ambassador_salary.rs index 0522420f2f51..bde55367b13b 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_salary_ambassador_salary.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_salary_ambassador_salary.rs @@ -187,4 +187,16 @@ impl pallet_salary::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) } + /// Storage: `Ambassador::Status` (r:1 w:1) + /// Proof: `AmbassadorSalary::Status` (`max_values`: Some(1), `max_size`: Some(56), added: 551, mode: `MaxEncodedLen`) + fn bump_offchain() -> Weight { + // Proof Size summary in bytes: + // Measured: `258` + // Estimated: `1541` + // Minimum execution time: 7_000_000 picoseconds. + Weight::from_parts(8_000_000, 0) + .saturating_add(Weight::from_parts(0, 1541)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_salary_fellowship_salary.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_salary_fellowship_salary.rs index 37680b4e5df7..a11a996e40f5 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_salary_fellowship_salary.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_salary_fellowship_salary.rs @@ -186,4 +186,16 @@ impl pallet_salary::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) } + /// Storage: `FellowshipSalary::Status` (r:1 w:1) + /// Proof: `FellowshipSalary::Status` (`max_values`: Some(1), `max_size`: Some(56), added: 551, mode: `MaxEncodedLen`) + fn bump_offchain() -> Weight { + // Proof Size summary in bytes: + // Measured: `258` + // Estimated: `1541` + // Minimum execution time: 7_000_000 picoseconds. + Weight::from_parts(8_000_000, 0) + .saturating_add(Weight::from_parts(0, 1541)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } } diff --git a/prdoc/pr_5163.prdoc b/prdoc/pr_5163.prdoc new file mode 100644 index 000000000000..21375ed06e05 --- /dev/null +++ b/prdoc/pr_5163.prdoc @@ -0,0 +1,17 @@ +title: Task(bump) Pallet Salary + +doc: + - audience: Runtime Dev + description: | + This PR places `pallet_salary::bump` on an offchain task, this acts as an alternative to + munaul execution (i.e tasks are executed in a random order). + +crates: + - name: collectives-westend-runtime + bump: minor + - name: staging-xcm-builder + bump: minor + - name: pallet-salary + bump: major + - name: umbrella + bump: major \ No newline at end of file diff --git a/substrate/frame/salary/src/benchmarking.rs b/substrate/frame/salary/src/benchmarking.rs index aeae8d2d67f8..216aedbd20b4 100644 --- a/substrate/frame/salary/src/benchmarking.rs +++ b/substrate/frame/salary/src/benchmarking.rs @@ -175,6 +175,22 @@ mod benchmarks { assert!(!matches!(Claimant::::get(&caller).unwrap().status, Attempted { .. })); } + #[benchmark] + fn bump_offchain() { + let caller = whitelisted_caller(); + ensure_member_with_salary::(&caller); + Salary::::init(RawOrigin::Signed(caller.clone()).into()).unwrap(); + Salary::::induct(RawOrigin::Signed(caller.clone()).into()).unwrap(); + System::::set_block_number(System::::block_number() + Salary::::cycle_period()); + + #[block] + { + Task::::bump_offchain().unwrap(); + } + + assert_eq!(Salary::::status().unwrap().cycle_index, 1u32.into()); + } + impl_benchmark_test_suite! { Salary, crate::tests::unit::new_test_ext(), diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs index ff1fcdc16490..9893b7c2d3e9 100644 --- a/substrate/frame/salary/src/lib.rs +++ b/substrate/frame/salary/src/lib.rs @@ -403,7 +403,7 @@ pub mod pallet { status.cycle_start.saturating_accrue(cycle_period); now >= status.cycle_start })] - #[pallet::task_weight(T::DbWeight::get().reads(1))] + #[pallet::task_weight(T::WeightInfo::bump_offchain())] #[pallet::task_index(0)] pub fn bump_offchain() -> DispatchResult { let mut status = Status::::get().ok_or(Error::::NotStarted)?; diff --git a/substrate/frame/salary/src/weights.rs b/substrate/frame/salary/src/weights.rs index d4e6331919b6..94b7ff0c1cf6 100644 --- a/substrate/frame/salary/src/weights.rs +++ b/substrate/frame/salary/src/weights.rs @@ -58,6 +58,7 @@ pub trait WeightInfo { fn payout() -> Weight; fn payout_other() -> Weight; fn check_payment() -> Weight; + fn bump_offchain() -> Weight; } /// Weights for `pallet_salary` using the Substrate node and recommended hardware. @@ -160,6 +161,18 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } + /// Storage: `Salary::Status` (r:1 w:1) + /// Proof: `Salary::Status` (`max_values`: Some(1), `max_size`: Some(56), added: 551, mode: `MaxEncodedLen`) + fn bump_offchain() -> Weight { + // Proof Size summary in bytes: + // Measured: `258` + // Estimated: `1541` + // Minimum execution time: 7_000_000 picoseconds. + Weight::from_parts(8_000_000, 0) + .saturating_add(Weight::from_parts(0, 1541)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } } // For backwards compatibility and tests. @@ -261,4 +274,16 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } + /// Storage: `Salary::Status` (r:1 w:1) + /// Proof: `Salary::Status` (`max_values`: Some(1), `max_size`: Some(56), added: 551, mode: `MaxEncodedLen`) + fn bump_offchain() -> Weight { + // Proof Size summary in bytes: + // Measured: `258` + // Estimated: `1541` + // Minimum execution time: 7_000_000 picoseconds. + Weight::from_parts(8_000_000, 0) + .saturating_add(Weight::from_parts(0, 1541)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } } From d108f47a1dde8fcbaefe86a455076787aef45801 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 12 Nov 2024 04:46:08 -0800 Subject: [PATCH 09/15] remove umbrella crate from pr_5163.prdoc --- prdoc/pr_5163.prdoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/prdoc/pr_5163.prdoc b/prdoc/pr_5163.prdoc index 21375ed06e05..801c41d79f0a 100644 --- a/prdoc/pr_5163.prdoc +++ b/prdoc/pr_5163.prdoc @@ -13,5 +13,3 @@ crates: bump: minor - name: pallet-salary bump: major - - name: umbrella - bump: major \ No newline at end of file From 1f9de5ae14f943d118835f0d39046d02a4fc0882 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 12 Nov 2024 07:07:17 -0800 Subject: [PATCH 10/15] fix benchmark --- Cargo.lock | 1 + substrate/frame/salary/src/lib.rs | 2 +- substrate/frame/salary/src/weights.rs | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eaa0d2667c73..6f3017478e63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3516,6 +3516,7 @@ dependencies = [ "cumulus-primitives-utility 0.7.0", "frame-benchmarking 28.0.0", "frame-executive 28.0.0", + "frame-metadata-hash-extension 0.1.0", "frame-support 28.0.0", "frame-system 28.0.0", "frame-system-benchmarking 28.0.0", diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs index 9893b7c2d3e9..ff1fcdc16490 100644 --- a/substrate/frame/salary/src/lib.rs +++ b/substrate/frame/salary/src/lib.rs @@ -403,7 +403,7 @@ pub mod pallet { status.cycle_start.saturating_accrue(cycle_period); now >= status.cycle_start })] - #[pallet::task_weight(T::WeightInfo::bump_offchain())] + #[pallet::task_weight(T::DbWeight::get().reads(1))] #[pallet::task_index(0)] pub fn bump_offchain() -> DispatchResult { let mut status = Status::::get().ok_or(Error::::NotStarted)?; diff --git a/substrate/frame/salary/src/weights.rs b/substrate/frame/salary/src/weights.rs index 94b7ff0c1cf6..52cb0e1f89bf 100644 --- a/substrate/frame/salary/src/weights.rs +++ b/substrate/frame/salary/src/weights.rs @@ -283,7 +283,7 @@ impl WeightInfo for () { // Minimum execution time: 7_000_000 picoseconds. Weight::from_parts(8_000_000, 0) .saturating_add(Weight::from_parts(0, 1541)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) } } From 14fd3417ffbdfc2980ffd58e22678e344387e188 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 12 Nov 2024 07:44:56 -0800 Subject: [PATCH 11/15] cargo +nightly fmt --- .../collectives-westend/src/lib.rs | 5 ++- .../xcm/xcm-builder/src/tests/pay/mock.rs | 2 +- substrate/frame/salary/src/lib.rs | 9 +++--- .../frame/salary/src/tests/integration.rs | 4 ++- substrate/frame/salary/src/tests/unit.rs | 31 ++++++++----------- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index ef3071aeeed4..947ca5e9ce53 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -94,7 +94,10 @@ use parachains_common::{ AccountId, AuraId, Balance, BlockNumber, Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO, }; -use sp_runtime::{RuntimeDebug, traits::{Verify, SaturatedConversion}}; +use sp_runtime::{ + traits::{SaturatedConversion, Verify}, + RuntimeDebug, +}; use testnet_parachains_constants::westend::{ account::*, consensus::*, currency::*, fee::WeightToFee, time::*, }; diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs index e9c0bb870b82..b12323a2b446 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs @@ -26,7 +26,7 @@ use frame_support::{ }; use frame_system::{EnsureRoot, EnsureSigned}; use polkadot_primitives::{AccountIndex, BlakeTwo256, Signature}; -use sp_runtime::{generic, traits::MaybeEquivalence, AccountId32, BuildStorage, testing::TestXt}; +use sp_runtime::{generic, testing::TestXt, traits::MaybeEquivalence, AccountId32, BuildStorage}; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; pub type TxExtension = ( diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs index ff1fcdc16490..46660ee74224 100644 --- a/substrate/frame/salary/src/lib.rs +++ b/substrate/frame/salary/src/lib.rs @@ -21,12 +21,12 @@ use codec::{Decode, Encode, MaxEncodedLen}; use core::marker::PhantomData; -use scale_info::{TypeInfo, prelude::vec}; -use sp_arithmetic::traits::{Saturating, Zero}; -use sp_runtime::{Perbill, RuntimeDebug}; use frame_system::offchain::CreateInherent; #[cfg(feature = "experimental")] use frame_system::offchain::SubmitTransaction; +use scale_info::{prelude::vec, TypeInfo}; +use sp_arithmetic::traits::{Saturating, Zero}; +use sp_runtime::{Perbill, RuntimeDebug}; use frame_support::{ defensive, @@ -101,7 +101,8 @@ pub mod pallet { pub struct Pallet(PhantomData<(T, I)>); #[pallet::config] - pub trait Config: CreateInherent> + frame_system::Config + pub trait Config: + CreateInherent> + frame_system::Config { type RuntimeTask: frame_support::traits::Task + IsType<::RuntimeTask> diff --git a/substrate/frame/salary/src/tests/integration.rs b/substrate/frame/salary/src/tests/integration.rs index 806b138a7446..bef75aad764e 100644 --- a/substrate/frame/salary/src/tests/integration.rs +++ b/substrate/frame/salary/src/tests/integration.rs @@ -28,7 +28,9 @@ use frame_support::{ use pallet_ranked_collective::{EnsureRanked, Geometric}; use sp_core::{ConstU16, Get}; use sp_runtime::{ - testing::TestXt, traits::{Convert, ReduceBy, ReplaceWithDefault}, BuildStorage + testing::TestXt, + traits::{Convert, ReduceBy, ReplaceWithDefault}, + BuildStorage, }; type Rank = u16; diff --git a/substrate/frame/salary/src/tests/unit.rs b/substrate/frame/salary/src/tests/unit.rs index 9c91f2f57540..ca58679dee74 100644 --- a/substrate/frame/salary/src/tests/unit.rs +++ b/substrate/frame/salary/src/tests/unit.rs @@ -19,17 +19,16 @@ use std::collections::BTreeMap; +use crate as pallet_salary; +use crate::*; use core::cell::RefCell; use frame_support::{ assert_noop, assert_ok, derive_impl, pallet_prelude::Weight, parameter_types, - traits::{tokens::ConvertRank, ConstU64}, + traits::{tokens::ConvertRank, ConstU64, Task}, }; use sp_runtime::{testing::TestXt, traits::Identity, BuildStorage, DispatchResult}; -use frame_support::traits::Task; -use crate as pallet_salary; -use crate::*; type Block = frame_system::mocking::MockBlock; pub type Extrinsic = TestXt; @@ -59,7 +58,6 @@ where } } - parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1_000_000, 0)); @@ -657,9 +655,7 @@ fn runtime_task_enumerate_works_via_frame_system_config() { fn runtime_task_enumerate_works_via_pallet_config() { new_test_ext().execute_with(|| { assert_eq!( - ::RuntimeTask::iter() - .collect::>() - .len(), + ::RuntimeTask::iter().collect::>().len(), 0 ); }); @@ -668,7 +664,7 @@ fn runtime_task_enumerate_works_via_pallet_config() { #[test] fn task_index_works_at_pallet_level() { new_test_ext().execute_with(|| { - assert_eq!(crate::pallet::Task::::BumpOffchain { }.task_index(), 0); + assert_eq!(crate::pallet::Task::::BumpOffchain {}.task_index(), 0); }); } @@ -676,9 +672,10 @@ fn task_index_works_at_pallet_level() { fn task_index_works_at_runtime_level() { new_test_ext().execute_with(|| { assert_eq!( - ::RuntimeTask::Salary(crate::pallet::Task::< - Test, - >::BumpOffchain {}).task_index(), + ::RuntimeTask::Salary( + crate::pallet::Task::::BumpOffchain {} + ) + .task_index(), 0 ); }); @@ -691,10 +688,9 @@ fn task_execution_works() { set_rank(1, 1); assert_ok!(Salary::init(RuntimeOrigin::signed(1))); - let task = - ::RuntimeTask::Salary(crate::pallet::Task::< - Test, - >::BumpOffchain {}); + let task = ::RuntimeTask::Salary( + crate::pallet::Task::::BumpOffchain {}, + ); assert_eq!( Salary::status(), Some(StatusType { @@ -718,7 +714,6 @@ fn task_execution_works() { }) ); System::assert_last_event(frame_system::Event::::TaskCompleted { task }.into()); - }); } @@ -742,7 +737,7 @@ fn task_execution_fails_for_invalid_task() { System::do_task( RuntimeOrigin::signed(1), ::RuntimeTask::Salary( - crate::pallet::Task::::BumpOffchain { } + crate::pallet::Task::::BumpOffchain {} ), ), frame_system::Error::::InvalidTask From a929126271292c25500c09cae504c195601710a8 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 12 Nov 2024 08:25:19 -0800 Subject: [PATCH 12/15] cargo +nightly fmt --- .../runtimes/collectives/collectives-westend/Cargo.toml | 1 + umbrella/Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml index 8359c3f888e6..ca2d1ae639b8 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml @@ -192,6 +192,7 @@ std = [ "frame-system-rpc-runtime-api/std", "frame-system/std", "frame-try-runtime?/std", + "frame-metadata-hash-extension/std", "log/std", "pallet-alliance/std", "pallet-asset-rate/std", diff --git a/umbrella/Cargo.toml b/umbrella/Cargo.toml index 085332abf8b8..d67a7ece91d9 100644 --- a/umbrella/Cargo.toml +++ b/umbrella/Cargo.toml @@ -533,6 +533,7 @@ experimental = [ "frame-system?/experimental", "pallet-salary?/experimental", "polkadot-sdk-frame?/experimental", + "staging-xcm-builder?/experimental", ] with-tracing = [ "frame-executive?/with-tracing", From ccea7990c278392632e1029994ce2be6150d846d Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 12 Nov 2024 08:57:39 -0800 Subject: [PATCH 13/15] adjust prdoc version bumps --- prdoc/pr_5163.prdoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prdoc/pr_5163.prdoc b/prdoc/pr_5163.prdoc index 801c41d79f0a..51b798b407ca 100644 --- a/prdoc/pr_5163.prdoc +++ b/prdoc/pr_5163.prdoc @@ -8,8 +8,8 @@ doc: crates: - name: collectives-westend-runtime - bump: minor + bump: Major - name: staging-xcm-builder - bump: minor + bump: Patch - name: pallet-salary - bump: major + bump: Patch From ad6380b547c777d9c4e431b67de644acc81b4c2a Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 12 Nov 2024 09:01:21 -0800 Subject: [PATCH 14/15] adjust prdoc version bumps 2 --- prdoc/pr_5163.prdoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prdoc/pr_5163.prdoc b/prdoc/pr_5163.prdoc index 51b798b407ca..e0ade052f98c 100644 --- a/prdoc/pr_5163.prdoc +++ b/prdoc/pr_5163.prdoc @@ -8,8 +8,8 @@ doc: crates: - name: collectives-westend-runtime - bump: Major + bump: major - name: staging-xcm-builder - bump: Patch + bump: patch - name: pallet-salary - bump: Patch + bump: patch From c206b30c697ed55501cd271b6ba8ca5016db95a6 Mon Sep 17 00:00:00 2001 From: doordashcon Date: Tue, 12 Nov 2024 09:51:42 -0800 Subject: [PATCH 15/15] add polkadot-sdk to prdoc --- prdoc/pr_5163.prdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prdoc/pr_5163.prdoc b/prdoc/pr_5163.prdoc index e0ade052f98c..53a1dc14adc2 100644 --- a/prdoc/pr_5163.prdoc +++ b/prdoc/pr_5163.prdoc @@ -13,3 +13,5 @@ crates: bump: patch - name: pallet-salary bump: patch + - name: polkadot-sdk + bump: patch