Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Uses RawOrigin in ElectionCompute event
  • Loading branch information
gpestana committed Dec 30, 2022
commit 9d1a25fd1df22d7adbbe944f4b0918c7b1de4b56
37 changes: 18 additions & 19 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ use frame_support::{
weights::Weight,
DefaultNoBound, EqNoBound, PartialEqNoBound,
};
use frame_system::{ensure_none, offchain::SendTransactionTypes};
use frame_system::{ensure_none, offchain::SendTransactionTypes, RawOrigin};
use scale_info::TypeInfo;
use sp_arithmetic::{
traits::{CheckedAdd, Zero},
Expand Down Expand Up @@ -931,7 +931,7 @@ pub mod pallet {
<QueuedSolution<T>>::put(ready);
Self::deposit_event(Event::SolutionStored {
compute: ElectionCompute::Unsigned,
account_id: None,
origin: RawOrigin::None,
prev_ejected: ejected_a_solution,
});

Expand Down Expand Up @@ -968,7 +968,7 @@ pub mod pallet {
origin: OriginFor<T>,
supports: Supports<T::AccountId>,
) -> DispatchResult {
T::ForceOrigin::ensure_origin(origin)?;
T::ForceOrigin::ensure_origin(origin.clone())?;
ensure!(Self::current_phase().is_emergency(), <Error<T>>::CallNotAllowed);

// bound supports with T::MaxWinners
Expand All @@ -984,7 +984,7 @@ pub mod pallet {

Self::deposit_event(Event::SolutionStored {
compute: ElectionCompute::Emergency,
account_id: None,
origin: RawOrigin::Root,
prev_ejected: QueuedSolution::<T>::exists(),
});

Expand Down Expand Up @@ -1062,7 +1062,7 @@ pub mod pallet {
signed_submissions.put();
Self::deposit_event(Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(who),
origin: RawOrigin::Signed(who),
prev_ejected: ejected_a_solution,
});
Ok(())
Expand Down Expand Up @@ -1105,7 +1105,7 @@ pub mod pallet {

Self::deposit_event(Event::SolutionStored {
compute: ElectionCompute::Fallback,
account_id: None,
origin: RawOrigin::Root,
prev_ejected: QueuedSolution::<T>::exists(),
});

Expand All @@ -1119,15 +1119,14 @@ pub mod pallet {
pub enum Event<T: Config> {
/// A solution was stored with the given compute.
///
/// If the solution is signed, this means that it hasn't yet been processed. If the
/// solution is unsigned, this means that it has also been processed.
///
/// If `account_id` is `None` if the solution is stored during the unsigned phase or by
/// The `origin` indicates the origin of the solution. If the origin is `Signed`, the
/// solution was stored during `Phase::Signed`. If the origin is `Unsigned`, the solution
/// was stored during the `Phase::Unsigned`. `Root` signals that the solution was stored by
/// `T::ForceOrigin`. The `bool` is `true` when a previous solution was ejected to make
/// room for this one.
SolutionStored {
compute: ElectionCompute,
account_id: Option<T::AccountId>,
origin: RawOrigin<T::AccountId>,
prev_ejected: bool,
},
/// The election has been finalized, with the given computation and score.
Expand Down Expand Up @@ -2175,27 +2174,27 @@ mod tests {
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::Slashed { account: 99, value: 5 },
Expand Down Expand Up @@ -2238,7 +2237,7 @@ mod tests {
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::Rewarded { account: 99, value: 7 },
Expand Down Expand Up @@ -2288,7 +2287,7 @@ mod tests {
Event::UnsignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Unsigned,
account_id: None,
origin: RawOrigin::None,
prev_ejected: false
},
Event::ElectionFinalized {
Expand Down Expand Up @@ -2403,7 +2402,7 @@ mod tests {
Event::EmergencyPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Fallback,
account_id: None,
origin: RawOrigin::Root,
prev_ejected: false
},
Event::ElectionFinalized {
Expand Down
38 changes: 19 additions & 19 deletions frame/election-provider-multi-phase/src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ mod tests {
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
}
]
Expand Down Expand Up @@ -652,7 +652,7 @@ mod tests {
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::Rewarded { account: 99, value: 7 }
Expand Down Expand Up @@ -687,7 +687,7 @@ mod tests {
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::Slashed { account: 99, value: 5 }
Expand Down Expand Up @@ -728,12 +728,12 @@ mod tests {
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(999),
origin: RawOrigin::Signed(999),
prev_ejected: false
},
Event::Rewarded { account: 99, value: 7 }
Expand Down Expand Up @@ -811,27 +811,27 @@ mod tests {
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(100),
origin: RawOrigin::Signed(100),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(101),
origin: RawOrigin::Signed(101),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(102),
origin: RawOrigin::Signed(102),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(103),
origin: RawOrigin::Signed(103),
prev_ejected: false
},
Event::Rewarded { account: 99, value: 7 },
Expand Down Expand Up @@ -899,12 +899,12 @@ mod tests {
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: true
}
]
Expand Down Expand Up @@ -1157,17 +1157,17 @@ mod tests {
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(100),
origin: RawOrigin::Signed(100),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(101),
origin: RawOrigin::Signed(101),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(102),
origin: RawOrigin::Signed(102),
prev_ejected: false
},
Event::Rewarded { account: 100, value: 7 },
Expand Down Expand Up @@ -1227,17 +1227,17 @@ mod tests {
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(999),
origin: RawOrigin::Signed(999),
prev_ejected: false
},
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(9999),
origin: RawOrigin::Signed(9999),
prev_ejected: false
},
Event::Slashed { account: 999, value: 5 },
Expand Down Expand Up @@ -1373,7 +1373,7 @@ mod tests {
Event::SignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Signed,
account_id: Some(99),
origin: RawOrigin::Signed(99),
prev_ejected: false
},
Event::Rewarded { account: 99, value: 7 }
Expand Down
2 changes: 1 addition & 1 deletion frame/election-provider-multi-phase/src/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ mod tests {
Event::UnsignedPhaseStarted { round: 1 },
Event::SolutionStored {
compute: ElectionCompute::Unsigned,
account_id: None,
origin: RawOrigin::None,
prev_ejected: false
}
]
Expand Down