diff --git a/substrate/frame/conviction-voting/src/lib.rs b/substrate/frame/conviction-voting/src/lib.rs index 466fc70a619b6..1f8ed7c04d6c7 100644 --- a/substrate/frame/conviction-voting/src/lib.rs +++ b/substrate/frame/conviction-voting/src/lib.rs @@ -398,7 +398,7 @@ impl, I: 'static> Pallet { Error::::InsufficientFunds ); T::Polls::try_access_poll(poll_index, |poll_status| { - let (tally, class) = poll_status.ensure_ongoing().ok_or(Error::::NotOngoing)?; + let (tally, class, _) = poll_status.ensure_ongoing().ok_or(Error::::NotOngoing)?; VotingFor::::try_mutate(who, &class, |voting| { if let Voting::Casting(Casting { ref mut votes, delegations, .. }) = voting { match votes.binary_search_by_key(&poll_index, |i| i.0) { diff --git a/substrate/frame/ranked-collective/src/lib.rs b/substrate/frame/ranked-collective/src/lib.rs index 53d5f0c6662d7..5ba2dd438d8f4 100644 --- a/substrate/frame/ranked-collective/src/lib.rs +++ b/substrate/frame/ranked-collective/src/lib.rs @@ -626,7 +626,7 @@ pub mod pallet { match status { PollStatus::None | PollStatus::Completed(..) => Err(Error::::NotPolling)?, - PollStatus::Ongoing(ref mut tally, class) => { + PollStatus::Ongoing(ref mut tally, class, _) => { match Voting::::get(&poll, &who) { Some(Aye(votes)) => { tally.bare_ayes.saturating_dec(); diff --git a/substrate/frame/referenda/src/lib.rs b/substrate/frame/referenda/src/lib.rs index 0cdf450d3b6c9..8bbb3bfea1a27 100644 --- a/substrate/frame/referenda/src/lib.rs +++ b/substrate/frame/referenda/src/lib.rs @@ -743,6 +743,7 @@ impl, I: 'static> Polling for Pallet { type Votes = VotesOf; type Moment = BlockNumberFor; type Class = TrackIdOf; + type Who = PalletsOriginOf; fn classes() -> Vec { T::Tracks::tracks().iter().map(|x| x.0).collect() @@ -750,11 +751,14 @@ impl, I: 'static> Polling for Pallet { fn access_poll( index: Self::Index, - f: impl FnOnce(PollStatus<&mut T::Tally, BlockNumberFor, TrackIdOf>) -> R, + f: impl FnOnce( + PollStatus<&mut T::Tally, BlockNumberFor, TrackIdOf, &PalletsOriginOf>, + ) -> R, ) -> R { match ReferendumInfoFor::::get(index) { Some(ReferendumInfo::Ongoing(mut status)) => { - let result = f(PollStatus::Ongoing(&mut status.tally, status.track)); + let result = + f(PollStatus::Ongoing(&mut status.tally, status.track, &status.origin)); let now = frame_system::Pallet::::block_number(); Self::ensure_alarm_at(&mut status, index, now + One::one()); ReferendumInfoFor::::insert(index, ReferendumInfo::Ongoing(status)); @@ -769,12 +773,13 @@ impl, I: 'static> Polling for Pallet { fn try_access_poll( index: Self::Index, f: impl FnOnce( - PollStatus<&mut T::Tally, BlockNumberFor, TrackIdOf>, + PollStatus<&mut T::Tally, BlockNumberFor, TrackIdOf, &PalletsOriginOf>, ) -> Result, ) -> Result { match ReferendumInfoFor::::get(index) { Some(ReferendumInfo::Ongoing(mut status)) => { - let result = f(PollStatus::Ongoing(&mut status.tally, status.track))?; + let result = + f(PollStatus::Ongoing(&mut status.tally, status.track, &status.origin))?; let now = frame_system::Pallet::::block_number(); Self::ensure_alarm_at(&mut status, index, now + One::one()); ReferendumInfoFor::::insert(index, ReferendumInfo::Ongoing(status)); diff --git a/substrate/frame/support/src/traits/voting.rs b/substrate/frame/support/src/traits/voting.rs index f18d4ed4e90b3..a1d831be40131 100644 --- a/substrate/frame/support/src/traits/voting.rs +++ b/substrate/frame/support/src/traits/voting.rs @@ -59,16 +59,16 @@ pub trait VoteTally { /// users. fn setup(class: Class, granularity: Perbill); } -pub enum PollStatus { +pub enum PollStatus { None, - Ongoing(Tally, Class), + Ongoing(Tally, Class, Who), Completed(Moment, bool), } -impl PollStatus { - pub fn ensure_ongoing(self) -> Option<(Tally, Class)> { +impl PollStatus { + pub fn ensure_ongoing(self) -> Option<(Tally, Class, Who)> { match self { - Self::Ongoing(t, c) => Some((t, c)), + Self::Ongoing(t, c, w) => Some((t, c, w)), _ => None, } } @@ -85,6 +85,7 @@ pub trait Polling { type Index: Parameter + Member + Ord + PartialOrd + Copy + HasCompact + MaxEncodedLen; type Votes: Parameter + Member + Ord + PartialOrd + Copy + HasCompact + MaxEncodedLen; type Class: Parameter + Member + Ord + PartialOrd + MaxEncodedLen; + type Who; type Moment; /// Provides a vec of values that `T` may take. @@ -98,12 +99,14 @@ pub trait Polling { fn access_poll( index: Self::Index, - f: impl FnOnce(PollStatus<&mut Tally, Self::Moment, Self::Class>) -> R, + f: impl FnOnce(PollStatus<&mut Tally, Self::Moment, Self::Class, &Self::Who>) -> R, ) -> R; fn try_access_poll( index: Self::Index, - f: impl FnOnce(PollStatus<&mut Tally, Self::Moment, Self::Class>) -> Result, + f: impl FnOnce( + PollStatus<&mut Tally, Self::Moment, Self::Class, &Self::Who>, + ) -> Result, ) -> Result; /// Create an ongoing majority-carries poll of given class lasting given period for the purpose