Make priviledged functions explicity use origin (#3045)

* Make priviledged functions explicity use `origin`

* Fix typo in docs

* Fix more tests

* Remove `root` pathway, add semicolons
This commit is contained in:
Shawn Tabrizi
2019-07-08 15:51:54 +02:00
committed by Bastian Köcher
parent 29311e98b4
commit 3d72844710
11 changed files with 71 additions and 114 deletions
+9 -5
View File
@@ -288,7 +288,7 @@ use primitives::traits::{
};
#[cfg(feature = "std")]
use primitives::{Serialize, Deserialize};
use system::ensure_signed;
use system::{ensure_signed, ensure_root};
use phragmen::{elect, ACCURACY, ExtendedBalance, equalize};
@@ -903,7 +903,8 @@ decl_module! {
}
/// The ideal number of validators.
fn set_validator_count(#[compact] new: u32) {
fn set_validator_count(origin, #[compact] new: u32) {
ensure_root(origin)?;
ValidatorCount::put(new);
}
@@ -917,17 +918,20 @@ decl_module! {
/// - Triggers the Phragmen election. Expensive but not user-controlled.
/// - Depends on state: `O(|edges| * |validators|)`.
/// # </weight>
fn force_new_era() {
fn force_new_era(origin) {
ensure_root(origin)?;
Self::apply_force_new_era()
}
/// Set the offline slash grace period.
fn set_offline_slash_grace(#[compact] new: u32) {
fn set_offline_slash_grace(origin, #[compact] new: u32) {
ensure_root(origin)?;
OfflineSlashGrace::put(new);
}
/// Set the validators who cannot be slashed (if any).
fn set_invulnerables(validators: Vec<T::AccountId>) {
fn set_invulnerables(origin, validators: Vec<T::AccountId>) {
ensure_root(origin)?;
<Invulnerables<T>>::put(validators);
}
}
+3 -3
View File
@@ -146,7 +146,7 @@ fn invulnerability_should_work() {
with_externalities(&mut ExtBuilder::default().build(),
|| {
// Make account 11 invulnerable
assert_ok!(Staking::set_invulnerables(vec![11]));
assert_ok!(Staking::set_invulnerables(Origin::ROOT, vec![11]));
// Give account 11 some funds
let _ = Balances::make_free_balance_be(&11, 70);
// There is no slash grace -- slash immediately.
@@ -213,7 +213,7 @@ fn offline_grace_should_delay_slashing() {
// Set offline slash grace
let offline_slash_grace = 1;
assert_ok!(Staking::set_offline_slash_grace(offline_slash_grace));
assert_ok!(Staking::set_offline_slash_grace(Origin::ROOT, offline_slash_grace));
assert_eq!(Staking::offline_slash_grace(), 1);
// Check unstake_threshold is 3 (default)
@@ -1846,7 +1846,7 @@ fn phragmen_linear_worse_case_equalize() {
}
assert_eq_uvec!(validator_controllers(), vec![40, 30]);
assert_ok!(Staking::set_validator_count(7));
assert_ok!(Staking::set_validator_count(Origin::ROOT, 7));
start_era(1);