Skip to content

Commit b0af318

Browse files
committed
small adjustments and weights
1 parent 735fbfa commit b0af318

File tree

6 files changed

+74
-91
lines changed

6 files changed

+74
-91
lines changed

pallets/inflation/src/lib.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ pub mod pallet {
213213
assert!(self.params.is_valid());
214214

215215
let starting_era = 1;
216-
let config = Pallet::<T>::recalculate_inflation(starting_era);
216+
let starting_decay_factor = Perquintill::one();
217+
let config = Pallet::<T>::recalculate_inflation(starting_era, starting_decay_factor);
217218

218219
ActiveInflationConfig::<T>::put(config);
219220
InflationParams::<T>::put(self.params);
@@ -249,15 +250,12 @@ pub mod pallet {
249250
//
250251
// This should be done as late as possible, to ensure all operations that modify issuance are done.
251252
if let Some(next_era) = DoRecalculation::<T>::get() {
252-
let current_config = ActiveInflationConfig::<T>::get();
253-
let mut new_config = Self::recalculate_inflation(next_era);
254-
// preserve the current decay factor
255-
new_config.decay_factor = current_config.decay_factor;
256-
257-
ActiveInflationConfig::<T>::put(new_config.clone());
253+
let decay_factor = ActiveInflationConfig::<T>::get().decay_factor;
254+
let config = Self::recalculate_inflation(next_era, decay_factor);
255+
ActiveInflationConfig::<T>::put(config.clone());
258256
DoRecalculation::<T>::kill();
259257

260-
Self::deposit_event(Event::<T>::NewInflationConfiguration { config: new_config });
258+
Self::deposit_event(Event::<T>::NewInflationConfiguration { config });
261259
}
262260

263261
// NOTE: weight of the `on_finalize` logic with recalculation has to be covered by the observer notify call.
@@ -309,13 +307,11 @@ pub mod pallet {
309307
) -> DispatchResult {
310308
ensure_root(origin)?;
311309

312-
let current_config = ActiveInflationConfig::<T>::get();
313-
let mut new_config = Self::recalculate_inflation(next_era);
314-
// preserve the current decay factor
315-
new_config.decay_factor = current_config.decay_factor;
316-
ActiveInflationConfig::<T>::put(new_config.clone());
310+
let decay_factor = ActiveInflationConfig::<T>::get().decay_factor;
311+
let config = Self::recalculate_inflation(next_era, decay_factor);
312+
ActiveInflationConfig::<T>::put(config.clone());
317313

318-
Self::deposit_event(Event::<T>::ForcedInflationRecalculation { config: new_config });
314+
Self::deposit_event(Event::<T>::ForcedInflationRecalculation { config });
319315

320316
Ok(().into())
321317
}
@@ -369,8 +365,6 @@ pub mod pallet {
369365

370366
impl<T: Config> Pallet<T> {
371367
/// Payout block rewards to the beneficiaries applying the decay factor.
372-
///
373-
/// Return the total amount issued.
374368
fn payout_block_rewards(config: &InflationConfiguration) {
375369
let collator_rewards = config.decay_factor * config.collator_reward_per_block;
376370
let treasury_rewards = config.decay_factor * config.treasury_reward_per_block;
@@ -384,8 +378,11 @@ pub mod pallet {
384378

385379
/// Recalculates the inflation based on the current total issuance & inflation parameters.
386380
///
387-
/// Returns the new inflation configuration with default (no) decay factor.
388-
pub(crate) fn recalculate_inflation(next_era: EraNumber) -> InflationConfiguration {
381+
/// Returns the new inflation configuration.
382+
pub(crate) fn recalculate_inflation(
383+
next_era: EraNumber,
384+
decay_factor: Perquintill,
385+
) -> InflationConfiguration {
389386
// Calculate max emission based on the current total issuance.
390387
let params = InflationParams::<T>::get();
391388
let total_issuance = T::Currency::total_issuance();
@@ -394,7 +391,7 @@ pub mod pallet {
394391
let recalculation_era =
395392
next_era.saturating_add(T::CycleConfiguration::eras_per_cycle());
396393

397-
Self::new_config(recalculation_era, max_emission)
394+
Self::new_config(recalculation_era, max_emission, decay_factor)
398395
}
399396

400397
/// Re-adjust the existing inflation configuration using the current inflation parameters.
@@ -447,15 +444,14 @@ pub mod pallet {
447444
.saturating_add(bonus_reward_pool);
448445

449446
// 4. Calculate new inflation configuration
450-
let mut new_config = Self::new_config(config.recalculation_era, max_emission);
451-
new_config.decay_factor = config.decay_factor;
452-
new_config
447+
Self::new_config(config.recalculation_era, max_emission, config.decay_factor)
453448
}
454449

455450
// Calculate new inflation configuration, based on the provided `max_emission`.
456451
fn new_config(
457452
recalculation_era: EraNumber,
458453
max_emission: Balance,
454+
decay_factor: Perquintill,
459455
) -> InflationConfiguration {
460456
let params = InflationParams::<T>::get();
461457

@@ -517,7 +513,7 @@ pub mod pallet {
517513
bonus_reward_pool_per_period,
518514
ideal_staking_rate: params.ideal_staking_rate,
519515
decay_rate: params.decay_rate,
520-
decay_factor: Perquintill::one(),
516+
decay_factor,
521517
};
522518
new_inflation_config.sanity_check();
523519

pallets/inflation/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl ExternalityBuilder {
136136
ext.execute_with(|| {
137137
// Set initial pallet inflation values
138138
InflationParams::<Test>::put(INIT_PARAMS);
139-
let config = Inflation::recalculate_inflation(1);
139+
let config = Inflation::recalculate_inflation(1, Perquintill::one());
140140
ActiveInflationConfig::<Test>::put(config);
141141

142142
System::set_block_number(1);

pallets/inflation/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ fn inflation_recalculation_works() {
280280
let now = System::block_number();
281281

282282
// Calculate new config
283-
let new_config = Inflation::recalculate_inflation(now);
283+
let decay_factor = Perquintill::one();
284+
let new_config = Inflation::recalculate_inflation(now, decay_factor);
284285
let max_emission = params.max_inflation_rate * total_issuance;
285286

286287
// Verify basics are ok
@@ -289,8 +290,7 @@ fn inflation_recalculation_works() {
289290
now + <Test as Config>::CycleConfiguration::eras_per_cycle()
290291
);
291292
assert_eq!(
292-
new_config.decay_factor,
293-
Perquintill::one(),
293+
new_config.decay_factor, decay_factor,
294294
"Default decay factor expected."
295295
);
296296

runtime/astar/src/weights/pallet_inflation.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
//! Autogenerated weights for `pallet_inflation`
2121
//!
22-
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 50.0.0
23-
//! DATE: 2025-09-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
22+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
23+
//! DATE: 2025-09-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
2424
//! WORST CASE MAP SIZE: `1000000`
2525
//! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz`
2626
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024
@@ -58,8 +58,8 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
5858
// Proof Size summary in bytes:
5959
// Measured: `0`
6060
// Estimated: `0`
61-
// Minimum execution time: 7_577_000 picoseconds.
62-
Weight::from_parts(7_757_000, 0)
61+
// Minimum execution time: 7_689_000 picoseconds.
62+
Weight::from_parts(7_822_000, 0)
6363
.saturating_add(Weight::from_parts(0, 0))
6464
.saturating_add(T::DbWeight::get().writes(1))
6565
}
@@ -69,8 +69,8 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
6969
// Proof Size summary in bytes:
7070
// Measured: `49`
7171
// Estimated: `1557`
72-
// Minimum execution time: 12_118_000 picoseconds.
73-
Weight::from_parts(12_565_000, 0)
72+
// Minimum execution time: 12_848_000 picoseconds.
73+
Weight::from_parts(13_176_000, 0)
7474
.saturating_add(Weight::from_parts(0, 1557))
7575
.saturating_add(T::DbWeight::get().reads(1))
7676
}
@@ -80,31 +80,27 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
8080
// Proof Size summary in bytes:
8181
// Measured: `49`
8282
// Estimated: `1557`
83-
// Minimum execution time: 12_086_000 picoseconds.
84-
Weight::from_parts(12_406_000, 0)
83+
// Minimum execution time: 11_715_000 picoseconds.
84+
Weight::from_parts(11_966_000, 0)
8585
.saturating_add(Weight::from_parts(0, 1557))
8686
.saturating_add(T::DbWeight::get().reads(1))
8787
}
88-
/// Storage: `Inflation::InflationParams` (r:1 w:1)
89-
/// Proof: `Inflation::InflationParams` (`max_values`: Some(1), `max_size`: Some(72), added: 567, mode: `MaxEncodedLen`)
9088
fn force_set_decay_factor() -> Weight {
9189
// Proof Size summary in bytes:
92-
// Measured: `49`
93-
// Estimated: `1557`
94-
// Minimum execution time: 8_950_000 picoseconds.
95-
Weight::from_parts(9_212_000, 0)
96-
.saturating_add(Weight::from_parts(0, 1557))
97-
.saturating_add(T::DbWeight::get().reads(1))
98-
.saturating_add(T::DbWeight::get().writes(1))
90+
// Measured: `0`
91+
// Estimated: `0`
92+
// Minimum execution time: 8_743_000 picoseconds.
93+
Weight::from_parts(8_932_000, 0)
94+
.saturating_add(Weight::from_parts(0, 0))
9995
}
10096
/// Storage: `Inflation::InflationParams` (r:1 w:0)
10197
/// Proof: `Inflation::InflationParams` (`max_values`: Some(1), `max_size`: Some(72), added: 567, mode: `MaxEncodedLen`)
10298
fn recalculation() -> Weight {
10399
// Proof Size summary in bytes:
104100
// Measured: `67`
105101
// Estimated: `1557`
106-
// Minimum execution time: 11_548_000 picoseconds.
107-
Weight::from_parts(11_874_000, 0)
102+
// Minimum execution time: 12_386_000 picoseconds.
103+
Weight::from_parts(12_610_000, 0)
108104
.saturating_add(Weight::from_parts(0, 1557))
109105
.saturating_add(T::DbWeight::get().reads(1))
110106
}
@@ -114,8 +110,8 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
114110
// Proof Size summary in bytes:
115111
// Measured: `174`
116112
// Estimated: `6196`
117-
// Minimum execution time: 42_321_000 picoseconds.
118-
Weight::from_parts(42_957_000, 0)
113+
// Minimum execution time: 43_146_000 picoseconds.
114+
Weight::from_parts(43_739_000, 0)
119115
.saturating_add(Weight::from_parts(0, 6196))
120116
.saturating_add(T::DbWeight::get().reads(2))
121117
.saturating_add(T::DbWeight::get().writes(2))

runtime/shibuya/src/weights/pallet_inflation.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
//! Autogenerated weights for `pallet_inflation`
2121
//!
22-
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 50.0.0
23-
//! DATE: 2025-09-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
22+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
23+
//! DATE: 2025-09-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
2424
//! WORST CASE MAP SIZE: `1000000`
2525
//! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz`
2626
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024
@@ -58,8 +58,8 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
5858
// Proof Size summary in bytes:
5959
// Measured: `0`
6060
// Estimated: `0`
61-
// Minimum execution time: 7_532_000 picoseconds.
62-
Weight::from_parts(7_683_000, 0)
61+
// Minimum execution time: 7_437_000 picoseconds.
62+
Weight::from_parts(7_704_000, 0)
6363
.saturating_add(Weight::from_parts(0, 0))
6464
.saturating_add(T::DbWeight::get().writes(1))
6565
}
@@ -69,8 +69,8 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
6969
// Proof Size summary in bytes:
7070
// Measured: `49`
7171
// Estimated: `1557`
72-
// Minimum execution time: 12_013_000 picoseconds.
73-
Weight::from_parts(12_252_000, 0)
72+
// Minimum execution time: 13_101_000 picoseconds.
73+
Weight::from_parts(13_355_000, 0)
7474
.saturating_add(Weight::from_parts(0, 1557))
7575
.saturating_add(T::DbWeight::get().reads(1))
7676
}
@@ -80,31 +80,27 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
8080
// Proof Size summary in bytes:
8181
// Measured: `49`
8282
// Estimated: `1557`
83-
// Minimum execution time: 12_229_000 picoseconds.
84-
Weight::from_parts(12_576_000, 0)
83+
// Minimum execution time: 11_917_000 picoseconds.
84+
Weight::from_parts(12_265_000, 0)
8585
.saturating_add(Weight::from_parts(0, 1557))
8686
.saturating_add(T::DbWeight::get().reads(1))
8787
}
88-
/// Storage: `Inflation::InflationParams` (r:1 w:1)
89-
/// Proof: `Inflation::InflationParams` (`max_values`: Some(1), `max_size`: Some(72), added: 567, mode: `MaxEncodedLen`)
9088
fn force_set_decay_factor() -> Weight {
9189
// Proof Size summary in bytes:
92-
// Measured: `49`
93-
// Estimated: `1557`
94-
// Minimum execution time: 9_180_000 picoseconds.
95-
Weight::from_parts(9_437_000, 0)
96-
.saturating_add(Weight::from_parts(0, 1557))
97-
.saturating_add(T::DbWeight::get().reads(1))
98-
.saturating_add(T::DbWeight::get().writes(1))
90+
// Measured: `0`
91+
// Estimated: `0`
92+
// Minimum execution time: 12_024_000 picoseconds.
93+
Weight::from_parts(12_140_000, 0)
94+
.saturating_add(Weight::from_parts(0, 0))
9995
}
10096
/// Storage: `Inflation::InflationParams` (r:1 w:0)
10197
/// Proof: `Inflation::InflationParams` (`max_values`: Some(1), `max_size`: Some(72), added: 567, mode: `MaxEncodedLen`)
10298
fn recalculation() -> Weight {
10399
// Proof Size summary in bytes:
104100
// Measured: `67`
105101
// Estimated: `1557`
106-
// Minimum execution time: 11_756_000 picoseconds.
107-
Weight::from_parts(12_031_000, 0)
102+
// Minimum execution time: 12_729_000 picoseconds.
103+
Weight::from_parts(12_943_000, 0)
108104
.saturating_add(Weight::from_parts(0, 1557))
109105
.saturating_add(T::DbWeight::get().reads(1))
110106
}
@@ -114,8 +110,8 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
114110
// Proof Size summary in bytes:
115111
// Measured: `174`
116112
// Estimated: `6196`
117-
// Minimum execution time: 42_658_000 picoseconds.
118-
Weight::from_parts(42_936_000, 0)
113+
// Minimum execution time: 43_380_000 picoseconds.
114+
Weight::from_parts(43_736_000, 0)
119115
.saturating_add(Weight::from_parts(0, 6196))
120116
.saturating_add(T::DbWeight::get().reads(2))
121117
.saturating_add(T::DbWeight::get().writes(2))

runtime/shiden/src/weights/pallet_inflation.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
//! Autogenerated weights for `pallet_inflation`
2121
//!
22-
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 50.0.0
23-
//! DATE: 2025-09-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
22+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
23+
//! DATE: 2025-09-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
2424
//! WORST CASE MAP SIZE: `1000000`
2525
//! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz`
2626
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024
@@ -37,7 +37,6 @@
3737
// --extrinsic=*
3838
// --wasm-execution=compiled
3939
// --heap-pages=4096
40-
// --json-input=./benchmark-results/shiden/json/inflation_weights.json
4140
// --output=./benchmark-results/shiden/runtime/inflation_weights.rs
4241
// --template=./scripts/templates/runtime-weight-template.hbs
4342

@@ -59,8 +58,8 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
5958
// Proof Size summary in bytes:
6059
// Measured: `0`
6160
// Estimated: `0`
62-
// Minimum execution time: 7_434_000 picoseconds.
63-
Weight::from_parts(7_569_000, 0)
61+
// Minimum execution time: 7_705_000 picoseconds.
62+
Weight::from_parts(7_876_000, 0)
6463
.saturating_add(Weight::from_parts(0, 0))
6564
.saturating_add(T::DbWeight::get().writes(1))
6665
}
@@ -70,8 +69,8 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
7069
// Proof Size summary in bytes:
7170
// Measured: `49`
7271
// Estimated: `1557`
73-
// Minimum execution time: 12_144_000 picoseconds.
74-
Weight::from_parts(12_355_000, 0)
72+
// Minimum execution time: 13_151_000 picoseconds.
73+
Weight::from_parts(13_472_000, 0)
7574
.saturating_add(Weight::from_parts(0, 1557))
7675
.saturating_add(T::DbWeight::get().reads(1))
7776
}
@@ -81,31 +80,27 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
8180
// Proof Size summary in bytes:
8281
// Measured: `49`
8382
// Estimated: `1557`
84-
// Minimum execution time: 12_169_000 picoseconds.
85-
Weight::from_parts(12_362_000, 0)
83+
// Minimum execution time: 12_012_000 picoseconds.
84+
Weight::from_parts(12_276_000, 0)
8685
.saturating_add(Weight::from_parts(0, 1557))
8786
.saturating_add(T::DbWeight::get().reads(1))
8887
}
89-
/// Storage: `Inflation::InflationParams` (r:1 w:1)
90-
/// Proof: `Inflation::InflationParams` (`max_values`: Some(1), `max_size`: Some(72), added: 567, mode: `MaxEncodedLen`)
9188
fn force_set_decay_factor() -> Weight {
9289
// Proof Size summary in bytes:
93-
// Measured: `49`
94-
// Estimated: `1557`
95-
// Minimum execution time: 8_842_000 picoseconds.
96-
Weight::from_parts(9_031_000, 0)
97-
.saturating_add(Weight::from_parts(0, 1557))
98-
.saturating_add(T::DbWeight::get().reads(1))
99-
.saturating_add(T::DbWeight::get().writes(1))
90+
// Measured: `0`
91+
// Estimated: `0`
92+
// Minimum execution time: 8_671_000 picoseconds.
93+
Weight::from_parts(9_012_000, 0)
94+
.saturating_add(Weight::from_parts(0, 0))
10095
}
10196
/// Storage: `Inflation::InflationParams` (r:1 w:0)
10297
/// Proof: `Inflation::InflationParams` (`max_values`: Some(1), `max_size`: Some(72), added: 567, mode: `MaxEncodedLen`)
10398
fn recalculation() -> Weight {
10499
// Proof Size summary in bytes:
105100
// Measured: `67`
106101
// Estimated: `1557`
107-
// Minimum execution time: 11_495_000 picoseconds.
108-
Weight::from_parts(11_845_000, 0)
102+
// Minimum execution time: 12_612_000 picoseconds.
103+
Weight::from_parts(12_822_000, 0)
109104
.saturating_add(Weight::from_parts(0, 1557))
110105
.saturating_add(T::DbWeight::get().reads(1))
111106
}
@@ -115,8 +110,8 @@ impl<T: frame_system::Config> pallet_inflation::WeightInfo for SubstrateWeight<T
115110
// Proof Size summary in bytes:
116111
// Measured: `174`
117112
// Estimated: `6196`
118-
// Minimum execution time: 42_577_000 picoseconds.
119-
Weight::from_parts(42_999_000, 0)
113+
// Minimum execution time: 42_860_000 picoseconds.
114+
Weight::from_parts(43_386_000, 0)
120115
.saturating_add(Weight::from_parts(0, 6196))
121116
.saturating_add(T::DbWeight::get().reads(2))
122117
.saturating_add(T::DbWeight::get().writes(2))

0 commit comments

Comments
 (0)