Skip to content

Commit

Permalink
Vote locks for all reasons except RESERVE (#13914)
Browse files Browse the repository at this point in the history
* Vote locks tip

* except reserve

* reason for delegate

* fix tests

---------

Co-authored-by: parity-processbot <>
  • Loading branch information
muharem authored Apr 24, 2023
1 parent 168a9ae commit c53f8c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,12 @@ impl<T: Config> Pallet<T> {
})?;
// Extend the lock to `balance` (rather than setting it) since we don't know what other
// votes are in place.
T::Currency::extend_lock(DEMOCRACY_ID, who, vote.balance(), WithdrawReasons::TRANSFER);
T::Currency::extend_lock(
DEMOCRACY_ID,
who,
vote.balance(),
WithdrawReasons::except(WithdrawReasons::RESERVE),
);
ReferendumInfoOf::<T>::insert(ref_index, ReferendumInfo::Ongoing(status));
Ok(())
}
Expand Down Expand Up @@ -1454,7 +1459,12 @@ impl<T: Config> Pallet<T> {
let votes = Self::increase_upstream_delegation(&target, conviction.votes(balance));
// Extend the lock to `balance` (rather than setting it) since we don't know what other
// votes are in place.
T::Currency::extend_lock(DEMOCRACY_ID, &who, balance, WithdrawReasons::TRANSFER);
T::Currency::extend_lock(
DEMOCRACY_ID,
&who,
balance,
WithdrawReasons::except(WithdrawReasons::RESERVE),
);
Ok(votes)
})?;
Self::deposit_event(Event::<T>::Delegated { who, target });
Expand Down Expand Up @@ -1499,7 +1509,12 @@ impl<T: Config> Pallet<T> {
if lock_needed.is_zero() {
T::Currency::remove_lock(DEMOCRACY_ID, who);
} else {
T::Currency::set_lock(DEMOCRACY_ID, who, lock_needed, WithdrawReasons::TRANSFER);
T::Currency::set_lock(
DEMOCRACY_ID,
who,
lock_needed,
WithdrawReasons::except(WithdrawReasons::RESERVE),
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/lock_voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn nay(x: u8, balance: u64) -> AccountVote<u64> {
}

fn the_lock(amount: u64) -> BalanceLock<u64> {
BalanceLock { id: DEMOCRACY_ID, amount, reasons: pallet_balances::Reasons::Misc }
BalanceLock { id: DEMOCRACY_ID, amount, reasons: pallet_balances::Reasons::All }
}

#[test]
Expand Down

0 comments on commit c53f8c5

Please sign in to comment.