Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions substrate/frame/staking-async/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1839,8 +1839,9 @@ impl<T: Config> Pallet<T> {
}
}

// ensure ledger consistency.
Self::ensure_ledger_consistent(ctrl)
Self::ensure_ledger_consistent(&ctrl)?;
Self::ensure_ledger_role_and_min_bond(&ctrl)?;
Ok(())
})
.collect::<Result<Vec<_>, _>>()?;
Ok(())
Expand Down Expand Up @@ -1914,7 +1915,40 @@ impl<T: Config> Pallet<T> {
.collect::<Result<(), TryRuntimeError>>()
}

fn ensure_ledger_consistent(ctrl: T::AccountId) -> Result<(), TryRuntimeError> {
fn ensure_ledger_role_and_min_bond(ctrl: &T::AccountId) -> Result<(), TryRuntimeError> {
let ledger = Self::ledger(StakingAccount::Controller(ctrl.clone()))?;
let stash = ledger.stash;

let is_nominator = Nominators::<T>::contains_key(&stash);
let is_validator = Validators::<T>::contains_key(&stash);

match (is_nominator, is_validator) {
(false, false) => {
if ledger.active < Self::min_chilled_bond() {
log!(warn, "Chilled stash {:?} has less than minimum bond", stash);
}
// is chilled
},
(true, false) => {
// Nominators must have a minimum bond.
if ledger.active < Self::min_nominator_bond() {
log!(warn, "Nominator {:?} has less than minimum bond", stash);
}
},
(false, true) => {
// Validators must have a minimum bond.
if ledger.active < Self::min_validator_bond() {
log!(warn, "Validator {:?} has less than minimum bond", stash);
}
},
(true, true) => {
ensure!(false, "Stash cannot be both nominator and validator");
},
}
Ok(())
}

fn ensure_ledger_consistent(ctrl: &T::AccountId) -> Result<(), TryRuntimeError> {
// ensures ledger.total == ledger.active + sum(ledger.unlocking).
let ledger = Self::ledger(StakingAccount::Controller(ctrl.clone()))?;

Expand Down
Loading