fix: Complete snowbridge pezpallet rebrand and critical bug fixes
- snowbridge-pezpallet-* → pezsnowbridge-pezpallet-* (201 refs) - pallet/ directories → pezpallet/ (4 locations) - Fixed pezpallet.rs self-include recursion bug - Fixed sc-chain-spec hardcoded crate name in derive macro - Reverted .pezpallet_by_name() to .pallet_by_name() (subxt API) - Added BizinikiwiConfig type alias for zombienet tests - Deleted obsolete session state files Verified: pezsnowbridge-pezpallet-*, pezpallet-staking, pezpallet-staking-async, pezframe-benchmarking-cli all pass cargo check
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
use crate::{
|
||||
verifier::{self, Verifier},
|
||||
Config, CurrentPhase, Pallet, Phase, Snapshot,
|
||||
Config, CurrentPhase, Pezpallet, Phase, Snapshot,
|
||||
};
|
||||
use pezframe_benchmarking::v2::*;
|
||||
use pezframe_election_provider_support::{ElectionDataProvider, ElectionProvider};
|
||||
@@ -28,7 +28,7 @@ benchmark with enough genesis stakers in staking (DataProvider) to fill a page o
|
||||
as per VoterSnapshotPerBlock and TargetSnapshotPerBlock. Generate at least \
|
||||
2 * VoterSnapshotPerBlock) nominators and TargetSnapshotPerBlock validators";
|
||||
|
||||
// TODO: remove unwraps from all benchmarks of this pallet -- it makes debugging via wasm harder
|
||||
// TODO: remove unwraps from all benchmarks of this pezpallet -- it makes debugging via wasm harder
|
||||
|
||||
#[benchmarks(where T: crate::signed::Config + crate::unsigned::Config + crate::verifier::Config)]
|
||||
mod benchmarks {
|
||||
@@ -40,7 +40,7 @@ mod benchmarks {
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::roll_next(true, false);
|
||||
Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
|
||||
assert_eq!(CurrentPhase::<T>::get(), Phase::Off);
|
||||
@@ -53,13 +53,13 @@ mod benchmarks {
|
||||
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
assert_eq!(CurrentPhase::<T>::get(), Phase::Snapshot(T::Pages::get()));
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::roll_next(true, false);
|
||||
Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
|
||||
// we have collected the target snapshot only
|
||||
@@ -81,10 +81,10 @@ mod benchmarks {
|
||||
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
// roll to the first block of the snapshot.
|
||||
Pallet::<T>::roll_until_matches(|| {
|
||||
Pezpallet::<T>::roll_until_matches(|| {
|
||||
CurrentPhase::<T>::get() == Phase::Snapshot(T::Pages::get() - 1)
|
||||
});
|
||||
|
||||
@@ -99,7 +99,7 @@ mod benchmarks {
|
||||
// take one more snapshot page.
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::roll_next(true, false);
|
||||
Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
|
||||
// we have now collected the first page of voters.
|
||||
@@ -118,9 +118,9 @@ mod benchmarks {
|
||||
fn on_initialize_into_signed() -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
Pallet::<T>::roll_until_before_matches(|| {
|
||||
Pezpallet::<T>::roll_until_before_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::Signed(_))
|
||||
});
|
||||
|
||||
@@ -128,7 +128,7 @@ mod benchmarks {
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::roll_next(true, false);
|
||||
Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
|
||||
assert!(CurrentPhase::<T>::get().is_signed());
|
||||
@@ -140,9 +140,9 @@ mod benchmarks {
|
||||
fn on_initialize_into_signed_validation() -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
Pallet::<T>::roll_until_before_matches(|| {
|
||||
Pezpallet::<T>::roll_until_before_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::SignedValidation(_))
|
||||
});
|
||||
|
||||
@@ -150,7 +150,7 @@ mod benchmarks {
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::roll_next(true, false);
|
||||
Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -160,16 +160,16 @@ mod benchmarks {
|
||||
fn on_initialize_into_unsigned() -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
Pallet::<T>::roll_until_before_matches(|| {
|
||||
Pezpallet::<T>::roll_until_before_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::Unsigned(_))
|
||||
});
|
||||
assert!(matches!(CurrentPhase::<T>::get(), Phase::SignedValidation(_)));
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::roll_next(true, false);
|
||||
Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
|
||||
assert!(matches!(CurrentPhase::<T>::get(), Phase::Unsigned(_)));
|
||||
@@ -180,14 +180,14 @@ mod benchmarks {
|
||||
fn export_non_terminal() -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
// submit a full solution.
|
||||
crate::Pallet::<T>::roll_to_signed_and_submit_full_solution()?;
|
||||
crate::Pezpallet::<T>::roll_to_signed_and_submit_full_solution()?;
|
||||
|
||||
// fully verify it in the signed validation phase.
|
||||
assert!(T::Verifier::queued_score().is_none());
|
||||
crate::Pallet::<T>::roll_until_matches(|| {
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::Unsigned(_))
|
||||
});
|
||||
|
||||
@@ -196,7 +196,7 @@ mod benchmarks {
|
||||
assert_eq!(verifier::QueuedSolution::<T>::valid_iter().count() as u32, T::Pages::get());
|
||||
|
||||
// Roll to Done phase to start export
|
||||
crate::Pallet::<T>::roll_until_matches(|| CurrentPhase::<T>::get().is_done());
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| CurrentPhase::<T>::get().is_done());
|
||||
|
||||
#[block]
|
||||
{
|
||||
@@ -215,14 +215,14 @@ mod benchmarks {
|
||||
fn export_terminal() -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
// submit a full solution.
|
||||
crate::Pallet::<T>::roll_to_signed_and_submit_full_solution()?;
|
||||
crate::Pezpallet::<T>::roll_to_signed_and_submit_full_solution()?;
|
||||
|
||||
// fully verify it in the signed validation phase.
|
||||
ensure!(T::Verifier::queued_score().is_none(), "nothing should be queued");
|
||||
crate::Pallet::<T>::roll_until_matches(|| {
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::Unsigned(_))
|
||||
});
|
||||
|
||||
@@ -234,7 +234,7 @@ mod benchmarks {
|
||||
);
|
||||
|
||||
// Roll to Done phase
|
||||
crate::Pallet::<T>::roll_until_matches(|| CurrentPhase::<T>::get().is_done());
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| CurrentPhase::<T>::get().is_done());
|
||||
|
||||
// Start export and fetch all pages except the last one
|
||||
(1..=T::Pages::get() - 1).rev().for_each(T::DataProvider::fetch_page);
|
||||
@@ -257,10 +257,10 @@ mod benchmarks {
|
||||
// heaviest case is emergency set.
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
// roll to signed so the snapshot exists
|
||||
Pallet::<T>::roll_until_before_matches(|| {
|
||||
Pezpallet::<T>::roll_until_before_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::Signed(_))
|
||||
});
|
||||
|
||||
@@ -271,7 +271,7 @@ mod benchmarks {
|
||||
#[block]
|
||||
{
|
||||
// fallback might decide to fail, that's okay..
|
||||
let maybe_err = Pallet::<T>::manage(origin, crate::ManagerOperation::EmergencyFallback);
|
||||
let maybe_err = Pezpallet::<T>::manage(origin, crate::ManagerOperation::EmergencyFallback);
|
||||
//.. but it cannot be bad origin.
|
||||
assert!(maybe_err.is_ok() || maybe_err.unwrap_err() != DispatchError::BadOrigin.into());
|
||||
}
|
||||
@@ -284,10 +284,10 @@ mod benchmarks {
|
||||
// heaviest case is emergency set.
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
// mine a single page solution.
|
||||
let solution = crate::Pallet::<T>::roll_to_signed_and_mine_solution(1);
|
||||
let solution = crate::Pezpallet::<T>::roll_to_signed_and_mine_solution(1);
|
||||
|
||||
// verify to get the support.
|
||||
let (voter_pages, all_targets, desired_targets) =
|
||||
@@ -316,7 +316,7 @@ mod benchmarks {
|
||||
.map_err(|_| -> BenchmarkError { "cannot create admin origin".into() })?;
|
||||
#[block]
|
||||
{
|
||||
assert_ok!(Pallet::<T>::admin(
|
||||
assert_ok!(Pezpallet::<T>::admin(
|
||||
origin,
|
||||
crate::AdminOperation::EmergencySetSolution(
|
||||
pezsp_std::boxed::Box::new(single_support),
|
||||
@@ -332,7 +332,7 @@ mod benchmarks {
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Pallet,
|
||||
Pezpallet,
|
||||
crate::mock::ExtBuilder::full().build_unchecked(),
|
||||
crate::mock::Runtime
|
||||
);
|
||||
|
||||
@@ -26,18 +26,18 @@ use pezframe_support::{traits::Get, BoundedVec};
|
||||
use pezsp_runtime::SaturatedConversion;
|
||||
use pezsp_std::{collections::btree_map::BTreeMap, convert::TryInto, prelude::*};
|
||||
|
||||
/// Emit a log specific to this pallet, setting the target to [`crate::LOG_PREFIX`]
|
||||
/// Emit a log specific to this pezpallet, setting the target to [`crate::LOG_PREFIX`]
|
||||
#[macro_export]
|
||||
macro_rules! log {
|
||||
($level:tt, $pattern:expr $(, $values:expr)* $(,)?) => {
|
||||
log::$level!(
|
||||
target: $crate::LOG_PREFIX,
|
||||
concat!("[#{:?}] 🗳🗳🗳 ", $pattern), <pezframe_system::Pallet<T>>::block_number() $(, $values)*
|
||||
concat!("[#{:?}] 🗳🗳🗳 ", $pattern), <pezframe_system::Pezpallet<T>>::block_number() $(, $values)*
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
/// Emit a log within a submodule of the pallet
|
||||
/// Emit a log within a submodule of the pezpallet
|
||||
#[macro_export]
|
||||
macro_rules! sublog {
|
||||
($level:tt, $sub_pallet:tt, $pattern:expr $(, $values:expr)* $(,)?) => {
|
||||
@@ -46,7 +46,7 @@ macro_rules! sublog {
|
||||
#[cfg(feature = "std")]
|
||||
log::$level!(
|
||||
target: format!("{}::{}", $crate::LOG_PREFIX, $sub_pallet).as_ref(),
|
||||
concat!("[#{:?}] 🗳🗳🗳 ", $pattern), <pezframe_system::Pallet<T>>::block_number() $(, $values )*
|
||||
concat!("[#{:?}] 🗳🗳🗳 ", $pattern), <pezframe_system::Pezpallet<T>>::block_number() $(, $values )*
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! # Multi-phase, multi-block, election provider pallet.
|
||||
//! # Multi-phase, multi-block, election provider pezpallet.
|
||||
//!
|
||||
//! > This pallet is sometimes abbreviated as `EPMB`, and `pezpallet_election_provider_multi_phase` as
|
||||
//! > This pezpallet is sometimes abbreviated as `EPMB`, and `pezpallet_election_provider_multi_phase` as
|
||||
//! > `EPM`.
|
||||
//!
|
||||
//! ## Overall idea
|
||||
@@ -28,40 +28,40 @@
|
||||
//! Nonetheless, it has a limited capacity in terms of number of voters it can process in a **single
|
||||
//! block**.
|
||||
//!
|
||||
//! This pallet takes `EPM` system, keeps most of its ideas and core premises, and extends it to
|
||||
//! support paginated, multi-block operations. The final goal of this pallet is to scale linearly
|
||||
//! This pezpallet takes `EPM` system, keeps most of its ideas and core premises, and extends it to
|
||||
//! support paginated, multi-block operations. The final goal of this pezpallet is to scale linearly
|
||||
//! with the number of blocks allocated to the elections. Moreover, the amount of work that it does
|
||||
//! in one block should be bounded and measurable, making it suitable for a teyrchain. In principle,
|
||||
//! with large enough blocks (in a dedicated teyrchain), the number of voters included in the NPoS
|
||||
//! system can grow significantly (yet, obviously not indefinitely).
|
||||
//!
|
||||
//! Note that this pallet does not consider how the recipient is processing the results. To ensure
|
||||
//! scalability, the recipient of this pallet's data (i.e. `pezpallet-staking`) must also be capable of
|
||||
//! Note that this pezpallet does not consider how the recipient is processing the results. To ensure
|
||||
//! scalability, the recipient of this pezpallet's data (i.e. `pezpallet-staking`) must also be capable of
|
||||
//! pagination and multi-block processing.
|
||||
//!
|
||||
//! ## Companion pallets
|
||||
//!
|
||||
//! This pallet will only function in a sensible way if it is peered with its companion pallets.
|
||||
//! This pezpallet will only function in a sensible way if it is peered with its companion pallets.
|
||||
//!
|
||||
//! - The [`verifier`] pallet provides a standard implementation of the [`verifier::Verifier`]. This
|
||||
//! pallet is mandatory.
|
||||
//! - The [`verifier`] pezpallet provides a standard implementation of the [`verifier::Verifier`]. This
|
||||
//! pezpallet is mandatory.
|
||||
//! - The [`unsigned`] module provides the implementation of unsigned submission by validators. If
|
||||
//! this pallet is included, then [`Config::UnsignedPhase`] will determine its duration.
|
||||
//! this pezpallet is included, then [`Config::UnsignedPhase`] will determine its duration.
|
||||
//! - The [`signed`] module provides the implementation of the signed submission by any account. If
|
||||
//! this pallet is included, the combined [`Config::SignedPhase`] and
|
||||
//! this pezpallet is included, the combined [`Config::SignedPhase`] and
|
||||
//! [`Config::SignedValidationPhase`] will determine its duration
|
||||
//!
|
||||
//! These pallets are in fact hierarchical. This particular one is the top level one. It contains
|
||||
//! the shared information that all child pallets use. All child pallets depend on the top level
|
||||
//! pallet ONLY, but not the other way around. For those cases, traits are used.
|
||||
//! pezpallet ONLY, but not the other way around. For those cases, traits are used.
|
||||
//!
|
||||
//! As in, notice that [`crate::verifier::Config`] relies on [`crate::Config`], but for the
|
||||
//! reverse, we rely on [`crate::verifier::Verifier`] trait, which is indeed part of
|
||||
//! [`crate::Config`]. This is merely an implementation opinion.
|
||||
//!
|
||||
//! ### Pallet Ordering:
|
||||
//! ### Pezpallet Ordering:
|
||||
//!
|
||||
//! TODO: @kiaenigma: this needs clarification and a enforcement. Signed pallet should come first.
|
||||
//! TODO: @kiaenigma: this needs clarification and a enforcement. Signed pezpallet should come first.
|
||||
//! Fixing this should yield removing `verifier_done` from the phase transition.
|
||||
//!
|
||||
//! The ordering of these pallets in a runtime should be:
|
||||
@@ -76,14 +76,14 @@
|
||||
//!
|
||||
//! ## Pagination
|
||||
//!
|
||||
//! Most of the external APIs of this pallet are paginated. All pagination follow a pattern where if
|
||||
//! Most of the external APIs of this pezpallet are paginated. All pagination follow a pattern where if
|
||||
//! `N` pages exist, the first paginated call is `function(N-1)` and the last one is `function(0)`.
|
||||
//! For example, with 3 pages, the `elect` of [`ElectionProvider`] is expected to be called as
|
||||
//! `elect(2) -> elect(1) -> elect(0)`. In essence, calling a paginated function with index 0 is
|
||||
//! always a signal of termination, meaning that no further calls will follow.
|
||||
//!
|
||||
//! The snapshot creation for voters (Nominators in staking), submission of signed pages, validation
|
||||
//! of signed solutions and exporting of pages are all paginated. Note that this pallet is yet to
|
||||
//! of signed solutions and exporting of pages are all paginated. Note that this pezpallet is yet to
|
||||
//! support paginated target (Validators in staking) snapshotting.
|
||||
//!
|
||||
//! ### Terminology Note: `msp` and `lsp`
|
||||
@@ -94,13 +94,13 @@
|
||||
//!
|
||||
//! ## Phases
|
||||
//!
|
||||
//! The operations in this pallet are divided intor rounds, a `u32` number stored in [`Round`].
|
||||
//! This value helps this pallet organize itself, and leaves the door open for lazy deletion of any
|
||||
//! The operations in this pezpallet are divided intor rounds, a `u32` number stored in [`Round`].
|
||||
//! This value helps this pezpallet organize itself, and leaves the door open for lazy deletion of any
|
||||
//! stale data. A round, under the happy path, starts by receiving the call to
|
||||
//! [`ElectionProvider::start`], and is terminated by receiving a call to
|
||||
//! [`ElectionProvider::elect`] with value 0.
|
||||
//!
|
||||
//! The timeline of pallet is overall as follows:
|
||||
//! The timeline of pezpallet is overall as follows:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! < Off >
|
||||
@@ -121,10 +121,10 @@
|
||||
//! * Duration of `Signed`, `SignedValidation` and `Unsigned` are determined by
|
||||
//! [`Config::SignedPhase`], [`Config::SignedValidationPhase`] and [`Config::UnsignedPhase`]
|
||||
//! respectively.
|
||||
//! * [`Config::Pages`] calls to elect are expected, but all in all the pallet will close a round
|
||||
//! * [`Config::Pages`] calls to elect are expected, but all in all the pezpallet will close a round
|
||||
//! once `elect(0)` is called.
|
||||
//!
|
||||
//! > Given this, it is rather important for the user of this pallet to ensure it always terminates
|
||||
//! > Given this, it is rather important for the user of this pezpallet to ensure it always terminates
|
||||
//! > election via `elect` before requesting a new one.
|
||||
//!
|
||||
//! ## Feasible Solution (correct solution)
|
||||
@@ -149,7 +149,7 @@
|
||||
//!
|
||||
//! 1. Do nothing: [`Continue`]
|
||||
//! 2. Force us into the emergency phase: [`crate::InitiateEmergencyPhase`]. This initiates
|
||||
//! [`Phase::Emergency`], which will halt almost all operations of this pallet, and it can only
|
||||
//! [`Phase::Emergency`], which will halt almost all operations of this pezpallet, and it can only
|
||||
//! be recovered by [`AdminOperation`], dispatched via [`Call::manage`].
|
||||
//! 3. compute an onchain from the give page of snapshot.
|
||||
//!
|
||||
@@ -163,7 +163,7 @@
|
||||
//! we don't have another choice as we cannot request another smaller snapshot from the data
|
||||
//! provider mid-election without more bookkeeping on the staking side.
|
||||
//!
|
||||
//! If onchain solution is to be seriously considered, an improvement to this pallet should
|
||||
//! If onchain solution is to be seriously considered, an improvement to this pezpallet should
|
||||
//! re-request a smaller set of voters from `T::DataProvider` in a stateless manner.
|
||||
//!
|
||||
//! ### Signed Phase
|
||||
@@ -182,15 +182,15 @@
|
||||
// - Naming convention is: `${singular}_page` for singular, e.g. `voter_page` for `Vec<Voter>`.
|
||||
// `paged_${plural}` for plural, e.g. `paged_voters` for `Vec<Vec<Voter>>`.
|
||||
//
|
||||
// - Since this crate has multiple `Pallet` and `Configs`, in each sub-pallet, we only reference the
|
||||
// local `Pallet` without a prefix and allow it to be imported via `use`. Avoid `super::Pallet`
|
||||
// except for the case of a modules that want to reference their local `Pallet` . The
|
||||
// `crate::Pallet` is always reserved for the parent pallet. Other sibling pallets must be
|
||||
// referenced with full path, e.g. `crate::Verifier::Pallet`. Do NOT write something like `use
|
||||
// unsigned::Pallet as UnsignedPallet`.
|
||||
// - Since this crate has multiple `Pezpallet` and `Configs`, in each sub-pezpallet, we only reference the
|
||||
// local `Pezpallet` without a prefix and allow it to be imported via `use`. Avoid `super::Pezpallet`
|
||||
// except for the case of a modules that want to reference their local `Pezpallet` . The
|
||||
// `crate::Pezpallet` is always reserved for the parent pezpallet. Other sibling pallets must be
|
||||
// referenced with full path, e.g. `crate::Verifier::Pezpallet`. Do NOT write something like `use
|
||||
// unsigned::Pezpallet as UnsignedPallet`.
|
||||
//
|
||||
// - Respecting private storage items with wrapper We move all implementations out of the `mod
|
||||
// pallet` as much as possible to ensure we NEVER access the internal storage items directly. All
|
||||
// pezpallet` as much as possible to ensure we NEVER access the internal storage items directly. All
|
||||
// operations should happen with the wrapper types.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
@@ -239,22 +239,22 @@ macro_rules! clear_round_based_map {
|
||||
}};
|
||||
}
|
||||
|
||||
/// The signed pallet
|
||||
/// The signed pezpallet
|
||||
pub mod signed;
|
||||
/// Common types of the pallet
|
||||
/// Common types of the pezpallet
|
||||
pub mod types;
|
||||
/// The unsigned pallet
|
||||
/// The unsigned pezpallet
|
||||
pub mod unsigned;
|
||||
/// The verifier pallet
|
||||
/// The verifier pezpallet
|
||||
pub mod verifier;
|
||||
/// The weight module
|
||||
pub mod weights;
|
||||
|
||||
pub use pallet::*;
|
||||
pub use pezpallet::*;
|
||||
pub use types::*;
|
||||
pub use weights::traits::pezpallet_election_provider_multi_block::WeightInfo;
|
||||
|
||||
/// A fallback implementation that transitions the pallet to the emergency phase.
|
||||
/// A fallback implementation that transitions the pezpallet to the emergency phase.
|
||||
pub struct InitiateEmergencyPhase<T>(pezsp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> ElectionProvider for InitiateEmergencyPhase<T> {
|
||||
type AccountId = T::AccountId;
|
||||
@@ -267,7 +267,7 @@ impl<T: Config> ElectionProvider for InitiateEmergencyPhase<T> {
|
||||
type MaxBackersPerWinnerFinal = <T::Verifier as Verifier>::MaxBackersPerWinnerFinal;
|
||||
|
||||
fn elect(_page: PageIndex) -> Result<BoundedSupportsOf<Self>, Self::Error> {
|
||||
Pallet::<T>::phase_transition(Phase::Emergency);
|
||||
Pezpallet::<T>::phase_transition(Phase::Emergency);
|
||||
Err("Emergency phase started.")
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ impl<T: Config, Queued, NotQueued> IfSolutionQueuedElse<T, Queued, NotQueued> {
|
||||
let queued_score = <T::Verifier as verifier::Verifier>::queued_score().is_some();
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let any_pages_queued = (Pallet::<T>::lsp()..=Pallet::<T>::msp()).any(|p| {
|
||||
let any_pages_queued = (Pezpallet::<T>::lsp()..=Pezpallet::<T>::msp()).any(|p| {
|
||||
<T::Verifier as verifier::Verifier>::get_queued_solution_page(p).is_some()
|
||||
});
|
||||
assert_eq!(
|
||||
@@ -407,9 +407,9 @@ impl<T: Config, Queued: Get<Phase<T>>, NotQueued: Get<Phase<T>>> Get<Phase<T>>
|
||||
}
|
||||
}
|
||||
|
||||
/// Internal errors of the pallet. This is used in the implementation of [`ElectionProvider`].
|
||||
/// Internal errors of the pezpallet. This is used in the implementation of [`ElectionProvider`].
|
||||
///
|
||||
/// Note that this is different from [`pallet::Error`].
|
||||
/// Note that this is different from [`pezpallet::Error`].
|
||||
#[derive(
|
||||
pezframe_support::DebugNoBound, pezframe_support::PartialEqNoBound, pezframe_support::EqNoBound,
|
||||
)]
|
||||
@@ -446,7 +446,7 @@ impl<T: Config> From<verifier::FeasibilityError> for ElectionError<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Different operations that only the [`Config::AdminOrigin`] can perform on the pallet.
|
||||
/// Different operations that only the [`Config::AdminOrigin`] can perform on the pezpallet.
|
||||
#[derive(
|
||||
Encode,
|
||||
Decode,
|
||||
@@ -464,7 +464,7 @@ pub enum AdminOperation<T: Config> {
|
||||
/// Set the given (single page) emergency solution.
|
||||
///
|
||||
/// Can only be called in emergency phase.
|
||||
EmergencySetSolution(Box<BoundedSupportsOf<Pallet<T>>>, ElectionScore),
|
||||
EmergencySetSolution(Box<BoundedSupportsOf<Pezpallet<T>>>, ElectionScore),
|
||||
/// Set the minimum untrusted score. This is directly communicated to the verifier component to
|
||||
/// be taken into account.
|
||||
///
|
||||
@@ -474,7 +474,7 @@ pub enum AdminOperation<T: Config> {
|
||||
}
|
||||
|
||||
/// Different operations that the [`Config::ManagerOrigin`] (or [`Config::AdminOrigin`]) can perform
|
||||
/// on the pallet.
|
||||
/// on the pezpallet.
|
||||
#[derive(
|
||||
Encode,
|
||||
Decode,
|
||||
@@ -516,7 +516,7 @@ impl OnRoundRotation for () {
|
||||
/// pallets, once the round is over.
|
||||
///
|
||||
/// This is intended to be phased out once we move to fully lazy deletion system to spare more PoV.
|
||||
/// In that case, simply use `()` on [`pallet::Config::OnRoundRotation`].
|
||||
/// In that case, simply use `()` on [`pezpallet::Config::OnRoundRotation`].
|
||||
pub struct CleanRound<T>(core::marker::PhantomData<T>);
|
||||
impl<T: Config> OnRoundRotation for CleanRound<T> {
|
||||
fn on_round_rotation(_ending: u32) {
|
||||
@@ -524,38 +524,38 @@ impl<T: Config> OnRoundRotation for CleanRound<T> {
|
||||
T::Verifier::kill();
|
||||
|
||||
// Kill the snapshot.
|
||||
pallet::Snapshot::<T>::kill();
|
||||
pezpallet::Snapshot::<T>::kill();
|
||||
|
||||
// Nothing to do in the signed pallet -- it is already in lazy-deletion mode.
|
||||
// Nothing to do in the signed pezpallet -- it is already in lazy-deletion mode.
|
||||
}
|
||||
}
|
||||
|
||||
#[pezframe_support::pallet]
|
||||
pub mod pallet {
|
||||
#[pezframe_support::pezpallet]
|
||||
pub mod pezpallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {
|
||||
/// Duration of the unsigned phase.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type UnsignedPhase: Get<BlockNumberFor<Self>>;
|
||||
/// Duration of the signed phase.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type SignedPhase: Get<BlockNumberFor<Self>>;
|
||||
/// Duration of the singed validation phase.
|
||||
///
|
||||
/// The duration of this should not be less than `T::Pages`, and there is no point in it
|
||||
/// being more than `SignedPhase::MaxSubmission::get() * T::Pages`. TODO: integrity test for
|
||||
/// it.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type SignedValidationPhase: Get<BlockNumberFor<Self>>;
|
||||
|
||||
/// The number of snapshot voters to fetch per block.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type VoterSnapshotPerBlock: Get<u32>;
|
||||
|
||||
/// The number of snapshot targets to fetch per block.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type TargetSnapshotPerBlock: Get<u32>;
|
||||
|
||||
/// The number of pages.
|
||||
@@ -564,7 +564,7 @@ pub mod pallet {
|
||||
///
|
||||
/// The solutions may contain at MOST this many pages, but less pages are acceptable as
|
||||
/// well.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type Pages: Get<PageIndex>;
|
||||
|
||||
/// Something that will provide the election data.
|
||||
@@ -596,15 +596,15 @@ pub mod pallet {
|
||||
MaxWinnersPerPage = <Self::Verifier as verifier::Verifier>::MaxWinnersPerPage,
|
||||
>;
|
||||
|
||||
/// The verifier pallet's interface.
|
||||
/// The verifier pezpallet's interface.
|
||||
type Verifier: verifier::Verifier<
|
||||
Solution = SolutionOf<Self::MinerConfig>,
|
||||
AccountId = Self::AccountId,
|
||||
> + verifier::AsynchronousVerifier;
|
||||
|
||||
/// The origin that can perform administration operations on this pallet.
|
||||
/// The origin that can perform administration operations on this pezpallet.
|
||||
///
|
||||
/// This is the highest privilege origin of this pallet, and should be configured
|
||||
/// This is the highest privilege origin of this pezpallet, and should be configured
|
||||
/// restrictively.
|
||||
type AdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
@@ -618,7 +618,7 @@ pub mod pallet {
|
||||
/// Common implementation is [`ProceedRegardlessOf`] or [`RevertToSignedIfNotQueuedOf`].
|
||||
type AreWeDone: Get<Phase<Self>>;
|
||||
|
||||
/// The weight of the pallet.
|
||||
/// The weight of the pezpallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
|
||||
/// Single type that implement [`super::OnRoundRotation`] to do something when the round
|
||||
@@ -626,15 +626,15 @@ pub mod pallet {
|
||||
type OnRoundRotation: super::OnRoundRotation;
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Manage this pallet.
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
/// Manage this pezpallet.
|
||||
///
|
||||
/// The origin of this call must be [`Config::ManagerOrigin`].
|
||||
///
|
||||
/// See [`ManagerOperation`] for various operations that are possible.
|
||||
#[pallet::weight(T::WeightInfo::manage_fallback().max(T::WeightInfo::export_terminal()))]
|
||||
#[pallet::call_index(0)]
|
||||
#[pezpallet::weight(T::WeightInfo::manage_fallback().max(T::WeightInfo::export_terminal()))]
|
||||
#[pezpallet::call_index(0)]
|
||||
pub fn manage(origin: OriginFor<T>, op: ManagerOperation<T>) -> DispatchResultWithPostInfo {
|
||||
T::ManagerOrigin::ensure_origin(origin.clone()).map(|_| ()).or_else(|_| {
|
||||
// try admin origin as well as admin is a superset.
|
||||
@@ -682,8 +682,8 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight(T::WeightInfo::admin_set())]
|
||||
#[pezpallet::call_index(1)]
|
||||
#[pezpallet::weight(T::WeightInfo::admin_set())]
|
||||
pub fn admin(origin: OriginFor<T>, op: AdminOperation<T>) -> DispatchResultWithPostInfo {
|
||||
T::AdminOrigin::ensure_origin(origin)?;
|
||||
match op {
|
||||
@@ -706,8 +706,8 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
#[pezpallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pezpallet<T> {
|
||||
fn on_initialize(_now: BlockNumberFor<T>) -> Weight {
|
||||
let current_phase = CurrentPhase::<T>::get();
|
||||
let weight1 = match current_phase {
|
||||
@@ -790,7 +790,7 @@ pub mod pallet {
|
||||
// We only accept data provider who's maximum votes per voter matches our
|
||||
// `T::Solution`'s `LIMIT`.
|
||||
//
|
||||
// NOTE that this pallet does not really need to enforce this in runtime. The
|
||||
// NOTE that this pezpallet does not really need to enforce this in runtime. The
|
||||
// solution cannot represent any voters more than `LIMIT` anyhow.
|
||||
assert_eq!(
|
||||
<T::DataProvider as ElectionDataProvider>::MaxVotesPerVoter::get(),
|
||||
@@ -821,8 +821,8 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
#[pezpallet::event]
|
||||
#[pezpallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// A phase transition happened. Only checks major changes in the variants, not minor inner
|
||||
/// values.
|
||||
@@ -838,8 +838,8 @@ pub mod pallet {
|
||||
UnexpectedVoterSnapshotFailed,
|
||||
}
|
||||
|
||||
/// Error of the pallet that can be returned in response to dispatches.
|
||||
#[pallet::error]
|
||||
/// Error of the pezpallet that can be returned in response to dispatches.
|
||||
#[pezpallet::error]
|
||||
pub enum Error<T> {
|
||||
/// Triggering the `Fallback` failed.
|
||||
Fallback,
|
||||
@@ -871,16 +871,16 @@ pub mod pallet {
|
||||
/// Internal counter for the number of rounds.
|
||||
///
|
||||
/// This is useful for de-duplication of transactions submitted to the pool, and general
|
||||
/// diagnostics of the pallet.
|
||||
/// diagnostics of the pezpallet.
|
||||
///
|
||||
/// This is merely incremented once per every time that an upstream `elect` is called.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn round)]
|
||||
#[pezpallet::storage]
|
||||
#[pezpallet::getter(fn round)]
|
||||
pub type Round<T: Config> = StorageValue<_, u32, ValueQuery>;
|
||||
|
||||
/// Current phase.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn current_phase)]
|
||||
#[pezpallet::storage]
|
||||
#[pezpallet::getter(fn current_phase)]
|
||||
pub type CurrentPhase<T: Config> = StorageValue<_, Phase<T>, ValueQuery>;
|
||||
|
||||
/// Wrapper struct for working with snapshots.
|
||||
@@ -928,10 +928,10 @@ pub mod pallet {
|
||||
|
||||
pub(crate) fn set_targets(targets: BoundedVec<T::AccountId, T::TargetSnapshotPerBlock>) {
|
||||
let hash = Self::write_storage_with_pre_allocate(
|
||||
&PagedTargetSnapshot::<T>::hashed_key_for(Self::round(), Pallet::<T>::msp()),
|
||||
&PagedTargetSnapshot::<T>::hashed_key_for(Self::round(), Pezpallet::<T>::msp()),
|
||||
targets,
|
||||
);
|
||||
PagedTargetSnapshotHash::<T>::insert(Self::round(), Pallet::<T>::msp(), hash);
|
||||
PagedTargetSnapshotHash::<T>::insert(Self::round(), Pezpallet::<T>::msp(), hash);
|
||||
}
|
||||
|
||||
pub(crate) fn set_voters(page: PageIndex, voters: VoterPageOf<T::MinerConfig>) {
|
||||
@@ -964,7 +964,7 @@ pub mod pallet {
|
||||
|
||||
pub(crate) fn targets() -> Option<BoundedVec<T::AccountId, T::TargetSnapshotPerBlock>> {
|
||||
// NOTE: targets always have one index, which is 0, aka lsp.
|
||||
PagedTargetSnapshot::<T>::get(Self::round(), Pallet::<T>::msp())
|
||||
PagedTargetSnapshot::<T>::get(Self::round(), Pezpallet::<T>::msp())
|
||||
}
|
||||
|
||||
/// Get a fingerprint of the snapshot, from all the hashes that are stored for each page of
|
||||
@@ -976,7 +976,7 @@ pub mod pallet {
|
||||
pub fn fingerprint() -> T::Hash {
|
||||
let mut hashed_target_and_voters =
|
||||
Self::targets_hash().unwrap_or_default().as_ref().to_vec();
|
||||
let hashed_voters = (Pallet::<T>::msp()..=Pallet::<T>::lsp())
|
||||
let hashed_voters = (Pezpallet::<T>::msp()..=Pezpallet::<T>::lsp())
|
||||
.map(|i| PagedVoterSnapshotHash::<T>::get(Self::round(), i).unwrap_or_default())
|
||||
.flat_map(|hash| <T::Hash as AsRef<[u8]>>::as_ref(&hash).to_owned())
|
||||
.collect::<Vec<u8>>();
|
||||
@@ -1001,11 +1001,11 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
pub(crate) fn targets_hash() -> Option<T::Hash> {
|
||||
PagedTargetSnapshotHash::<T>::get(Self::round(), Pallet::<T>::msp())
|
||||
PagedTargetSnapshotHash::<T>::get(Self::round(), Pezpallet::<T>::msp())
|
||||
}
|
||||
|
||||
fn round() -> u32 {
|
||||
Pallet::<T>::round()
|
||||
Pezpallet::<T>::round()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1034,7 +1034,7 @@ pub mod pallet {
|
||||
up_to_page = up_to_page.min(T::Pages::get());
|
||||
// ensure that voter pages that should exist, indeed to exist..
|
||||
let mut sum_existing_voters: usize = 0;
|
||||
for p in (crate::Pallet::<T>::lsp()..=crate::Pallet::<T>::msp())
|
||||
for p in (crate::Pezpallet::<T>::lsp()..=crate::Pezpallet::<T>::msp())
|
||||
.rev()
|
||||
.take(up_to_page as usize)
|
||||
{
|
||||
@@ -1052,7 +1052,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
// ..and those that should not exist, indeed DON'T.
|
||||
for p in (crate::Pallet::<T>::lsp()..=crate::Pallet::<T>::msp())
|
||||
for p in (crate::Pezpallet::<T>::lsp()..=crate::Pezpallet::<T>::msp())
|
||||
.take((T::Pages::get() - up_to_page) as usize)
|
||||
{
|
||||
ensure!(
|
||||
@@ -1083,7 +1083,7 @@ pub mod pallet {
|
||||
);
|
||||
|
||||
// ensure that voter pages that should exist, indeed to exist..
|
||||
for p in crate::Pallet::<T>::lsp()..=crate::Pallet::<T>::msp() {
|
||||
for p in crate::Pezpallet::<T>::lsp()..=crate::Pezpallet::<T>::msp() {
|
||||
ensure!(
|
||||
Self::voters_hash(p).is_some() &&
|
||||
Self::voters_decode_len(p).unwrap_or_default() as u32 ==
|
||||
@@ -1100,7 +1100,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
pub(crate) fn targets_decode_len() -> Option<usize> {
|
||||
PagedTargetSnapshot::<T>::decode_len(Self::round(), Pallet::<T>::msp())
|
||||
PagedTargetSnapshot::<T>::decode_len(Self::round(), Pezpallet::<T>::msp())
|
||||
}
|
||||
|
||||
pub(crate) fn voters_hash(page: PageIndex) -> Option<T::Hash> {
|
||||
@@ -1110,7 +1110,7 @@ pub mod pallet {
|
||||
pub(crate) fn sanity_check() -> Result<(), &'static str> {
|
||||
// check the snapshot existence based on the phase. This checks all of the needed
|
||||
// conditions except for the metadata values.
|
||||
let phase = Pallet::<T>::current_phase();
|
||||
let phase = Pezpallet::<T>::current_phase();
|
||||
let _ = match phase {
|
||||
// no page should exist in this phase.
|
||||
Phase::Off => Self::ensure_snapshot(false, T::Pages::get()),
|
||||
@@ -1151,7 +1151,7 @@ pub mod pallet {
|
||||
|
||||
pub(crate) fn voters_iter_flattened() -> impl Iterator<Item = VoterOf<T::MinerConfig>> {
|
||||
let key_range =
|
||||
(crate::Pallet::<T>::lsp()..=crate::Pallet::<T>::msp()).collect::<Vec<_>>();
|
||||
(crate::Pezpallet::<T>::lsp()..=crate::Pezpallet::<T>::msp()).collect::<Vec<_>>();
|
||||
key_range
|
||||
.into_iter()
|
||||
.flat_map(|k| PagedVoterSnapshot::<T>::get(Self::round(), k).unwrap_or_default())
|
||||
@@ -1166,20 +1166,20 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
pub(crate) fn remove_target_page() {
|
||||
PagedTargetSnapshot::<T>::remove(Self::round(), Pallet::<T>::msp());
|
||||
PagedTargetSnapshot::<T>::remove(Self::round(), Pezpallet::<T>::msp());
|
||||
}
|
||||
|
||||
pub(crate) fn remove_target(at: usize) {
|
||||
PagedTargetSnapshot::<T>::mutate(
|
||||
Self::round(),
|
||||
crate::Pallet::<T>::msp(),
|
||||
crate::Pezpallet::<T>::msp(),
|
||||
|maybe_targets| {
|
||||
if let Some(targets) = maybe_targets {
|
||||
targets.remove(at);
|
||||
// and update the hash.
|
||||
PagedTargetSnapshotHash::<T>::insert(
|
||||
Self::round(),
|
||||
crate::Pallet::<T>::msp(),
|
||||
crate::Pezpallet::<T>::msp(),
|
||||
T::Hashing::hash(&targets.encode()),
|
||||
)
|
||||
} else {
|
||||
@@ -1191,10 +1191,10 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
/// Desired number of targets to elect for this round.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type DesiredTargets<T> = StorageMap<_, Twox64Concat, u32, u32>;
|
||||
/// Paginated voter snapshot. At most [`T::Pages`] keys will exist.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type PagedVoterSnapshot<T: Config> = StorageDoubleMap<
|
||||
_,
|
||||
Twox64Concat,
|
||||
@@ -1206,13 +1206,13 @@ pub mod pallet {
|
||||
/// Same as [`PagedVoterSnapshot`], but it will store the hash of the snapshot.
|
||||
///
|
||||
/// The hash is generated using [`pezframe_system::Config::Hashing`].
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type PagedVoterSnapshotHash<T: Config> =
|
||||
StorageDoubleMap<_, Twox64Concat, u32, Twox64Concat, PageIndex, T::Hash>;
|
||||
/// Paginated target snapshot.
|
||||
///
|
||||
/// For the time being, since we assume one pages of targets, at most ONE key will exist.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type PagedTargetSnapshot<T: Config> = StorageDoubleMap<
|
||||
_,
|
||||
Twox64Concat,
|
||||
@@ -1224,15 +1224,15 @@ pub mod pallet {
|
||||
/// Same as [`PagedTargetSnapshot`], but it will store the hash of the snapshot.
|
||||
///
|
||||
/// The hash is generated using [`pezframe_system::Config::Hashing`].
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type PagedTargetSnapshotHash<T: Config> =
|
||||
StorageDoubleMap<_, Twox64Concat, u32, Twox64Concat, PageIndex, T::Hash>;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(PhantomData<T>);
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
/// Returns the most significant page of the snapshot.
|
||||
///
|
||||
/// Based on the contract of `ElectionDataProvider`, this is the first page that is filled.
|
||||
@@ -1440,7 +1440,7 @@ impl<T: Config> Pallet<T> {
|
||||
#[allow(unused)]
|
||||
#[cfg(any(feature = "runtime-benchmarks", test))]
|
||||
// helper code for testing and benchmarking
|
||||
impl<T> Pallet<T>
|
||||
impl<T> Pezpallet<T>
|
||||
where
|
||||
T: Config + crate::signed::Config + crate::unsigned::Config + crate::verifier::Config,
|
||||
BlockNumberFor<T>: From<u32>,
|
||||
@@ -1461,7 +1461,7 @@ where
|
||||
loop {
|
||||
let should_break = pezframe_support::storage::with_transaction(
|
||||
|| -> TransactionOutcome<Result<_, DispatchError>> {
|
||||
Pallet::<T>::roll_next(true, false);
|
||||
Pezpallet::<T>::roll_next(true, false);
|
||||
if criteria() {
|
||||
TransactionOutcome::Rollback(Ok(true))
|
||||
} else {
|
||||
@@ -1500,12 +1500,12 @@ where
|
||||
use types::Pagify;
|
||||
|
||||
// register alice
|
||||
let alice = crate::Pallet::<T>::funded_account("alice", 0);
|
||||
signed::Pallet::<T>::register(RawOrigin::Signed(alice.clone()).into(), score)?;
|
||||
let alice = crate::Pezpallet::<T>::funded_account("alice", 0);
|
||||
signed::Pezpallet::<T>::register(RawOrigin::Signed(alice.clone()).into(), score)?;
|
||||
|
||||
// submit pages
|
||||
for (index, page) in solution_pages.pagify(T::Pages::get()) {
|
||||
signed::Pallet::<T>::submit_page(
|
||||
signed::Pezpallet::<T>::submit_page(
|
||||
RawOrigin::Signed(alice.clone()).into(),
|
||||
index,
|
||||
Some(Box::new(page.clone())),
|
||||
@@ -1557,27 +1557,27 @@ where
|
||||
|
||||
/// Roll all pallets forward, for the given number of blocks.
|
||||
pub(crate) fn roll_to(n: BlockNumberFor<T>, with_signed: bool, try_state: bool) {
|
||||
let now = pezframe_system::Pallet::<T>::block_number();
|
||||
let now = pezframe_system::Pezpallet::<T>::block_number();
|
||||
assert!(n > now, "cannot roll to current or past block");
|
||||
let one: BlockNumberFor<T> = 1u32.into();
|
||||
let mut i = now + one;
|
||||
while i <= n {
|
||||
pezframe_system::Pallet::<T>::set_block_number(i);
|
||||
pezframe_system::Pezpallet::<T>::set_block_number(i);
|
||||
|
||||
Pallet::<T>::on_initialize(i);
|
||||
verifier::Pallet::<T>::on_initialize(i);
|
||||
unsigned::Pallet::<T>::on_initialize(i);
|
||||
Pezpallet::<T>::on_initialize(i);
|
||||
verifier::Pezpallet::<T>::on_initialize(i);
|
||||
unsigned::Pezpallet::<T>::on_initialize(i);
|
||||
|
||||
if with_signed {
|
||||
signed::Pallet::<T>::on_initialize(i);
|
||||
signed::Pezpallet::<T>::on_initialize(i);
|
||||
}
|
||||
|
||||
// invariants must hold at the end of each block.
|
||||
if try_state {
|
||||
Pallet::<T>::do_try_state(i).unwrap();
|
||||
verifier::Pallet::<T>::do_try_state(i).unwrap();
|
||||
unsigned::Pallet::<T>::do_try_state(i).unwrap();
|
||||
signed::Pallet::<T>::do_try_state(i).unwrap();
|
||||
Pezpallet::<T>::do_try_state(i).unwrap();
|
||||
verifier::Pezpallet::<T>::do_try_state(i).unwrap();
|
||||
unsigned::Pezpallet::<T>::do_try_state(i).unwrap();
|
||||
signed::Pezpallet::<T>::do_try_state(i).unwrap();
|
||||
}
|
||||
|
||||
i += one;
|
||||
@@ -1587,14 +1587,14 @@ where
|
||||
/// Roll to next block.
|
||||
pub(crate) fn roll_next(with_signed: bool, try_state: bool) {
|
||||
Self::roll_to(
|
||||
pezframe_system::Pallet::<T>::block_number() + 1u32.into(),
|
||||
pezframe_system::Pezpallet::<T>::block_number() + 1u32.into(),
|
||||
with_signed,
|
||||
try_state,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> ElectionProvider for Pallet<T> {
|
||||
impl<T: Config> ElectionProvider for Pezpallet<T> {
|
||||
type AccountId = T::AccountId;
|
||||
type BlockNumber = BlockNumberFor<T>;
|
||||
type Error = ElectionError<T>;
|
||||
@@ -1630,7 +1630,7 @@ impl<T: Config> ElectionProvider for Pallet<T> {
|
||||
.map_err(|err| {
|
||||
// if any pages returns an error, we go into the emergency phase and don't do
|
||||
// anything else anymore. This will prevent any new submissions to signed and
|
||||
// unsigned pallet, and thus the verifier will also be almost stuck, except for the
|
||||
// unsigned pezpallet, and thus the verifier will also be almost stuck, except for the
|
||||
// submission of emergency solutions.
|
||||
log!(debug, "fallback also ({:?}) failed for page {:?}", err, remaining);
|
||||
err
|
||||
@@ -2468,8 +2468,8 @@ mod election_provider {
|
||||
assert_eq!(Round::<Runtime>::get(), 1);
|
||||
// and the snapshot is cleared,
|
||||
assert_storage_noop!(Snapshot::<Runtime>::kill());
|
||||
// signed pallet is clean.
|
||||
// NOTE: in the future, if and when we add lazy cleanup to the signed pallet, this
|
||||
// signed pezpallet is clean.
|
||||
// NOTE: in the future, if and when we add lazy cleanup to the signed pezpallet, this
|
||||
// assertion might break.
|
||||
assert_ok!(signed::Submissions::<Runtime>::ensure_killed(0));
|
||||
});
|
||||
@@ -2518,7 +2518,7 @@ mod election_provider {
|
||||
assert_full_snapshot();
|
||||
|
||||
// there are 3 pages (indexes 2..=0), but we short circuit by just calling 0.
|
||||
let _solution = crate::Pallet::<Runtime>::elect(0).unwrap();
|
||||
let _solution = crate::Pezpallet::<Runtime>::elect(0).unwrap();
|
||||
|
||||
// round is incremented.
|
||||
assert_eq!(MultiBlock::round(), round + 1);
|
||||
@@ -2530,7 +2530,7 @@ mod election_provider {
|
||||
assert_eq!(Round::<Runtime>::get(), 1);
|
||||
// the snapshot is cleared,
|
||||
assert_none_snapshot();
|
||||
// and signed pallet is clean.
|
||||
// and signed pezpallet is clean.
|
||||
assert_ok!(signed::Submissions::<Runtime>::ensure_killed(round));
|
||||
});
|
||||
}
|
||||
@@ -2580,7 +2580,7 @@ mod election_provider {
|
||||
let solutions = (1..=MultiBlock::msp())
|
||||
.rev() // 2, 1
|
||||
.map(|page| {
|
||||
crate::Pallet::<Runtime>::elect(page as PageIndex).unwrap();
|
||||
crate::Pezpallet::<Runtime>::elect(page as PageIndex).unwrap();
|
||||
assert!(MultiBlock::current_phase().is_export());
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -2675,7 +2675,7 @@ mod election_provider {
|
||||
assert_eq!(MultiBlock::current_phase(), Phase::Off);
|
||||
// the snapshot is cleared,
|
||||
assert_storage_noop!(Snapshot::<Runtime>::kill());
|
||||
// and signed pallet is clean.
|
||||
// and signed pezpallet is clean.
|
||||
assert_ok!(signed::Submissions::<Runtime>::ensure_killed(round));
|
||||
});
|
||||
}
|
||||
@@ -2904,7 +2904,7 @@ mod manage_ops {
|
||||
// This scenario have multiple outcomes:
|
||||
// 1. rotate in off => almost a noop
|
||||
// 2. rotate mid signed, validation, unsigned, done, but NOT export => clear all data, move to
|
||||
// next round and be off. Note: all of the data in this pallet is indexed by the round index,
|
||||
// next round and be off. Note: all of the data in this pezpallet is indexed by the round index,
|
||||
// so moving to the next round will implicitly make the old data unavaioable, even if not
|
||||
// cleared out. This secnario needs further testing.
|
||||
// 3. rotate mid export: same as above, except staking will be out of sync and will also need
|
||||
@@ -2923,7 +2923,7 @@ mod manage_ops {
|
||||
|
||||
// we have snapshot data now for this round.
|
||||
assert_full_snapshot();
|
||||
// there is some data in the verifier pallet
|
||||
// there is some data in the verifier pezpallet
|
||||
assert!(verifier::QueuedSolution::<T>::queued_score().is_some());
|
||||
// phase is
|
||||
assert_eq!(MultiBlock::current_phase(), Phase::SignedValidation(2));
|
||||
|
||||
@@ -505,7 +505,7 @@ fn all_pallets_sanity_checks() {
|
||||
|
||||
/// Fully verify a solution.
|
||||
///
|
||||
/// This will progress the blocks until the verifier pallet is done verifying it.
|
||||
/// This will progress the blocks until the verifier pezpallet is done verifying it.
|
||||
///
|
||||
/// The solution must have already been loaded via `load_and_start_verification`.
|
||||
///
|
||||
@@ -608,7 +608,7 @@ pub fn ensure_targets(pages: PageIndex, count: usize) {
|
||||
assert_eq!(crate::Snapshot::<Runtime>::targets().unwrap().len(), count);
|
||||
}
|
||||
|
||||
/// get the events of the multi-block pallet.
|
||||
/// get the events of the multi-block pezpallet.
|
||||
pub fn multi_block_events() -> Vec<crate::Event<Runtime>> {
|
||||
System::events()
|
||||
.into_iter()
|
||||
@@ -629,7 +629,7 @@ pub fn multi_block_events_since_last_call() -> Vec<crate::Event<Runtime>> {
|
||||
events.into_iter().skip(already_seen as usize).collect()
|
||||
}
|
||||
|
||||
/// get the events of the verifier pallet.
|
||||
/// get the events of the verifier pezpallet.
|
||||
pub fn verifier_events() -> Vec<crate::verifier::Event<Runtime>> {
|
||||
System::events()
|
||||
.into_iter()
|
||||
@@ -640,7 +640,7 @@ pub fn verifier_events() -> Vec<crate::verifier::Event<Runtime>> {
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
/// get the events of the verifier pallet since last call.
|
||||
/// get the events of the verifier pezpallet since last call.
|
||||
pub fn verifier_events_since_last_call() -> Vec<crate::verifier::Event<Runtime>> {
|
||||
let events = verifier_events();
|
||||
let already_seen = VerifierEvents::get();
|
||||
@@ -650,7 +650,7 @@ pub fn verifier_events_since_last_call() -> Vec<crate::verifier::Event<Runtime>>
|
||||
|
||||
/// proceed block number to `n`.
|
||||
pub fn roll_to(n: BlockNumber) {
|
||||
crate::Pallet::<Runtime>::roll_to(
|
||||
crate::Pezpallet::<Runtime>::roll_to(
|
||||
n,
|
||||
matches!(SignedPhaseSwitch::get(), SignedSwitch::Real),
|
||||
true,
|
||||
|
||||
@@ -135,7 +135,7 @@ pub fn signed_events_since_last_call() -> Vec<crate::signed::Event<Runtime>> {
|
||||
events.into_iter().skip(already_seen as usize).collect()
|
||||
}
|
||||
|
||||
/// get the events of the verifier pallet.
|
||||
/// get the events of the verifier pezpallet.
|
||||
pub fn signed_events() -> Vec<crate::signed::Event<Runtime>> {
|
||||
System::events()
|
||||
.into_iter()
|
||||
@@ -144,7 +144,7 @@ pub fn signed_events() -> Vec<crate::signed::Event<Runtime>> {
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
/// Load a signed solution into its pallet.
|
||||
/// Load a signed solution into its pezpallet.
|
||||
pub fn load_signed_for_verification(who: AccountId, paged: PagedRawSolution<Runtime>) {
|
||||
let initial_balance = Balances::free_balance(&who);
|
||||
assert_eq!(balances(who), (initial_balance, 0));
|
||||
|
||||
@@ -115,7 +115,7 @@ impl ElectionDataProvider for MockStaking {
|
||||
}
|
||||
|
||||
fn next_election_prediction(_: u64) -> u64 {
|
||||
unreachable!("not used in this pallet")
|
||||
unreachable!("not used in this pezpallet")
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{
|
||||
signed::{Config, Pallet, Submissions},
|
||||
signed::{Config, Pezpallet, Submissions},
|
||||
types::PagedRawSolution,
|
||||
unsigned::miner::OffchainWorkerMiner,
|
||||
CurrentPhase, Phase, Round,
|
||||
@@ -37,13 +37,13 @@ mod benchmarks {
|
||||
fn register_not_full() -> Result<(), BenchmarkError> {
|
||||
CurrentPhase::<T>::put(Phase::Signed(T::SignedPhase::get() - One::one()));
|
||||
let round = Round::<T>::get();
|
||||
let alice = crate::Pallet::<T>::funded_account("alice", 0);
|
||||
let alice = crate::Pezpallet::<T>::funded_account("alice", 0);
|
||||
let score = ElectionScore::default();
|
||||
|
||||
assert_eq!(Submissions::<T>::sorted_submitters(round).len(), 0);
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::register(RawOrigin::Signed(alice).into(), score)?;
|
||||
Pezpallet::<T>::register(RawOrigin::Signed(alice).into(), score)?;
|
||||
}
|
||||
|
||||
assert_eq!(Submissions::<T>::sorted_submitters(round).len(), 1);
|
||||
@@ -56,20 +56,20 @@ mod benchmarks {
|
||||
let round = Round::<T>::get();
|
||||
|
||||
for i in 0..T::MaxSubmissions::get() {
|
||||
let submitter = crate::Pallet::<T>::funded_account("submitter", i);
|
||||
let submitter = crate::Pezpallet::<T>::funded_account("submitter", i);
|
||||
let score = ElectionScore { minimal_stake: i.into(), ..Default::default() };
|
||||
Pallet::<T>::register(RawOrigin::Signed(submitter.clone()).into(), score)?;
|
||||
Pezpallet::<T>::register(RawOrigin::Signed(submitter.clone()).into(), score)?;
|
||||
|
||||
// The first one, which will be ejected, has also submitted all pages
|
||||
if i == 0 {
|
||||
for p in 0..T::Pages::get() {
|
||||
let page = Some(Default::default());
|
||||
Pallet::<T>::submit_page(RawOrigin::Signed(submitter.clone()).into(), p, page)?;
|
||||
Pezpallet::<T>::submit_page(RawOrigin::Signed(submitter.clone()).into(), p, page)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let who = crate::Pallet::<T>::funded_account("who", 0);
|
||||
let who = crate::Pezpallet::<T>::funded_account("who", 0);
|
||||
let score =
|
||||
ElectionScore { minimal_stake: T::MaxSubmissions::get().into(), ..Default::default() };
|
||||
|
||||
@@ -80,7 +80,7 @@ mod benchmarks {
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::register(RawOrigin::Signed(who).into(), score)?;
|
||||
Pezpallet::<T>::register(RawOrigin::Signed(who).into(), score)?;
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
@@ -94,9 +94,9 @@ mod benchmarks {
|
||||
fn submit_page() -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
crate::Pallet::<T>::roll_until_matches(|| {
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::Signed(_))
|
||||
});
|
||||
|
||||
@@ -106,12 +106,12 @@ mod benchmarks {
|
||||
let page = Some(Box::new(solution_pages[0].clone()));
|
||||
|
||||
// register alice
|
||||
let alice = crate::Pallet::<T>::funded_account("alice", 0);
|
||||
Pallet::<T>::register(RawOrigin::Signed(alice.clone()).into(), score)?;
|
||||
let alice = crate::Pezpallet::<T>::funded_account("alice", 0);
|
||||
Pezpallet::<T>::register(RawOrigin::Signed(alice.clone()).into(), score)?;
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::submit_page(RawOrigin::Signed(alice).into(), 0, page)?;
|
||||
Pezpallet::<T>::submit_page(RawOrigin::Signed(alice).into(), 0, page)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -121,9 +121,9 @@ mod benchmarks {
|
||||
fn unset_page() -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
crate::Pallet::<T>::roll_until_matches(|| {
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::Signed(_))
|
||||
});
|
||||
|
||||
@@ -133,15 +133,15 @@ mod benchmarks {
|
||||
let page = Some(Box::new(solution_pages[0].clone()));
|
||||
|
||||
// register alice
|
||||
let alice = crate::Pallet::<T>::funded_account("alice", 0);
|
||||
Pallet::<T>::register(RawOrigin::Signed(alice.clone()).into(), score)?;
|
||||
let alice = crate::Pezpallet::<T>::funded_account("alice", 0);
|
||||
Pezpallet::<T>::register(RawOrigin::Signed(alice.clone()).into(), score)?;
|
||||
|
||||
// submit page
|
||||
Pallet::<T>::submit_page(RawOrigin::Signed(alice.clone()).into(), 0, page)?;
|
||||
Pezpallet::<T>::submit_page(RawOrigin::Signed(alice.clone()).into(), 0, page)?;
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::submit_page(RawOrigin::Signed(alice).into(), 0, None)?;
|
||||
Pezpallet::<T>::submit_page(RawOrigin::Signed(alice).into(), 0, None)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -150,21 +150,21 @@ mod benchmarks {
|
||||
#[benchmark(pov_mode = Measured)]
|
||||
fn bail() -> Result<(), BenchmarkError> {
|
||||
CurrentPhase::<T>::put(Phase::Signed(T::SignedPhase::get() - One::one()));
|
||||
let alice = crate::Pallet::<T>::funded_account("alice", 0);
|
||||
let alice = crate::Pezpallet::<T>::funded_account("alice", 0);
|
||||
|
||||
// register alice
|
||||
let score = ElectionScore::default();
|
||||
Pallet::<T>::register(RawOrigin::Signed(alice.clone()).into(), score)?;
|
||||
Pezpallet::<T>::register(RawOrigin::Signed(alice.clone()).into(), score)?;
|
||||
|
||||
// submit all pages
|
||||
for p in 0..T::Pages::get() {
|
||||
let page = Some(Default::default());
|
||||
Pallet::<T>::submit_page(RawOrigin::Signed(alice.clone()).into(), p, page)?;
|
||||
Pezpallet::<T>::submit_page(RawOrigin::Signed(alice.clone()).into(), p, page)?;
|
||||
}
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::bail(RawOrigin::Signed(alice).into())?;
|
||||
Pezpallet::<T>::bail(RawOrigin::Signed(alice).into())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -174,32 +174,32 @@ mod benchmarks {
|
||||
fn clear_old_round_data(p: Linear<1, { T::Pages::get() }>) -> Result<(), BenchmarkError> {
|
||||
// set signed phase and alice ready to submit
|
||||
CurrentPhase::<T>::put(Phase::Signed(T::SignedPhase::get() - One::one()));
|
||||
let alice = crate::Pallet::<T>::funded_account("alice", 0);
|
||||
let alice = crate::Pezpallet::<T>::funded_account("alice", 0);
|
||||
|
||||
// register alice
|
||||
let score = ElectionScore::default();
|
||||
Pallet::<T>::register(RawOrigin::Signed(alice.clone()).into(), score)?;
|
||||
Pezpallet::<T>::register(RawOrigin::Signed(alice.clone()).into(), score)?;
|
||||
|
||||
// submit a solution with p pages.
|
||||
for pp in 0..p {
|
||||
let page = Some(Default::default());
|
||||
Pallet::<T>::submit_page(RawOrigin::Signed(alice.clone()).into(), pp, page)?;
|
||||
Pezpallet::<T>::submit_page(RawOrigin::Signed(alice.clone()).into(), pp, page)?;
|
||||
}
|
||||
|
||||
// force rotate to the next round.
|
||||
let prev_round = Round::<T>::get();
|
||||
crate::Pallet::<T>::rotate_round();
|
||||
crate::Pezpallet::<T>::rotate_round();
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::clear_old_round_data(RawOrigin::Signed(alice).into(), prev_round, p)?;
|
||||
Pezpallet::<T>::clear_old_round_data(RawOrigin::Signed(alice).into(), prev_round, p)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Pallet,
|
||||
Pezpallet,
|
||||
crate::mock::ExtBuilder::signed().build_unchecked(),
|
||||
crate::mock::Runtime
|
||||
);
|
||||
|
||||
@@ -79,8 +79,8 @@ use pezsp_std::prelude::*;
|
||||
|
||||
/// Explore all weights
|
||||
pub use crate::weights::traits::pezpallet_election_provider_multi_block_signed::*;
|
||||
/// Exports of this pallet
|
||||
pub use pallet::*;
|
||||
/// Exports of this pezpallet
|
||||
pub use pezpallet::*;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking;
|
||||
@@ -111,7 +111,7 @@ pub struct SubmissionMetadata<T: Config> {
|
||||
pages: BoundedVec<bool, T::Pages>,
|
||||
}
|
||||
|
||||
impl<T: Config> SolutionDataProvider for Pallet<T> {
|
||||
impl<T: Config> SolutionDataProvider for Pezpallet<T> {
|
||||
type Solution = SolutionOf<T::MinerConfig>;
|
||||
|
||||
// `get_page` should only be called when a leader exists.
|
||||
@@ -221,12 +221,12 @@ impl<Balance: From<u32> + Saturating, G: Get<Balance>> CalculatePageDeposit<Bala
|
||||
}
|
||||
}
|
||||
|
||||
#[pezframe_support::pallet]
|
||||
pub mod pallet {
|
||||
#[pezframe_support::pezpallet]
|
||||
pub mod pezpallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
#[pallet::disable_pezframe_system_supertrait_check]
|
||||
#[pezpallet::config]
|
||||
#[pezpallet::disable_pezframe_system_supertrait_check]
|
||||
pub trait Config: crate::Config {
|
||||
/// Handler to the currency.
|
||||
type Currency: Inspect<Self::AccountId>
|
||||
@@ -239,7 +239,7 @@ pub mod pallet {
|
||||
/// Extra deposit per-page.
|
||||
type DepositPerPage: CalculatePageDeposit<BalanceOf<Self>>;
|
||||
|
||||
/// The fixed deposit charged upon [`Pallet::register`] from [`Invulnerables`].
|
||||
/// The fixed deposit charged upon [`Pezpallet::register`] from [`Invulnerables`].
|
||||
type InvulnerableDeposit: Get<BalanceOf<Self>>;
|
||||
|
||||
/// Base reward that is given to the winner.
|
||||
@@ -250,7 +250,7 @@ pub mod pallet {
|
||||
type MaxSubmissions: Get<u32>;
|
||||
|
||||
/// The ratio of the deposit to return in case a signed account submits a solution via
|
||||
/// [`Pallet::register`], but later calls [`Pallet::bail`].
|
||||
/// [`Pezpallet::register`], but later calls [`Pezpallet::bail`].
|
||||
///
|
||||
/// This should be large enough to cover for the deletion cost of possible all pages. To be
|
||||
/// safe, you can put it to 100% to begin with to fully dis-incentivize bailing.
|
||||
@@ -266,12 +266,12 @@ pub mod pallet {
|
||||
/// submitter for the winner.
|
||||
type EstimateCallFee: EstimateCallFee<Call<Self>, BalanceOf<Self>>;
|
||||
|
||||
/// Provided weights of this pallet.
|
||||
/// Provided weights of this pezpallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
|
||||
/// The hold reason of this palelt.
|
||||
#[pallet::composite_enum]
|
||||
#[pezpallet::composite_enum]
|
||||
pub enum HoldReason {
|
||||
/// Because of submitting a signed solution.
|
||||
#[codec(index = 0)]
|
||||
@@ -287,7 +287,7 @@ pub mod pallet {
|
||||
/// * If _ejected_ by better solution from [`SortedScores`], they will get their full deposit
|
||||
/// back.
|
||||
/// * They always get their tx-fee back even if they are _discarded_.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type Invulnerables<T: Config> =
|
||||
StorageValue<_, BoundedVec<T::AccountId, ConstU32<16>>, ValueQuery>;
|
||||
|
||||
@@ -327,7 +327,7 @@ pub mod pallet {
|
||||
/// purely independent.
|
||||
pub(crate) struct Submissions<T: Config>(pezsp_std::marker::PhantomData<T>);
|
||||
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type SortedScores<T: Config> = StorageMap<
|
||||
_,
|
||||
Twox64Concat,
|
||||
@@ -337,7 +337,7 @@ pub mod pallet {
|
||||
>;
|
||||
|
||||
/// Triple map from (round, account, page) to a solution page.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
type SubmissionStorage<T: Config> = StorageNMap<
|
||||
_,
|
||||
(
|
||||
@@ -353,7 +353,7 @@ pub mod pallet {
|
||||
///
|
||||
/// invariant: for any Key1 of type `AccountId` in [`Submissions`], this storage map also has a
|
||||
/// value.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
type SubmissionMetadataStorage<T: Config> =
|
||||
StorageDoubleMap<_, Twox64Concat, u32, Twox64Concat, T::AccountId, SubmissionMetadata<T>>;
|
||||
|
||||
@@ -472,7 +472,7 @@ pub mod pallet {
|
||||
if sorted_scores.is_full() {
|
||||
let remove_idx = sorted_scores
|
||||
.iter()
|
||||
.position(|(x, _)| !Pallet::<T>::is_invulnerable(x))
|
||||
.position(|(x, _)| !Pezpallet::<T>::is_invulnerable(x))
|
||||
.ok_or(Error::<T>::QueueFull)?;
|
||||
if insert_idx > remove_idx {
|
||||
// we have a better solution
|
||||
@@ -496,14 +496,14 @@ pub mod pallet {
|
||||
debug_assert!(_r.unique <= T::Pages::get());
|
||||
|
||||
if let Some(metadata) = maybe_metadata {
|
||||
Pallet::<T>::settle_deposit(
|
||||
Pezpallet::<T>::settle_deposit(
|
||||
&discarded,
|
||||
metadata.deposit,
|
||||
T::EjectGraceRatio::get(),
|
||||
);
|
||||
}
|
||||
|
||||
Pallet::<T>::deposit_event(Event::<T>::Ejected(round, discarded));
|
||||
Pezpallet::<T>::deposit_event(Event::<T>::Ejected(round, discarded));
|
||||
true
|
||||
} else {
|
||||
// we don't have a better solution
|
||||
@@ -542,10 +542,10 @@ pub mod pallet {
|
||||
|
||||
/// Get the deposit of a registration with the given number of pages.
|
||||
fn deposit_for(who: &T::AccountId, pages: usize) -> BalanceOf<T> {
|
||||
if Pallet::<T>::is_invulnerable(who) {
|
||||
if Pezpallet::<T>::is_invulnerable(who) {
|
||||
T::InvulnerableDeposit::get()
|
||||
} else {
|
||||
let round = Pallet::<T>::current_round();
|
||||
let round = Pezpallet::<T>::current_round();
|
||||
let queue_size = Self::submitters_count(round);
|
||||
let base = T::DepositBase::calculate_base_deposit(queue_size);
|
||||
let pages = T::DepositPerPage::calculate_page_deposit(queue_size, pages);
|
||||
@@ -740,11 +740,11 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(PhantomData<T>);
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
#[pezpallet::event]
|
||||
#[pezpallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// Upcoming submission has been registered for the given account, with the given score.
|
||||
Registered(u32, T::AccountId, ElectionScore),
|
||||
@@ -762,7 +762,7 @@ pub mod pallet {
|
||||
Bailed(u32, T::AccountId),
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
#[pezpallet::error]
|
||||
pub enum Error<T> {
|
||||
/// The phase is not signed.
|
||||
PhaseNotSigned,
|
||||
@@ -784,17 +784,17 @@ pub mod pallet {
|
||||
TooManyInvulnerables,
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
/// Register oneself for an upcoming signed election.
|
||||
#[pallet::weight(SignedWeightsOf::<T>::register_eject())]
|
||||
#[pallet::call_index(0)]
|
||||
#[pezpallet::weight(SignedWeightsOf::<T>::register_eject())]
|
||||
#[pezpallet::call_index(0)]
|
||||
pub fn register(
|
||||
origin: OriginFor<T>,
|
||||
claimed_score: ElectionScore,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
ensure!(crate::Pallet::<T>::current_phase().is_signed(), Error::<T>::PhaseNotSigned);
|
||||
ensure!(crate::Pezpallet::<T>::current_phase().is_signed(), Error::<T>::PhaseNotSigned);
|
||||
|
||||
// note: we could already check if this is a duplicate here, but prefer keeping the code
|
||||
// simple for now.
|
||||
@@ -825,21 +825,21 @@ pub mod pallet {
|
||||
|
||||
/// Submit a single page of a solution.
|
||||
///
|
||||
/// Must always come after [`Pallet::register`].
|
||||
/// Must always come after [`Pezpallet::register`].
|
||||
///
|
||||
/// `maybe_solution` can be set to `None` to erase the page.
|
||||
///
|
||||
/// Collects deposits from the signed origin based on [`Config::DepositBase`] and
|
||||
/// [`Config::DepositPerPage`].
|
||||
#[pallet::weight(SignedWeightsOf::<T>::submit_page())]
|
||||
#[pallet::call_index(1)]
|
||||
#[pezpallet::weight(SignedWeightsOf::<T>::submit_page())]
|
||||
#[pezpallet::call_index(1)]
|
||||
pub fn submit_page(
|
||||
origin: OriginFor<T>,
|
||||
page: PageIndex,
|
||||
maybe_solution: Option<Box<SolutionOf<T::MinerConfig>>>,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
ensure!(crate::Pallet::<T>::current_phase().is_signed(), Error::<T>::PhaseNotSigned);
|
||||
ensure!(crate::Pezpallet::<T>::current_phase().is_signed(), Error::<T>::PhaseNotSigned);
|
||||
let is_set = maybe_solution.is_some();
|
||||
|
||||
let round = Self::current_round();
|
||||
@@ -859,11 +859,11 @@ pub mod pallet {
|
||||
/// A portion of the deposit may be returned, based on the [`Config::EjectGraceRatio`].
|
||||
///
|
||||
/// This will fully remove the solution from storage.
|
||||
#[pallet::weight(SignedWeightsOf::<T>::bail())]
|
||||
#[pallet::call_index(2)]
|
||||
#[pezpallet::weight(SignedWeightsOf::<T>::bail())]
|
||||
#[pezpallet::call_index(2)]
|
||||
pub fn bail(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
ensure!(crate::Pallet::<T>::current_phase().is_signed(), Error::<T>::PhaseNotSigned);
|
||||
ensure!(crate::Pezpallet::<T>::current_phase().is_signed(), Error::<T>::PhaseNotSigned);
|
||||
let round = Self::current_round();
|
||||
let metadata = Submissions::<T>::take_submission_with_data(round, &who)
|
||||
.ok_or(Error::<T>::NoSubmission)?;
|
||||
@@ -881,8 +881,8 @@ pub mod pallet {
|
||||
///
|
||||
/// This can only be called for submissions that end up being discarded, as in they are not
|
||||
/// processed and they end up lingering in the queue.
|
||||
#[pallet::call_index(3)]
|
||||
#[pallet::weight(SignedWeightsOf::<T>::clear_old_round_data(*witness_pages))]
|
||||
#[pezpallet::call_index(3)]
|
||||
#[pezpallet::weight(SignedWeightsOf::<T>::clear_old_round_data(*witness_pages))]
|
||||
pub fn clear_old_round_data(
|
||||
origin: OriginFor<T>,
|
||||
round: u32,
|
||||
@@ -925,8 +925,8 @@ pub mod pallet {
|
||||
/// Set the invulnerable list.
|
||||
///
|
||||
/// Dispatch origin must the the same as [`crate::Config::AdminOrigin`].
|
||||
#[pallet::call_index(4)]
|
||||
#[pallet::weight(T::DbWeight::get().writes(1))]
|
||||
#[pezpallet::call_index(4)]
|
||||
#[pezpallet::weight(T::DbWeight::get().writes(1))]
|
||||
pub fn set_invulnerables(origin: OriginFor<T>, inv: Vec<T::AccountId>) -> DispatchResult {
|
||||
<T as crate::Config>::AdminOrigin::ensure_origin(origin)?;
|
||||
let bounded: BoundedVec<_, ConstU32<16>> =
|
||||
@@ -936,8 +936,8 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::view_functions]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pezpallet::view_functions]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
/// Get the deposit amount that will be held for a solution of `pages`.
|
||||
///
|
||||
/// This allows an offchain application to know what [`Config::DepositPerPage`] and
|
||||
@@ -948,14 +948,14 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
#[pezpallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pezpallet<T> {
|
||||
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
|
||||
// this code is only called when at the boundary of phase transition, which is already
|
||||
// captured by the parent pallet. No need for weight.
|
||||
// captured by the parent pezpallet. No need for weight.
|
||||
let weight_taken_into_account: Weight = Default::default();
|
||||
|
||||
if crate::Pallet::<T>::current_phase().is_signed_validation_opened_now() {
|
||||
if crate::Pezpallet::<T>::current_phase().is_signed_validation_opened_now() {
|
||||
let maybe_leader = Submissions::<T>::leader(Self::current_round());
|
||||
sublog!(
|
||||
debug,
|
||||
@@ -982,14 +982,14 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
#[cfg(any(feature = "try-runtime", test, feature = "runtime-benchmarks"))]
|
||||
pub(crate) fn do_try_state(_n: BlockNumberFor<T>) -> Result<(), pezsp_runtime::TryRuntimeError> {
|
||||
Submissions::<T>::sanity_check_round(Self::current_round())
|
||||
}
|
||||
|
||||
fn current_round() -> u32 {
|
||||
crate::Pallet::<T>::round()
|
||||
crate::Pezpallet::<T>::round()
|
||||
}
|
||||
|
||||
fn is_invulnerable(who: &T::AccountId) -> bool {
|
||||
@@ -1040,7 +1040,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
// Try to start verification again if we still have submissions
|
||||
if let crate::types::Phase::SignedValidation(remaining_blocks) =
|
||||
crate::Pallet::<T>::current_phase()
|
||||
crate::Pezpallet::<T>::current_phase()
|
||||
{
|
||||
// Only start verification if there are sufficient blocks remaining
|
||||
// Note: SignedValidation(N) means N+1 blocks remaining in the phase
|
||||
|
||||
@@ -63,7 +63,7 @@ mod calls {
|
||||
#[test]
|
||||
fn cannot_register_if_not_signed() {
|
||||
ExtBuilder::signed().build_and_execute(|| {
|
||||
assert!(!crate::Pallet::<T>::current_phase().is_signed());
|
||||
assert!(!crate::Pezpallet::<T>::current_phase().is_signed());
|
||||
assert_noop!(
|
||||
SignedPallet::register(RuntimeOrigin::signed(99), Default::default()),
|
||||
Error::<T>::PhaseNotSigned
|
||||
@@ -655,7 +655,7 @@ mod e2e {
|
||||
// 99 now has their deposit returned.
|
||||
assert_eq!(balances(99), (100, 0));
|
||||
|
||||
// signed pallet should be in 100% clean state.
|
||||
// signed pezpallet should be in 100% clean state.
|
||||
assert_ok!(Submissions::<Runtime>::ensure_killed(0));
|
||||
})
|
||||
}
|
||||
@@ -675,7 +675,7 @@ mod e2e {
|
||||
assert_eq!(Submissions::<Runtime>::submitters_count(current_round), 1);
|
||||
|
||||
roll_to_signed_validation_open();
|
||||
roll_next(); // one block so signed pallet will send start signal.
|
||||
roll_next(); // one block so signed pezpallet will send start signal.
|
||||
roll_to_full_verification();
|
||||
|
||||
// Check that rejection events were properly generated
|
||||
@@ -696,13 +696,13 @@ mod e2e {
|
||||
);
|
||||
|
||||
// Verify no-restart conditions are met
|
||||
assert!(crate::Pallet::<Runtime>::current_phase().is_signed_validation());
|
||||
assert!(crate::Pezpallet::<Runtime>::current_phase().is_signed_validation());
|
||||
assert!(!Submissions::<Runtime>::has_leader(current_round));
|
||||
assert_eq!(Submissions::<Runtime>::submitters_count(current_round), 0);
|
||||
assert_eq!(VerifierPallet::status(), crate::verifier::Status::Nothing);
|
||||
|
||||
// Verifier should remain idle for the rest of the signed validation phase
|
||||
while crate::Pallet::<Runtime>::current_phase().is_signed_validation() {
|
||||
while crate::Pezpallet::<Runtime>::current_phase().is_signed_validation() {
|
||||
roll_next();
|
||||
assert_eq!(VerifierPallet::status(), crate::verifier::Status::Nothing);
|
||||
}
|
||||
@@ -817,7 +817,7 @@ mod e2e {
|
||||
roll_to_signed_validation_open();
|
||||
assert_eq!(MultiBlock::current_phase(), Phase::SignedValidation(3));
|
||||
assert!(matches!(VerifierPallet::status(), crate::verifier::Status::Nothing));
|
||||
roll_next(); // one block so signed-pallet will send the start signal
|
||||
roll_next(); // one block so signed-pezpallet will send the start signal
|
||||
assert_eq!(MultiBlock::current_phase(), Phase::SignedValidation(2));
|
||||
assert!(matches!(VerifierPallet::status(), crate::verifier::Status::Ongoing(2)));
|
||||
|
||||
@@ -959,11 +959,11 @@ mod e2e {
|
||||
);
|
||||
|
||||
// we have 1 block left in signed verification, but we cannot do anything here.
|
||||
assert_eq!(crate::Pallet::<T>::current_phase(), Phase::SignedValidation(0));
|
||||
assert_eq!(crate::Pezpallet::<T>::current_phase(), Phase::SignedValidation(0));
|
||||
|
||||
// we go back to signed next
|
||||
roll_next();
|
||||
assert_eq!(crate::Pallet::<T>::current_phase(), Phase::Signed(4));
|
||||
assert_eq!(crate::Pezpallet::<T>::current_phase(), Phase::Signed(4));
|
||||
|
||||
// no one submits again, and we go to verification again
|
||||
roll_to_signed_validation_open();
|
||||
@@ -995,15 +995,15 @@ mod e2e {
|
||||
vec![crate::signed::Event::Rewarded(0, 999, 7)]
|
||||
);
|
||||
|
||||
// verifier is `Nothing`, and will remain so as signed-pallet will not start it
|
||||
// verifier is `Nothing`, and will remain so as signed-pezpallet will not start it
|
||||
// again.
|
||||
|
||||
assert_eq!(crate::Pallet::<T>::current_phase(), Phase::SignedValidation(0));
|
||||
assert_eq!(crate::Pezpallet::<T>::current_phase(), Phase::SignedValidation(0));
|
||||
assert_eq!(VerifierPallet::status(), crate::verifier::Status::Nothing);
|
||||
|
||||
// next block we go to done
|
||||
roll_next();
|
||||
assert_eq!(crate::Pallet::<T>::current_phase(), Phase::Done);
|
||||
assert_eq!(crate::Pezpallet::<T>::current_phase(), Phase::Done);
|
||||
assert_eq!(VerifierPallet::status(), crate::verifier::Status::Nothing);
|
||||
})
|
||||
}
|
||||
@@ -1042,7 +1042,7 @@ mod e2e {
|
||||
assert_eq!(Submissions::<Runtime>::submitters_count(current_round), 2);
|
||||
|
||||
roll_to_signed_validation_open();
|
||||
roll_next(); // one block so signed-pallet will send the start signal
|
||||
roll_next(); // one block so signed-pezpallet will send the start signal
|
||||
assert!(matches!(MultiBlock::current_phase(), Phase::SignedValidation(_)));
|
||||
assert!(matches!(VerifierPallet::status(), crate::verifier::Status::Ongoing(_)));
|
||||
|
||||
@@ -1099,7 +1099,7 @@ mod e2e {
|
||||
assert_eq!(VerifierPallet::status(), crate::verifier::Status::Nothing);
|
||||
|
||||
roll_to_signed_validation_open();
|
||||
roll_next(); // one block so signed-pallet will send the start signal
|
||||
roll_next(); // one block so signed-pezpallet will send the start signal
|
||||
|
||||
// Now in the next validation phase, the good solution starts verification
|
||||
assert!(matches!(VerifierPallet::status(), crate::verifier::Status::Ongoing(_)));
|
||||
@@ -1111,7 +1111,7 @@ mod e2e {
|
||||
roll_next(); // Process page 0
|
||||
|
||||
// Good solution should be fully verified and accepted
|
||||
assert_eq!(crate::Pallet::<T>::current_phase(), Phase::SignedValidation(0));
|
||||
assert_eq!(crate::Pezpallet::<T>::current_phase(), Phase::SignedValidation(0));
|
||||
assert_eq!(VerifierPallet::status(), crate::verifier::Status::Nothing);
|
||||
assert_eq!(Submissions::<Runtime>::submitters_count(current_round), 0);
|
||||
});
|
||||
@@ -1158,7 +1158,7 @@ mod e2e {
|
||||
|
||||
// Move to verification phase
|
||||
roll_to_signed_validation_open();
|
||||
roll_next(); // one block so signed-pallet will send the start signal
|
||||
roll_next(); // one block so signed-pezpallet will send the start signal
|
||||
assert!(matches!(VerifierPallet::status(), crate::verifier::Status::Ongoing(_)));
|
||||
|
||||
// Process first invalid solution (91)
|
||||
@@ -1228,7 +1228,7 @@ mod e2e {
|
||||
]
|
||||
);
|
||||
|
||||
assert_eq!(crate::Pallet::<T>::current_phase(), Phase::SignedValidation(0));
|
||||
assert_eq!(crate::Pezpallet::<T>::current_phase(), Phase::SignedValidation(0));
|
||||
assert_eq!(VerifierPallet::status(), crate::verifier::Status::Nothing);
|
||||
|
||||
// Check that all expected events were emitted in the correct order
|
||||
@@ -1249,7 +1249,7 @@ mod e2e {
|
||||
|
||||
// finally done
|
||||
roll_next();
|
||||
assert_eq!(crate::Pallet::<T>::current_phase(), Phase::Done);
|
||||
assert_eq!(crate::Pezpallet::<T>::current_phase(), Phase::Done);
|
||||
// verifier has done nothing
|
||||
assert_eq!(VerifierPallet::status(), crate::verifier::Status::Nothing);
|
||||
assert!(
|
||||
@@ -1605,7 +1605,7 @@ mod invulnerables {
|
||||
assert_ok!(SignedPallet::register(RuntimeOrigin::signed(99), invalid_score));
|
||||
|
||||
roll_to_signed_validation_open();
|
||||
roll_next(); // one block so signed pallet will send start signal.
|
||||
roll_next(); // one block so signed pezpallet will send start signal.
|
||||
roll_to_full_verification();
|
||||
|
||||
// Check that rejection events were properly generated
|
||||
@@ -1678,7 +1678,7 @@ mod defensive_tests {
|
||||
|
||||
// Delete the score storage
|
||||
let full_key =
|
||||
crate::signed::pallet::SortedScores::<Runtime>::hashed_key_for(current_round);
|
||||
crate::signed::pezpallet::SortedScores::<Runtime>::hashed_key_for(current_round);
|
||||
unhashed::kill(&full_key);
|
||||
|
||||
// Complete verification - this should trigger score unavailable detection
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Common types and traits of the EPMB pallet group.
|
||||
//! Common types and traits of the EPMB pezpallet group.
|
||||
//!
|
||||
//! ## [`SolutionOf`]
|
||||
//!
|
||||
//! This type is among the most cryptic used in the EPMB pallet. The origins of this type go back to
|
||||
//! This type is among the most cryptic used in the EPMB pezpallet. The origins of this type go back to
|
||||
//! the fact that sending a solution, with hundreds or thousands of account-ids in it would be too
|
||||
//! large for a chain to handle. This was particularly the case in a single page solution, as
|
||||
//! developed in `election-provider-multi-phase`. To combat this, a "compact" custom type is
|
||||
@@ -32,7 +32,7 @@
|
||||
//!
|
||||
//! ## [`Phase`]
|
||||
//!
|
||||
//! This is the most important type of this pallet, demonstrating the state-machine used
|
||||
//! This is the most important type of this pezpallet, demonstrating the state-machine used
|
||||
//! to manage the election process and its various phases.
|
||||
|
||||
use crate::{unsigned::miner::MinerConfig, verifier};
|
||||
@@ -227,7 +227,7 @@ impl<T: MinerConfig> Get<u32> for MaxFlattenedVoters<T> {
|
||||
/// This is bounded by [`MaxFlattenedVoters`].
|
||||
pub type AllVoterPagesFlattenedOf<T> = BoundedVec<VoterOf<T>, MaxFlattenedVoters<T>>;
|
||||
|
||||
/// Current phase of the pallet.
|
||||
/// Current phase of the pezpallet.
|
||||
#[derive(
|
||||
PartialEqNoBound,
|
||||
EqNoBound,
|
||||
@@ -271,7 +271,7 @@ pub enum Phase<T: crate::Config> {
|
||||
/// The inner value should be read as "`remaining` number of pages are left to be fetched".
|
||||
/// Thus, if inner value is `0` if the snapshot is complete and we are ready to move on.
|
||||
///
|
||||
/// This value should be interpreted after `on_initialize` of this pallet has already been
|
||||
/// This value should be interpreted after `on_initialize` of this pezpallet has already been
|
||||
/// called.
|
||||
Snapshot(PageIndex),
|
||||
/// Snapshot is done, and we are waiting for `Export` to kick in.
|
||||
@@ -280,7 +280,7 @@ pub enum Phase<T: crate::Config> {
|
||||
///
|
||||
/// Once this is active, no more signed or solutions will be accepted.
|
||||
Export(PageIndex),
|
||||
/// The emergency phase. This is could be enabled by one of the fallbacks, and locks the pallet
|
||||
/// The emergency phase. This is could be enabled by one of the fallbacks, and locks the pezpallet
|
||||
/// such that only governance can change the state.
|
||||
Emergency,
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{
|
||||
unsigned::{miner::OffchainWorkerMiner, Call, Config, Pallet},
|
||||
unsigned::{miner::OffchainWorkerMiner, Call, Config, Pezpallet},
|
||||
verifier::Verifier,
|
||||
CurrentPhase, Phase,
|
||||
};
|
||||
@@ -34,9 +34,9 @@ mod benchmarks {
|
||||
fn validate_unsigned() -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
crate::Pallet::<T>::roll_until_matches(|| {
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::Unsigned(_))
|
||||
});
|
||||
let call: Call<T> = OffchainWorkerMiner::<T>::mine_solution(T::MinerPages::get(), false)
|
||||
@@ -45,7 +45,7 @@ mod benchmarks {
|
||||
|
||||
#[block]
|
||||
{
|
||||
assert_ok!(Pallet::<T>::validate_unsigned(TransactionSource::Local, &call));
|
||||
assert_ok!(Pezpallet::<T>::validate_unsigned(TransactionSource::Local, &call));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -55,10 +55,10 @@ mod benchmarks {
|
||||
fn submit_unsigned() -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
// roll to unsigned phase open
|
||||
crate::Pallet::<T>::roll_until_matches(|| {
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::Unsigned(_))
|
||||
});
|
||||
// TODO: we need to better ensure that this is actually worst case
|
||||
@@ -69,7 +69,7 @@ mod benchmarks {
|
||||
assert!(T::Verifier::queued_score().is_none());
|
||||
#[block]
|
||||
{
|
||||
assert_ok!(Pallet::<T>::submit_unsigned(RawOrigin::None.into(), Box::new(solution)));
|
||||
assert_ok!(Pezpallet::<T>::submit_unsigned(RawOrigin::None.into(), Box::new(solution)));
|
||||
}
|
||||
|
||||
// something is queued
|
||||
@@ -81,10 +81,10 @@ mod benchmarks {
|
||||
fn mine_solution(p: Linear<1, { T::Pages::get() }>) -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
// roll to unsigned phase open
|
||||
crate::Pallet::<T>::roll_until_matches(|| {
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::Unsigned(_))
|
||||
});
|
||||
|
||||
@@ -97,7 +97,7 @@ mod benchmarks {
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Pallet,
|
||||
Pezpallet,
|
||||
crate::mock::ExtBuilder::full().build_unchecked(),
|
||||
crate::mock::Runtime
|
||||
);
|
||||
|
||||
@@ -15,17 +15,17 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! The miner code for the EPMB pallet.
|
||||
//! The miner code for the EPMB pezpallet.
|
||||
//!
|
||||
//! It is broadly consisted of two main types:
|
||||
//!
|
||||
//! * [`crate::unsigned::miner::BaseMiner`], which is more generic, needs parameterization via
|
||||
//! [`crate::unsigned::miner::MinerConfig`], and can be used by an external implementation.
|
||||
//! * [`crate::unsigned::miner::OffchainWorkerMiner`], which is more opinionated, and is used by
|
||||
//! this pallet via the `offchain_worker` hook to also mine solutions during the
|
||||
//! this pezpallet via the `offchain_worker` hook to also mine solutions during the
|
||||
//! `Phase::Unsigned`.
|
||||
|
||||
use super::{Call, Config, Pallet};
|
||||
use super::{Call, Config, Pezpallet};
|
||||
use crate::{
|
||||
helpers,
|
||||
types::{PadSolutionPages, *},
|
||||
@@ -75,7 +75,7 @@ pub enum MinerError<T: MinerConfig> {
|
||||
Solver(MinerSolverErrorOf<T>),
|
||||
/// Snapshot data was unavailable unexpectedly.
|
||||
SnapshotUnAvailable(SnapshotType),
|
||||
/// The base, common errors from the pallet.
|
||||
/// The base, common errors from the pezpallet.
|
||||
Common(CommonError),
|
||||
/// The solution generated from the miner is not feasible.
|
||||
Feasibility(verifier::FeasibilityError),
|
||||
@@ -112,7 +112,7 @@ impl<T: MinerConfig> From<CommonError> for MinerError<T> {
|
||||
pub enum OffchainMinerError<T: Config> {
|
||||
/// An error in the base miner.
|
||||
BaseMiner(MinerError<T::MinerConfig>),
|
||||
/// The base, common errors from the pallet.
|
||||
/// The base, common errors from the pezpallet.
|
||||
Common(CommonError),
|
||||
/// Something went wrong fetching the lock.
|
||||
Lock(&'static str),
|
||||
@@ -143,7 +143,7 @@ impl<T: Config> From<CommonError> for OffchainMinerError<T> {
|
||||
/// Configurations for the miner.
|
||||
///
|
||||
/// This is extracted from the main crate's config so that an offchain miner can readily use the
|
||||
/// [`BaseMiner`] without needing to deal with the rest of the pallet's configuration.
|
||||
/// [`BaseMiner`] without needing to deal with the rest of the pezpallet's configuration.
|
||||
pub trait MinerConfig {
|
||||
/// The account id type.
|
||||
type AccountId: Ord + Clone + codec::Codec + core::fmt::Debug;
|
||||
@@ -165,7 +165,7 @@ pub trait MinerConfig {
|
||||
///
|
||||
/// This value is not set in stone, and it is up to an individual miner to configure. A good
|
||||
/// value is something like 75% of the total block length, which can be fetched from the system
|
||||
/// pallet.
|
||||
/// pezpallet.
|
||||
type MaxLength: Get<u32>;
|
||||
/// Maximum number of votes per voter.
|
||||
///
|
||||
@@ -208,7 +208,7 @@ pub trait MinerConfig {
|
||||
}
|
||||
|
||||
/// A base miner that is only capable of mining a new solution and checking it against the state of
|
||||
/// this pallet for feasibility, and trimming its length/weight.
|
||||
/// this pezpallet for feasibility, and trimming its length/weight.
|
||||
pub struct BaseMiner<T: MinerConfig>(pezsp_std::marker::PhantomData<T>);
|
||||
|
||||
/// Parameterized `BoundedSupports` for the miner.
|
||||
@@ -690,7 +690,7 @@ impl<T: Config> OffchainWorkerMiner<T> {
|
||||
.ok_or(MinerError::SnapshotUnAvailable(SnapshotType::Targets))?;
|
||||
|
||||
// This is the range of voters that we are interested in.
|
||||
let voter_pages_range = crate::Pallet::<T>::msp_range_for(pages as usize);
|
||||
let voter_pages_range = crate::Pezpallet::<T>::msp_range_for(pages as usize);
|
||||
|
||||
sublog!(
|
||||
debug,
|
||||
@@ -727,7 +727,7 @@ impl<T: Config> OffchainWorkerMiner<T> {
|
||||
return Err(OffchainMinerError::<T>::ZeroPages);
|
||||
}
|
||||
let (voter_pages, all_targets, desired_targets) = Self::fetch_snapshot(pages)?;
|
||||
let round = crate::Pallet::<T>::round();
|
||||
let round = crate::Pezpallet::<T>::round();
|
||||
BaseMiner::<T::MinerConfig>::mine_solution(MineInput {
|
||||
desired_targets,
|
||||
all_targets,
|
||||
@@ -782,7 +782,7 @@ impl<T: Config> OffchainWorkerMiner<T> {
|
||||
do_feasibility: bool,
|
||||
) -> Result<(), OffchainMinerError<T>> {
|
||||
// NOTE: we prefer cheap checks first, so first run unsigned checks.
|
||||
Pallet::<T>::unsigned_specific_checks(paged_solution)?;
|
||||
Pezpallet::<T>::unsigned_specific_checks(paged_solution)?;
|
||||
Self::base_check_solution(paged_solution, maybe_snapshot_fingerprint, do_feasibility)
|
||||
}
|
||||
|
||||
@@ -817,7 +817,7 @@ impl<T: Config> OffchainWorkerMiner<T> {
|
||||
maybe_snapshot_fingerprint: Option<T::Hash>,
|
||||
do_feasibility: bool,
|
||||
) -> Result<(), OffchainMinerError<T>> {
|
||||
let _ = crate::Pallet::<T>::snapshot_independent_checks(
|
||||
let _ = crate::Pezpallet::<T>::snapshot_independent_checks(
|
||||
paged_solution,
|
||||
maybe_snapshot_fingerprint,
|
||||
)?;
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
|
||||
//! ## The unsigned phase, and its miner.
|
||||
//!
|
||||
//! This pallet deals with unsigned submissions. These are backup, "possibly" multi-page submissions
|
||||
//! This pezpallet deals with unsigned submissions. These are backup, "possibly" multi-page submissions
|
||||
//! from validators.
|
||||
//!
|
||||
//! This pallet has two miners, described in [`unsigned::miner`].
|
||||
//! This pezpallet has two miners, described in [`unsigned::miner`].
|
||||
//!
|
||||
//! As it stands, a validator can, during the unsigned phase, submit up to
|
||||
//! [`unsigned::Config::MinerPages`] pages. While this can be more than 1, it can likely not be a
|
||||
@@ -71,16 +71,16 @@
|
||||
|
||||
/// Export weights
|
||||
pub use crate::weights::traits::pezpallet_election_provider_multi_block_unsigned::*;
|
||||
/// Exports of this pallet
|
||||
pub use pallet::*;
|
||||
/// Exports of this pezpallet
|
||||
pub use pezpallet::*;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking;
|
||||
|
||||
/// The miner.
|
||||
pub mod miner;
|
||||
|
||||
#[pezframe_support::pallet]
|
||||
mod pallet {
|
||||
#[pezframe_support::pezpallet]
|
||||
mod pezpallet {
|
||||
use super::WeightInfo;
|
||||
use crate::{
|
||||
types::*,
|
||||
@@ -102,8 +102,8 @@ mod pallet {
|
||||
|
||||
pub(crate) type UnsignedWeightsOf<T> = <T as Config>::WeightInfo;
|
||||
|
||||
#[pallet::config]
|
||||
#[pallet::disable_pezframe_system_supertrait_check]
|
||||
#[pezpallet::config]
|
||||
#[pezpallet::disable_pezframe_system_supertrait_check]
|
||||
pub trait Config: crate::Config + CreateBare<Call<Self>> {
|
||||
/// The repeat threshold of the offchain worker.
|
||||
///
|
||||
@@ -127,15 +127,15 @@ mod pallet {
|
||||
/// The number of pages that the offchain miner will try and submit.
|
||||
type MinerPages: Get<PageIndex>;
|
||||
|
||||
/// Runtime weight information of this pallet.
|
||||
/// Runtime weight information of this pezpallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(PhantomData<T>);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
/// Submit an unsigned solution.
|
||||
///
|
||||
/// This works very much like an inherent, as only the validators are permitted to submit
|
||||
@@ -146,13 +146,13 @@ mod pallet {
|
||||
/// verified on the fly.
|
||||
///
|
||||
/// The `paged_solution` may contain at most [`Config::MinerPages`] pages. They are
|
||||
/// interpreted as msp -> lsp, as per [`crate::Pallet::msp_range_for`].
|
||||
/// interpreted as msp -> lsp, as per [`crate::Pezpallet::msp_range_for`].
|
||||
///
|
||||
/// For example, if `Pages = 4`, and `MinerPages = 2`, our full snapshot range would be [0,
|
||||
/// 1, 2, 3], with 3 being msp. But, in this case, then the `paged_raw_solution.pages` is
|
||||
/// expected to correspond to `[snapshot(2), snapshot(3)]`.
|
||||
#[pallet::weight((UnsignedWeightsOf::<T>::submit_unsigned(), DispatchClass::Operational))]
|
||||
#[pallet::call_index(0)]
|
||||
#[pezpallet::weight((UnsignedWeightsOf::<T>::submit_unsigned(), DispatchClass::Operational))]
|
||||
#[pezpallet::call_index(0)]
|
||||
pub fn submit_unsigned(
|
||||
origin: OriginFor<T>,
|
||||
paged_solution: Box<PagedRawSolution<T::MinerConfig>>,
|
||||
@@ -168,7 +168,7 @@ mod pallet {
|
||||
let claimed_score = paged_solution.score;
|
||||
|
||||
// we select the most significant pages, based on `T::MinerPages`.
|
||||
let page_indices = crate::Pallet::<T>::msp_range_for(T::MinerPages::get() as usize);
|
||||
let page_indices = crate::Pezpallet::<T>::msp_range_for(T::MinerPages::get() as usize);
|
||||
<T::Verifier as Verifier>::verify_synchronous_multi(
|
||||
paged_solution.solution_pages,
|
||||
page_indices,
|
||||
@@ -180,8 +180,8 @@ mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::validate_unsigned]
|
||||
impl<T: Config> ValidateUnsigned for Pallet<T> {
|
||||
#[pezpallet::validate_unsigned]
|
||||
impl<T: Config> ValidateUnsigned for Pezpallet<T> {
|
||||
type Call = Call<T>;
|
||||
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
|
||||
if let Call::submit_unsigned { paged_solution, .. } = call {
|
||||
@@ -232,8 +232,8 @@ mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
#[pezpallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pezpallet<T> {
|
||||
fn integrity_test() {
|
||||
assert!(
|
||||
UnsignedWeightsOf::<T>::submit_unsigned().all_lte(T::BlockWeights::get().max_block),
|
||||
@@ -258,7 +258,7 @@ mod pallet {
|
||||
// This should only come useful in an **abrupt** termination of execution, otherwise the
|
||||
// guard will be dropped upon successful execution.
|
||||
let mut lock =
|
||||
StorageLock::<BlockAndTime<pezframe_system::Pallet<T>>>::with_block_deadline(
|
||||
StorageLock::<BlockAndTime<pezframe_system::Pezpallet<T>>>::with_block_deadline(
|
||||
miner::OffchainWorkerMiner::<T>::OFFCHAIN_LOCK,
|
||||
T::UnsignedPhase::get().saturated_into(),
|
||||
);
|
||||
@@ -279,12 +279,12 @@ mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
/// Internal logic of the offchain worker, to be executed only when the offchain lock is
|
||||
/// acquired with success.
|
||||
fn do_synchronized_offchain_worker(now: BlockNumberFor<T>) {
|
||||
use miner::OffchainWorkerMiner;
|
||||
let current_phase = crate::Pallet::<T>::current_phase();
|
||||
let current_phase = crate::Pezpallet::<T>::current_phase();
|
||||
sublog!(
|
||||
trace,
|
||||
"unsigned",
|
||||
@@ -334,18 +334,18 @@ mod pallet {
|
||||
paged_solution: &PagedRawSolution<T::MinerConfig>,
|
||||
) -> Result<(), CommonError> {
|
||||
Self::unsigned_specific_checks(paged_solution)
|
||||
.and(crate::Pallet::<T>::snapshot_independent_checks(paged_solution, None))
|
||||
.and(crate::Pezpallet::<T>::snapshot_independent_checks(paged_solution, None))
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// The checks that are specific to the (this) unsigned pallet.
|
||||
/// The checks that are specific to the (this) unsigned pezpallet.
|
||||
///
|
||||
/// ensure solution has the correct phase, and it has only 1 page.
|
||||
pub fn unsigned_specific_checks(
|
||||
paged_solution: &PagedRawSolution<T::MinerConfig>,
|
||||
) -> Result<(), CommonError> {
|
||||
ensure!(
|
||||
crate::Pallet::<T>::current_phase().is_unsigned(),
|
||||
crate::Pezpallet::<T>::current_phase().is_unsigned(),
|
||||
CommonError::EarlySubmission
|
||||
);
|
||||
ensure!(
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{
|
||||
verifier::{Config, Event, FeasibilityError, Pallet, Status, StatusStorage},
|
||||
verifier::{Config, Event, FeasibilityError, Pezpallet, Status, StatusStorage},
|
||||
CurrentPhase, Phase,
|
||||
};
|
||||
use pezframe_benchmarking::v2::*;
|
||||
@@ -35,33 +35,33 @@ mod benchmarks {
|
||||
where
|
||||
<T as pezframe_system::Config>::RuntimeEvent: TryInto<Event<T>>,
|
||||
{
|
||||
pezframe_system::Pallet::<T>::read_events_for_pallet::<Event<T>>()
|
||||
pezframe_system::Pezpallet::<T>::read_events_for_pallet::<Event<T>>()
|
||||
}
|
||||
|
||||
#[benchmark(pov_mode = Measured)]
|
||||
fn on_initialize_valid_non_terminal() -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
// roll to signed validation, with a solution stored in the signed pallet
|
||||
crate::Pallet::<T>::roll_to_signed_and_submit_full_solution()?;
|
||||
// roll to signed validation, with a solution stored in the signed pezpallet
|
||||
crate::Pezpallet::<T>::roll_to_signed_and_submit_full_solution()?;
|
||||
|
||||
// roll to verification
|
||||
crate::Pallet::<T>::roll_until_matches(|| {
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::SignedValidation(_))
|
||||
});
|
||||
// send start signal
|
||||
crate::Pallet::<T>::roll_next(true, false);
|
||||
crate::Pezpallet::<T>::roll_next(true, false);
|
||||
|
||||
// start signal must have been sent by now
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pallet::<T>::msp()));
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pezpallet::<T>::msp()));
|
||||
|
||||
#[block]
|
||||
{
|
||||
crate::Pallet::<T>::roll_next(true, false);
|
||||
crate::Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pallet::<T>::msp() - 1));
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pezpallet::<T>::msp() - 1));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -70,26 +70,26 @@ mod benchmarks {
|
||||
fn on_initialize_valid_terminal() -> Result<(), BenchmarkError> {
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
// roll to signed validation, with a solution stored in the signed pallet
|
||||
// roll to signed validation, with a solution stored in the signed pezpallet
|
||||
assert!(
|
||||
T::SignedValidationPhase::get() >= T::Pages::get().into(),
|
||||
"Signed validation phase must be larger than the number of pages"
|
||||
);
|
||||
|
||||
crate::Pallet::<T>::roll_to_signed_and_submit_full_solution()?;
|
||||
crate::Pezpallet::<T>::roll_to_signed_and_submit_full_solution()?;
|
||||
// roll to before the last page of verification
|
||||
crate::Pallet::<T>::roll_until_matches(|| {
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::SignedValidation(_))
|
||||
});
|
||||
// send start signal
|
||||
crate::Pallet::<T>::roll_next(true, false);
|
||||
crate::Pezpallet::<T>::roll_next(true, false);
|
||||
|
||||
// start signal must have been sent by now
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pallet::<T>::msp()));
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pezpallet::<T>::msp()));
|
||||
for _ in 0..(T::Pages::get() - 1) {
|
||||
crate::Pallet::<T>::roll_next(true, false);
|
||||
crate::Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
|
||||
// we must have verified all pages by now, minus the last one.
|
||||
@@ -101,7 +101,7 @@ mod benchmarks {
|
||||
// verify the last page.
|
||||
#[block]
|
||||
{
|
||||
crate::Pallet::<T>::roll_next(true, false);
|
||||
crate::Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
|
||||
// we are done
|
||||
@@ -124,34 +124,34 @@ mod benchmarks {
|
||||
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
// roll to signed validation, with a solution stored in the signed pallet
|
||||
// roll to signed validation, with a solution stored in the signed pezpallet
|
||||
|
||||
// but this solution is corrupt
|
||||
let mut paged_solution = crate::Pallet::<T>::roll_to_signed_and_mine_full_solution();
|
||||
let mut paged_solution = crate::Pezpallet::<T>::roll_to_signed_and_mine_full_solution();
|
||||
paged_solution.score.minimal_stake -= 1;
|
||||
crate::Pallet::<T>::submit_full_solution(paged_solution)?;
|
||||
crate::Pezpallet::<T>::submit_full_solution(paged_solution)?;
|
||||
|
||||
// roll to verification
|
||||
crate::Pallet::<T>::roll_until_matches(|| {
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::SignedValidation(_))
|
||||
});
|
||||
// send start signal
|
||||
crate::Pallet::<T>::roll_next(true, false);
|
||||
crate::Pezpallet::<T>::roll_next(true, false);
|
||||
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pallet::<T>::msp()));
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pezpallet::<T>::msp()));
|
||||
// verify all pages, except for the last one.
|
||||
for i in 0..T::Pages::get() - 1 {
|
||||
crate::Pallet::<T>::roll_next(true, false);
|
||||
crate::Pezpallet::<T>::roll_next(true, false);
|
||||
assert_eq!(
|
||||
StatusStorage::<T>::get(),
|
||||
Status::Ongoing(crate::Pallet::<T>::msp() - 1 - i)
|
||||
Status::Ongoing(crate::Pezpallet::<T>::msp() - 1 - i)
|
||||
);
|
||||
}
|
||||
|
||||
// next page to be verified is the last one
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pallet::<T>::lsp()));
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pezpallet::<T>::lsp()));
|
||||
assert!(matches!(
|
||||
&events_for::<T>()[..],
|
||||
[Event::Verified(_, _), .., Event::Verified(1, _)]
|
||||
@@ -159,7 +159,7 @@ mod benchmarks {
|
||||
|
||||
#[block]
|
||||
{
|
||||
crate::Pallet::<T>::roll_next(true, false);
|
||||
crate::Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
|
||||
// we are now reset.
|
||||
@@ -186,12 +186,12 @@ mod benchmarks {
|
||||
|
||||
#[cfg(test)]
|
||||
crate::mock::ElectionStart::set(pezsp_runtime::traits::Bounded::max_value());
|
||||
crate::Pallet::<T>::start().unwrap();
|
||||
crate::Pezpallet::<T>::start().unwrap();
|
||||
|
||||
// roll to signed validation, with a solution stored in the signed pallet, but this solution
|
||||
// roll to signed validation, with a solution stored in the signed pezpallet, but this solution
|
||||
// is corrupt in its msp.
|
||||
let mut paged_solution = crate::Pallet::<T>::roll_to_signed_and_mine_full_solution();
|
||||
let page_to_corrupt = crate::Pallet::<T>::msp() - v;
|
||||
let mut paged_solution = crate::Pezpallet::<T>::roll_to_signed_and_mine_full_solution();
|
||||
let page_to_corrupt = crate::Pezpallet::<T>::msp() - v;
|
||||
crate::log!(
|
||||
info,
|
||||
"pages of solution: {:?}, to corrupt {}, v {}",
|
||||
@@ -200,30 +200,30 @@ mod benchmarks {
|
||||
v
|
||||
);
|
||||
paged_solution.solution_pages[page_to_corrupt as usize].corrupt();
|
||||
crate::Pallet::<T>::submit_full_solution(paged_solution)?;
|
||||
crate::Pezpallet::<T>::submit_full_solution(paged_solution)?;
|
||||
|
||||
// roll to verification
|
||||
crate::Pallet::<T>::roll_until_matches(|| {
|
||||
crate::Pezpallet::<T>::roll_until_matches(|| {
|
||||
matches!(CurrentPhase::<T>::get(), Phase::SignedValidation(_))
|
||||
});
|
||||
// send start signal
|
||||
crate::Pallet::<T>::roll_next(true, false);
|
||||
crate::Pezpallet::<T>::roll_next(true, false);
|
||||
|
||||
// we should be ready to go
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pallet::<T>::msp()));
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pezpallet::<T>::msp()));
|
||||
|
||||
// validate the the parameterized number of valid pages.
|
||||
for _ in 0..v {
|
||||
crate::Pallet::<T>::roll_next(true, false);
|
||||
crate::Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
|
||||
// we are still ready to continue
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pallet::<T>::msp() - v));
|
||||
assert_eq!(StatusStorage::<T>::get(), Status::Ongoing(crate::Pezpallet::<T>::msp() - v));
|
||||
|
||||
// verify one page, which will be invalid.
|
||||
#[block]
|
||||
{
|
||||
crate::Pallet::<T>::roll_next(true, false);
|
||||
crate::Pezpallet::<T>::roll_next(true, false);
|
||||
}
|
||||
|
||||
// we are now reset, because this page was invalid.
|
||||
@@ -238,7 +238,7 @@ mod benchmarks {
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Pallet,
|
||||
Pezpallet,
|
||||
crate::mock::ExtBuilder::full().build_unchecked(),
|
||||
crate::mock::Runtime
|
||||
);
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! The implementation of the verifier pallet, and an implementation of [`crate::Verifier`] and
|
||||
//! [`crate::AsynchronousVerifier`] for [`Pallet`].
|
||||
//! The implementation of the verifier pezpallet, and an implementation of [`crate::Verifier`] and
|
||||
//! [`crate::AsynchronousVerifier`] for [`Pezpallet`].
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
@@ -36,7 +36,7 @@ use pezframe_support::{
|
||||
traits::{defensive_prelude::*, Get},
|
||||
};
|
||||
use pezframe_system::pezpallet_prelude::*;
|
||||
use pallet::*;
|
||||
use pezpallet::*;
|
||||
use pezsp_npos_elections::{evaluate_support, ElectionScore};
|
||||
use pezsp_std::{collections::btree_map::BTreeMap, prelude::*};
|
||||
|
||||
@@ -48,7 +48,7 @@ pub(crate) type SupportsOfVerifier<V> = pezframe_election_provider_support::Boun
|
||||
|
||||
pub(crate) type VerifierWeightsOf<T> = <T as super::Config>::WeightInfo;
|
||||
|
||||
/// The status of this pallet.
|
||||
/// The status of this pezpallet.
|
||||
#[derive(
|
||||
Encode, Decode, scale_info::TypeInfo, Clone, Copy, MaxEncodedLen, Debug, PartialEq, Eq,
|
||||
)]
|
||||
@@ -107,28 +107,28 @@ impl pezsp_npos_elections::Backings for PartialBackings {
|
||||
}
|
||||
}
|
||||
|
||||
#[pezframe_support::pallet]
|
||||
pub(crate) mod pallet {
|
||||
#[pezframe_support::pezpallet]
|
||||
pub(crate) mod pezpallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
#[pallet::disable_pezframe_system_supertrait_check]
|
||||
#[pezpallet::config]
|
||||
#[pezpallet::disable_pezframe_system_supertrait_check]
|
||||
pub trait Config: crate::Config {
|
||||
/// Maximum number of backers, per winner, among all pages of an election.
|
||||
///
|
||||
/// This can only be checked at the very final step of verification.
|
||||
///
|
||||
/// NOTE: at the moment, we don't check this, and it is in place for future compatibility.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type MaxBackersPerWinnerFinal: Get<u32>;
|
||||
|
||||
/// Maximum number of backers, per winner, per page.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type MaxBackersPerWinner: Get<u32>;
|
||||
|
||||
/// Maximum number of supports (aka. winners/validators/targets) that can be represented in
|
||||
/// a page of results.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type MaxWinnersPerPage: Get<u32>;
|
||||
|
||||
/// Something that can provide the solution data to the verifier.
|
||||
@@ -138,12 +138,12 @@ pub(crate) mod pallet {
|
||||
Solution = SolutionOf<Self::MinerConfig>,
|
||||
>;
|
||||
|
||||
/// The weight information of this pallet.
|
||||
/// The weight information of this pezpallet.
|
||||
type WeightInfo: super::WeightInfo;
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
#[pezpallet::event]
|
||||
#[pezpallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T> {
|
||||
/// A verification failed at the given page.
|
||||
///
|
||||
@@ -168,7 +168,7 @@ pub(crate) mod pallet {
|
||||
/// - `QueuedSolutionBackings`
|
||||
///
|
||||
/// As the name suggests, `QueuedValidVariant` points to the correct variant between
|
||||
/// `QueuedSolutionX` and `QueuedSolutionY`. In the context of this pallet, by VALID and
|
||||
/// `QueuedSolutionX` and `QueuedSolutionY`. In the context of this pezpallet, by VALID and
|
||||
/// INVALID variant we mean either of these two storage items, based on the value of
|
||||
/// `QueuedValidVariant`.
|
||||
///
|
||||
@@ -191,7 +191,7 @@ pub(crate) mod pallet {
|
||||
/// - The number of existing keys in `QueuedSolutionBackings` must always match that of the
|
||||
/// INVALID variant.
|
||||
///
|
||||
/// Moreover, the following conditions must be met when this pallet is in [`Status::Nothing`],
|
||||
/// Moreover, the following conditions must be met when this pezpallet is in [`Status::Nothing`],
|
||||
/// meaning that no ongoing asynchronous verification is ongoing.
|
||||
///
|
||||
/// - No keys should exist in the INVALID variant.
|
||||
@@ -202,7 +202,7 @@ pub(crate) mod pallet {
|
||||
/// > the number of keys in the VALID variant. In fact, an empty solution with score of [0, 0,
|
||||
/// > 0] can also be correct.
|
||||
///
|
||||
/// No additional conditions must be met when the pallet is in [`Status::Ongoing`]. The number
|
||||
/// No additional conditions must be met when the pezpallet is in [`Status::Ongoing`]. The number
|
||||
/// of pages in
|
||||
pub struct QueuedSolution<T: Config>(pezsp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> QueuedSolution<T> {
|
||||
@@ -219,7 +219,7 @@ pub(crate) mod pallet {
|
||||
}
|
||||
|
||||
fn round() -> u32 {
|
||||
crate::Pallet::<T>::round()
|
||||
crate::Pezpallet::<T>::round()
|
||||
}
|
||||
|
||||
/// Finalize a correct solution.
|
||||
@@ -275,14 +275,14 @@ pub(crate) mod pallet {
|
||||
/// known to be valid. At this stage, we write to the invalid variant. Once all pages are
|
||||
/// verified, a call to [`finalize_correct`] will seal the correct pages and flip the
|
||||
/// invalid/valid variants.
|
||||
pub(crate) fn set_invalid_page(page: PageIndex, supports: SupportsOfVerifier<Pallet<T>>) {
|
||||
pub(crate) fn set_invalid_page(page: PageIndex, supports: SupportsOfVerifier<Pezpallet<T>>) {
|
||||
use pezframe_support::traits::TryCollect;
|
||||
Self::mutate_checked(|| {
|
||||
let backings: BoundedVec<_, _> = supports
|
||||
.iter()
|
||||
.map(|(x, s)| (x.clone(), PartialBackings { total: s.total, backers: s.voters.len() as u32 } ))
|
||||
.try_collect()
|
||||
.expect("`SupportsOfVerifier` is bounded by <Pallet<T> as Verifier>::MaxWinnersPerPage, which is assured to be the same as `T::MaxWinnersPerPage` in an integrity test");
|
||||
.expect("`SupportsOfVerifier` is bounded by <Pezpallet<T> as Verifier>::MaxWinnersPerPage, which is assured to be the same as `T::MaxWinnersPerPage` in an integrity test");
|
||||
QueuedSolutionBackings::<T>::insert(Self::round(), page, backings);
|
||||
|
||||
match Self::invalid() {
|
||||
@@ -300,7 +300,7 @@ pub(crate) mod pallet {
|
||||
/// solution.
|
||||
pub(crate) fn force_set_single_page_valid(
|
||||
page: PageIndex,
|
||||
supports: SupportsOfVerifier<Pallet<T>>,
|
||||
supports: SupportsOfVerifier<Pezpallet<T>>,
|
||||
score: ElectionScore,
|
||||
) {
|
||||
Self::mutate_checked(|| {
|
||||
@@ -322,7 +322,7 @@ pub(crate) mod pallet {
|
||||
|
||||
pub(crate) fn force_set_multi_page_valid(
|
||||
pages: Vec<PageIndex>,
|
||||
supports: Vec<SupportsOfVerifier<Pallet<T>>>,
|
||||
supports: Vec<SupportsOfVerifier<Pezpallet<T>>>,
|
||||
score: ElectionScore,
|
||||
) {
|
||||
debug_assert_eq!(pages.len(), supports.len());
|
||||
@@ -405,7 +405,7 @@ pub(crate) mod pallet {
|
||||
/// Get a page of the current queued (aka valid) solution.
|
||||
pub(crate) fn get_queued_solution_page(
|
||||
page: PageIndex,
|
||||
) -> Option<SupportsOfVerifier<Pallet<T>>> {
|
||||
) -> Option<SupportsOfVerifier<Pezpallet<T>>> {
|
||||
match Self::valid() {
|
||||
ValidSolution::X => QueuedSolutionX::<T>::get(Self::round(), page),
|
||||
ValidSolution::Y => QueuedSolutionY::<T>::get(Self::round(), page),
|
||||
@@ -425,7 +425,7 @@ pub(crate) mod pallet {
|
||||
#[cfg(any(test, feature = "runtime-benchmarks", feature = "try-runtime", debug_assertions))]
|
||||
impl<T: Config> QueuedSolution<T> {
|
||||
pub(crate) fn valid_iter(
|
||||
) -> impl Iterator<Item = (PageIndex, SupportsOfVerifier<Pallet<T>>)> {
|
||||
) -> impl Iterator<Item = (PageIndex, SupportsOfVerifier<Pezpallet<T>>)> {
|
||||
match Self::valid() {
|
||||
ValidSolution::X => QueuedSolutionX::<T>::iter_prefix(Self::round()),
|
||||
ValidSolution::Y => QueuedSolutionY::<T>::iter_prefix(Self::round()),
|
||||
@@ -433,14 +433,14 @@ pub(crate) mod pallet {
|
||||
}
|
||||
|
||||
pub(crate) fn invalid_iter(
|
||||
) -> impl Iterator<Item = (PageIndex, SupportsOfVerifier<Pallet<T>>)> {
|
||||
) -> impl Iterator<Item = (PageIndex, SupportsOfVerifier<Pezpallet<T>>)> {
|
||||
match Self::invalid() {
|
||||
ValidSolution::X => QueuedSolutionX::<T>::iter_prefix(Self::round()),
|
||||
ValidSolution::Y => QueuedSolutionY::<T>::iter_prefix(Self::round()),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_valid_page(page: PageIndex) -> Option<SupportsOfVerifier<Pallet<T>>> {
|
||||
pub(crate) fn get_valid_page(page: PageIndex) -> Option<SupportsOfVerifier<Pezpallet<T>>> {
|
||||
match Self::valid() {
|
||||
ValidSolution::X => QueuedSolutionX::<T>::get(Self::round(), page),
|
||||
ValidSolution::Y => QueuedSolutionY::<T>::get(Self::round(), page),
|
||||
@@ -464,7 +464,7 @@ pub(crate) mod pallet {
|
||||
pub(crate) fn sanity_check() -> Result<(), pezsp_runtime::DispatchError> {
|
||||
// score is correct and better than min-score.
|
||||
ensure!(
|
||||
Pallet::<T>::minimum_score()
|
||||
Pezpallet::<T>::minimum_score()
|
||||
.zip(Self::queued_score())
|
||||
.map_or(true, |(min_score, score)| score.strict_better(min_score)),
|
||||
"queued solution has weak score (min-score)"
|
||||
@@ -509,30 +509,30 @@ pub(crate) mod pallet {
|
||||
/// Writing theses supports on top of a *good* queued supports is wrong, since we might bail.
|
||||
/// Writing them to a bugger and copying at the ned is slightly better, but expensive. This flag
|
||||
/// system is best of both worlds.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
type QueuedSolutionX<T: Config> = StorageDoubleMap<
|
||||
_,
|
||||
Twox64Concat,
|
||||
u32,
|
||||
Twox64Concat,
|
||||
PageIndex,
|
||||
SupportsOfVerifier<Pallet<T>>,
|
||||
SupportsOfVerifier<Pezpallet<T>>,
|
||||
>;
|
||||
|
||||
/// The `Y` variant of the current queued solution. Might be the valid one or not.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
type QueuedSolutionY<T: Config> = StorageDoubleMap<
|
||||
_,
|
||||
Twox64Concat,
|
||||
u32,
|
||||
Twox64Concat,
|
||||
PageIndex,
|
||||
SupportsOfVerifier<Pallet<T>>,
|
||||
SupportsOfVerifier<Pezpallet<T>>,
|
||||
>;
|
||||
/// Pointer to the variant of [`QueuedSolutionX`] or [`QueuedSolutionY`] that is currently
|
||||
/// valid.
|
||||
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
type QueuedValidVariant<T: Config> =
|
||||
StorageMap<_, Twox64Concat, u32, ValidSolution, ValueQuery>;
|
||||
|
||||
@@ -544,7 +544,7 @@ pub(crate) mod pallet {
|
||||
/// This can only ever live for the invalid variant of the solution. Once it is valid, we don't
|
||||
/// need this information anymore; the score is already computed once in
|
||||
/// [`QueuedSolutionScore`], and the backing counts are checked.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
type QueuedSolutionBackings<T: Config> = StorageDoubleMap<
|
||||
_,
|
||||
Twox64Concat,
|
||||
@@ -557,25 +557,25 @@ pub(crate) mod pallet {
|
||||
/// The score of the valid variant of [`QueuedSolution`].
|
||||
///
|
||||
/// This only ever lives for the `valid` variant.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
type QueuedSolutionScore<T: Config> = StorageMap<_, Twox64Concat, u32, ElectionScore>;
|
||||
|
||||
// -- ^^ private storage items, managed by `QueuedSolution`.
|
||||
|
||||
/// The minimum score that each solution must attain in order to be considered feasible.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn minimum_score)]
|
||||
#[pezpallet::storage]
|
||||
#[pezpallet::getter(fn minimum_score)]
|
||||
pub(crate) type MinimumScore<T: Config> = StorageValue<_, ElectionScore>;
|
||||
|
||||
/// Storage item for [`Status`].
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn status_storage)]
|
||||
#[pezpallet::storage]
|
||||
#[pezpallet::getter(fn status_storage)]
|
||||
pub(crate) type StatusStorage<T: Config> = StorageValue<_, Status, ValueQuery>;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
#[pezpallet::pezpallet]
|
||||
pub struct Pezpallet<T>(PhantomData<T>);
|
||||
|
||||
#[pallet::genesis_config]
|
||||
#[pezpallet::genesis_config]
|
||||
#[derive(pezframe_support::DefaultNoBound)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
/// Initial value for [`MinimumScore`]
|
||||
@@ -583,18 +583,18 @@ pub(crate) mod pallet {
|
||||
_marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
#[pezpallet::genesis_build]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {
|
||||
MinimumScore::<T>::put(self.minimum_score);
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
#[pezpallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pezpallet<T> {
|
||||
fn integrity_test() {
|
||||
// ensure that we have funneled some of our type parameters EXACTLY as-is to the
|
||||
// verifier trait interface we implement.
|
||||
@@ -617,7 +617,7 @@ pub(crate) mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
fn do_on_initialize() -> Weight {
|
||||
if let Status::Ongoing(current_page) = Self::status_storage() {
|
||||
let page_solution =
|
||||
@@ -638,7 +638,7 @@ impl<T: Config> Pallet<T> {
|
||||
Self::deposit_event(Event::<T>::Verified(current_page, supports.len() as u32));
|
||||
QueuedSolution::<T>::set_invalid_page(current_page, supports);
|
||||
|
||||
if current_page > crate::Pallet::<T>::lsp() {
|
||||
if current_page > crate::Pezpallet::<T>::lsp() {
|
||||
// not last page, just tick forward.
|
||||
StatusStorage::<T>::put(Status::Ongoing(current_page.saturating_sub(1)));
|
||||
VerifierWeightsOf::<T>::on_initialize_valid_non_terminal()
|
||||
@@ -927,7 +927,7 @@ pub fn feasibility_check_page_inner_with_snapshot<T: MinerConfig>(
|
||||
Ok(bounded_supports)
|
||||
}
|
||||
|
||||
impl<T: Config> Verifier for Pallet<T> {
|
||||
impl<T: Config> Verifier for Pezpallet<T> {
|
||||
type AccountId = T::AccountId;
|
||||
type Solution = SolutionOf<T::MinerConfig>;
|
||||
type MaxBackersPerWinner = T::MaxBackersPerWinner;
|
||||
@@ -985,11 +985,11 @@ impl<T: Config> Verifier for Pallet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> AsynchronousVerifier for Pallet<T> {
|
||||
impl<T: Config> AsynchronousVerifier for Pezpallet<T> {
|
||||
type SolutionDataProvider = T::SolutionDataProvider;
|
||||
|
||||
fn status() -> Status {
|
||||
Pallet::<T>::status_storage()
|
||||
Pezpallet::<T>::status_storage()
|
||||
}
|
||||
|
||||
fn start() -> Result<(), &'static str> {
|
||||
@@ -999,7 +999,7 @@ impl<T: Config> AsynchronousVerifier for Pallet<T> {
|
||||
if Self::ensure_score_quality(claimed_score).is_err() {
|
||||
// don't do anything, report back that this solution was garbage.
|
||||
Self::deposit_event(Event::<T>::VerificationFailed(
|
||||
crate::Pallet::<T>::msp(),
|
||||
crate::Pezpallet::<T>::msp(),
|
||||
FeasibilityError::ScoreTooLow,
|
||||
));
|
||||
T::SolutionDataProvider::report_result(VerificationResult::Rejected);
|
||||
@@ -1007,7 +1007,7 @@ impl<T: Config> AsynchronousVerifier for Pallet<T> {
|
||||
Ok(())
|
||||
} else {
|
||||
// This solution is good enough to win, we start verifying it in the next block.
|
||||
StatusStorage::<T>::put(Status::Ongoing(crate::Pallet::<T>::msp()));
|
||||
StatusStorage::<T>::put(Status::Ongoing(crate::Pezpallet::<T>::msp()));
|
||||
Ok(())
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -15,18 +15,18 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! # The Verifier Pallet
|
||||
//! # The Verifier Pezpallet
|
||||
//!
|
||||
//! This pallet has no end-user functionality, and is only used internally by other pallets in the
|
||||
//! This pezpallet has no end-user functionality, and is only used internally by other pallets in the
|
||||
//! EPMB machinery to verify solutions.
|
||||
//!
|
||||
//! ### *Feasibility* Check
|
||||
//!
|
||||
//! Before explaining the pallet itself, it should be explained what a *verification* even means.
|
||||
//! Before explaining the pezpallet itself, it should be explained what a *verification* even means.
|
||||
//! Verification of a solution page ([`crate::unsigned::miner::MinerConfig::Solution`]) includes the
|
||||
//! process of checking all of its edges against a snapshot to be correct. For instance, all voters
|
||||
//! that are presented in a solution page must have actually voted for the winner that they are
|
||||
//! backing, based on the snapshot kept in the parent pallet.
|
||||
//! backing, based on the snapshot kept in the parent pezpallet.
|
||||
//!
|
||||
//! Such checks are bound to each page of the solution, and happen per-page. After checking all of
|
||||
//! the edges in each page, a handful of other checks are performed. These checks cannot happen
|
||||
@@ -48,11 +48,11 @@
|
||||
//!
|
||||
//! ## Modes of Verification
|
||||
//!
|
||||
//! The verifier pallet provide two modes of functionality:
|
||||
//! The verifier pezpallet provide two modes of functionality:
|
||||
//!
|
||||
//! 1. Single or multi-page, synchronous verification. This is useful in the context of single-page,
|
||||
//! emergency, or unsigned solutions that need to be verified on the fly. This is similar to how
|
||||
//! the old school `multi-phase` pallet works. See [`Verifier::verify_synchronous`] and
|
||||
//! the old school `multi-phase` pezpallet works. See [`Verifier::verify_synchronous`] and
|
||||
//! [`Verifier::verify_synchronous_multi`].
|
||||
//! 2. Multi-page, asynchronous verification. This is useful in the context of multi-page, signed
|
||||
//! solutions. See [`verifier::AsynchronousVerifier`] and [`verifier::SolutionDataProvider`].
|
||||
@@ -78,7 +78,7 @@ pub use crate::weights::traits::pezpallet_election_provider_multi_block_verifier
|
||||
|
||||
use pezframe_election_provider_support::PageIndex;
|
||||
use impls::SupportsOfVerifier;
|
||||
pub use impls::{feasibility_check_page_inner_with_snapshot, pallet::*, Status};
|
||||
pub use impls::{feasibility_check_page_inner_with_snapshot, pezpallet::*, Status};
|
||||
use pezsp_core::Get;
|
||||
use pezsp_npos_elections::ElectionScore;
|
||||
use pezsp_std::{fmt::Debug, prelude::*};
|
||||
@@ -99,7 +99,7 @@ pub enum FeasibilityError {
|
||||
WrongWinnerCount,
|
||||
/// The snapshot is not available.
|
||||
///
|
||||
/// Kinda defensive: The pallet should technically never attempt to do a feasibility check
|
||||
/// Kinda defensive: The pezpallet should technically never attempt to do a feasibility check
|
||||
/// when no snapshot is present.
|
||||
SnapshotUnavailable,
|
||||
/// A vote is invalid.
|
||||
@@ -144,7 +144,7 @@ pub trait Verifier {
|
||||
/// Maximum number of winners that can be represented in each page.
|
||||
///
|
||||
/// A reasonable value for this should be the maximum number of winners that the election user
|
||||
/// (e.g. the staking pallet) could ever desire.
|
||||
/// (e.g. the staking pezpallet) could ever desire.
|
||||
type MaxWinnersPerPage: Get<u32>;
|
||||
|
||||
/// Maximum number of backers, per winner, among all pages of an election.
|
||||
@@ -227,7 +227,7 @@ pub enum VerificationResult {
|
||||
|
||||
/// Something that can provide candidate solutions to the verifier.
|
||||
///
|
||||
/// In reality, this can be implemented by the [`crate::signed::Pallet`], where signed solutions are
|
||||
/// In reality, this can be implemented by the [`crate::signed::Pezpallet`], where signed solutions are
|
||||
/// queued and sorted based on claimed score, and they are put forth one by one, from best to worse.
|
||||
pub trait SolutionDataProvider {
|
||||
/// The opaque solution type.
|
||||
@@ -280,7 +280,7 @@ pub trait AsynchronousVerifier: Verifier {
|
||||
/// derived from a full solution) are valid and the solution is verified. The solution is
|
||||
/// queued and is ready for further export.
|
||||
/// 2. The solution checks verification at one of the steps. Nothing is stored inside the
|
||||
/// verifier pallet and all intermediary data is removed.
|
||||
/// verifier pezpallet and all intermediary data is removed.
|
||||
///
|
||||
/// In both cases, the [`SolutionDataProvider`] is informed via
|
||||
/// [`SolutionDataProvider::report_result`]. It is sensible for the data provide to call `start`
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! WeightInfo for the election provider multi-block pallet group.
|
||||
//! WeightInfo for the election provider multi-block pezpallet group.
|
||||
|
||||
mod pezpallet_election_provider_multi_block_hez_size;
|
||||
mod pezpallet_election_provider_multi_block_signed_hez_size;
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@
|
||||
|
||||
//! Autogenerated weights for `pezpallet_election_provider_multi_block`
|
||||
//!
|
||||
//! This is a special template for `election-provider-multi-block` pallet. This is required because
|
||||
//! This is a special template for `election-provider-multi-block` pezpallet. This is required because
|
||||
// ! we don't want to generate the `trait WeightInfo`.
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
@@ -31,8 +31,8 @@
|
||||
// ../../../../../target/release/frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --pallet
|
||||
// pezpallet
|
||||
// --pezpallet
|
||||
// pezpallet_election_provider_multi_block
|
||||
// --extrinsic
|
||||
// *
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@
|
||||
|
||||
//! Autogenerated weights for `pezpallet_election_provider_multi_block`
|
||||
//!
|
||||
//! This is a special template for `election-provider-multi-block` pallet. This is required because
|
||||
//! This is a special template for `election-provider-multi-block` pezpallet. This is required because
|
||||
// ! we don't want to generate the `trait WeightInfo`.
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
@@ -31,8 +31,8 @@
|
||||
// ../../../../../target/release/frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --pallet
|
||||
// pezpallet
|
||||
// --pezpallet
|
||||
// pezpallet_election_provider_multi_block
|
||||
// --extrinsic
|
||||
// *
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@
|
||||
|
||||
//! Autogenerated weights for `pezpallet_election_provider_multi_block_signed`
|
||||
//!
|
||||
//! This is a special template for `election-provider-multi-block` pallet. This is required because
|
||||
//! This is a special template for `election-provider-multi-block` pezpallet. This is required because
|
||||
// ! we don't want to generate the `trait WeightInfo`.
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
@@ -31,8 +31,8 @@
|
||||
// ../../../../../target/release/frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --pallet
|
||||
// pezpallet
|
||||
// --pezpallet
|
||||
// pezpallet_election_provider_multi_block_signed
|
||||
// --extrinsic
|
||||
// *
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@
|
||||
|
||||
//! Autogenerated weights for `pezpallet_election_provider_multi_block_signed`
|
||||
//!
|
||||
//! This is a special template for `election-provider-multi-block` pallet. This is required because
|
||||
//! This is a special template for `election-provider-multi-block` pezpallet. This is required because
|
||||
// ! we don't want to generate the `trait WeightInfo`.
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
@@ -31,8 +31,8 @@
|
||||
// ../../../../../target/release/frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --pallet
|
||||
// pezpallet
|
||||
// --pezpallet
|
||||
// pezpallet_election_provider_multi_block_signed
|
||||
// --extrinsic
|
||||
// *
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@
|
||||
|
||||
//! Autogenerated weights for `pezpallet_election_provider_multi_block_unsigned`
|
||||
//!
|
||||
//! This is a special template for `election-provider-multi-block` pallet. This is required because
|
||||
//! This is a special template for `election-provider-multi-block` pezpallet. This is required because
|
||||
// ! we don't want to generate the `trait WeightInfo`.
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
@@ -31,8 +31,8 @@
|
||||
// ../../../../../target/release/frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --pallet
|
||||
// pezpallet
|
||||
// --pezpallet
|
||||
// pezpallet_election_provider_multi_block_unsigned
|
||||
// --extrinsic
|
||||
// *
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@
|
||||
|
||||
//! Autogenerated weights for `pezpallet_election_provider_multi_block_unsigned`
|
||||
//!
|
||||
//! This is a special template for `election-provider-multi-block` pallet. This is required because
|
||||
//! This is a special template for `election-provider-multi-block` pezpallet. This is required because
|
||||
// ! we don't want to generate the `trait WeightInfo`.
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
@@ -31,8 +31,8 @@
|
||||
// ../../../../../target/release/frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --pallet
|
||||
// pezpallet
|
||||
// --pezpallet
|
||||
// pezpallet_election_provider_multi_block_unsigned
|
||||
// --extrinsic
|
||||
// *
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@
|
||||
|
||||
//! Autogenerated weights for `pezpallet_election_provider_multi_block_verifier`
|
||||
//!
|
||||
//! This is a special template for `election-provider-multi-block` pallet. This is required because
|
||||
//! This is a special template for `election-provider-multi-block` pezpallet. This is required because
|
||||
// ! we don't want to generate the `trait WeightInfo`.
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
@@ -31,8 +31,8 @@
|
||||
// ../../../../../target/release/frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --pallet
|
||||
// pezpallet
|
||||
// --pezpallet
|
||||
// pezpallet_election_provider_multi_block_verifier
|
||||
// --extrinsic
|
||||
// *
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@
|
||||
|
||||
//! Autogenerated weights for `pezpallet_election_provider_multi_block_verifier`
|
||||
//!
|
||||
//! This is a special template for `election-provider-multi-block` pallet. This is required because
|
||||
//! This is a special template for `election-provider-multi-block` pezpallet. This is required because
|
||||
// ! we don't want to generate the `trait WeightInfo`.
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
@@ -31,8 +31,8 @@
|
||||
// ../../../../../target/release/frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --pallet
|
||||
// pezpallet
|
||||
// --pezpallet
|
||||
// pezpallet_election_provider_multi_block_verifier
|
||||
// --extrinsic
|
||||
// *
|
||||
|
||||
Reference in New Issue
Block a user