Skip to content

Commit cdb4726

Browse files
authored
Scale and increase validator count (#6417)
1 parent 41c7729 commit cdb4726

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/lib.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ use frame_support::{
303303
};
304304
use pallet_session::historical;
305305
use sp_runtime::{
306-
Perbill, PerU16, PerThing, RuntimeDebug, DispatchError,
306+
Percent, Perbill, PerU16, PerThing, RuntimeDebug, DispatchError,
307307
curve::PiecewiseLinear,
308308
traits::{
309309
Convert, Zero, StaticLookup, CheckedSub, Saturating, SaturatedConversion, AtLeast32Bit,
@@ -1794,6 +1794,34 @@ decl_module! {
17941794
ValidatorCount::put(new);
17951795
}
17961796

1797+
/// Increments the ideal number of validators.
1798+
///
1799+
/// The dispatch origin must be Root.
1800+
///
1801+
/// # <weight>
1802+
/// Base Weight: 1.717 µs
1803+
/// Read/Write: Validator Count
1804+
/// # </weight>
1805+
#[weight = 2 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(1, 1)]
1806+
fn increase_validator_count(origin, #[compact] additional: u32) {
1807+
ensure_root(origin)?;
1808+
ValidatorCount::mutate(|n| *n += additional);
1809+
}
1810+
1811+
/// Scale up the ideal number of validators by a factor.
1812+
///
1813+
/// The dispatch origin must be Root.
1814+
///
1815+
/// # <weight>
1816+
/// Base Weight: 1.717 µs
1817+
/// Read/Write: Validator Count
1818+
/// # </weight>
1819+
#[weight = 2 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(1, 1)]
1820+
fn scale_validator_count(origin, factor: Percent) {
1821+
ensure_root(origin)?;
1822+
ValidatorCount::mutate(|n| *n += factor * *n);
1823+
}
1824+
17971825
/// Force there to be no new eras indefinitely.
17981826
///
17991827
/// The dispatch origin must be Root.

0 commit comments

Comments
 (0)