From 74dfc944d0de9f63f5a7cf9a07c34cca93f21a79 Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 13 Apr 2023 18:47:04 +0200 Subject: [PATCH 1/4] Vote locks tip --- frame/conviction-voting/src/lib.rs | 9 +++++++-- frame/democracy/src/lib.rs | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/frame/conviction-voting/src/lib.rs b/frame/conviction-voting/src/lib.rs index 072e57035484d..e786ab6eb37ef 100644 --- a/frame/conviction-voting/src/lib.rs +++ b/frame/conviction-voting/src/lib.rs @@ -639,7 +639,12 @@ impl, I: 'static> Pallet { }, } }); - T::Currency::extend_lock(CONVICTION_VOTING_ID, who, amount, WithdrawReasons::TRANSFER); + T::Currency::extend_lock( + CONVICTION_VOTING_ID, + who, + amount, + WithdrawReasons::TRANSFER | WithdrawReasons::TIP, + ); } /// Rejig the lock on an account. It will never get more stringent (since that would indicate @@ -669,7 +674,7 @@ impl, I: 'static> Pallet { CONVICTION_VOTING_ID, who, lock_needed, - WithdrawReasons::TRANSFER, + WithdrawReasons::TRANSFER | WithdrawReasons::TIP, ); } } diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index a3d7f103a98f3..96ecb321258b8 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -1308,7 +1308,12 @@ impl Pallet { })?; // 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::TRANSFER | WithdrawReasons::TIP, + ); ReferendumInfoOf::::insert(ref_index, ReferendumInfo::Ongoing(status)); Ok(()) } @@ -1499,7 +1504,12 @@ impl Pallet { 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::TRANSFER | WithdrawReasons::TIP, + ); } } From 1af127b63c98d21109422f984e931c0be23c5d20 Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 24 Apr 2023 13:41:25 +0200 Subject: [PATCH 2/4] except reserve --- frame/conviction-voting/src/lib.rs | 4 ++-- frame/democracy/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/conviction-voting/src/lib.rs b/frame/conviction-voting/src/lib.rs index e786ab6eb37ef..3ad81486ed26d 100644 --- a/frame/conviction-voting/src/lib.rs +++ b/frame/conviction-voting/src/lib.rs @@ -643,7 +643,7 @@ impl, I: 'static> Pallet { CONVICTION_VOTING_ID, who, amount, - WithdrawReasons::TRANSFER | WithdrawReasons::TIP, + WithdrawReasons::except(WithdrawReasons::RESERVE), ); } @@ -674,7 +674,7 @@ impl, I: 'static> Pallet { CONVICTION_VOTING_ID, who, lock_needed, - WithdrawReasons::TRANSFER | WithdrawReasons::TIP, + WithdrawReasons::except(WithdrawReasons::RESERVE), ); } } diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 96ecb321258b8..f02e70798f95c 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -1312,7 +1312,7 @@ impl Pallet { DEMOCRACY_ID, who, vote.balance(), - WithdrawReasons::TRANSFER | WithdrawReasons::TIP, + WithdrawReasons::except(WithdrawReasons::RESERVE), ); ReferendumInfoOf::::insert(ref_index, ReferendumInfo::Ongoing(status)); Ok(()) @@ -1508,7 +1508,7 @@ impl Pallet { DEMOCRACY_ID, who, lock_needed, - WithdrawReasons::TRANSFER | WithdrawReasons::TIP, + WithdrawReasons::except(WithdrawReasons::RESERVE), ); } } From 5de00f1b141ddb98f00cfa1e51cb57ae93486e95 Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 24 Apr 2023 14:19:58 +0200 Subject: [PATCH 3/4] reason for delegate --- frame/democracy/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index f02e70798f95c..4cfd4958400c9 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -1459,7 +1459,12 @@ impl Pallet { 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::::Delegated { who, target }); From 03d3fd2a51025ea5209cbcd7dde01aa5022e4c34 Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 24 Apr 2023 14:22:25 +0200 Subject: [PATCH 4/4] fix tests --- frame/democracy/src/tests/lock_voting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/democracy/src/tests/lock_voting.rs b/frame/democracy/src/tests/lock_voting.rs index 9b9172ff02b45..31f2e3f3dcc26 100644 --- a/frame/democracy/src/tests/lock_voting.rs +++ b/frame/democracy/src/tests/lock_voting.rs @@ -34,7 +34,7 @@ fn nay(x: u8, balance: u64) -> AccountVote { } fn the_lock(amount: u64) -> BalanceLock { - BalanceLock { id: DEMOCRACY_ID, amount, reasons: pallet_balances::Reasons::Misc } + BalanceLock { id: DEMOCRACY_ID, amount, reasons: pallet_balances::Reasons::All } } #[test]