Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement wrapping of EPM types #1600

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e74c2ec
Implement wrapping of EPM types
wirednkod Sep 16, 2023
06a0283
fmt
wirednkod Sep 17, 2023
6285a1b
minor renaming
wirednkod Sep 17, 2023
af1f952
Update tests
wirednkod Sep 17, 2023
eb2bc25
fmt
wirednkod Sep 17, 2023
13325a2
minor fix on type passed to 'exists' and 'not_exists' fn of SnapshotW…
wirednkod Sep 17, 2023
211eec9
Merge branch 'master' into nik-wrap-epm-types
wirednkod Sep 17, 2023
2ca30ed
fix: export-genesis-state command (#1521)
Moliholy Sep 17, 2023
cf5c195
[Backport] Version bumps from release 1.1.0 (#1580)
EgorPopelyaev Sep 17, 2023
e389988
Executor: Remove `LegacyInstanceReuse` strategy (#1486)
yjhmelody Sep 18, 2023
a8e82a3
xcm-builder: PayOverXcm supports fallible convertors for asset kind a…
muharem Sep 18, 2023
1d5a9d2
[improve docs] Example pallet crate and Basic Example pallet (#1546)
Sep 18, 2023
f6072e8
[improve docs]: Timestamp pallet (#1435)
Sep 18, 2023
d569e72
"Common good" vs "System" parachain clean up (#1406)
bkontur Sep 18, 2023
614aa31
Implements a variable deposit base calculation for EPM signed submiss…
gpestana Sep 18, 2023
e05d369
Bump docker/setup-buildx-action from 2.1.0 to 3.0.0 (#1551)
dependabot[bot] Sep 18, 2023
519a0f0
Replace secrets with the new ones (#1564)
chevdor Sep 18, 2023
f14bf34
Broker pallet: `RegionDropped` event fix & additional tests (#1609)
Szegoo Sep 18, 2023
a50e6ba
Bump docker/login-action from 2 to 3 (#1531)
dependabot[bot] Sep 18, 2023
20052e1
Bump docker/build-push-action from 4 to 5 (#1552)
dependabot[bot] Sep 18, 2023
5d34664
chainHead: Add support for storage closest merkle descendant #14818 …
lexnv Sep 18, 2023
372929f
Bump the known_good_semver group with 1 update (#1606)
dependabot[bot] Sep 18, 2023
8900d5b
Move ISSUE_TEMPLATE (#1567)
chevdor Sep 18, 2023
e6f5e23
[ci] Publish implementers guide (#1615)
alvicsam Sep 18, 2023
a181ced
Replace free for all collation in `cumulus` runtimes (#1251)
georgepisaltu Sep 18, 2023
ffe5db0
Staking: Add `dest` to `Rewarded` to aid in reward calculations (#1602)
Sep 18, 2023
340c683
Implement wrapping of EPM types
wirednkod Sep 16, 2023
5d3073c
fmt
wirednkod Sep 17, 2023
66d8d3b
minor renaming
wirednkod Sep 17, 2023
9c31d4e
Update tests
wirednkod Sep 17, 2023
81955a5
fmt
wirednkod Sep 17, 2023
75f237f
minor fix on type passed to 'exists' and 'not_exists' fn of SnapshotW…
wirednkod Sep 17, 2023
e5411f2
Add minor documentation about wrapper
wirednkod Sep 18, 2023
31699a9
Add minor documentation about wrapper
wirednkod Sep 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions polkadot/xcm/xcm-builder/src/universal_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorMulti
let xcm = msg.take().ok_or(MissingArgument)?;

// find exporter
let Some((bridge, maybe_payment)) = Bridges::exporter_for(&remote_network, &remote_location, &xcm) else {
let Some((bridge, maybe_payment)) =
Bridges::exporter_for(&remote_network, &remote_location, &xcm)
else {
// We need to make sure that msg is not consumed in case of `NotApplicable`.
*msg = Some(xcm);
return Err(SendError::NotApplicable)
Expand Down Expand Up @@ -236,7 +238,9 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorMulti
let xcm = msg.take().ok_or(MissingArgument)?;

// find exporter
let Some((bridge, maybe_payment)) = Bridges::exporter_for(&remote_network, &remote_location, &xcm) else {
let Some((bridge, maybe_payment)) =
Bridges::exporter_for(&remote_network, &remote_location, &xcm)
else {
// We need to make sure that msg is not consumed in case of `NotApplicable`.
*msg = Some(xcm);
return Err(SendError::NotApplicable)
Expand Down
65 changes: 39 additions & 26 deletions substrate/frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,16 @@ pub mod migrations;
pub mod signed;
pub mod unsigned;
pub mod weights;
use unsigned::VoterOf;
pub use weights::WeightInfo;

use frame_support::pallet_prelude::PhantomData;

pub use signed::{
BalanceOf, NegativeImbalanceOf, PositiveImbalanceOf, SignedSubmission, SignedSubmissionOf,
SignedSubmissions, SubmissionIndicesOf,
};
use unsigned::VoterOf;
pub use unsigned::{Miner, MinerConfig};
pub use weights::WeightInfo;

/// The solution type used by this crate.
pub type SolutionOf<T> = <T as MinerConfig>::Solution;
Expand Down Expand Up @@ -1353,6 +1355,35 @@ pub mod pallet {
pub struct Pallet<T>(_);
}

pub struct SnapshotWrapper<T>(PhantomData<T>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could add a small documentation that this wrapper handles the synchronization of Snapshot, SnapshotMetadata and DesiredTargets


impl<T: Config> SnapshotWrapper<T> {
/// kill all snapshot related storage items at the same time
pub fn kill() {
<Snapshot<T>>::kill();
<SnapshotMetadata<T>>::kill();
<DesiredTargets<T>>::kill();
}
/// Set all snapshot related storage items at the same time
pub fn set(metadata: SolutionOrSnapshotSize, desired_targets: u32, buffer: Vec<u8>) {
<SnapshotMetadata<T>>::put(metadata);
<DesiredTargets<T>>::put(desired_targets);
sp_io::storage::set(&<Snapshot<T>>::hashed_key(), &buffer);
}

/// Check if all of the storage items exist
pub fn exists() -> bool {
<Snapshot<T>>::exists() && <SnapshotMetadata<T>>::exists() && <DesiredTargets<T>>::exists()
}

/// Check if all of the storage items do not exist
pub fn not_exists() -> bool {
!<Snapshot<T>>::exists() &&
!<SnapshotMetadata<T>>::exists() &&
!<DesiredTargets<T>>::exists()
}
}

impl<T: Config> Pallet<T> {
/// Internal logic of the offchain worker, to be executed only when the offchain lock is
/// acquired with success.
Expand Down Expand Up @@ -1404,9 +1435,6 @@ impl<T: Config> Pallet<T> {
SolutionOrSnapshotSize { voters: voters.len() as u32, targets: targets.len() as u32 };
log!(info, "creating a snapshot with metadata {:?}", metadata);

<SnapshotMetadata<T>>::put(metadata);
<DesiredTargets<T>>::put(desired_targets);

// instead of using storage APIs, we do a manual encoding into a fixed-size buffer.
// `encoded_size` encodes it without storing it anywhere, this should not cause any
// allocation.
Expand All @@ -1421,7 +1449,7 @@ impl<T: Config> Pallet<T> {
// buffer should have not re-allocated since.
debug_assert!(buffer.len() == size && size == buffer.capacity());

sp_io::storage::set(&<Snapshot<T>>::hashed_key(), &buffer);
SnapshotWrapper::<T>::set(metadata, desired_targets, buffer);
}

/// Parts of [`create_snapshot`] that happen outside of this pallet.
Expand Down Expand Up @@ -1504,9 +1532,7 @@ impl<T: Config> Pallet<T> {

/// Kill everything created by [`Pallet::create_snapshot`].
pub fn kill_snapshot() {
<Snapshot<T>>::kill();
<SnapshotMetadata<T>>::kill();
<DesiredTargets<T>>::kill();
SnapshotWrapper::<T>::kill();
}

/// Checks the feasibility of a solution.
Expand Down Expand Up @@ -1615,15 +1641,7 @@ impl<T: Config> Pallet<T> {
// - [`DesiredTargets`] exists if and only if [`Snapshot`] is present.
// - [`SnapshotMetadata`] exist if and only if [`Snapshot`] is present.
fn try_state_snapshot() -> Result<(), TryRuntimeError> {
if <Snapshot<T>>::exists() &&
<SnapshotMetadata<T>>::exists() &&
<DesiredTargets<T>>::exists()
{
Ok(())
} else if !<Snapshot<T>>::exists() &&
!<SnapshotMetadata<T>>::exists() &&
!<DesiredTargets<T>>::exists()
{
if SnapshotWrapper::<T>::exists() || SnapshotWrapper::<T>::not_exists() {
Ok(())
} else {
Err("If snapshot exists, metadata and desired targets should be set too. Otherwise, none should be set.".into())
Expand Down Expand Up @@ -1758,18 +1776,13 @@ mod feasibility_check {
assert!(MultiPhase::current_phase().is_signed());
let solution = raw_solution();

// For whatever reason it might be:
<Snapshot<Runtime>>::kill();

// kill all `Snapshot, `SnapshotMetadata` and `DesiredTargets` for the storage state to
// be consistent, by using the `SnapshotWrapper` for the try_state checks to pass.
<SnapshotWrapper<Runtime>>::kill();
assert_noop!(
MultiPhase::feasibility_check(solution, COMPUTE),
FeasibilityError::SnapshotUnavailable
);

// kill also `SnapshotMetadata` and `DesiredTargets` for the storage state to be
// consistent for the try_state checks to pass.
<SnapshotMetadata<Runtime>>::kill();
<DesiredTargets<Runtime>>::kill();
})
}

Expand Down