diff --git a/.github/workflows/runtimes-matrix.json b/.github/workflows/runtimes-matrix.json index 8219c0615f260cbbc279d63317e1664e338920d7..e560ed9fc6dd31683abd538a034ac26974e8c002 100644 --- a/.github/workflows/runtimes-matrix.json +++ b/.github/workflows/runtimes-matrix.json @@ -6,7 +6,7 @@ "header": "substrate/HEADER-APACHE2", "template": "substrate/.maintain/frame-weight-template.hbs", "bench_features": "runtime-benchmarks", - "bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic,pallet_nomination_pools,pallet_remark,pallet_transaction_storage,pallet_election_provider_multi_block,pallet_election_provider_multi_block::signed,pallet_election_provider_multi_block::unsigned,pallet_election_provider_multi_block::verifier", + "bench_flags": "--exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic,pallet_nomination_pools,pallet_remark,pallet_transaction_storage,pallet_election_provider_multi_block,pallet_election_provider_multi_block::signed,pallet_election_provider_multi_block::unsigned,pallet_election_provider_multi_block::verifier", "uri": null, "is_relay": false }, diff --git a/Cargo.lock b/Cargo.lock index 56daf8f482d9b02ff03a508fc9baafe43c6f89ad..2b0448a3baeed3ca0864ab10e1b6ac0aa1e0e7b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8749,6 +8749,7 @@ checksum = "c33070833c9ee02266356de0c43f723152bd38bd96ddf52c82b3af10c9138b28" name = "kitchensink-runtime" version = "3.0.0-dev" dependencies = [ + "array-bytes", "log", "node-primitives", "pallet-example-mbm", @@ -12425,16 +12426,11 @@ dependencies = [ name = "pallet-nis" version = "28.0.0" dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", "pallet-balances", "parity-scale-codec", + "polkadot-sdk-frame", "scale-info", - "sp-arithmetic 23.0.0", - "sp-core 28.0.0", "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] @@ -16202,6 +16198,7 @@ dependencies = [ "pallet-examples", "parity-scale-codec", "scale-info", + "serde", "sp-api 26.0.0", "sp-arithmetic 23.0.0", "sp-block-builder", diff --git a/polkadot/runtime/parachains/src/configuration/benchmarking.rs b/polkadot/runtime/parachains/src/configuration/benchmarking.rs index adc7f31a7b2913e020b3db5f7595de96abaac742..49c1876adca00a1826fa1a179fdefb1724c76cc7 100644 --- a/polkadot/runtime/parachains/src/configuration/benchmarking.rs +++ b/polkadot/runtime/parachains/src/configuration/benchmarking.rs @@ -13,45 +13,91 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see <http://www.gnu.org/licenses/>. +#![cfg(feature = "runtime-benchmarks")] use crate::configuration::*; -use frame_benchmarking::{benchmarks, BenchmarkError, BenchmarkResult}; +use frame_benchmarking::v2::*; use frame_system::RawOrigin; use polkadot_primitives::{ExecutorParam, ExecutorParams, PvfExecKind, PvfPrepKind}; use sp_runtime::traits::One; -benchmarks! { - set_config_with_block_number {}: set_code_retention_period(RawOrigin::Root, One::one()) +#[benchmarks] +mod benchmarks { + use super::*; - set_config_with_u32 {}: set_max_code_size(RawOrigin::Root, 100) + #[benchmark] + fn set_config_with_block_number() { + #[extrinsic_call] + set_code_retention_period(RawOrigin::Root, One::one()); + } - set_config_with_option_u32 {}: set_max_validators(RawOrigin::Root, Some(10)) + #[benchmark] + fn set_config_with_u32() { + #[extrinsic_call] + set_max_code_size(RawOrigin::Root, 100); + } - set_hrmp_open_request_ttl {}: { - Err(BenchmarkError::Override( - BenchmarkResult::from_weight(T::BlockWeights::get().max_block) - ))?; + #[benchmark] + fn set_config_with_option_u32() { + #[extrinsic_call] + set_max_validators(RawOrigin::Root, Some(10)); } - set_config_with_balance {}: set_hrmp_sender_deposit(RawOrigin::Root, 100_000_000_000) + #[benchmark] + fn set_hrmp_open_request_ttl() -> Result<(), BenchmarkError> { + #[block] + { + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + T::BlockWeights::get().max_block, + )))?; + } + Ok(()) + } - set_config_with_executor_params {}: set_executor_params(RawOrigin::Root, ExecutorParams::from(&[ - ExecutorParam::MaxMemoryPages(2080), - ExecutorParam::StackLogicalMax(65536), - ExecutorParam::StackNativeMax(256 * 1024 * 1024), - ExecutorParam::WasmExtBulkMemory, - ExecutorParam::PrecheckingMaxMemory(2 * 1024 * 1024 * 1024), - ExecutorParam::PvfPrepTimeout(PvfPrepKind::Precheck, 60_000), - ExecutorParam::PvfPrepTimeout(PvfPrepKind::Prepare, 360_000), - ExecutorParam::PvfExecTimeout(PvfExecKind::Backing, 2_000), - ExecutorParam::PvfExecTimeout(PvfExecKind::Approval, 12_000), - ][..])) + #[benchmark] + fn set_config_with_balance() { + #[extrinsic_call] + set_hrmp_sender_deposit(RawOrigin::Root, 100_000_000_000); + } - set_config_with_perbill {}: set_on_demand_fee_variability(RawOrigin::Root, Perbill::from_percent(100)) + #[benchmark] + fn set_config_with_executor_params() { + #[extrinsic_call] + set_executor_params( + RawOrigin::Root, + ExecutorParams::from( + &[ + ExecutorParam::MaxMemoryPages(2080), + ExecutorParam::StackLogicalMax(65536), + ExecutorParam::StackNativeMax(256 * 1024 * 1024), + ExecutorParam::WasmExtBulkMemory, + ExecutorParam::PrecheckingMaxMemory(2 * 1024 * 1024 * 1024), + ExecutorParam::PvfPrepTimeout(PvfPrepKind::Precheck, 60_000), + ExecutorParam::PvfPrepTimeout(PvfPrepKind::Prepare, 360_000), + ExecutorParam::PvfExecTimeout(PvfExecKind::Backing, 2_000), + ExecutorParam::PvfExecTimeout(PvfExecKind::Approval, 12_000), + ][..], + ), + ); + } - set_node_feature{}: set_node_feature(RawOrigin::Root, 255, true) + #[benchmark] + fn set_config_with_perbill() { + #[extrinsic_call] + set_on_demand_fee_variability(RawOrigin::Root, Perbill::from_percent(100)); + } + + #[benchmark] + fn set_node_feature() { + #[extrinsic_call] + set_node_feature(RawOrigin::Root, 255, true); + } - set_config_with_scheduler_params {} : set_scheduler_params(RawOrigin::Root, SchedulerParams::default()) + #[benchmark] + fn set_config_with_scheduler_params() { + #[extrinsic_call] + set_scheduler_params(RawOrigin::Root, SchedulerParams::default()); + } impl_benchmark_test_suite!( Pallet, diff --git a/polkadot/runtime/rococo/src/weights/pallet_nis.rs b/polkadot/runtime/rococo/src/weights/pallet_nis.rs index 531b9be0b8df34e2c45870ded2eca0fbffd225ce..1d1a6afab8eba44741f3da1c8a352f6b060dc497 100644 --- a/polkadot/runtime/rococo/src/weights/pallet_nis.rs +++ b/polkadot/runtime/rococo/src/weights/pallet_nis.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for `pallet_nis` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2025-02-22, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2025-03-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `d3a9aad6f7a3`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `bd5e4dfa0790`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 // Executed Command: @@ -64,11 +64,11 @@ impl<T: frame_system::Config> pallet_nis::WeightInfo for WeightInfo<T> { // Proof Size summary in bytes: // Measured: `6213 + l * (48 ±0)` // Estimated: `51487` - // Minimum execution time: 51_535_000 picoseconds. - Weight::from_parts(48_054_720, 0) + // Minimum execution time: 49_715_000 picoseconds. + Weight::from_parts(47_437_903, 0) .saturating_add(Weight::from_parts(0, 51487)) - // Standard Error: 1_637 - .saturating_add(Weight::from_parts(116_321, 0).saturating_mul(l.into())) + // Standard Error: 1_376 + .saturating_add(Weight::from_parts(103_572, 0).saturating_mul(l.into())) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -84,8 +84,8 @@ impl<T: frame_system::Config> pallet_nis::WeightInfo for WeightInfo<T> { // Proof Size summary in bytes: // Measured: `54215` // Estimated: `51487` - // Minimum execution time: 173_342_000 picoseconds. - Weight::from_parts(184_974_000, 0) + // Minimum execution time: 158_994_000 picoseconds. + Weight::from_parts(163_192_000, 0) .saturating_add(Weight::from_parts(0, 51487)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) @@ -101,11 +101,11 @@ impl<T: frame_system::Config> pallet_nis::WeightInfo for WeightInfo<T> { // Proof Size summary in bytes: // Measured: `6209 + l * (48 ±0)` // Estimated: `51487` - // Minimum execution time: 48_913_000 picoseconds. - Weight::from_parts(40_310_888, 0) + // Minimum execution time: 47_456_000 picoseconds. + Weight::from_parts(39_000_499, 0) .saturating_add(Weight::from_parts(0, 51487)) - // Standard Error: 1_567 - .saturating_add(Weight::from_parts(98_720, 0).saturating_mul(l.into())) + // Standard Error: 1_374 + .saturating_add(Weight::from_parts(87_646, 0).saturating_mul(l.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -117,8 +117,8 @@ impl<T: frame_system::Config> pallet_nis::WeightInfo for WeightInfo<T> { // Proof Size summary in bytes: // Measured: `225` // Estimated: `3593` - // Minimum execution time: 33_430_000 picoseconds. - Weight::from_parts(34_693_000, 0) + // Minimum execution time: 33_224_000 picoseconds. + Weight::from_parts(34_527_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -137,8 +137,8 @@ impl<T: frame_system::Config> pallet_nis::WeightInfo for WeightInfo<T> { // Proof Size summary in bytes: // Measured: `387` // Estimated: `3593` - // Minimum execution time: 70_761_000 picoseconds. - Weight::from_parts(72_954_000, 0) + // Minimum execution time: 68_688_000 picoseconds. + Weight::from_parts(70_098_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(5)) @@ -157,8 +157,8 @@ impl<T: frame_system::Config> pallet_nis::WeightInfo for WeightInfo<T> { // Proof Size summary in bytes: // Measured: `543` // Estimated: `3593` - // Minimum execution time: 89_467_000 picoseconds. - Weight::from_parts(92_605_000, 0) + // Minimum execution time: 85_968_000 picoseconds. + Weight::from_parts(87_276_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(5)) @@ -175,8 +175,8 @@ impl<T: frame_system::Config> pallet_nis::WeightInfo for WeightInfo<T> { // Proof Size summary in bytes: // Measured: `387` // Estimated: `3593` - // Minimum execution time: 56_865_000 picoseconds. - Weight::from_parts(57_749_000, 0) + // Minimum execution time: 53_366_000 picoseconds. + Weight::from_parts(54_742_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) @@ -193,8 +193,8 @@ impl<T: frame_system::Config> pallet_nis::WeightInfo for WeightInfo<T> { // Proof Size summary in bytes: // Measured: `488` // Estimated: `3593` - // Minimum execution time: 91_240_000 picoseconds. - Weight::from_parts(93_106_000, 0) + // Minimum execution time: 88_287_000 picoseconds. + Weight::from_parts(90_235_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) @@ -209,8 +209,8 @@ impl<T: frame_system::Config> pallet_nis::WeightInfo for WeightInfo<T> { // Proof Size summary in bytes: // Measured: `6658` // Estimated: `7487` - // Minimum execution time: 23_148_000 picoseconds. - Weight::from_parts(24_318_000, 0) + // Minimum execution time: 21_256_000 picoseconds. + Weight::from_parts(22_594_000, 0) .saturating_add(Weight::from_parts(0, 7487)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -221,8 +221,8 @@ impl<T: frame_system::Config> pallet_nis::WeightInfo for WeightInfo<T> { // Proof Size summary in bytes: // Measured: `76` // Estimated: `51487` - // Minimum execution time: 5_213_000 picoseconds. - Weight::from_parts(5_487_000, 0) + // Minimum execution time: 5_026_000 picoseconds. + Weight::from_parts(5_304_000, 0) .saturating_add(Weight::from_parts(0, 51487)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -233,8 +233,8 @@ impl<T: frame_system::Config> pallet_nis::WeightInfo for WeightInfo<T> { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_226_000 picoseconds. - Weight::from_parts(5_480_000, 0) + // Minimum execution time: 4_905_000 picoseconds. + Weight::from_parts(5_189_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } diff --git a/polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_configuration.rs b/polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_configuration.rs index ef8cfb1ed51fc6ab7733e2a2e7af8ed1a3d5feaa..6bbec592bb4cd7113d6910418eb0dfffb767c7e7 100644 --- a/polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_configuration.rs +++ b/polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_configuration.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for `polkadot_runtime_parachains::configuration` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2025-02-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2025-02-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `d3a9aad6f7a3`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `13d69b199c54`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 // Executed Command: @@ -61,8 +61,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 11_055_000 picoseconds. - Weight::from_parts(11_488_000, 0) + // Minimum execution time: 10_901_000 picoseconds. + Weight::from_parts(11_468_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -77,8 +77,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 11_125_000 picoseconds. - Weight::from_parts(11_591_000, 0) + // Minimum execution time: 10_847_000 picoseconds. + Weight::from_parts(11_499_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -93,8 +93,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 11_127_000 picoseconds. - Weight::from_parts(11_499_000, 0) + // Minimum execution time: 11_143_000 picoseconds. + Weight::from_parts(11_488_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -119,8 +119,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_955_000 picoseconds. - Weight::from_parts(11_407_000, 0) + // Minimum execution time: 11_126_000 picoseconds. + Weight::from_parts(11_416_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -135,8 +135,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 13_162_000 picoseconds. - Weight::from_parts(13_403_000, 0) + // Minimum execution time: 13_119_000 picoseconds. + Weight::from_parts(13_612_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -151,8 +151,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_868_000 picoseconds. - Weight::from_parts(11_438_000, 0) + // Minimum execution time: 11_072_000 picoseconds. + Weight::from_parts(11_412_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -167,8 +167,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 13_354_000 picoseconds. - Weight::from_parts(14_407_000, 0) + // Minimum execution time: 13_268_000 picoseconds. + Weight::from_parts(13_664_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -183,8 +183,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 11_283_000 picoseconds. - Weight::from_parts(12_054_000, 0) + // Minimum execution time: 11_047_000 picoseconds. + Weight::from_parts(11_298_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) diff --git a/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_configuration.rs b/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_configuration.rs index 6e27b729a361bf8e2a1fdc7d2c997b85ed3abff0..98b98b3c19cc2723283c67dc34053cc81c553b5f 100644 --- a/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_configuration.rs +++ b/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_configuration.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for `polkadot_runtime_parachains::configuration` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2025-02-22, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2025-02-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `3a2e9ae8a8f5`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `13d69b199c54`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 // Executed Command: @@ -61,8 +61,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_475_000 picoseconds. - Weight::from_parts(11_132_000, 0) + // Minimum execution time: 10_838_000 picoseconds. + Weight::from_parts(11_218_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -77,8 +77,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_419_000 picoseconds. - Weight::from_parts(11_052_000, 0) + // Minimum execution time: 10_949_000 picoseconds. + Weight::from_parts(11_200_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -93,8 +93,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_613_000 picoseconds. - Weight::from_parts(11_170_000, 0) + // Minimum execution time: 10_975_000 picoseconds. + Weight::from_parts(11_519_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -119,8 +119,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_818_000 picoseconds. - Weight::from_parts(11_183_000, 0) + // Minimum execution time: 10_729_000 picoseconds. + Weight::from_parts(11_195_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -135,8 +135,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 12_672_000 picoseconds. - Weight::from_parts(13_154_000, 0) + // Minimum execution time: 12_949_000 picoseconds. + Weight::from_parts(13_251_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -151,8 +151,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_814_000 picoseconds. - Weight::from_parts(11_120_000, 0) + // Minimum execution time: 10_683_000 picoseconds. + Weight::from_parts(11_196_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -167,8 +167,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 12_919_000 picoseconds. - Weight::from_parts(13_455_000, 0) + // Minimum execution time: 12_855_000 picoseconds. + Weight::from_parts(13_484_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -183,8 +183,8 @@ impl<T: frame_system::Config> polkadot_runtime_parachains::configuration::Weight // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_495_000 picoseconds. - Weight::from_parts(11_189_000, 0) + // Minimum execution time: 10_933_000 picoseconds. + Weight::from_parts(11_367_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) diff --git a/prdoc/pr_6293.prdoc b/prdoc/pr_6293.prdoc new file mode 100644 index 0000000000000000000000000000000000000000..dfd4bdee45744af17d0ed91db9764aa79bb0de4b --- /dev/null +++ b/prdoc/pr_6293.prdoc @@ -0,0 +1,11 @@ +title: Migrate pallet-nis benchmark to v2 +doc: +- audience: Runtime Dev + description: |- + - Refactor to use the `frame` crate. + - Use procedural macro version `construct_runtime` in mock. + - Expose `PalletId` to `frame::pallet_prelude`. + - Part of #6202. +crates: +- name: pallet-nis + bump: patch diff --git a/prdoc/pr_7764.prdoc b/prdoc/pr_7764.prdoc new file mode 100644 index 0000000000000000000000000000000000000000..c90c132092ffe4a5f20e6ec4430120eb78c5c0f0 --- /dev/null +++ b/prdoc/pr_7764.prdoc @@ -0,0 +1,17 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Add Serialize & Deserialize to umbrella crate derive module + +doc: + - audience: Runtime Dev + description: | + This PR adds serde::Serialize and serde::Deserialize to the frame umbrella crate + `derive` and indirectly `prelude` modules. They can now be accessed through those. + Note: serde will still need to be added as a dependency in consuming crates. That or + you'll need to specify th `#[serde(crate = "PATH_TO_SERDE::serde")]` attribute at the + location where Serialize/Deserialize are used. + +crates: +- name: polkadot-sdk-frame + bump: minor diff --git a/prdoc/pr_7784.prdoc b/prdoc/pr_7784.prdoc new file mode 100644 index 0000000000000000000000000000000000000000..cb8d5e8a425910448dfd00b97008e6439d25adbb --- /dev/null +++ b/prdoc/pr_7784.prdoc @@ -0,0 +1,11 @@ +title: '[pallet-revive] block.timestamps should return seconds' +doc: +- audience: Runtime Dev + description: |- + In solidity `block.timestamp` should be expressed in seconds + see https://docs.soliditylang.org/en/latest/units-and-global-variables.html#block-and-transaction-properties +crates: +- name: pallet-revive + bump: patch +- name: pallet-revive-uapi + bump: patch diff --git a/substrate/bin/node/cli/src/chain_spec.rs b/substrate/bin/node/cli/src/chain_spec.rs index af08ca7f60996ca3949811da814639743e0b22c3..08efe2cf4bd613b8bed74c970886c2ddcb7a9fcf 100644 --- a/substrate/bin/node/cli/src/chain_spec.rs +++ b/substrate/bin/node/cli/src/chain_spec.rs @@ -20,9 +20,10 @@ use polkadot_sdk::*; -use crate::chain_spec::{sc_service::Properties, sp_runtime::AccountId32}; +use crate::chain_spec::sc_service::Properties; use kitchensink_runtime::{ - constants::currency::*, wasm_binary_unwrap, Block, MaxNominations, SessionKeys, StakerStatus, + genesis_config_presets::{session_keys, Staker, StakingPlaygroundConfig, STASH}, + wasm_binary_unwrap, Block, MaxNominations, StakerStatus, }; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_chain_spec::ChainSpecExtension; @@ -33,20 +34,13 @@ use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; use sp_consensus_beefy::ecdsa_crypto::AuthorityId as BeefyId; use sp_consensus_grandpa::AuthorityId as GrandpaId; -use sp_core::{ - crypto::{get_public_from_string_or_panic, UncheckedInto}, - sr25519, -}; -use sp_keyring::Sr25519Keyring; +use sp_core::crypto::UncheckedInto; use sp_mixnet::types::AuthorityId as MixnetId; -use sp_runtime::Perbill; pub use kitchensink_runtime::RuntimeGenesisConfig; pub use node_primitives::{AccountId, Balance, Signature}; const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; -const ENDOWMENT: Balance = 10_000_000 * DOLLARS; -const STASH: Balance = ENDOWMENT / 1000; /// Node `ChainSpec` extensions. /// @@ -70,17 +64,6 @@ pub fn flaming_fir_config() -> Result<ChainSpec, String> { ChainSpec::from_json_bytes(&include_bytes!("../res/flaming-fir.json")[..]) } -fn session_keys( - grandpa: GrandpaId, - babe: BabeId, - im_online: ImOnlineId, - authority_discovery: AuthorityDiscoveryId, - mixnet: MixnetId, - beefy: BeefyId, -) -> SessionKeys { - SessionKeys { grandpa, babe, im_online, authority_discovery, mixnet, beefy } -} - fn configure_accounts_for_staging_testnet() -> ( Vec<( AccountId, @@ -229,7 +212,7 @@ fn configure_accounts_for_staging_testnet() -> ( fn staging_testnet_config_genesis() -> serde_json::Value { let (initial_authorities, root_key, endowed_accounts) = configure_accounts_for_staging_testnet(); - testnet_genesis(initial_authorities, vec![], root_key, Some(endowed_accounts)) + testnet_genesis(initial_authorities, vec![], root_key, endowed_accounts) } /// Staging testnet config. @@ -246,23 +229,10 @@ pub fn staging_testnet_config() -> ChainSpec { .build() } -/// Helper function to generate stash, controller and session key from seed. -pub fn authority_keys_from_seed( - seed: &str, -) -> (AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId, MixnetId, BeefyId) -{ - ( - get_public_from_string_or_panic::<sr25519::Public>(&format!("{}//stash", seed)).into(), - get_public_from_string_or_panic::<sr25519::Public>(seed).into(), - get_public_from_string_or_panic::<GrandpaId>(seed), - get_public_from_string_or_panic::<BabeId>(seed), - get_public_from_string_or_panic::<ImOnlineId>(seed), - get_public_from_string_or_panic::<AuthorityDiscoveryId>(seed), - get_public_from_string_or_panic::<MixnetId>(seed), - get_public_from_string_or_panic::<BeefyId>(seed), - ) -} - +/// Configure the accounts for the testnet. +/// +/// * Adds `initial_authorities` and `initial_nominators` to endowed accounts if missing. +/// * Sets up the stakers consisting of the `initial_authorities` and `initial_nominators`. fn configure_accounts( initial_authorities: Vec<( AccountId, @@ -275,7 +245,7 @@ fn configure_accounts( BeefyId, )>, initial_nominators: Vec<AccountId>, - endowed_accounts: Option<Vec<AccountId>>, + endowed_accounts: Vec<AccountId>, stash: Balance, ) -> ( Vec<( @@ -289,11 +259,9 @@ fn configure_accounts( BeefyId, )>, Vec<AccountId>, - usize, - Vec<(AccountId, AccountId, Balance, StakerStatus<AccountId>)>, + Vec<Staker>, ) { - let mut endowed_accounts: Vec<AccountId> = - endowed_accounts.unwrap_or_else(default_endowed_accounts); + let mut endowed_accounts = endowed_accounts; // endow all authorities and nominators. initial_authorities .iter() @@ -324,9 +292,7 @@ fn configure_accounts( })) .collect::<Vec<_>>(); - let num_endowed_accounts = endowed_accounts.len(); - - (initial_authorities, endowed_accounts, num_endowed_accounts, stakers) + (initial_authorities, endowed_accounts, stakers) } /// Helper function to create RuntimeGenesisConfig json patch for testing. @@ -343,103 +309,61 @@ pub fn testnet_genesis( )>, initial_nominators: Vec<AccountId>, root_key: AccountId, - endowed_accounts: Option<Vec<AccountId>>, + endowed_accounts: Vec<AccountId>, ) -> serde_json::Value { - let (initial_authorities, endowed_accounts, num_endowed_accounts, stakers) = + let (initial_authorities, endowed_accounts, stakers) = configure_accounts(initial_authorities, initial_nominators, endowed_accounts, STASH); - const MAX_COLLECTIVE_SIZE: usize = 50; - - let dev_stakers = if cfg!(feature = "staking-playground") { - let random_validators = - std::option_env!("VALIDATORS").map(|s| s.parse::<u32>().unwrap()).unwrap_or(100); - let random_nominators = std::option_env!("NOMINATORS") - .map(|s| s.parse::<u32>().unwrap()) - .unwrap_or(3000); - Some((random_validators, random_nominators)) - } else { - None - }; - let validator_count = if cfg!(feature = "staking-playground") { - std::option_env!("VALIDATOR_COUNT") - .map(|v| v.parse::<u32>().unwrap()) - .unwrap_or(100) + let staking_playground_config = if cfg!(feature = "staking-playground") { + Some(get_staking_playground_config()) } else { - initial_authorities.len() as u32 + None }; - let minimum_validator_count = - if cfg!(feature = "staking-playground") { 10 } else { initial_authorities.len() as u32 }; - - serde_json::json!({ - "balances": { - "balances": endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect::<Vec<_>>(), - }, - "session": { - "keys": initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - ), - ) - }) - .collect::<Vec<_>>(), - }, - "staking": { - "validatorCount": validator_count, - "minimumValidatorCount": minimum_validator_count, - "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::<Vec<_>>(), - "slashRewardFraction": Perbill::from_percent(10), - "stakers": stakers.clone(), - "devStakers": dev_stakers - }, - "elections": { - "members": endowed_accounts - .iter() - .take(((num_endowed_accounts + 1) / 2).min(MAX_COLLECTIVE_SIZE)) - .cloned() - .map(|member| (member, STASH)) - .collect::<Vec<_>>(), - }, - "technicalCommittee": { - "members": endowed_accounts - .iter() - .take(((num_endowed_accounts + 1) / 2).min(MAX_COLLECTIVE_SIZE)) - .cloned() - .collect::<Vec<_>>(), - }, - "sudo": { "key": Some(root_key.clone()) }, - "babe": { - "epochConfig": Some(kitchensink_runtime::BABE_GENESIS_EPOCH_CONFIG), - }, - "society": { "pot": 0 }, - "assets": { - // This asset is used by the NIS pallet as counterpart currency. - "assets": vec![(9, Sr25519Keyring::Alice.to_account_id(), true, 1)], - }, - "nominationPools": { - "minCreateBond": 10 * DOLLARS, - "minJoinBond": 1 * DOLLARS, - }, - }) + // Todo: After #7748 is done, we can refactor this to avoid + // calling into the native runtime. + kitchensink_runtime::genesis_config_presets::kitchensink_genesis( + initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + // stash account is controller + x.0.clone(), + session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + ), + ) + }) + .collect(), + root_key, + endowed_accounts, + stakers, + staking_playground_config, + ) } -fn development_config_genesis_json() -> serde_json::Value { - testnet_genesis( - vec![authority_keys_from_seed("Alice")], - vec![], - Sr25519Keyring::Alice.to_account_id(), - None, - ) +fn get_staking_playground_config() -> StakingPlaygroundConfig { + let random_validators = + std::option_env!("VALIDATORS").map(|s| s.parse::<u32>().unwrap()).unwrap_or(100); + let random_nominators = std::option_env!("NOMINATORS") + .map(|s| s.parse::<u32>().unwrap()) + .unwrap_or(3000); + + let validator_count = std::option_env!("VALIDATOR_COUNT") + .map(|v| v.parse::<u32>().unwrap()) + .unwrap_or(100); + + StakingPlaygroundConfig { + dev_stakers: (random_validators, random_nominators), + validator_count, + minimum_validator_count: 10, + } } fn props() -> Properties { @@ -448,23 +372,6 @@ fn props() -> Properties { properties } -fn eth_account(from: subxt_signer::eth::Keypair) -> AccountId32 { - let mut account_id = AccountId32::new([0xEE; 32]); - <AccountId32 as AsMut<[u8; 32]>>::as_mut(&mut account_id)[..20] - .copy_from_slice(&from.public_key().to_account_id().as_ref()); - account_id -} - -fn default_endowed_accounts() -> Vec<AccountId> { - Sr25519Keyring::well_known() - .map(|k| k.to_account_id()) - .chain([ - eth_account(subxt_signer::eth::dev::alith()), - eth_account(subxt_signer::eth::dev::baltathar()), - ]) - .collect() -} - /// Development config (single validator Alice). pub fn development_config() -> ChainSpec { ChainSpec::builder(wasm_binary_unwrap(), Default::default()) @@ -472,26 +379,17 @@ pub fn development_config() -> ChainSpec { .with_id("dev") .with_chain_type(ChainType::Development) .with_properties(props()) - .with_genesis_config_patch(development_config_genesis_json()) + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) .build() } -fn local_testnet_genesis() -> serde_json::Value { - testnet_genesis( - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], - vec![], - Sr25519Keyring::Alice.to_account_id(), - None, - ) -} - /// Local testnet config (multivalidator Alice + Bob). pub fn local_testnet_config() -> ChainSpec { ChainSpec::builder(wasm_binary_unwrap(), Default::default()) .with_name("Local Testnet") .with_id("local_testnet") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(local_testnet_genesis()) + .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) .build() } @@ -499,8 +397,9 @@ pub fn local_testnet_config() -> ChainSpec { pub(crate) mod tests { use super::*; use crate::service::{new_full_base, NewFullBase}; + use kitchensink_runtime::genesis_config_presets::well_known_including_eth_accounts; use sc_service_test; - use sp_runtime::BuildStorage; + use sp_runtime::{AccountId32, BuildStorage}; /// Local testnet config (single validator - Alice). pub fn integration_test_config_with_single_authority() -> ChainSpec { @@ -508,12 +407,7 @@ pub(crate) mod tests { .with_name("Integration Test") .with_id("test") .with_chain_type(ChainType::Development) - .with_genesis_config_patch(testnet_genesis( - vec![authority_keys_from_seed("Alice")], - vec![], - Sr25519Keyring::Alice.to_account_id(), - None, - )) + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) .build() } @@ -522,11 +416,18 @@ pub(crate) mod tests { ChainSpec::builder(wasm_binary_unwrap(), Default::default()) .with_name("Integration Test") .with_id("test") - .with_chain_type(ChainType::Development) - .with_genesis_config_patch(local_testnet_genesis()) + .with_chain_type(ChainType::Local) + .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) .build() } + fn eth_account(from: subxt_signer::eth::Keypair) -> AccountId32 { + let mut account_id = AccountId32::new([0xEE; 32]); + <AccountId32 as AsMut<[u8; 32]>>::as_mut(&mut account_id)[..20] + .copy_from_slice(&from.public_key().to_account_id().as_ref()); + account_id + } + #[test] #[ignore] fn test_connectivity() { @@ -559,4 +460,15 @@ pub(crate) mod tests { fn test_staging_test_net_chain_spec() { staging_testnet_config().build_storage().unwrap(); } + + #[test] + fn ensure_eth_accounts_are_in_endowed() { + let alith = eth_account(subxt_signer::eth::dev::alith()); + let baltathar = eth_account(subxt_signer::eth::dev::baltathar()); + + let endowed = well_known_including_eth_accounts(); + + assert!(endowed.contains(&alith), "Alith must be in endowed for integration tests"); + assert!(endowed.contains(&baltathar), "Baltathar must be in endowed for integration tests"); + } } diff --git a/substrate/bin/node/cli/tests/benchmark_pallet_works.rs b/substrate/bin/node/cli/tests/benchmark_pallet_works.rs index d913228881a4e93b78fc03b51d3050c26a5f617a..623f7e3473fc0e0d7f9ce7d9f9b843e36fa4a5a4 100644 --- a/substrate/bin/node/cli/tests/benchmark_pallet_works.rs +++ b/substrate/bin/node/cli/tests/benchmark_pallet_works.rs @@ -45,11 +45,9 @@ fn benchmark_pallet_args_work() { &["--list", "--pallet=pallet_balances", "--chain=dev", "--genesis-builder=spec-genesis"], true, ); - - // Error because the genesis runtime does not have any presets in it: benchmark_pallet_args( &["--list", "--pallet=pallet_balances", "--chain=dev", "--genesis-builder=spec-runtime"], - false, + true, ); // Error because no runtime is provided: benchmark_pallet_args( diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 07c97f8c271e75724d368745f731ff09568da5c4..c0eac973c7a462a7f2934946a1b770123c394f29 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -19,6 +19,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] # third-party dependencies +array-bytes = { workspace = true } codec = { features = [ "derive", "max-encoded-len", diff --git a/substrate/bin/node/runtime/src/genesis_config_presets.rs b/substrate/bin/node/runtime/src/genesis_config_presets.rs new file mode 100644 index 0000000000000000000000000000000000000000..99ae8f1d839390424f196a40ef35c34bc86ac336 --- /dev/null +++ b/substrate/bin/node/runtime/src/genesis_config_presets.rs @@ -0,0 +1,234 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Genesis Presets for the Kitchensink Runtime + +use polkadot_sdk::*; + +use crate::{ + constants::currency::*, frame_support::build_struct_json_patch, AccountId, AssetsConfig, + BabeConfig, Balance, BalancesConfig, ElectionsConfig, NominationPoolsConfig, + RuntimeGenesisConfig, SessionConfig, SessionKeys, SocietyConfig, StakerStatus, StakingConfig, + SudoConfig, TechnicalCommitteeConfig, BABE_GENESIS_EPOCH_CONFIG, +}; +use alloc::{vec, vec::Vec}; +use pallet_im_online::sr25519::AuthorityId as ImOnlineId; +use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; +use sp_consensus_babe::AuthorityId as BabeId; +use sp_consensus_beefy::ecdsa_crypto::AuthorityId as BeefyId; +use sp_consensus_grandpa::AuthorityId as GrandpaId; +use sp_core::{crypto::get_public_from_string_or_panic, sr25519}; +use sp_genesis_builder::PresetId; +use sp_keyring::Sr25519Keyring; +use sp_mixnet::types::AuthorityId as MixnetId; +use sp_runtime::Perbill; + +pub const ENDOWMENT: Balance = 10_000_000 * DOLLARS; +pub const STASH: Balance = ENDOWMENT / 1000; + +pub struct StakingPlaygroundConfig { + /// (Validators, Nominators) + pub dev_stakers: (u32, u32), + pub validator_count: u32, + pub minimum_validator_count: u32, +} + +/// The staker type as supplied ot the Staking config. +pub type Staker = (AccountId, AccountId, Balance, StakerStatus<AccountId>); + +/// Helper function to create RuntimeGenesisConfig json patch for testing. +pub fn kitchensink_genesis( + initial_authorities: Vec<(AccountId, AccountId, SessionKeys)>, + root_key: AccountId, + endowed_accounts: Vec<AccountId>, + stakers: Vec<Staker>, + staking_playground_config: Option<StakingPlaygroundConfig>, +) -> serde_json::Value { + let (validator_count, min_validator_count, dev_stakers) = match staking_playground_config { + Some(c) => (c.validator_count, c.minimum_validator_count, Some(c.dev_stakers)), + None => { + let authorities_count = initial_authorities.len() as u32; + (authorities_count, authorities_count, None) + }, + }; + + let collective = collective(&endowed_accounts); + + build_struct_json_patch!(RuntimeGenesisConfig { + balances: BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(), + ..Default::default() + }, + session: SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { (x.0.clone(), x.1.clone(), x.2.clone()) }) + .collect(), + }, + staking: StakingConfig { + validator_count, + minimum_validator_count: min_validator_count, + invulnerables: initial_authorities + .iter() + .map(|x| x.0.clone()) + .collect::<Vec<_>>() + .try_into() + .expect("Too many invulnerable validators: upper limit is MaxInvulnerables from pallet staking config"), + slash_reward_fraction: Perbill::from_percent(10), + stakers, + dev_stakers + }, + elections: ElectionsConfig { + members: collective.iter().cloned().map(|member| (member, STASH)).collect(), + }, + technical_committee: TechnicalCommitteeConfig { members: collective }, + sudo: SudoConfig { key: Some(root_key) }, + babe: BabeConfig { epoch_config: BABE_GENESIS_EPOCH_CONFIG }, + society: SocietyConfig { pot: 0 }, + assets: AssetsConfig { + // This asset is used by the NIS pallet as counterpart currency. + assets: vec![(9, Sr25519Keyring::Alice.to_account_id(), true, 1)], + ..Default::default() + }, + nomination_pools: NominationPoolsConfig { + min_create_bond: 10 * DOLLARS, + min_join_bond: 1 * DOLLARS, + }, + }) +} + +/// Provides the JSON representation of predefined genesis config for given `id`. +pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> { + // Note: Can't use `Sr25519Keyring::Alice.to_seed()` because the seed comes with `//`. + let (alice_stash, alice, alice_session_keys) = authority_keys_from_seed("Alice"); + let (bob_stash, _bob, bob_session_keys) = authority_keys_from_seed("Bob"); + + let endowed = well_known_including_eth_accounts(); + + let patch = match id.as_ref() { + sp_genesis_builder::DEV_RUNTIME_PRESET => kitchensink_genesis( + // Use stash as controller account, otherwise grandpa can't load the authority set at + // genesis. + vec![(alice_stash.clone(), alice_stash.clone(), alice_session_keys)], + alice.clone(), + endowed, + vec![validator(alice_stash.clone())], + None, + ), + sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => kitchensink_genesis( + vec![ + // Use stash as controller account, otherwise grandpa can't load the authority set + // at genesis. + (alice_stash.clone(), alice_stash.clone(), alice_session_keys), + (bob_stash.clone(), bob_stash.clone(), bob_session_keys), + ], + alice, + endowed, + vec![validator(alice_stash), validator(bob_stash)], + None, + ), + _ => return None, + }; + + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} + +/// List of supported presets. +pub fn preset_names() -> Vec<PresetId> { + vec![ + PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET), + PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET), + ] +} + +/// Sets up the `account` to be a staker of validator variant as supplied to the +/// staking config. +pub fn validator(account: AccountId) -> Staker { + // validator, controller, stash, staker status + (account.clone(), account, STASH, StakerStatus::Validator) +} + +/// Extract some accounts from endowed to be put into the collective. +fn collective(endowed: &[AccountId]) -> Vec<AccountId> { + const MAX_COLLECTIVE_SIZE: usize = 50; + let endowed_accounts_count = endowed.len(); + endowed + .iter() + .take(((endowed_accounts_count + 1) / 2).min(MAX_COLLECTIVE_SIZE)) + .cloned() + .collect() +} + +/// The Keyring's wellknown accounts + Alith and Baltathar. +/// +/// Some integration tests require these ETH accounts. +pub fn well_known_including_eth_accounts() -> Vec<AccountId> { + Sr25519Keyring::well_known() + .map(|k| k.to_account_id()) + .chain([ + // subxt_signer::eth::dev::alith() + array_bytes::hex_n_into_unchecked( + "f24ff3a9cf04c71dbc94d0b566f7a27b94566caceeeeeeeeeeeeeeeeeeeeeeee", + ), + // subxt_signer::eth::dev::baltathar() + array_bytes::hex_n_into_unchecked( + "3cd0a705a2dc65e5b1e1205896baa2be8a07c6e0eeeeeeeeeeeeeeeeeeeeeeee", + ), + ]) + .collect::<Vec<_>>() +} + +/// Helper function to generate stash, controller and session key from seed. +/// +/// Note: `//` is prepended internally. +pub fn authority_keys_from_seed(seed: &str) -> (AccountId, AccountId, SessionKeys) { + ( + get_public_from_string_or_panic::<sr25519::Public>(&alloc::format!("{seed}//stash")).into(), + get_public_from_string_or_panic::<sr25519::Public>(seed).into(), + session_keys_from_seed(seed), + ) +} + +pub fn session_keys( + grandpa: GrandpaId, + babe: BabeId, + im_online: ImOnlineId, + authority_discovery: AuthorityDiscoveryId, + mixnet: MixnetId, + beefy: BeefyId, +) -> SessionKeys { + SessionKeys { grandpa, babe, im_online, authority_discovery, mixnet, beefy } +} + +/// We have this method as there is no straight forward way to convert the +/// account keyring into these ids. +/// +/// Note: `//` is prepended internally. +pub fn session_keys_from_seed(seed: &str) -> SessionKeys { + session_keys( + get_public_from_string_or_panic::<GrandpaId>(seed), + get_public_from_string_or_panic::<BabeId>(seed), + get_public_from_string_or_panic::<ImOnlineId>(seed), + get_public_from_string_or_panic::<AuthorityDiscoveryId>(seed), + get_public_from_string_or_panic::<MixnetId>(seed), + get_public_from_string_or_panic::<BeefyId>(seed), + ) +} diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 22e266cc1867853a58241cb59560b70b01b079f3..94729a26b6d55f2a17a8991925635f91b866a596 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -127,12 +127,12 @@ pub use frame_system::Call as SystemCall; #[cfg(any(feature = "std", test))] pub use pallet_balances::Call as BalancesCall; #[cfg(any(feature = "std", test))] -pub use pallet_staking::StakerStatus; -#[cfg(any(feature = "std", test))] pub use pallet_sudo::Call as SudoCall; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; +pub use pallet_staking::StakerStatus; + /// Implementations of some helper traits passed into runtime modules as associated types. pub mod impls; #[cfg(not(feature = "runtime-benchmarks"))] @@ -150,6 +150,9 @@ mod voter_bags; /// Runtime API definition for assets. pub mod assets_api; +/// Genesis presets used by this runtime. +pub mod genesis_config_presets; + // Make the WASM binary available. #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); @@ -4112,11 +4115,11 @@ impl_runtime_apis! { } fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> { - get_preset::<RuntimeGenesisConfig>(id, |_| None) + get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset) } fn preset_names() -> Vec<sp_genesis_builder::PresetId> { - vec![] + genesis_config_presets::preset_names() } } } diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 8fc0d84684305bf062dcf2566eff7b934bb8407d..97568933374559548e20607bef0e7e390cbd3004 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -24,6 +24,7 @@ codec = { features = [ scale-info = { features = [ "derive", ], workspace = true } +serde = { workspace = true } # primitive deps, used for developing FRAME pallets. sp-arithmetic = { workspace = true } @@ -95,6 +96,7 @@ std = [ "frame-try-runtime?/std", "log/std", "scale-info/std", + "serde/std", "sp-api?/std", "sp-arithmetic/std", "sp-block-builder?/std", diff --git a/substrate/frame/nis/Cargo.toml b/substrate/frame/nis/Cargo.toml index ec1a5d93bcbaaaac93669eed46ffe211c751ff4b..f1cf7f31fdc8091d0532db8f3c7aeb75e646492f 100644 --- a/substrate/frame/nis/Cargo.toml +++ b/substrate/frame/nis/Cargo.toml @@ -17,13 +17,8 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { features = ["derive"], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } +frame = { workspace = true, features = ["runtime"] } scale-info = { features = ["derive"], workspace = true } -sp-arithmetic = { workspace = true } -sp-core = { workspace = true } -sp-runtime = { workspace = true } [dev-dependencies] pallet-balances = { workspace = true, default-features = true } @@ -33,26 +28,14 @@ sp-io = { workspace = true, default-features = true } default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", + "frame/std", "scale-info/std", - "sp-arithmetic/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", + "frame/runtime-benchmarks", "pallet-balances/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-balances/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/nis/src/benchmarking.rs b/substrate/frame/nis/src/benchmarking.rs index 2c7ad651f990340c3a8ee13a0a3066d3abd94218..26024e1a6250ad24e657fcc338b7aa8f50afa79b 100644 --- a/substrate/frame/nis/src/benchmarking.rs +++ b/substrate/frame/nis/src/benchmarking.rs @@ -19,19 +19,9 @@ #![cfg(feature = "runtime-benchmarks")] -use super::*; -use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller, BenchmarkError}; -use frame_support::traits::{ - fungible::Inspect as FunInspect, nonfungible::Inspect, EnsureOrigin, Get, -}; -use frame_system::RawOrigin; -use sp_arithmetic::Perquintill; -use sp_runtime::{ - traits::{Bounded, One, Zero}, - DispatchError, PerThing, -}; - -use crate::Pallet as Nis; +use frame::benchmarking::prelude::*; + +use crate::*; const SEED: u32 = 0; @@ -49,62 +39,88 @@ fn fill_queues<T: Config>() -> Result<(), DispatchError> { T::Currency::set_balance(&caller, T::MinBid::get() * BalanceOf::<T>::from(queues + bids)); for _ in 0..bids { - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; } for d in 1..queues { - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1 + d)?; + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1 + d)?; } Ok(()) } -benchmarks! { - place_bid { - let l in 0..(T::MaxQueueLen::get() - 1); +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn place_bid(l: Linear<0, { T::MaxQueueLen::get() - 1 }>) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let ed = T::Currency::minimum_balance(); let bid = T::MinBid::get(); T::Currency::set_balance(&caller, (ed + bid) * BalanceOf::<T>::from(l + 1) + bid); - for i in 0..l { - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; + for _ in 0..l { + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; } - }: _(RawOrigin::Signed(caller.clone()), T::MinBid::get() * BalanceOf::<T>::from(2u32), 1) - verify { - assert_eq!(QueueTotals::<T>::get()[0], (l + 1, T::MinBid::get() * BalanceOf::<T>::from(l + 2))); + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), T::MinBid::get() * BalanceOf::<T>::from(2_u32), 1); + + assert_eq!( + QueueTotals::<T>::get()[0], + (l + 1, T::MinBid::get() * BalanceOf::<T>::from(l + 2)) + ); + + Ok(()) } - place_bid_max { + #[benchmark] + fn place_bid_max() -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let origin = RawOrigin::Signed(caller.clone()); let ed = T::Currency::minimum_balance(); let bid = T::MinBid::get(); let ql = T::MaxQueueLen::get(); T::Currency::set_balance(&caller, (ed + bid) * BalanceOf::<T>::from(ql + 1) + bid); - for i in 0..T::MaxQueueLen::get() { - Nis::<T>::place_bid(origin.clone().into(), T::MinBid::get(), 1)?; + for _ in 0..T::MaxQueueLen::get() { + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; } - }: place_bid(origin, T::MinBid::get() * BalanceOf::<T>::from(2u32), 1) - verify { - assert_eq!(QueueTotals::<T>::get()[0], ( - T::MaxQueueLen::get(), - T::MinBid::get() * BalanceOf::<T>::from(T::MaxQueueLen::get() + 1), - )); + + #[extrinsic_call] + place_bid(origin, T::MinBid::get() * BalanceOf::<T>::from(2_u32), 1); + + assert_eq!( + QueueTotals::<T>::get()[0], + ( + T::MaxQueueLen::get(), + T::MinBid::get() * BalanceOf::<T>::from(T::MaxQueueLen::get() + 1), + ) + ); + + Ok(()) } - retract_bid { - let l in 1..T::MaxQueueLen::get(); + #[benchmark] + fn retract_bid(l: Linear<1, { T::MaxQueueLen::get() }>) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let ed = T::Currency::minimum_balance(); let bid = T::MinBid::get(); T::Currency::set_balance(&caller, (ed + bid) * BalanceOf::<T>::from(l + 1) + bid); - for i in 0..l { - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; + for _ in 0..l { + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?; } - }: _(RawOrigin::Signed(caller.clone()), T::MinBid::get(), 1) - verify { - assert_eq!(QueueTotals::<T>::get()[0], (l - 1, T::MinBid::get() * BalanceOf::<T>::from(l - 1))); + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), T::MinBid::get(), 1); + + assert_eq!( + QueueTotals::<T>::get()[0], + (l - 1, T::MinBid::get() * BalanceOf::<T>::from(l - 1)) + ); + + Ok(()) } - fund_deficit { + #[benchmark] + fn fund_deficit() -> Result<(), BenchmarkError> { T::BenchmarkSetup::create_counterpart_asset(); let origin = T::FundOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; @@ -112,49 +128,65 @@ benchmarks! { let bid = T::MinBid::get().max(One::one()); let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&caller, ed + bid); - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::<T>::process_queues(Perquintill::one(), 1, 1, &mut WeightCounter::unlimited()); - Nis::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; - let original = T::Currency::balance(&Nis::<T>::account_id()); - T::Currency::set_balance(&Nis::<T>::account_id(), BalanceOf::<T>::min_value()); - }: _<T::RuntimeOrigin>(origin) - verify { + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::<T>::process_queues(Perquintill::one(), 1, 1, &mut WeightCounter::unlimited()); + Pallet::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; + let original = T::Currency::balance(&Pallet::<T>::account_id()); + T::Currency::set_balance(&Pallet::<T>::account_id(), BalanceOf::<T>::min_value()); + + #[extrinsic_call] + _(origin as T::RuntimeOrigin); + // Must fund at least 99.999% of the required amount. - let missing = Perquintill::from_rational( - T::Currency::balance(&Nis::<T>::account_id()), original).left_from_one(); + let missing = + Perquintill::from_rational(T::Currency::balance(&Pallet::<T>::account_id()), original) + .left_from_one(); assert!(missing <= Perquintill::one() / 100_000); + + Ok(()) } - communify { + #[benchmark] + fn communify() -> Result<(), BenchmarkError> { T::BenchmarkSetup::create_counterpart_asset(); let caller: T::AccountId = whitelisted_caller(); let bid = T::MinBid::get().max(One::one()) * 100u32.into(); let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&caller, ed + bid + bid); - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); - }: _(RawOrigin::Signed(caller.clone()), 0) - verify { - assert_eq!(Nis::<T>::owner(&0), None); + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), 0); + + assert_eq!(Pallet::<T>::owner(&0), None); + + Ok(()) } - privatize { + #[benchmark] + fn privatize() -> Result<(), BenchmarkError> { T::BenchmarkSetup::create_counterpart_asset(); let caller: T::AccountId = whitelisted_caller(); let bid = T::MinBid::get().max(One::one()); let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&caller, ed + bid + bid); - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); - Nis::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; - }: _(RawOrigin::Signed(caller.clone()), 0) - verify { - assert_eq!(Nis::<T>::owner(&0), Some(caller)); + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); + Pallet::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), 0); + + assert_eq!(Pallet::<T>::owner(&0), Some(caller)); + + Ok(()) } - thaw_private { + #[benchmark] + fn thaw_private() -> Result<(), BenchmarkError> { T::BenchmarkSetup::create_counterpart_asset(); let whale: T::AccountId = account("whale", 0, SEED); let caller: T::AccountId = whitelisted_caller(); @@ -162,17 +194,27 @@ benchmarks! { let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&caller, ed + bid + bid); // Ensure we don't get throttled. - T::Currency::set_balance(&whale, T::ThawThrottle::get().0.saturating_reciprocal_mul_ceil(T::Currency::balance(&caller))); - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); + T::Currency::set_balance( + &whale, + T::ThawThrottle::get() + .0 + .saturating_reciprocal_mul_ceil(T::Currency::balance(&caller)), + ); + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); frame_system::Pallet::<T>::set_block_number(Receipts::<T>::get(0).unwrap().expiry); - }: _(RawOrigin::Signed(caller.clone()), 0, None) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), 0, None); + assert!(Receipts::<T>::get(0).is_none()); + + Ok(()) } - thaw_communal { + #[benchmark] + fn thaw_communal() -> Result<(), BenchmarkError> { T::BenchmarkSetup::create_counterpart_asset(); let whale: T::AccountId = account("whale", 0, SEED); let caller: T::AccountId = whitelisted_caller(); @@ -180,69 +222,93 @@ benchmarks! { let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&caller, ed + bid + bid); // Ensure we don't get throttled. - T::Currency::set_balance(&whale, T::ThawThrottle::get().0.saturating_reciprocal_mul_ceil(T::Currency::balance(&caller))); - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; - Nis::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); + T::Currency::set_balance( + &whale, + T::ThawThrottle::get() + .0 + .saturating_reciprocal_mul_ceil(T::Currency::balance(&caller)), + ); + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; + Pallet::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); frame_system::Pallet::<T>::set_block_number(Receipts::<T>::get(0).unwrap().expiry); - Nis::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; - }: _(RawOrigin::Signed(caller.clone()), 0) - verify { + Pallet::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), 0); + assert!(Receipts::<T>::get(0).is_none()); + + Ok(()) } - process_queues { + #[benchmark] + fn process_queues() -> Result<(), BenchmarkError> { fill_queues::<T>()?; - }: { - Nis::<T>::process_queues( - Perquintill::one(), - Zero::zero(), - u32::max_value(), - &mut WeightCounter::unlimited(), - ) + + #[block] + { + Pallet::<T>::process_queues( + Perquintill::one(), + Zero::zero(), + u32::max_value(), + &mut WeightCounter::unlimited(), + ); + } + + Ok(()) } - process_queue { - let our_account = Nis::<T>::account_id(); - let issuance = Nis::<T>::issuance(); + #[benchmark] + fn process_queue() { + let our_account = Pallet::<T>::account_id(); + let issuance = Pallet::<T>::issuance(); let mut summary = Summary::<T>::get(); - }: { - Nis::<T>::process_queue( - 1u32, - 1u32.into(), - &our_account, - &issuance, - 0, - &mut Bounded::max_value(), - &mut (T::MaxQueueLen::get(), Bounded::max_value()), - &mut summary, - &mut WeightCounter::unlimited(), - ) + + #[block] + { + Pallet::<T>::process_queue( + 1_u32, + 1_u32.into(), + &our_account, + &issuance, + 0, + &mut Bounded::max_value(), + &mut (T::MaxQueueLen::get(), Bounded::max_value()), + &mut summary, + &mut WeightCounter::unlimited(), + ); + } } - process_bid { + #[benchmark] + fn process_bid() { let who = account::<T::AccountId>("bidder", 0, SEED); let min_bid = T::MinBid::get().max(One::one()); let ed = T::Currency::minimum_balance(); T::Currency::set_balance(&who, ed + min_bid); - let bid = Bid { - amount: T::MinBid::get(), - who, - }; - let our_account = Nis::<T>::account_id(); - let issuance = Nis::<T>::issuance(); + let bid = Bid { amount: T::MinBid::get(), who }; + let our_account = Pallet::<T>::account_id(); + let issuance = Pallet::<T>::issuance(); let mut summary = Summary::<T>::get(); - }: { - Nis::<T>::process_bid( - bid, - 2u32.into(), - &our_account, - &issuance, - &mut Bounded::max_value(), - &mut Bounded::max_value(), - &mut summary, - ) + + #[block] + { + Pallet::<T>::process_bid( + bid, + 2_u32.into(), + &our_account, + &issuance, + &mut Bounded::max_value(), + &mut Bounded::max_value(), + &mut summary, + ); + } } - impl_benchmark_test_suite!(Nis, crate::mock::new_test_ext_empty(), crate::mock::Test); + impl_benchmark_test_suite! { + Pallet, + mock::new_test_ext_empty(), + mock::Test + } } diff --git a/substrate/frame/nis/src/lib.rs b/substrate/frame/nis/src/lib.rs index 87e2276e768d0fcb5370b189882823d0604898a2..6ce15fc560c632b8f64605ba5ad88449ce56e1c1 100644 --- a/substrate/frame/nis/src/lib.rs +++ b/substrate/frame/nis/src/lib.rs @@ -78,24 +78,28 @@ extern crate alloc; -use frame_support::traits::{ - fungible::{self, Inspect as FunInspect, Mutate as FunMutate}, - tokens::{DepositConsequence, Fortitude, Preservation, Provenance, WithdrawConsequence}, -}; -pub use pallet::*; -use sp_arithmetic::{traits::Unsigned, RationalArg}; -use sp_core::TypedGet; -use sp_runtime::{ - traits::{Convert, ConvertBack}, - DispatchError, Perquintill, -}; +pub mod weights; mod benchmarking; #[cfg(test)] mod mock; #[cfg(test)] mod tests; -pub mod weights; + +pub use pallet::*; +pub use weights::WeightInfo; + +use alloc::{vec, vec::Vec}; +use frame::prelude::*; +use fungible::{ + Balanced as FunBalanced, Inspect as FunInspect, Mutate as FunMutate, + MutateHold as FunMutateHold, +}; +use nonfungible::{Inspect as NftInspect, Transfer as NftTransfer}; +use tokens::{Balance, Restriction::*}; +use Fortitude::*; +use Precision::*; +use Preservation::*; pub struct WithMaximumOf<A: TypedGet>(core::marker::PhantomData<A>); impl<A: TypedGet> Convert<Perquintill, A::Type> for WithMaximumOf<A> @@ -169,33 +173,9 @@ impl BenchmarkSetup for () { fn create_counterpart_asset() {} } -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { - use super::{FunInspect, FunMutate}; - pub use crate::weights::WeightInfo; - use alloc::{vec, vec::Vec}; - use frame_support::{ - pallet_prelude::*, - traits::{ - fungible::{self, hold::Mutate as FunHoldMutate, Balanced as FunBalanced}, - nonfungible::{Inspect as NftInspect, Transfer as NftTransfer}, - tokens::{ - Balance, - Fortitude::Polite, - Precision::{BestEffort, Exact}, - Preservation::Expendable, - Restriction::{Free, OnHold}, - }, - Defensive, DefensiveSaturating, OnUnbalanced, - }, - PalletId, - }; - use frame_system::pallet_prelude::*; - use sp_arithmetic::{PerThing, Perquintill}; - use sp_runtime::{ - traits::{AccountIdConversion, Bounded, Convert, ConvertBack, Saturating, Zero}, - Rounding, TokenError, - }; + use super::*; type BalanceOf<T> = <<T as Config>::Currency as FunInspect<<T as frame_system::Config>::AccountId>>::Balance; @@ -224,7 +204,7 @@ pub mod pallet { type Currency: FunInspect<Self::AccountId, Balance = Self::CurrencyBalance> + FunMutate<Self::AccountId> + FunBalanced<Self::AccountId> - + FunHoldMutate<Self::AccountId, Reason = Self::RuntimeHoldReason>; + + FunMutateHold<Self::AccountId, Reason = Self::RuntimeHoldReason>; /// Overarching hold reason. type RuntimeHoldReason: From<HoldReason>; diff --git a/substrate/frame/nis/src/mock.rs b/substrate/frame/nis/src/mock.rs index 82b9f55b919bea0160a0c98f605a37878b304136..0e71e43f56bd7e5f98a2fc70b96696c5781b1eeb 100644 --- a/substrate/frame/nis/src/mock.rs +++ b/substrate/frame/nis/src/mock.rs @@ -17,32 +17,38 @@ //! Test environment for NIS pallet. -use crate::{self as pallet_nis, Perquintill, WithMaximumOf}; - -use frame_support::{ - derive_impl, ord_parameter_types, parameter_types, - traits::{fungible::Inspect, ConstU32, ConstU64, StorageMapShim}, - weights::Weight, - PalletId, -}; -use pallet_balances::{Instance1, Instance2}; -use sp_core::ConstU128; -use sp_runtime::BuildStorage; +use frame::{runtime::prelude::*, testing_prelude::*, traits::StorageMapShim}; -type Block = frame_system::mocking::MockBlock<Test>; +use crate::{self as pallet_nis, *}; pub type Balance = u64; +type Block = frame_system::mocking::MockBlock<Test>; + // Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( - pub enum Test - { - System: frame_system, - Balances: pallet_balances::<Instance1>, - NisBalances: pallet_balances::<Instance2>, - Nis: pallet_nis, - } -); +#[frame_construct_runtime] +mod runtime { + #[runtime::runtime] + #[runtime::derive( + RuntimeCall, + RuntimeError, + RuntimeEvent, + RuntimeFreezeReason, + RuntimeHoldReason, + RuntimeOrigin, + RuntimeTask + )] + pub struct Test; + + #[runtime::pallet_index(0)] + pub type System = frame_system; + #[runtime::pallet_index(1)] + pub type Balances = pallet_balances<Instance1>; + #[runtime::pallet_index(2)] + pub type NisBalances = pallet_balances<Instance2>; + #[runtime::pallet_index(3)] + pub type Nis = pallet_nis; +} #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { @@ -50,7 +56,7 @@ impl frame_system::Config for Test { type AccountData = pallet_balances::AccountData<Balance>; } -impl pallet_balances::Config<Instance1> for Test { +impl pallet_balances::Config<pallet_balances::Instance1> for Test { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; @@ -67,13 +73,13 @@ impl pallet_balances::Config<Instance1> for Test { type DoneSlashHandler = (); } -impl pallet_balances::Config<Instance2> for Test { +impl pallet_balances::Config<pallet_balances::Instance2> for Test { type Balance = u128; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; type ExistentialDeposit = ConstU128<1>; type AccountStore = StorageMapShim< - pallet_balances::Account<Test, Instance2>, + pallet_balances::Account<Test, pallet_balances::Instance2>, u64, pallet_balances::AccountData<u128>, >; @@ -106,7 +112,7 @@ impl pallet_nis::Config for Test { type RuntimeEvent = RuntimeEvent; type PalletId = NisPalletId; type Currency = Balances; - type CurrencyBalance = <Self as pallet_balances::Config<Instance1>>::Balance; + type CurrencyBalance = <Self as pallet_balances::Config<pallet_balances::Instance1>>::Balance; type FundOrigin = frame_system::EnsureSigned<Self::AccountId>; type Deficit = (); type IgnoredIssuance = IgnoredIssuance; @@ -131,7 +137,7 @@ impl pallet_nis::Config for Test { // our desired mockup. pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap(); - pallet_balances::GenesisConfig::<Test, Instance1> { + pallet_balances::GenesisConfig::<Test, pallet_balances::Instance1> { balances: vec![(1, 100), (2, 100), (3, 100), (4, 100)], ..Default::default() } diff --git a/substrate/frame/nis/src/tests.rs b/substrate/frame/nis/src/tests.rs index 10c39a0d48edb4f7c586d55d54e4ada7495aede4..945532364e00a694af7da4f580429309d0f980fd 100644 --- a/substrate/frame/nis/src/tests.rs +++ b/substrate/frame/nis/src/tests.rs @@ -17,21 +17,13 @@ //! Tests for NIS pallet. -use super::*; -use crate::{mock::*, Error}; -use frame_support::{ - assert_noop, assert_ok, - traits::{ - fungible::{hold::Inspect as InspectHold, Inspect as FunInspect, Mutate as FunMutate}, - nonfungible::{Inspect, Transfer}, - tokens::{Fortitude::Force, Precision::Exact, Preservation::Expendable}, - }, -}; -use sp_arithmetic::Perquintill; -use sp_runtime::{ - Saturating, - TokenError::{self, FundsUnavailable}, +use frame::testing_prelude::*; + +use crate::{ + mock::{Balance, *}, + *, }; +use fungible::InspectHold; fn pot() -> Balance { Balances::free_balance(&Nis::account_id()) @@ -78,7 +70,7 @@ fn place_bid_works() { new_test_ext().execute_with(|| { System::run_to_block::<AllPalletsWithSystem>(1); assert_noop!(Nis::place_bid(signed(1), 1, 2), Error::<Test>::AmountTooSmall); - assert_noop!(Nis::place_bid(signed(1), 101, 2), FundsUnavailable); + assert_noop!(Nis::place_bid(signed(1), 101, 2), TokenError::FundsUnavailable); assert_noop!(Nis::place_bid(signed(1), 10, 4), Error::<Test>::DurationTooBig); assert_ok!(Nis::place_bid(signed(1), 10, 2)); assert_eq!(Balances::reserved_balance(1), 10); diff --git a/substrate/frame/nis/src/weights.rs b/substrate/frame/nis/src/weights.rs index 2842d6fbc5b01bb837aeead8dfd24a96ee39213b..97f126c540fa49578bd1e1755229f9bc367eb74c 100644 --- a/substrate/frame/nis/src/weights.rs +++ b/substrate/frame/nis/src/weights.rs @@ -35,9 +35,9 @@ //! Autogenerated weights for `pallet_nis` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2025-02-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2025-03-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `4563561839a5`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `bd5e4dfa0790`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` // Executed Command: @@ -54,7 +54,7 @@ // --steps=50 // --repeat=20 // --heap-pages=4096 -// --template=substrate/.maintain/frame-weight-template.hbs +// --template=substrate/.maintain/frame-umbrella-weight-template.hbs // --no-storage-info // --no-min-squares // --no-median-slopes @@ -67,8 +67,7 @@ #![allow(missing_docs)] #![allow(dead_code)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use core::marker::PhantomData; +use frame::weights_prelude::*; /// Weight functions needed for `pallet_nis`. pub trait WeightInfo { @@ -99,10 +98,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `6115 + l * (48 ±0)` // Estimated: `51487` - // Minimum execution time: 45_697_000 picoseconds. - Weight::from_parts(46_540_958, 51487) - // Standard Error: 1_097 - .saturating_add(Weight::from_parts(99_061, 0).saturating_mul(l.into())) + // Minimum execution time: 43_703_000 picoseconds. + Weight::from_parts(42_231_449, 51487) + // Standard Error: 1_303 + .saturating_add(Weight::from_parts(92_036, 0).saturating_mul(l.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -116,8 +115,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `54117` // Estimated: `51487` - // Minimum execution time: 151_410_000 picoseconds. - Weight::from_parts(164_191_000, 51487) + // Minimum execution time: 146_230_000 picoseconds. + Weight::from_parts(154_165_000, 51487) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -132,10 +131,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `6115 + l * (48 ±0)` // Estimated: `51487` - // Minimum execution time: 46_132_000 picoseconds. - Weight::from_parts(39_240_527, 51487) - // Standard Error: 1_206 - .saturating_add(Weight::from_parts(82_315, 0).saturating_mul(l.into())) + // Minimum execution time: 43_614_000 picoseconds. + Weight::from_parts(37_201_688, 51487) + // Standard Error: 1_241 + .saturating_add(Weight::from_parts(79_738, 0).saturating_mul(l.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -147,8 +146,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `153` // Estimated: `3593` - // Minimum execution time: 31_132_000 picoseconds. - Weight::from_parts(32_025_000, 3593) + // Minimum execution time: 29_920_000 picoseconds. + Weight::from_parts(30_761_000, 3593) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -168,8 +167,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `533` // Estimated: `3892` - // Minimum execution time: 74_327_000 picoseconds. - Weight::from_parts(76_096_000, 3892) + // Minimum execution time: 71_257_000 picoseconds. + Weight::from_parts(72_559_000, 3892) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } @@ -189,8 +188,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `699` // Estimated: `3892` - // Minimum execution time: 97_108_000 picoseconds. - Weight::from_parts(98_562_000, 3892) + // Minimum execution time: 92_578_000 picoseconds. + Weight::from_parts(94_495_000, 3892) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } @@ -206,8 +205,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `316` // Estimated: `3892` - // Minimum execution time: 51_390_000 picoseconds. - Weight::from_parts(52_693_000, 3892) + // Minimum execution time: 48_478_000 picoseconds. + Weight::from_parts(49_690_000, 3892) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -225,8 +224,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `642` // Estimated: `3675` - // Minimum execution time: 94_872_000 picoseconds. - Weight::from_parts(96_477_000, 3675) + // Minimum execution time: 89_681_000 picoseconds. + Weight::from_parts(92_693_000, 3675) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -240,8 +239,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `6563` // Estimated: `7487` - // Minimum execution time: 20_317_000 picoseconds. - Weight::from_parts(21_176_000, 7487) + // Minimum execution time: 19_670_000 picoseconds. + Weight::from_parts(22_353_000, 7487) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -251,8 +250,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `0` // Estimated: `51487` - // Minimum execution time: 2_861_000 picoseconds. - Weight::from_parts(2_979_000, 51487) + // Minimum execution time: 2_755_000 picoseconds. + Weight::from_parts(2_944_000, 51487) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -262,8 +261,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 4_061_000 picoseconds. - Weight::from_parts(4_288_000, 0) + // Minimum execution time: 3_919_000 picoseconds. + Weight::from_parts(4_114_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } } @@ -281,10 +280,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6115 + l * (48 ±0)` // Estimated: `51487` - // Minimum execution time: 45_697_000 picoseconds. - Weight::from_parts(46_540_958, 51487) - // Standard Error: 1_097 - .saturating_add(Weight::from_parts(99_061, 0).saturating_mul(l.into())) + // Minimum execution time: 43_703_000 picoseconds. + Weight::from_parts(42_231_449, 51487) + // Standard Error: 1_303 + .saturating_add(Weight::from_parts(92_036, 0).saturating_mul(l.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -298,8 +297,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `54117` // Estimated: `51487` - // Minimum execution time: 151_410_000 picoseconds. - Weight::from_parts(164_191_000, 51487) + // Minimum execution time: 146_230_000 picoseconds. + Weight::from_parts(154_165_000, 51487) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -314,10 +313,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6115 + l * (48 ±0)` // Estimated: `51487` - // Minimum execution time: 46_132_000 picoseconds. - Weight::from_parts(39_240_527, 51487) - // Standard Error: 1_206 - .saturating_add(Weight::from_parts(82_315, 0).saturating_mul(l.into())) + // Minimum execution time: 43_614_000 picoseconds. + Weight::from_parts(37_201_688, 51487) + // Standard Error: 1_241 + .saturating_add(Weight::from_parts(79_738, 0).saturating_mul(l.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -329,8 +328,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `153` // Estimated: `3593` - // Minimum execution time: 31_132_000 picoseconds. - Weight::from_parts(32_025_000, 3593) + // Minimum execution time: 29_920_000 picoseconds. + Weight::from_parts(30_761_000, 3593) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -350,8 +349,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `533` // Estimated: `3892` - // Minimum execution time: 74_327_000 picoseconds. - Weight::from_parts(76_096_000, 3892) + // Minimum execution time: 71_257_000 picoseconds. + Weight::from_parts(72_559_000, 3892) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } @@ -371,8 +370,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `699` // Estimated: `3892` - // Minimum execution time: 97_108_000 picoseconds. - Weight::from_parts(98_562_000, 3892) + // Minimum execution time: 92_578_000 picoseconds. + Weight::from_parts(94_495_000, 3892) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } @@ -388,8 +387,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `316` // Estimated: `3892` - // Minimum execution time: 51_390_000 picoseconds. - Weight::from_parts(52_693_000, 3892) + // Minimum execution time: 48_478_000 picoseconds. + Weight::from_parts(49_690_000, 3892) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -407,8 +406,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `642` // Estimated: `3675` - // Minimum execution time: 94_872_000 picoseconds. - Weight::from_parts(96_477_000, 3675) + // Minimum execution time: 89_681_000 picoseconds. + Weight::from_parts(92_693_000, 3675) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -422,8 +421,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6563` // Estimated: `7487` - // Minimum execution time: 20_317_000 picoseconds. - Weight::from_parts(21_176_000, 7487) + // Minimum execution time: 19_670_000 picoseconds. + Weight::from_parts(22_353_000, 7487) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -433,8 +432,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `51487` - // Minimum execution time: 2_861_000 picoseconds. - Weight::from_parts(2_979_000, 51487) + // Minimum execution time: 2_755_000 picoseconds. + Weight::from_parts(2_944_000, 51487) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -444,8 +443,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 4_061_000 picoseconds. - Weight::from_parts(4_288_000, 0) + // Minimum execution time: 3_919_000 picoseconds. + Weight::from_parts(4_114_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } } diff --git a/substrate/frame/revive/src/exec.rs b/substrate/frame/revive/src/exec.rs index bb8d4600152e6fd0ea1a5811fbb02dbff9c24044..d88d4f206fa470e77241afed8454f2470dcdd726 100644 --- a/substrate/frame/revive/src/exec.rs +++ b/substrate/frame/revive/src/exec.rs @@ -357,7 +357,7 @@ pub trait Ext: sealing::Sealed { /// Returns the value transferred along with this call. fn value_transferred(&self) -> U256; - /// Returns the timestamp of the current block + /// Returns the timestamp of the current block in seconds. fn now(&self) -> U256; /// Returns the minimum balance that is required for creating an account. @@ -1796,7 +1796,7 @@ where } fn now(&self) -> U256 { - self.timestamp.into() + (self.timestamp / 1000u32.into()).into() } fn minimum_balance(&self) -> U256 { diff --git a/substrate/frame/revive/uapi/src/host.rs b/substrate/frame/revive/uapi/src/host.rs index 3b0432d93005f57a360a9a185d9472bf2ad5be4f..676af60ec804474b426f6c1acd51486b15821d75 100644 --- a/substrate/frame/revive/uapi/src/host.rs +++ b/substrate/frame/revive/uapi/src/host.rs @@ -325,7 +325,7 @@ pub trait HostFn: private::Sealed { salt: Option<&[u8; 32]>, ) -> Result; - /// Load the latest block timestamp into the supplied buffer + /// Load the latest block timestamp in seconds into the supplied buffer /// /// # Parameters /// diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 1c4b2ed5b821d56a4e320cbc7ae272561c6ee904..c912c2fe7d4fb8dc5f7cbf276ed4a575f76d1c1a 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -189,7 +189,7 @@ pub mod prelude { /// `frame_system`'s parent crate, which is mandatory in all pallets build with this crate. /// /// Conveniently, the keyword `frame_system` is in scope as one uses `use - /// polkadot_sdk_frame::prelude::*` + /// polkadot_sdk_frame::prelude::*`. #[doc(inline)] pub use frame_system; @@ -199,13 +199,16 @@ pub mod prelude { #[doc(no_inline)] pub use frame_support::pallet_prelude::*; - /// Dispatch types from `frame-support`, other fundamental traits + /// Dispatch types from `frame-support`, other fundamental traits. #[doc(no_inline)] pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; - pub use frame_support::traits::{ - Contains, EitherOf, EstimateNextSessionRotation, Everything, IsSubType, MapSuccess, - NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler, - VariantCount, VariantCountOf, + pub use frame_support::{ + traits::{ + Contains, Defensive, DefensiveSaturating, EitherOf, EstimateNextSessionRotation, + Everything, IsSubType, MapSuccess, NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, + RankedMembers, RankedMembersSwapHandler, VariantCount, VariantCountOf, + }, + PalletId, }; /// Pallet prelude of `frame-system`. @@ -220,7 +223,7 @@ pub mod prelude { #[doc(no_inline)] pub use super::derive::*; - /// All hashing related things + /// All hashing related things. pub use super::hashing::*; /// All account related things. @@ -229,11 +232,15 @@ pub mod prelude { /// All arithmetic types and traits used for safe math. pub use super::arithmetic::*; + /// All token related types and traits. + pub use super::token::*; + /// Runtime traits #[doc(no_inline)] pub use sp_runtime::traits::{ - BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, ReduceBy, - ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput, + AccountIdConversion, BlockNumberProvider, Bounded, Convert, ConvertBack, DispatchInfoOf, + Dispatchable, ReduceBy, ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, + TrailingZeroInput, }; /// Bounded storage related types. @@ -537,6 +544,20 @@ pub mod arithmetic { pub use sp_arithmetic::{traits::*, *}; } +/// All token related types and traits. +pub mod token { + pub use frame_support::traits::{ + tokens, + tokens::{ + currency, fungible, fungibles, imbalance, nonfungible, nonfungible_v2, nonfungibles, + nonfungibles_v2, pay, AssetId, BalanceStatus, DepositConsequence, ExistenceRequirement, + Fortitude, Pay, Precision, Preservation, Provenance, WithdrawConsequence, + WithdrawReasons, + }, + OnUnbalanced, + }; +} + /// All derive macros used in frame. /// /// This is already part of the [`prelude`]. @@ -548,6 +569,13 @@ pub mod derive { PartialOrdNoBound, RuntimeDebugNoBound, }; pub use scale_info::TypeInfo; + pub use serde; + /// The `serde` `Serialize`/`Deserialize` derive macros and traits. + /// + /// You will either need to add `serde` as a dependency in your crate's `Cargo.toml` + /// or specify the `#[serde(crate = "PATH_TO_THIS_CRATE::serde")]` attribute that points + /// to the path where serde can be found. + pub use serde::{Deserialize, Serialize}; pub use sp_runtime::RuntimeDebug; }