From 8d69e5c87ea1d21210898e48bb141473ff0a18f0 Mon Sep 17 00:00:00 2001 From: Uncle Stretch Date: Tue, 29 Jul 2025 14:51:15 +0300 Subject: [PATCH] rustfmt casper runtime and fix typos Signed-off-by: Uncle Stretch --- runtime/casper/Cargo.toml | 2 +- runtime/casper/constants/src/lib.rs | 10 +- .../constants/src/weights/block_weights.rs | 66 +- .../src/weights/extrinsic_weights.rs | 66 +- runtime/casper/constants/src/weights/mod.rs | 4 +- .../constants/src/weights/paritydb_weights.rs | 80 +- .../constants/src/weights/rocksdb_weights.rs | 80 +- runtime/casper/src/bag_thresholds.rs | 401 +++++---- runtime/casper/src/cult/mod.rs | 54 +- runtime/casper/src/cult/origins.rs | 4 +- runtime/casper/src/cult/tracks.rs | 5 +- runtime/casper/src/genesis_config_presets.rs | 127 ++- runtime/casper/src/impls.rs | 17 +- runtime/casper/src/lib.rs | 811 +++++++++--------- 14 files changed, 897 insertions(+), 830 deletions(-) diff --git a/runtime/casper/Cargo.toml b/runtime/casper/Cargo.toml index 2d3e39f..e1dbf58 100644 --- a/runtime/casper/Cargo.toml +++ b/runtime/casper/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "casper-runtime" -version = "3.5.28" +version = "3.5.29" build = "build.rs" description = "Runtime of the Casper Network" edition.workspace = true diff --git a/runtime/casper/constants/src/lib.rs b/runtime/casper/constants/src/lib.rs index 75a8f9f..9004a04 100644 --- a/runtime/casper/constants/src/lib.rs +++ b/runtime/casper/constants/src/lib.rs @@ -10,15 +10,15 @@ pub mod currency { /// Constant values used within runtime. pub const FTSO: Balance = 1_000_000_000; // 10^9 - pub const STNK: Balance = 1_000 * FTSO; // 10^12 - pub const STRH: Balance = 1_000 * STNK; // 10^15 - pub const CSPR: Balance = 1_000 * STRH; // 10^18 + pub const STNK: Balance = 1_000 * FTSO; // 10^12 + pub const STRH: Balance = 1_000 * STNK; // 10^15 + pub const CSPR: Balance = 1_000 * STRH; // 10^18 /// The existential deposit. pub const EXISTENTIAL_DEPOSIT: Balance = STNK; pub const fn deposit(items: u32, bytes: u32) -> Balance { - (items as Balance) * 200 * STRH + (bytes as Balance) * 1000 * STNK + (items as Balance) * 200 * STRH + (bytes as Balance) * 1000 * STNK } } @@ -86,7 +86,7 @@ pub mod fee { #[cfg(test)] mod tests { use super::{ - currency::{STNK, STRH, CSPR}, + currency::{CSPR, STNK, STRH}, fee::WeightToFee, }; use crate::weights::ExtrinsicBaseWeight; diff --git a/runtime/casper/constants/src/weights/block_weights.rs b/runtime/casper/constants/src/weights/block_weights.rs index 2676df5..889782b 100644 --- a/runtime/casper/constants/src/weights/block_weights.rs +++ b/runtime/casper/constants/src/weights/block_weights.rs @@ -37,43 +37,43 @@ use sp_core::parameter_types; use sp_weights::{constants::WEIGHT_REF_TIME_PER_NANOS, Weight}; parameter_types! { - /// Time to execute an empty block. - /// Calculated by multiplying the *Average* with `1.0` and adding `0`. - /// - /// Stats nanoseconds: - /// Min, Max: 64_363_191, 66_078_314 - /// Average: 64_551_214 - /// Median: 64_500_078 - /// Std-Dev: 229678.99 - /// - /// Percentiles nanoseconds: - /// 99th: 65_668_012 - /// 95th: 64_888_421 - /// 75th: 64_563_448 - pub const BlockExecutionWeight: Weight = - Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(64_551_214), 0); + /// Time to execute an empty block. + /// Calculated by multiplying the *Average* with `1.0` and adding `0`. + /// + /// Stats nanoseconds: + /// Min, Max: 64_363_191, 66_078_314 + /// Average: 64_551_214 + /// Median: 64_500_078 + /// Std-Dev: 229678.99 + /// + /// Percentiles nanoseconds: + /// 99th: 65_668_012 + /// 95th: 64_888_421 + /// 75th: 64_563_448 + pub const BlockExecutionWeight: Weight = + Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(64_551_214), 0); } #[cfg(test)] mod test_weights { - use sp_weights::constants; + use sp_weights::constants; - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::BlockExecutionWeight::get(); + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::BlockExecutionWeight::get(); - // At least 100 µs. - assert!( - w.ref_time() >= 100u64 * constants::WEIGHT_REF_TIME_PER_MICROS, - "Weight should be at least 100 µs." - ); - // At most 50 ms. - assert!( - w.ref_time() <= 50u64 * constants::WEIGHT_REF_TIME_PER_MILLIS, - "Weight should be at most 50 ms." - ); - } + // At least 100 µs. + assert!( + w.ref_time() >= 100u64 * constants::WEIGHT_REF_TIME_PER_MICROS, + "Weight should be at least 100 µs." + ); + // At most 50 ms. + assert!( + w.ref_time() <= 50u64 * constants::WEIGHT_REF_TIME_PER_MILLIS, + "Weight should be at most 50 ms." + ); + } } diff --git a/runtime/casper/constants/src/weights/extrinsic_weights.rs b/runtime/casper/constants/src/weights/extrinsic_weights.rs index d8c68d0..4ec8a37 100644 --- a/runtime/casper/constants/src/weights/extrinsic_weights.rs +++ b/runtime/casper/constants/src/weights/extrinsic_weights.rs @@ -37,43 +37,43 @@ use sp_core::parameter_types; use sp_weights::{constants::WEIGHT_REF_TIME_PER_NANOS, Weight}; parameter_types! { - /// Time to execute a NO-OP extrinsic, for example `System::remark`. - /// Calculated by multiplying the *Average* with `1.0` and adding `0`. - /// - /// Stats nanoseconds: - /// Min, Max: 402_868, 1_292_427 - /// Average: 565_926 - /// Median: 414_626 - /// Std-Dev: 283192.19 - /// - /// Percentiles nanoseconds: - /// 99th: 1_251_123 - /// 95th: 1_196_903 - /// 75th: 491_329 - pub const ExtrinsicBaseWeight: Weight = - Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(565_926), 0); + /// Time to execute a NO-OP extrinsic, for example `System::remark`. + /// Calculated by multiplying the *Average* with `1.0` and adding `0`. + /// + /// Stats nanoseconds: + /// Min, Max: 402_868, 1_292_427 + /// Average: 565_926 + /// Median: 414_626 + /// Std-Dev: 283192.19 + /// + /// Percentiles nanoseconds: + /// 99th: 1_251_123 + /// 95th: 1_196_903 + /// 75th: 491_329 + pub const ExtrinsicBaseWeight: Weight = + Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(565_926), 0); } #[cfg(test)] mod test_weights { - use sp_weights::constants; + use sp_weights::constants; - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::ExtrinsicBaseWeight::get(); + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::ExtrinsicBaseWeight::get(); - // At least 10 µs. - assert!( - w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS, - "Weight should be at least 10 µs." - ); - // At most 1 ms. - assert!( - w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, - "Weight should be at most 1 ms." - ); - } + // At least 10 µs. + assert!( + w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS, + "Weight should be at least 10 µs." + ); + // At most 1 ms. + assert!( + w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Weight should be at most 1 ms." + ); + } } diff --git a/runtime/casper/constants/src/weights/mod.rs b/runtime/casper/constants/src/weights/mod.rs index 148e07b..adadde8 100644 --- a/runtime/casper/constants/src/weights/mod.rs +++ b/runtime/casper/constants/src/weights/mod.rs @@ -1,9 +1,9 @@ pub mod block_weights; pub mod extrinsic_weights; -pub mod rocksdb_weights; pub mod paritydb_weights; +pub mod rocksdb_weights; pub use block_weights::BlockExecutionWeight; pub use extrinsic_weights::ExtrinsicBaseWeight; -pub use rocksdb_weights::constants::RocksDbWeight; pub use paritydb_weights::constants::ParityDbWeight; +pub use rocksdb_weights::constants::RocksDbWeight; diff --git a/runtime/casper/constants/src/weights/paritydb_weights.rs b/runtime/casper/constants/src/weights/paritydb_weights.rs index 22be330..d7f1c54 100644 --- a/runtime/casper/constants/src/weights/paritydb_weights.rs +++ b/runtime/casper/constants/src/weights/paritydb_weights.rs @@ -37,47 +37,47 @@ /// Storage DB weights for the `Development` runtime and `ParityDb`. pub mod constants { - use frame_support::weights::constants; - use sp_core::parameter_types; - use sp_weights::RuntimeDbWeight; + use frame_support::weights::constants; + use sp_core::parameter_types; + use sp_weights::RuntimeDbWeight; - parameter_types! { - /// `ParityDB` can be enabled with a feature flag, but is still experimental. These weights - /// are available for brave runtime engineers who may want to try this out as default. - pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight { - read: 40_820 * constants::WEIGHT_REF_TIME_PER_NANOS, - write: 293_659 * constants::WEIGHT_REF_TIME_PER_NANOS, - }; - } + parameter_types! { + /// `ParityDB` can be enabled with a feature flag, but is still experimental. These weights + /// are available for brave runtime engineers who may want to try this out as default. + pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight { + read: 40_820 * constants::WEIGHT_REF_TIME_PER_NANOS, + write: 293_659 * constants::WEIGHT_REF_TIME_PER_NANOS, + }; + } - #[cfg(test)] - mod test_db_weights { - use super::constants::ParityDbWeight as W; - use sp_weights::constants; + #[cfg(test)] + mod test_db_weights { + use super::constants::ParityDbWeight as W; + use sp_weights::constants; - /// Checks that all weights exist and have sane values. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn bound() { - // At least 1 µs. - assert!( - W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, - "Read weight should be at least 1 µs." - ); - assert!( - W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, - "Write weight should be at least 1 µs." - ); - // At most 1 ms. - assert!( - W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, - "Read weight should be at most 1 ms." - ); - assert!( - W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, - "Write weight should be at most 1 ms." - ); - } - } + /// Checks that all weights exist and have sane values. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn bound() { + // At least 1 µs. + assert!( + W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, + "Read weight should be at least 1 µs." + ); + assert!( + W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, + "Write weight should be at least 1 µs." + ); + // At most 1 ms. + assert!( + W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Read weight should be at most 1 ms." + ); + assert!( + W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Write weight should be at most 1 ms." + ); + } + } } diff --git a/runtime/casper/constants/src/weights/rocksdb_weights.rs b/runtime/casper/constants/src/weights/rocksdb_weights.rs index 112ad0e..b930e7f 100644 --- a/runtime/casper/constants/src/weights/rocksdb_weights.rs +++ b/runtime/casper/constants/src/weights/rocksdb_weights.rs @@ -36,47 +36,47 @@ /// Storage DB weights for the `Development` runtime and `RocksDb`. pub mod constants { - use frame_support::weights::constants; - use sp_core::parameter_types; - use sp_weights::RuntimeDbWeight; + use frame_support::weights::constants; + use sp_core::parameter_types; + use sp_weights::RuntimeDbWeight; - parameter_types! { - /// By default, Substrate uses `RocksDB`, so this will be the weight used throughout - /// the runtime. - pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight { - read: 31_627 * constants::WEIGHT_REF_TIME_PER_NANOS, - write: 412_279 * constants::WEIGHT_REF_TIME_PER_NANOS, - }; - } + parameter_types! { + /// By default, Substrate uses `RocksDB`, so this will be the weight used throughout + /// the runtime. + pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight { + read: 31_627 * constants::WEIGHT_REF_TIME_PER_NANOS, + write: 412_279 * constants::WEIGHT_REF_TIME_PER_NANOS, + }; + } - #[cfg(test)] - mod test_db_weights { - use super::constants::RocksDbWeight as W; - use sp_weights::constants; + #[cfg(test)] + mod test_db_weights { + use super::constants::RocksDbWeight as W; + use sp_weights::constants; - /// Checks that all weights exist and have sane values. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn bound() { - // At least 1 µs. - assert!( - W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, - "Read weight should be at least 1 µs." - ); - assert!( - W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, - "Write weight should be at least 1 µs." - ); - // At most 1 ms. - assert!( - W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, - "Read weight should be at most 1 ms." - ); - assert!( - W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, - "Write weight should be at most 1 ms." - ); - } - } + /// Checks that all weights exist and have sane values. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn bound() { + // At least 1 µs. + assert!( + W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, + "Read weight should be at least 1 µs." + ); + assert!( + W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, + "Write weight should be at least 1 µs." + ); + // At most 1 ms. + assert!( + W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Read weight should be at most 1 ms." + ); + assert!( + W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Write weight should be at most 1 ms." + ); + } + } } diff --git a/runtime/casper/src/bag_thresholds.rs b/runtime/casper/src/bag_thresholds.rs index db22661..8ebaa1b 100644 --- a/runtime/casper/src/bag_thresholds.rs +++ b/runtime/casper/src/bag_thresholds.rs @@ -1,4 +1,3 @@ - //! Autogenerated bag thresholds. //! //! Generated on 2024-06-30T17:36:29.986756974+00:00 @@ -19,204 +18,204 @@ pub const CONSTANT_RATIO: f64 = 1.1717610304252650; /// Upper thresholds delimiting the bag list. pub const THRESHOLDS: [u64; 200] = [ - 368_934, - 432_302, - 506_555, - 593_561, - 695_512, - 814_974, - 954_955, - 1_118_979, - 1_311_176, - 1_536_385, - 1_800_276, - 2_109_493, - 2_471_822, - 2_896_385, - 3_393_871, - 3_976_806, - 4_659_866, - 5_460_249, - 6_398_107, - 7_497_052, - 8_784_753, - 10_293_631, - 12_061_676, - 14_133_402, - 16_560_970, - 19_405_499, - 22_738_608, - 26_644_215, - 31_220_653, - 36_583_145, - 42_866_704, - 50_229_533, - 58_857_009, - 68_966_350, - 80_812_081, - 94_692_447, - 110_956_919, - 130_014_994, - 152_346_503, - 178_513_695, - 209_175_391, - 245_103_572, - 287_202_814, - 336_533_065, - 394_336_331, - 462_067_946, - 541_433_213, - 634_430_340, - 743_400_749, - 871_088_028, - 1_020_707_005, - 1_196_024_692, - 1_401_455_126, - 1_642_170_503, - 1_924_231_401, - 2_254_739_369, - 2_642_015_726, - 3_095_811_069, - 3_627_550_768, - 4_250_622_626, - 4_980_713_948, - 5_836_206_508, - 6_838_639_352, - 8_013_251_094, - 9_389_615_359, - 11_002_385_368, - 12_892_166_416, - 15_106_538_204, - 17_701_252_772, - 20_741_638_188, - 24_304_243_336, - 28_478_765_215, - 33_370_307_274, - 39_102_025_637, - 45_818_229_852, - 53_688_016_224, - 62_909_525_212, - 73_714_930_086, - 86_376_282_435, - 101_212_361_710, - 118_596_701_249, - 138_966_992_861, - 162_836_106_750, - 190_805_004_236, - 223_577_868_374, - 261_979_833_426, - 306_977_759_566, - 359_704_575_867, - 421_487_804_467, - 493_882_984_074, - 578_712_834_328, - 678_113_147_073, - 794_586_559_959, - 931_065_566_260, - 1_090_986_347_314, - 1_278_375_286_509, - 1_497_950_342_990, - 1_755_239_837_428, - 2_056_721_640_548, - 2_409_986_268_826, - 2_823_927_993_670, - 3_308_968_775_710, - 3_877_320_662_271, - 4_543_293_254_512, - 5_323_653_985_431, - 6_238_050_279_596, - 7_309_504_223_464, - 8_564_992_200_784, - 10_036_124_086_775, - 11_759_939_101_395, - 13_779_838_359_189, - 16_146_677_594_857, - 18_920_047_576_494, - 22_169_774_443_928, - 25_977_677_746_713, - 30_439_630_444_544, - 35_667_972_735_463, - 41_794_340_485_686, - 48_972_979_473_452, - 57_384_628_890_807, - 67_241_071_879_663, - 78_790_467_672_613, - 92_323_599_587_750, - 108_181_196_185_512, - 126_762_509_914_973, - 148_535_369_237_262, - 174_047_957_312_051, - 203_942_613_803_381, - 238_972_007_297_872, - 280_018_085_514_148, - 328_114_280_419_768, - 384_471_527_321_912, - 450_508_753_023_899, - 527_888_600_658_885, - 618_559_290_657_806, - 724_803_671_800_312, - 849_296_697_324_749, - 995_172_773_194_022, - 1_166_104_674_168_996, - 1_366_396_014_587_981, - 1_601_089_602_022_588, - 1_876_094_401_869_165, - 2_198_334_309_509_284, - 2_575_922_475_729_812, - 3_018_365_574_456_765, - 3_536_803_155_725_606, - 4_144_288_110_164_365, - 4_856_115_306_345_371, - 5_690_206_675_227_153, - 6_667_562_437_096_890, - 7_812_789_831_717_443, - 9_154_722_663_709_264, - 10_727_147_261_685_494, - 12_569_653_128_876_154, - 14_728_629_702_380_078, - 17_258_434_316_813_044, - 20_222_760_778_595_608, - 23_696_243_007_970_824, - 27_766_334_124_227_376, - 32_535_508_284_536_868, - 38_123_840_712_898_664, - 44_672_030_877_514_808, - 52_344_944_932_226_008, - 61_335_766_611_338_904, - 71_870_861_086_426_040, - 84_215_474_244_181_664, - 98_680_410_878_114_672, - 115_629_859_933_328_176, - 135_490_563_823_405_696, - 158_762_562_678_613_984, - 186_031_784_037_248_448, - 217_984_794_955_336_608, - 255_426_087_953_905_344, - 299_298_336_018_362_496, - 350_706_126_617_443_648, - 410_943_772_301_709_248, - 481_527_898_079_096_320, - 564_235_626_031_673_920, - 661_149_318_561_518_720, - 774_709_006_782_606_976, - 907_773_824_067_321_216, - 1_063_693_991_482_207_616, - 1_246_395_167_516_354_560, - 1_460_477_285_806_034_432, - 1_711_330_369_328_773_120, - 2_005_270_236_962_732_544, - 2_349_697_519_144_566_784, - 2_753_283_986_220_526_592, - 3_226_190_880_747_145_216, - 3_780_324_750_772_868_096, - 4_429_637_225_307_749_376, - 5_190_476_279_536_719_872, - 6_081_997_833_707_842_560, - 7_126_648_048_669_730_816, - 8_350_728_460_987_448_320, - 9_785_058_186_248_239_104, - 11_465_749_863_089_412_096, - 13_435_118_874_171_990_016, - 15_742_748_735_885_697_024, - 18_446_744_073_709_551_615, + 368_934, + 432_302, + 506_555, + 593_561, + 695_512, + 814_974, + 954_955, + 1_118_979, + 1_311_176, + 1_536_385, + 1_800_276, + 2_109_493, + 2_471_822, + 2_896_385, + 3_393_871, + 3_976_806, + 4_659_866, + 5_460_249, + 6_398_107, + 7_497_052, + 8_784_753, + 10_293_631, + 12_061_676, + 14_133_402, + 16_560_970, + 19_405_499, + 22_738_608, + 26_644_215, + 31_220_653, + 36_583_145, + 42_866_704, + 50_229_533, + 58_857_009, + 68_966_350, + 80_812_081, + 94_692_447, + 110_956_919, + 130_014_994, + 152_346_503, + 178_513_695, + 209_175_391, + 245_103_572, + 287_202_814, + 336_533_065, + 394_336_331, + 462_067_946, + 541_433_213, + 634_430_340, + 743_400_749, + 871_088_028, + 1_020_707_005, + 1_196_024_692, + 1_401_455_126, + 1_642_170_503, + 1_924_231_401, + 2_254_739_369, + 2_642_015_726, + 3_095_811_069, + 3_627_550_768, + 4_250_622_626, + 4_980_713_948, + 5_836_206_508, + 6_838_639_352, + 8_013_251_094, + 9_389_615_359, + 11_002_385_368, + 12_892_166_416, + 15_106_538_204, + 17_701_252_772, + 20_741_638_188, + 24_304_243_336, + 28_478_765_215, + 33_370_307_274, + 39_102_025_637, + 45_818_229_852, + 53_688_016_224, + 62_909_525_212, + 73_714_930_086, + 86_376_282_435, + 101_212_361_710, + 118_596_701_249, + 138_966_992_861, + 162_836_106_750, + 190_805_004_236, + 223_577_868_374, + 261_979_833_426, + 306_977_759_566, + 359_704_575_867, + 421_487_804_467, + 493_882_984_074, + 578_712_834_328, + 678_113_147_073, + 794_586_559_959, + 931_065_566_260, + 1_090_986_347_314, + 1_278_375_286_509, + 1_497_950_342_990, + 1_755_239_837_428, + 2_056_721_640_548, + 2_409_986_268_826, + 2_823_927_993_670, + 3_308_968_775_710, + 3_877_320_662_271, + 4_543_293_254_512, + 5_323_653_985_431, + 6_238_050_279_596, + 7_309_504_223_464, + 8_564_992_200_784, + 10_036_124_086_775, + 11_759_939_101_395, + 13_779_838_359_189, + 16_146_677_594_857, + 18_920_047_576_494, + 22_169_774_443_928, + 25_977_677_746_713, + 30_439_630_444_544, + 35_667_972_735_463, + 41_794_340_485_686, + 48_972_979_473_452, + 57_384_628_890_807, + 67_241_071_879_663, + 78_790_467_672_613, + 92_323_599_587_750, + 108_181_196_185_512, + 126_762_509_914_973, + 148_535_369_237_262, + 174_047_957_312_051, + 203_942_613_803_381, + 238_972_007_297_872, + 280_018_085_514_148, + 328_114_280_419_768, + 384_471_527_321_912, + 450_508_753_023_899, + 527_888_600_658_885, + 618_559_290_657_806, + 724_803_671_800_312, + 849_296_697_324_749, + 995_172_773_194_022, + 1_166_104_674_168_996, + 1_366_396_014_587_981, + 1_601_089_602_022_588, + 1_876_094_401_869_165, + 2_198_334_309_509_284, + 2_575_922_475_729_812, + 3_018_365_574_456_765, + 3_536_803_155_725_606, + 4_144_288_110_164_365, + 4_856_115_306_345_371, + 5_690_206_675_227_153, + 6_667_562_437_096_890, + 7_812_789_831_717_443, + 9_154_722_663_709_264, + 10_727_147_261_685_494, + 12_569_653_128_876_154, + 14_728_629_702_380_078, + 17_258_434_316_813_044, + 20_222_760_778_595_608, + 23_696_243_007_970_824, + 27_766_334_124_227_376, + 32_535_508_284_536_868, + 38_123_840_712_898_664, + 44_672_030_877_514_808, + 52_344_944_932_226_008, + 61_335_766_611_338_904, + 71_870_861_086_426_040, + 84_215_474_244_181_664, + 98_680_410_878_114_672, + 115_629_859_933_328_176, + 135_490_563_823_405_696, + 158_762_562_678_613_984, + 186_031_784_037_248_448, + 217_984_794_955_336_608, + 255_426_087_953_905_344, + 299_298_336_018_362_496, + 350_706_126_617_443_648, + 410_943_772_301_709_248, + 481_527_898_079_096_320, + 564_235_626_031_673_920, + 661_149_318_561_518_720, + 774_709_006_782_606_976, + 907_773_824_067_321_216, + 1_063_693_991_482_207_616, + 1_246_395_167_516_354_560, + 1_460_477_285_806_034_432, + 1_711_330_369_328_773_120, + 2_005_270_236_962_732_544, + 2_349_697_519_144_566_784, + 2_753_283_986_220_526_592, + 3_226_190_880_747_145_216, + 3_780_324_750_772_868_096, + 4_429_637_225_307_749_376, + 5_190_476_279_536_719_872, + 6_081_997_833_707_842_560, + 7_126_648_048_669_730_816, + 8_350_728_460_987_448_320, + 9_785_058_186_248_239_104, + 11_465_749_863_089_412_096, + 13_435_118_874_171_990_016, + 15_742_748_735_885_697_024, + 18_446_744_073_709_551_615, ]; diff --git a/runtime/casper/src/cult/mod.rs b/runtime/casper/src/cult/mod.rs index 539aa21..84cdf85 100644 --- a/runtime/casper/src/cult/mod.rs +++ b/runtime/casper/src/cult/mod.rs @@ -2,25 +2,34 @@ use super::*; use frame_support::{ parameter_types, traits::{ - EitherOf, EitherOfDiverse, MapSuccess, OriginTrait, TryWithMorphedArg, - tokens::pay::PayFromAccount, + tokens::pay::PayFromAccount, EitherOf, EitherOfDiverse, MapSuccess, OriginTrait, + TryWithMorphedArg, }, }; use frame_system::EnsureRootWithSuccess; +use pallet_ranked_collective::EnsureOfRank; use sp_core::{ConstU128, ConstU32}; use sp_runtime::traits::{ConstU16, TakeFirst}; -use pallet_ranked_collective::EnsureOfRank; use crate::{ - // weights, - RuntimeCall, RuntimeEvent, Scheduler, DAYS, CSPR, AccountId, Balance, - TreasuryAccount, Balances, Preimage, Runtime, + AccountId, + Balance, + Balances, + Preimage, + Runtime, + // weights, + RuntimeCall, + RuntimeEvent, + Scheduler, + TreasuryAccount, + CSPR, + DAYS, }; mod origins; pub use origins::{ - pallet_cult_origins, Geniuses, Degens, Zombies, Skeletons, Ghosts, - EnsureCanRetainAt, EnsureCanPromoteTo, EnsureCult, ToVoice, CultTreasurySpender, + pallet_cult_origins, CultTreasurySpender, Degens, EnsureCanPromoteTo, EnsureCanRetainAt, + EnsureCult, Geniuses, Ghosts, Skeletons, ToVoice, Zombies, }; mod tracks; @@ -45,14 +54,10 @@ parameter_types! { impl pallet_whitelist::Config for Runtime { type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; - type WhitelistOrigin = EitherOfDiverse< - EnsureRootWithSuccess>, - Skeletons, - >; - type DispatchWhitelistedOrigin = EitherOf< - EnsureRootWithSuccess>, - Geniuses, - >; + type WhitelistOrigin = + EitherOfDiverse>, Skeletons>; + type DispatchWhitelistedOrigin = + EitherOf>, Geniuses>; type Preimages = Preimage; type WeightInfo = weights::pallet_whitelist::WeightInfo; } @@ -71,7 +76,7 @@ impl pallet_referenda::Config for Runtime { type Scheduler = Scheduler; type Currency = Balances; type SubmitOrigin = EitherOf< - pallet_ranked_collective::EnsureMember, + pallet_ranked_collective::EnsureMember, MapSuccess< TryWithMorphedArg< RuntimeOrigin, @@ -81,7 +86,7 @@ impl pallet_referenda::Config for Runtime { (AccountId, u16), >, TakeFirst, - > + >, >; type CancelOrigin = Skeletons; type KillOrigin = Ghosts; @@ -100,7 +105,7 @@ pub type CultCollectiveInstance = pallet_ranked_collective::Instance1; impl pallet_ranked_collective::Config for Runtime { type WeightInfo = weights::pallet_ranked_collective::WeightInfo; type RuntimeEvent = RuntimeEvent; - + #[cfg(not(feature = "runtime-benchmarks"))] type PromoteOrigin = frame_system::EnsureNever; #[cfg(feature = "runtime-benchmarks")] @@ -123,7 +128,7 @@ impl pallet_ranked_collective::Config for Runtime { type MinRankOfClass = tracks::MinRankOfClass; type MemberSwappedHandler = (crate::CultCore, crate::CultSalary); type VoteWeight = pallet_ranked_collective::Geometric; - + #[cfg(feature = "runtime-benchmarks")] type BenchmarkSetup = (crate::CultCore, crate::CultSalary); } @@ -135,10 +140,13 @@ impl pallet_core_fellowship::Config for Runtime { type Members = pallet_ranked_collective::Pallet; type Balance = Balance; - type ParamsOrigin = EitherOf>, Skeletons>; + type ParamsOrigin = + EitherOf>, Skeletons>; type InductOrigin = EitherOf>, Zombies>; - type ApproveOrigin = EitherOf>, EnsureCanRetainAt>; - type PromoteOrigin = EitherOf>, EnsureCanPromoteTo>; + type ApproveOrigin = + EitherOf>, EnsureCanRetainAt>; + type PromoteOrigin = + EitherOf>, EnsureCanPromoteTo>; type EvidenceSize = ConstU32<65536>; } diff --git a/runtime/casper/src/cult/origins.rs b/runtime/casper/src/cult/origins.rs index 3cb917d..fd08b49 100644 --- a/runtime/casper/src/cult/origins.rs +++ b/runtime/casper/src/cult/origins.rs @@ -5,8 +5,8 @@ pub use pallet_cult_origins::*; #[frame_support::pallet] pub mod pallet_cult_origins { - use crate::{Balance, CSPR}; use super::ranks; + use crate::{Balance, CSPR}; use frame_support::pallet_prelude::*; use pallet_ranked_collective::Rank; @@ -114,7 +114,7 @@ pub mod pallet_cult_origins { } #[cfg(feature = "runtime-benchmarks")] fn try_successful_origin() -> Result { - // By convention the more privileged origins go later, + // By convention the more privileged origins go later, // so for greatest chance of success, we want the last one. let _result: Result = Err(()); $( diff --git a/runtime/casper/src/cult/tracks.rs b/runtime/casper/src/cult/tracks.rs index 703fa87..7957d7c 100644 --- a/runtime/casper/src/cult/tracks.rs +++ b/runtime/casper/src/cult/tracks.rs @@ -1,4 +1,4 @@ -use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, CSPR, HOURS, MINUTES}; +use crate::{Balance, BlockNumber, RuntimeOrigin, CSPR, DAYS, HOURS, MINUTES}; use pallet_ranked_collective::Rank; use sp_runtime::{traits::Convert, Perbill}; @@ -255,7 +255,6 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15 min_support: RETAIN_MIN_SUPPORT, }, ), - ( constants::PROMOTE_TO_GENIUSES, pallet_referenda::TrackInfo { @@ -347,7 +346,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { // It is important that this is NOT availiable in production! let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into(); if &root == id { - return Ok(tracks::GHOSTS) + return Ok(tracks::GHOSTS); } } diff --git a/runtime/casper/src/genesis_config_presets.rs b/runtime/casper/src/genesis_config_presets.rs index 64f6c06..d7bc506 100644 --- a/runtime/casper/src/genesis_config_presets.rs +++ b/runtime/casper/src/genesis_config_presets.rs @@ -3,24 +3,24 @@ use pallet_staking::Forcing; use sp_staking::StakerStatus; use crate::{opaque::SessionKeys, BABE_GENESIS_EPOCH_CONFIG}; -use primitives::{AccountId, AccountPublic}; use casper_runtime_constants::currency::CSPR; +use primitives::{AccountId, AccountPublic}; -use ghost_slow_clap::sr25519::AuthorityId as SlowClapId; use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use babe_primitives::AuthorityId as BabeId; +use ghost_slow_clap::sr25519::AuthorityId as SlowClapId; use grandpa_primitives::AuthorityId as GrandpaId; +use sp_core::{sr25519, Pair, Public}; +use sp_runtime::{traits::IdentifyAccount, Perbill}; #[cfg(not(feature = "std"))] use sp_std::alloc::format; -use sp_std::vec::Vec; use sp_std::prelude::*; -use sp_core::{sr25519, Pair, Public}; -use sp_runtime::{Perbill, traits::IdentifyAccount}; +use sp_std::vec::Vec; #[derive(Encode, Clone)] -struct PreparedNetworkData { - chain_name: Vec, +struct PreparedNetworkData { + chain_name: Vec, default_endpoint: Vec, finality_delay: Option, release_delay: Option, @@ -84,40 +84,69 @@ fn casper_testnet_accounts() -> Vec { fn casper_testnet_evm_accounts() -> Vec<(AccountId, u128, u8)> { vec![ // 01c928771aea942a1e7ac06adf2b73dfbc9a25d9eaa516e3673116af7f345198 - (get_account_id_from_seed::("1A69d2D5568D1878023EeB121a73d33B9116A760"), 1337 * CSPR, 1), + ( + get_account_id_from_seed::("1A69d2D5568D1878023EeB121a73d33B9116A760"), + 1337 * CSPR, + 1, + ), // b19a435901872f817185f7234a1484eae837613f9d10cf21927a23c2d8cb9139 - (get_account_id_from_seed::("2f86cfBED3fbc1eCf2989B9aE5fc019a837A9C12"), 1337 * CSPR, 2), + ( + get_account_id_from_seed::("2f86cfBED3fbc1eCf2989B9aE5fc019a837A9C12"), + 1337 * CSPR, + 2, + ), // d3baf57b74d65719b2dc33f5a464176022d0cc5edbca002234229f3e733875fc - (get_account_id_from_seed::("e83f67361Ac74D42A48E2DAfb6706eb047D8218D"), 69 * CSPR, 3), + ( + get_account_id_from_seed::("e83f67361Ac74D42A48E2DAfb6706eb047D8218D"), + 69 * CSPR, + 3, + ), // c4683d566436af6b58b4a59c8f501319226e85b21869bf93d5eeb4596d4791d4 - (get_account_id_from_seed::("827ee4ad9b259b6fa1390ed60921508c78befd63"), 69 * CSPR, 4), + ( + get_account_id_from_seed::("827ee4ad9b259b6fa1390ed60921508c78befd63"), + 69 * CSPR, + 4, + ), ] } fn casper_testnet_evm_networks() -> Vec<(u32, Vec)> { vec![ - (1, PreparedNetworkData { - chain_name: "ethereum-mainnet".into(), - default_endpoint: "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7/".into(), - finality_delay: Some(40), - release_delay: Some(80), - network_type: Default::default(), - gatekeeper: "0x4d224452801aced8b2f0aebe155379bb5d594381".into(), - topic_name: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef".into(), - incoming_fee: 0, - outgoing_fee: 0, - }.encode()), - (56, PreparedNetworkData { - chain_name: "bnb-mainnet".into(), - default_endpoint: "https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab/".into(), - finality_delay: Some(20), - release_delay: Some(40), - network_type: Default::default(), - gatekeeper: "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82".into(), - topic_name: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef".into(), - incoming_fee: 0, - outgoing_fee: 0, - }.encode()) + ( + 1, + PreparedNetworkData { + chain_name: "ethereum-mainnet".into(), + default_endpoint: + "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7/".into(), + finality_delay: Some(40), + release_delay: Some(80), + network_type: Default::default(), + gatekeeper: "0x4d224452801aced8b2f0aebe155379bb5d594381".into(), + topic_name: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" + .into(), + incoming_fee: 0, + outgoing_fee: 0, + } + .encode(), + ), + ( + 56, + PreparedNetworkData { + chain_name: "bnb-mainnet".into(), + default_endpoint: + "https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab/" + .into(), + finality_delay: Some(20), + release_delay: Some(40), + network_type: Default::default(), + gatekeeper: "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82".into(), + topic_name: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" + .into(), + incoming_fee: 0, + outgoing_fee: 0, + } + .encode(), + ), ] } @@ -127,7 +156,12 @@ fn casper_session_keys( authority_discovery: AuthorityDiscoveryId, slow_clap: SlowClapId, ) -> SessionKeys { - SessionKeys { babe, grandpa, authority_discovery, slow_clap } + SessionKeys { + babe, + grandpa, + authority_discovery, + slow_clap, + } } fn testnet_config_genesis( @@ -143,8 +177,7 @@ fn testnet_config_genesis( ghost_accounts: Option>, evm_networks: Option)>>, ) -> serde_json::Value { - let endowed_accounts: Vec = - endowed_accounts.unwrap_or_else(casper_testnet_accounts); + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(casper_testnet_accounts); let ghost_accounts: Vec<(AccountId, u128, u8)> = ghost_accounts.unwrap_or_else(casper_testnet_evm_accounts); @@ -218,7 +251,9 @@ fn testnet_config_genesis( fn casper_development_config_genesis() -> serde_json::Value { testnet_config_genesis( vec![get_authority_keys_from_seed("Alice")], - None, None, None, + None, + None, + None, ) } @@ -226,10 +261,12 @@ fn casper_development_config_genesis() -> serde_json::Value { fn casper_local_config_genesis() -> serde_json::Value { testnet_config_genesis( vec![ - get_authority_keys_from_seed("Alice"), + get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob"), ], - None, None, None, + None, + None, + None, ) } @@ -240,15 +277,17 @@ pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option casper_local_config_genesis(), _ => return None, }; - Some(serde_json::to_string(&patch) - .expect("serialization to json is expected to work; qed") - .into_bytes()) + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work; qed") + .into_bytes(), + ) } /// Returns a list of identifiers for available builtin `RuntimeGenesisConfig` presets. pub fn preset_names() -> Vec { Vec::from([ - sp_genesis_builder::PresetId::from("local_testnet"), - sp_genesis_builder::PresetId::from("development"), + sp_genesis_builder::PresetId::from("local_testnet"), + sp_genesis_builder::PresetId::from("development"), ]) } diff --git a/runtime/casper/src/impls.rs b/runtime/casper/src/impls.rs index 8728457..c3ed55d 100644 --- a/runtime/casper/src/impls.rs +++ b/runtime/casper/src/impls.rs @@ -1,8 +1,5 @@ use super::*; -use frame_support::{ - dispatch::DispatchResultWithPostInfo, - traits::PrivilegeCmp, -}; +use frame_support::{dispatch::DispatchResultWithPostInfo, traits::PrivilegeCmp}; use pallet_alliance::{ProposalIndex, ProposalProvider}; use sp_runtime::DispatchError; use sp_std::{cmp::Ordering, marker::PhantomData}; @@ -14,7 +11,8 @@ type HashOf = ::Hash; /// Proposal provider for alliance pallet. /// Adapter from collective pallet to alliance proposal provider trait. pub struct AllianceProposalProvider(PhantomData<(T, I)>); -impl ProposalProvider, HashOf, ProposalOf> for AllianceProposalProvider +impl ProposalProvider, HashOf, ProposalOf> + for AllianceProposalProvider where T: pallet_collective::Config + frame_system::Config, I: 'static, @@ -25,7 +23,12 @@ where proposal: Box>, length_bound: u32, ) -> Result<(u32, u32), DispatchError> { - pallet_collective::Pallet::::do_propose_proposed(who, threshold, proposal, length_bound) + pallet_collective::Pallet::::do_propose_proposed( + who, + threshold, + proposal, + length_bound, + ) } fn vote_proposal( @@ -61,7 +64,7 @@ pub struct EqualOrGreatestRootCmp; impl PrivilegeCmp for EqualOrGreatestRootCmp { fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option { if left == right { - return Some(Ordering::Equal) + return Some(Ordering::Equal); } match (left, right) { diff --git a/runtime/casper/src/lib.rs b/runtime/casper/src/lib.rs index 0f0c288..9053f1c 100644 --- a/runtime/casper/src/lib.rs +++ b/runtime/casper/src/lib.rs @@ -1,63 +1,59 @@ #![cfg_attr(not(feature = "std"), no_std)] - // `construct_runtime!` does a lot of recursion and requires us to increase // the limit to 256 #![recursion_limit = "256"] -use frame_system::{EnsureRoot, EnsureRootWithSuccess}; -use runtime_common::{ - impls::DealWithFees, BlockHashCount, BlockLength, CurrencyToVote, - SlowAdjustingFeeUpdate, impl_runtime_weights, prod_or_fast, -}; use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use frame_election_provider_support::{ - generate_solution_type, onchain, SequentialPhragmen, - bounds::ElectionBoundsBuilder, + bounds::ElectionBoundsBuilder, generate_solution_type, onchain, SequentialPhragmen, }; use frame_support::{ - construct_runtime, parameter_types, - genesis_builder_helper::{build_state, get_preset}, + construct_runtime, + genesis_builder_helper::{build_state, get_preset}, + parameter_types, traits::{ - fungible::HoldConsideration, - tokens::UnityAssetBalanceConversion, - ConstU128, ConstU32, EitherOf, EitherOfDiverse, InstanceFilter, - KeyOwnerProofSystem, LinearStoragePrice, WithdrawReasons, + fungible::HoldConsideration, tokens::UnityAssetBalanceConversion, ConstU128, ConstU32, + EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, + WithdrawReasons, }, - weights::ConstantMultiplier, PalletId + weights::ConstantMultiplier, + PalletId, +}; +use frame_system::{EnsureRoot, EnsureRootWithSuccess}; +use runtime_common::{ + impl_runtime_weights, impls::DealWithFees, prod_or_fast, BlockHashCount, BlockLength, + CurrencyToVote, SlowAdjustingFeeUpdate, }; +use frame_support::traits::tokens::pay::PayFromAccount; #[cfg(feature = "runtime-benchmarks")] use runtime_common::benchmarking::BenchmarkTreasuryHelper; -use frame_support::traits::tokens::pay::PayFromAccount; -use pallet_transaction_payment::FungibleAdapter; +use codec::{Decode, Encode, MaxEncodedLen}; +use ghost_slow_clap::sr25519::AuthorityId as SlowClapId; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_identity::legacy::IdentityInfo; -use ghost_slow_clap::sr25519::AuthorityId as SlowClapId; use pallet_session::historical as session_historical; +use pallet_transaction_payment::FungibleAdapter; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; -use codec::{Decode, Encode, MaxEncodedLen}; use primitives::{ - AccountId, AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce, - Signature, ReserveIdentifier, + AccountId, AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce, ReserveIdentifier, + Signature, }; use sp_core::OpaqueMetadata; -use sp_runtime::{ - create_runtime_str, generic, impl_opaque_keys, FixedU128, - curve::PiecewiseLinear, - traits::{ - AccountIdLookup, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT, - OpaqueKeys, SaturatedConversion, Verify, IdentityLookup, ConvertInto, - ConstU16, - }, - transaction_validity::{ - TransactionPriority, TransactionSource, TransactionValidity, - }, - ApplyExtrinsicResult, KeyTypeId, Perbill, Percent, Permill, - RuntimeDebug, -}; use sp_genesis_builder::PresetId; +use sp_runtime::{ + create_runtime_str, + curve::PiecewiseLinear, + generic, impl_opaque_keys, + traits::{ + AccountIdLookup, BlakeTwo256, Block as BlockT, ConstU16, ConvertInto, + Extrinsic as ExtrinsicT, IdentityLookup, OpaqueKeys, SaturatedConversion, Verify, + }, + transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, + ApplyExtrinsicResult, FixedU128, KeyTypeId, Perbill, Percent, Permill, RuntimeDebug, +}; use sp_std::prelude::*; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; @@ -75,20 +71,20 @@ pub use pallet_timestamp::Call as TimestampCall; pub use sp_runtime::BuildStorage; /// Constant values used within the runtime. -use casper_runtime_constants::{currency::*, time::*, fee::*}; +use casper_runtime_constants::{currency::*, fee::*, time::*}; -mod weights; mod bag_thresholds; -mod impls; mod genesis_config_presets; +mod impls; +mod weights; pub use impls::{AllianceProposalProvider, EqualOrGreatestRootCmp}; // Governance configuration. pub mod cult; use cult::{ - pallet_cult_origins, CultCollectiveInstance, CultTreasurySpender, - Geniuses, Degens, Zombies, Skeletons, Ghosts, + pallet_cult_origins, CultCollectiveInstance, CultTreasurySpender, Degens, Geniuses, Ghosts, + Skeletons, Zombies, }; pub const LOG_TARGET: &str = "runtime::casper"; @@ -122,7 +118,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { impl_name: create_runtime_str!("casper-svengali"), authoring_version: 0, spec_version: 1, - impl_version : 0, + impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 0, @@ -246,10 +242,10 @@ impl pallet_babe::Config for Runtime { type MaxAuthorities = MaxAuthorities; type MaxNominators = MaxNominators; - type KeyOwnerProof = + type KeyOwnerProof = >::Proof; - type EquivocationReportSystem = + type EquivocationReportSystem = pallet_babe::EquivocationReportSystem; } @@ -362,7 +358,7 @@ parameter_types! { pub const MaxElectingVoters: u32 = 22_500; // ... and all of the validators as electable targets. Whilist this is the // case, we cannot and shall increase the size of the validator intentions. - pub ElectionBounds: frame_election_provider_support::bounds::ElectionBounds = + pub ElectionBounds: frame_election_provider_support::bounds::ElectionBounds = ElectionBoundsBuilder::default().voters_count(MaxElectingVoters::get().into()).build(); // Setup election pallet to support maximum winners upto 1_200. This will // mean Staking Pallet cannot have active validators higher than this count. @@ -422,13 +418,15 @@ impl pallet_election_provider_multi_phase::Config for Runtime { type SignedMaxSubmissions = SignedMaxSubmissions; type SignedMaxRefunds = SignedMaxRefunds; type SignedRewardBase = SignedRewardBase; - type SignedDepositBase = GeometricDepositBase; + type SignedDepositBase = + GeometricDepositBase; type SignedDepositByte = SignedDepositByte; type SignedDepositWeight = (); - type SignedMaxWeight = ::MaxWeight; + type SignedMaxWeight = + ::MaxWeight; type MinerConfig = Self; type SlashHandler = (); - type RewardHandler= (); + type RewardHandler = (); type BetterSignedThreshold = (); type OffchainRepeat = OffchainRepeat; type MinerTxPriority = NposSolutionPriority; @@ -449,10 +447,7 @@ impl pallet_election_provider_multi_phase::Config for Runtime { (), >; type BenchmarkingConfig = runtime_common::elections::BenchmarkConfig; - type ForceOrigin = EitherOf< - EnsureRootWithSuccess>, - Zombies, - >; + type ForceOrigin = EitherOf>, Zombies>; type MaxWinners = MaxActiveValidators; type ElectionBounds = ElectionBounds; type WeightInfo = weights::pallet_election_provider_multi_phase::WeightInfo; @@ -508,10 +503,7 @@ impl pallet_staking::Config for Runtime { type SessionsPerEra = SessionsPerEra; type BondingDuration = BondingDuration; type SlashDeferDuration = SlashDeferDuration; - type AdminOrigin = EitherOf< - EnsureRootWithSuccess>, - Skeletons, - >; + type AdminOrigin = EitherOf>, Skeletons>; type SessionInterface = Self; type EraPayout = pallet_staking::ConvertCurve; type MaxExposurePageSize = MaxExposurePageSize; @@ -535,10 +527,7 @@ impl pallet_fast_unstake::Config for Runtime { type Currency = Balances; type BatchSize = frame_support::traits::ConstU32<16>; type Deposit = ConstU128<{ STRH }>; - type ControlOrigin = EitherOf< - EnsureRootWithSuccess>, - Zombies, - >; + type ControlOrigin = EitherOf>, Zombies>; type Staking = Staking; type MaxErasToCheckPerBlock = ConstU32<1>; type WeightInfo = weights::pallet_fast_unstake::WeightInfo; @@ -565,7 +554,7 @@ impl pallet_identity::Config for Runtime { type Slashed = Treasury; type ForceOrigin = Geniuses; - type RegistrarOrigin = Geniuses; + type RegistrarOrigin = Geniuses; type UsernameAuthorityOrigin = Geniuses; type OffchainSignature = Signature; @@ -599,10 +588,7 @@ impl pallet_treasury::Config for Runtime { type ApproveOrigin = frame_support::traits::NeverEnsureOrigin; #[cfg(feature = "runtime-benchmarks")] type ApproveOrigin = EnsureRoot; - type RejectOrigin = EitherOf< - EnsureRootWithSuccess>, - Degens, - >; + type RejectOrigin = EitherOf>, Degens>; type RuntimeEvent = RuntimeEvent; type OnSlash = Treasury; @@ -625,10 +611,7 @@ impl pallet_treasury::Config for Runtime { type MaxApprovals = MaxApprovals; type WeightInfo = (); - type SpendOrigin = EitherOf< - EnsureRootWithSuccess, - CultTreasurySpender - >; + type SpendOrigin = EitherOf, CultTreasurySpender>; type AssetKind = (); type Beneficiary = AccountId; @@ -696,7 +679,7 @@ parameter_types! { } parameter_types! { - pub MaxSetIdSessionEntries: u32 = + pub MaxSetIdSessionEntries: u32 = BondingDuration::get() * SessionsPerEra::get(); } @@ -708,17 +691,16 @@ impl pallet_grandpa::Config for Runtime { type MaxNominators = MaxNominators; type MaxSetIdSessionEntries = MaxSetIdSessionEntries; - type KeyOwnerProof = - >::Proof; + type KeyOwnerProof = >::Proof; type EquivocationReportSystem = pallet_grandpa::EquivocationReportSystem; } -/// Submits a transaction with the node's public and signature type. Adheres +/// 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 +where RuntimeCall: From, { fn create_transaction>( @@ -726,13 +708,17 @@ where public: ::Signer, account: AccountId, nonce: ::Nonce, - ) -> Option<(RuntimeCall, ::SignaturePayload)> { + ) -> Option<( + RuntimeCall, + ::SignaturePayload, + )> { 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; + .map(|c| c / 2) + .unwrap_or(2) as u64; let current_block = System::block_number() .saturated_into::() @@ -746,9 +732,10 @@ where frame_system::CheckSpecVersion::::new(), frame_system::CheckTxVersion::::new(), frame_system::CheckGenesis::::new(), - frame_system::CheckMortality::::from( - generic::Era::mortal(period, current_block), - ), + 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), @@ -771,7 +758,7 @@ impl frame_system::offchain::SigningTypes for Runtime { } impl frame_system::offchain::SendTransactionTypes for Runtime -where +where RuntimeCall: From, { type Extrinsic = UncheckedExtrinsic; @@ -830,8 +817,17 @@ parameter_types! { /// The type used to represent the kinds of proxying allowed. #[derive( - Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, - Decode, RuntimeDebug, MaxEncodedLen, scale_info::TypeInfo, + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + Encode, + Decode, + RuntimeDebug, + MaxEncodedLen, + scale_info::TypeInfo, )] pub enum ProxyType { Any = 0, @@ -856,42 +852,40 @@ impl InstanceFilter for ProxyType { ProxyType::NonTransfer => matches!(c, RuntimeCall::Balances { .. }), ProxyType::Governance => matches!( c, - RuntimeCall::Bounties { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::ChildBounties { .. } | - RuntimeCall::CultReferenda { .. } | - RuntimeCall::CultCollective { .. } | - RuntimeCall::Whitelist { .. } | - RuntimeCall::AllianceMotion { .. } | - RuntimeCall::Alliance { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Bounties { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::ChildBounties { .. } + | RuntimeCall::CultReferenda { .. } + | RuntimeCall::CultCollective { .. } + | RuntimeCall::Whitelist { .. } + | RuntimeCall::AllianceMotion { .. } + | RuntimeCall::Alliance { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::Staking => matches!( c, - RuntimeCall::Staking { .. } | - RuntimeCall::Session { .. } | - RuntimeCall::Utility { .. } | - RuntimeCall::FastUnstake { .. } | - RuntimeCall::VoterList { .. } | - RuntimeCall::NominationPools { .. } + RuntimeCall::Staking { .. } + | RuntimeCall::Session { .. } + | RuntimeCall::Utility { .. } + | RuntimeCall::FastUnstake { .. } + | RuntimeCall::VoterList { .. } + | RuntimeCall::NominationPools { .. } ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | - RuntimeCall::Utility { .. } + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility { .. } ), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | - RuntimeCall::Utility { .. } | - RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) + | RuntimeCall::Utility { .. } + | RuntimeCall::Multisig { .. } ), ProxyType::NominationPools => matches!( - c, - RuntimeCall::NominationPools { .. } | - RuntimeCall::Utility { .. } + c, + RuntimeCall::NominationPools { .. } | RuntimeCall::Utility { .. } ), - } } @@ -940,10 +934,7 @@ impl pallet_nomination_pools::Config for Runtime { type MaxUnbonding = ::MaxUnlockingChunks; type PalletId = PoolsPalletId; type MaxPointsToBalance = MaxPointsToBalance; - type AdminOrigin = EitherOf< - EnsureRootWithSuccess>, - Zombies, - >; + type AdminOrigin = EitherOf>, Zombies>; type WeightInfo = weights::pallet_nomination_pools::WeightInfo; } @@ -952,19 +943,19 @@ impl frame_support::traits::OnRuntimeUpgrade for InitiateNominationPools { fn on_runtime_upgrade() -> Weight { // we use one as an indicator if this has already been set. if pallet_nomination_pools::MaxPools::::get().is_none() { - pallet_nomination_pools::MinJoinBond::::put(5 * CSPR); - pallet_nomination_pools::MinCreateBond::::put(100 * CSPR); + pallet_nomination_pools::MinJoinBond::::put(5 * CSPR); + pallet_nomination_pools::MinCreateBond::::put(100 * CSPR); - pallet_nomination_pools::MaxPools::::put(0); - pallet_nomination_pools::MaxPoolMembersPerPool::::put(0); - pallet_nomination_pools::MaxPoolMembers::::put(0); + pallet_nomination_pools::MaxPools::::put(0); + pallet_nomination_pools::MaxPoolMembersPerPool::::put(0); + pallet_nomination_pools::MaxPoolMembers::::put(0); - log::info!(target: LOG_TARGET, "🎉 pools config initiated"); - ::DbWeight::get().reads_writes(1, 5) - } else { - log::info!(target: LOG_TARGET, "😏 pools config already initiated"); - ::DbWeight::get().reads(1) - } + log::info!(target: LOG_TARGET, "🎉 pools config initiated"); + ::DbWeight::get().reads_writes(1, 5) + } else { + log::info!(target: LOG_TARGET, "😏 pools config already initiated"); + ::DbWeight::get().reads(1) + } } } @@ -1039,29 +1030,20 @@ impl ghost_networks::Config for Runtime { type NetworkId = u64; type Currency = Balances; - type RegisterOrigin = EitherOf< - EnsureRootWithSuccess>, - Ghosts, - >; - type UpdateOrigin = EitherOf< - EnsureRootWithSuccess>, - Zombies, - >; - type RemoveOrigin = EitherOf< - EnsureRootWithSuccess>, - Skeletons, - >; + type RegisterOrigin = EitherOf>, Ghosts>; + type UpdateOrigin = EitherOf>, Zombies>; + type RemoveOrigin = + EitherOf>, Skeletons>; type WeightInfo = weights::ghost_networks::WeightInfo; } parameter_types! { pub ClaimPrefix: &'static [u8] = b"CasperAccountId:"; - pub MaximumWithdrawAmount: Balance = 500 * CSPR; + pub MaximumWithdrawAmount: Balance = 500 * CSPR; pub VestingBlocks: u32 = 10 * WEEKS; } - impl ghost_claims::Config for Runtime { type RuntimeEvent = RuntimeEvent; type VestingSchedule = Vesting; @@ -1081,7 +1063,7 @@ parameter_types! { // will be used in `Perbill::from_percent()` pub const OffenceThreshold: u32 = 40; pub const SlowClapUnsignedPriority: TransactionPriority = TransactionPriority::MAX; - pub const SlowClapHistoryDepth: sp_staking::SessionIndex = + pub const SlowClapHistoryDepth: sp_staking::SessionIndex = StakingHistoryDepth::get() * SessionsPerEra::get(); } @@ -1112,7 +1094,7 @@ impl ghost_sudo::Config for Runtime { } construct_runtime! { - pub enum Runtime + pub enum Runtime { // Basic stuff; balances is uncallable initially. System: frame_system = 0, @@ -1154,7 +1136,7 @@ construct_runtime! { Bounties: pallet_bounties = 30, ChildBounties: pallet_child_bounties = 31, - // Election pallet. Only works with staking, but places here to + // Election pallet. Only works with staking, but places here to // maintain indicies. ElectionProviderMultiPhase: pallet_election_provider_multi_phase = 32, @@ -1617,306 +1599,343 @@ sp_api::impl_runtime_apis! { #[cfg(test)] mod test_fees { - use super::*; - use frame_support::{dispatch::GetDispatchInfo, weights::WeightToFee as WeightToFeeT}; - use keyring::Sr25519Keyring::{Alice, Charlie}; - use pallet_transaction_payment::Multiplier; - use runtime_common::MinimumMultiplier; - use separator::Separatable; - use sp_runtime::{assert_eq_error_rate, FixedPointNumber, MultiAddress, MultiSignature}; + use super::*; + use frame_support::{dispatch::GetDispatchInfo, weights::WeightToFee as WeightToFeeT}; + use keyring::Sr25519Keyring::{Alice, Charlie}; + use pallet_transaction_payment::Multiplier; + use runtime_common::MinimumMultiplier; + use separator::Separatable; + use sp_runtime::{assert_eq_error_rate, FixedPointNumber, MultiAddress, MultiSignature}; - #[test] - fn payout_weight_portion() { - use pallet_staking::WeightInfo; - let payout_weight = - ::WeightInfo::payout_stakers_alive_staked( - MaxNominatorRewardedPerValidator::get(), - ) - .ref_time() as f64; - let block_weight = BlockWeights::get().max_block.ref_time() as f64; + #[test] + fn payout_weight_portion() { + use pallet_staking::WeightInfo; + let payout_weight = + ::WeightInfo::payout_stakers_alive_staked( + MaxNominatorRewardedPerValidator::get(), + ) + .ref_time() as f64; + let block_weight = BlockWeights::get().max_block.ref_time() as f64; - println!( - "a full payout takes {:.2} of the block weight [{} / {}]", - payout_weight / block_weight, - payout_weight, - block_weight - ); - assert!(payout_weight * 2f64 < block_weight); - } + println!( + "a full payout takes {:.2} of the block weight [{} / {}]", + payout_weight / block_weight, + payout_weight, + block_weight + ); + assert!(payout_weight * 2f64 < block_weight); + } - #[test] - fn block_cost() { - let max_block_weight = BlockWeights::get().max_block; - let raw_fee = WeightToFee::weight_to_fee(&max_block_weight); + #[test] + fn block_cost() { + let max_block_weight = BlockWeights::get().max_block; + let raw_fee = WeightToFee::weight_to_fee(&max_block_weight); - let fee_with_multiplier = |m: Multiplier| { - println!( + let fee_with_multiplier = |m: Multiplier| { + println!( "Full Block weight == {} // multiplier: {:?} // WeightToFee(full_block) == {} plank", max_block_weight, m, m.saturating_mul_int(raw_fee).separated_string(), ); - }; - fee_with_multiplier(MinimumMultiplier::get()); - fee_with_multiplier(Multiplier::from_rational(1, 2)); - fee_with_multiplier(Multiplier::from_u32(1)); - fee_with_multiplier(Multiplier::from_u32(2)); - } + }; + fee_with_multiplier(MinimumMultiplier::get()); + fee_with_multiplier(Multiplier::from_rational(1, 2)); + fee_with_multiplier(Multiplier::from_u32(1)); + fee_with_multiplier(Multiplier::from_u32(2)); + } - #[test] - fn transfer_cost_min_multiplier() { - let min_multiplier = MinimumMultiplier::get(); - let call = pallet_balances::Call::::transfer_keep_alive { - dest: Charlie.to_account_id().into(), - value: Default::default(), - }; - let info = call.get_dispatch_info(); - println!("call = {:?} / info = {:?}", call, info); - // convert to runtime call. - let call = RuntimeCall::Balances(call); - let extra: SignedExtra = ( - frame_system::CheckNonZeroSender::::new(), - frame_system::CheckSpecVersion::::new(), - frame_system::CheckTxVersion::::new(), - frame_system::CheckGenesis::::new(), - frame_system::CheckMortality::::from(generic::Era::immortal()), - frame_system::CheckNonce::::from(1), - frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from(0), - ); - let uxt = UncheckedExtrinsic { - function: call, - signature: Some(( - MultiAddress::Id(Alice.to_account_id()), - MultiSignature::Sr25519(Alice.sign(b"foo")), - extra, - )), - }; - let len = uxt.encoded_size(); + #[test] + fn transfer_cost_min_multiplier() { + let min_multiplier = MinimumMultiplier::get(); + let call = pallet_balances::Call::::transfer_keep_alive { + dest: Charlie.to_account_id().into(), + value: Default::default(), + }; + let info = call.get_dispatch_info(); + println!("call = {:?} / info = {:?}", call, info); + // convert to runtime call. + let call = RuntimeCall::Balances(call); + let extra: SignedExtra = ( + frame_system::CheckNonZeroSender::::new(), + frame_system::CheckSpecVersion::::new(), + frame_system::CheckTxVersion::::new(), + frame_system::CheckGenesis::::new(), + frame_system::CheckMortality::::from(generic::Era::immortal()), + frame_system::CheckNonce::::from(1), + frame_system::CheckWeight::::new(), + pallet_transaction_payment::ChargeTransactionPayment::::from(0), + ); + let uxt = UncheckedExtrinsic { + function: call, + signature: Some(( + MultiAddress::Id(Alice.to_account_id()), + MultiSignature::Sr25519(Alice.sign(b"foo")), + extra, + )), + }; + let len = uxt.encoded_size(); - let mut ext = sp_io::TestExternalities::new_empty(); - let mut test_with_multiplier = |m: Multiplier| { - ext.execute_with(|| { - pallet_transaction_payment::NextFeeMultiplier::::put(m); - let fee = TransactionPayment::query_fee_details(uxt.clone(), len as u32); - println!( - "multiplier = {:?} // fee details = {:?} // final fee = {:?}", - pallet_transaction_payment::NextFeeMultiplier::::get(), - fee, - fee.final_fee().separated_string(), - ); - }); - }; + let mut ext = sp_io::TestExternalities::new_empty(); + let mut test_with_multiplier = |m: Multiplier| { + ext.execute_with(|| { + pallet_transaction_payment::NextFeeMultiplier::::put(m); + let fee = TransactionPayment::query_fee_details(uxt.clone(), len as u32); + println!( + "multiplier = {:?} // fee details = {:?} // final fee = {:?}", + pallet_transaction_payment::NextFeeMultiplier::::get(), + fee, + fee.final_fee().separated_string(), + ); + }); + }; - test_with_multiplier(min_multiplier); - test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1u128)); - test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_0u128)); - test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_00u128)); - test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_000u128)); - test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_000_000u128)); - test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_000_000_000u128)); - } + test_with_multiplier(min_multiplier); + test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1u128)); + test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_0u128)); + test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_00u128)); + test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_000u128)); + test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_000_000u128)); + test_with_multiplier(Multiplier::saturating_from_rational( + 1u128, + 1_000_000_000u128, + )); + } - #[test] - fn nominator_limit() { - use pallet_election_provider_multi_phase::WeightInfo; - // starting point of the nominators. - let target_voters: u32 = 50_000; + #[test] + fn nominator_limit() { + use pallet_election_provider_multi_phase::WeightInfo; + // starting point of the nominators. + let target_voters: u32 = 50_000; - // assuming we want around 5k candidates and 1k active validators. (March 31, 2021) - let all_targets: u32 = 5_000; - let desired: u32 = 1_000; - let weight_with = |active| { - ::WeightInfo::submit_unsigned( - active, - all_targets, - active, - desired, - ) - }; + // assuming we want around 5k candidates and 1k active validators. (March 31, 2021) + let all_targets: u32 = 5_000; + let desired: u32 = 1_000; + let weight_with = |active| { + ::WeightInfo::submit_unsigned( + active, + all_targets, + active, + desired, + ) + }; - let mut active = target_voters; - while weight_with(active).all_lte(OffchainSolutionWeightLimit::get()) || - active == target_voters - { - active += 1; - } + let mut active = target_voters; + while weight_with(active).all_lte(OffchainSolutionWeightLimit::get()) + || active == target_voters + { + active += 1; + } - println!("can support {} nominators to yield a weight of {}", active, weight_with(active)); - assert!(active > target_voters, "we need to reevaluate the weight of the election system"); - } + println!( + "can support {} nominators to yield a weight of {}", + active, + weight_with(active) + ); + assert!( + active > target_voters, + "we need to reevaluate the weight of the election system" + ); + } - #[test] - fn signed_deposit_is_sensible() { - // ensure this number does not change, or that it is checked after each change. - // a 1 MB solution should take (40 + 10) DOTs of deposit. - let deposit = SignedDepositBase::get() + (SignedDepositByte::get() * 1024 * 1024); - assert_eq_error_rate!(deposit, 50 * DOLLARS, DOLLARS); - } + #[test] + fn signed_deposit_is_sensible() { + // ensure this number does not change, or that it is checked after each change. + // a 1 MB solution should take (40 + 10) DOTs of deposit. + let deposit = SignedDepositBase::get() + (SignedDepositByte::get() * 1024 * 1024); + assert_eq_error_rate!(deposit, 50 * DOLLARS, DOLLARS); + } } #[cfg(test)] mod test { - use super::*; - - #[test] - fn call_size() { - RuntimeCall::assert_size_under(256) - } + use super::*; #[test] - fn check_whitelist() { - let whitelist: HashSet = AllPalletsWithSystem::whitelisted_storage_keys() - .iter() - .map(|e| HexDisplay::from(&e.key).to_string()) - .collect(); + fn call_size() { + RuntimeCall::assert_size_under(256) + } - // Block number - assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac")); - // Total issuance - assert!(whitelist.contains("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80")); - // Execution phase - assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a")); - // Event count - assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850")); - // System events - assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7")); - } + #[test] + fn check_whitelist() { + let whitelist: HashSet = AllPalletsWithSystem::whitelisted_storage_keys() + .iter() + .map(|e| HexDisplay::from(&e.key).to_string()) + .collect(); - #[test] - fn check_treasury_pallet_id() { - assert_eq!( - ::index() as u8, - casper_runtime_constants::TREASURY_PALLET_ID - ); - } + // Block number + assert!( + whitelist.contains("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac") + ); + // Total issuance + assert!( + whitelist.contains("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80") + ); + // Execution phase + assert!( + whitelist.contains("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a") + ); + // Event count + assert!( + whitelist.contains("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850") + ); + // System events + assert!( + whitelist.contains("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7") + ); + } + + #[test] + fn check_treasury_pallet_id() { + assert_eq!( + ::index() as u8, + casper_runtime_constants::TREASURY_PALLET_ID + ); + } } #[cfg(test)] mod multiplier_tests { - use super::*; - use frame_support::{dispatch::DispatchInfo, traits::OnFinalize}; - use runtime_common::{MinimumMultiplier, TargetBlockFullness}; - use separator::Separatable; - use sp_runtime::traits::Convert; + use super::*; + use frame_support::{dispatch::DispatchInfo, traits::OnFinalize}; + use runtime_common::{MinimumMultiplier, TargetBlockFullness}; + use separator::Separatable; + use sp_runtime::traits::Convert; - fn run_with_system_weight(w: Weight, mut assertions: F) - where - F: FnMut() -> (), - { - let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap() - .into(); - t.execute_with(|| { - System::set_block_consumed_resources(w, 0); - assertions() - }); - } + fn run_with_system_weight(w: Weight, mut assertions: F) + where + F: FnMut() -> (), + { + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap() + .into(); + t.execute_with(|| { + System::set_block_consumed_resources(w, 0); + assertions() + }); + } - #[test] - fn multiplier_can_grow_from_zero() { - let minimum_multiplier = MinimumMultiplier::get(); - let target = TargetBlockFullness::get() * - BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap(); - // if the min is too small, then this will not change, and we are doomed forever. - // the weight is 1/100th bigger than target. - run_with_system_weight(target.saturating_mul(101) / 100, || { - let next = SlowAdjustingFeeUpdate::::convert(minimum_multiplier); - assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier); - }) - } + #[test] + fn multiplier_can_grow_from_zero() { + let minimum_multiplier = MinimumMultiplier::get(); + let target = TargetBlockFullness::get() + * BlockWeights::get() + .get(DispatchClass::Normal) + .max_total + .unwrap(); + // if the min is too small, then this will not change, and we are doomed forever. + // the weight is 1/100th bigger than target. + run_with_system_weight(target.saturating_mul(101) / 100, || { + let next = SlowAdjustingFeeUpdate::::convert(minimum_multiplier); + assert!( + next > minimum_multiplier, + "{:?} !>= {:?}", + next, + minimum_multiplier + ); + }) + } - #[test] - fn fast_unstake_estimate() { - use pallet_fast_unstake::WeightInfo; - let block_time = BlockWeights::get().max_block.ref_time() as f32; - let on_idle = weights::pallet_fast_unstake::WeightInfo::::on_idle_check( - 300, - ::BatchSize::get(), - ) - .ref_time() as f32; - println!("ratio of block weight for full batch fast-unstake {}", on_idle / block_time); - assert!(on_idle / block_time <= 0.5f32) - } + #[test] + fn fast_unstake_estimate() { + use pallet_fast_unstake::WeightInfo; + let block_time = BlockWeights::get().max_block.ref_time() as f32; + let on_idle = weights::pallet_fast_unstake::WeightInfo::::on_idle_check( + 300, + ::BatchSize::get(), + ) + .ref_time() as f32; + println!( + "ratio of block weight for full batch fast-unstake {}", + on_idle / block_time + ); + assert!(on_idle / block_time <= 0.5f32) + } - #[test] - #[ignore] - fn multiplier_growth_simulator() { - // assume the multiplier is initially set to its minimum. We update it with values twice the - //target (target is 25%, thus 50%) and we see at which point it reaches 1. - let mut multiplier = MinimumMultiplier::get(); - let block_weight = BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap(); - let mut blocks = 0; - let mut fees_paid = 0; + #[test] + #[ignore] + fn multiplier_growth_simulator() { + // assume the multiplier is initially set to its minimum. We update it with values twice the + //target (target is 25%, thus 50%) and we see at which point it reaches 1. + let mut multiplier = MinimumMultiplier::get(); + let block_weight = BlockWeights::get() + .get(DispatchClass::Normal) + .max_total + .unwrap(); + let mut blocks = 0; + let mut fees_paid = 0; - frame_system::Pallet::::set_block_consumed_resources(Weight::MAX, 0); - let info = DispatchInfo { weight: Weight::MAX, ..Default::default() }; + frame_system::Pallet::::set_block_consumed_resources(Weight::MAX, 0); + let info = DispatchInfo { + weight: Weight::MAX, + ..Default::default() + }; - let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap() - .into(); - // set the minimum - t.execute_with(|| { - pallet_transaction_payment::NextFeeMultiplier::::set(MinimumMultiplier::get()); - }); + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap() + .into(); + // set the minimum + t.execute_with(|| { + pallet_transaction_payment::NextFeeMultiplier::::set(MinimumMultiplier::get()); + }); - while multiplier <= Multiplier::from_u32(1) { - t.execute_with(|| { - // imagine this tx was called. - let fee = TransactionPayment::compute_fee(0, &info, 0); - fees_paid += fee; + while multiplier <= Multiplier::from_u32(1) { + t.execute_with(|| { + // imagine this tx was called. + let fee = TransactionPayment::compute_fee(0, &info, 0); + fees_paid += fee; - // this will update the multiplier. - System::set_block_consumed_resources(block_weight, 0); - TransactionPayment::on_finalize(1); - let next = TransactionPayment::next_fee_multiplier(); + // this will update the multiplier. + System::set_block_consumed_resources(block_weight, 0); + TransactionPayment::on_finalize(1); + let next = TransactionPayment::next_fee_multiplier(); - assert!(next > multiplier, "{:?} !>= {:?}", next, multiplier); - multiplier = next; + assert!(next > multiplier, "{:?} !>= {:?}", next, multiplier); + multiplier = next; - println!( - "block = {} / multiplier {:?} / fee = {:?} / fess so far {:?}", - blocks, - multiplier, - fee.separated_string(), - fees_paid.separated_string() - ); - }); - blocks += 1; - } - } + println!( + "block = {} / multiplier {:?} / fee = {:?} / fess so far {:?}", + blocks, + multiplier, + fee.separated_string(), + fees_paid.separated_string() + ); + }); + blocks += 1; + } + } - #[test] - #[ignore] - fn multiplier_cool_down_simulator() { - // assume the multiplier is initially set to its minimum. We update it with values twice the - //target (target is 25%, thus 50%) and we see at which point it reaches 1. - let mut multiplier = Multiplier::from_u32(2); - let mut blocks = 0; + #[test] + #[ignore] + fn multiplier_cool_down_simulator() { + // assume the multiplier is initially set to its minimum. We update it with values twice the + //target (target is 25%, thus 50%) and we see at which point it reaches 1. + let mut multiplier = Multiplier::from_u32(2); + let mut blocks = 0; - let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap() - .into(); - // set the minimum - t.execute_with(|| { - pallet_transaction_payment::NextFeeMultiplier::::set(multiplier); - }); + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap() + .into(); + // set the minimum + t.execute_with(|| { + pallet_transaction_payment::NextFeeMultiplier::::set(multiplier); + }); - while multiplier > Multiplier::from_u32(0) { - t.execute_with(|| { - // this will update the multiplier. - TransactionPayment::on_finalize(1); - let next = TransactionPayment::next_fee_multiplier(); + while multiplier > Multiplier::from_u32(0) { + t.execute_with(|| { + // this will update the multiplier. + TransactionPayment::on_finalize(1); + let next = TransactionPayment::next_fee_multiplier(); - assert!(next < multiplier, "{:?} !>= {:?}", next, multiplier); - multiplier = next; + assert!(next < multiplier, "{:?} !>= {:?}", next, multiplier); + multiplier = next; - println!("block = {} / multiplier {:?}", blocks, multiplier); - }); - blocks += 1; - } - } + println!("block = {} / multiplier {:?}", blocks, multiplier); + }); + blocks += 1; + } + } }