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

[WIP] PoV friendly, multi-block Election Provider Multi-Phase pallet #2504

Merged
merged 34 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3f8ee9b
Starts implementing the multi-block EPM pallet
gpestana Oct 20, 2023
d1b34f9
Election provider support changes (to cont.)
gpestana Nov 1, 2023
5135b3e
Merge branch 'master' into gpestana/epm-multi-block
gpestana Nov 1, 2023
082f1fe
Merge branch 'master' into gpestana/epm-multi-block
gpestana Nov 3, 2023
d86de43
Merge branch 'master' into gpestana/epm-multi-block
gpestana Nov 6, 2023
d569d18
Adds verifier
gpestana Nov 7, 2023
aca05b0
finish draft impl of verifier
gpestana Nov 7, 2023
49ebb4d
Final forgotten bits
gpestana Nov 7, 2023
f576cc9
improves tests and mock
gpestana Nov 7, 2023
11f62f9
Merge branch 'master' into gpestana/epm-multi-block
gpestana Nov 7, 2023
3e401d5
Merge branch 'master' into gpestana/epm-multi-block
gpestana Nov 22, 2023
717602f
tests and more improvements
gpestana Nov 24, 2023
1709ab4
Adds signed sub-pallet and a few other improvements
gpestana Nov 27, 2023
18d9599
more core tests; staking integration finished; playground/integration…
gpestana Dec 6, 2023
26a6acd
Adds unsigned/miner -- squash
gpestana Dec 10, 2023
ee343fb
e2e integration tests with staking (single page)
gpestana Jan 10, 2024
ef2a866
Fixes multi page election
gpestana Jan 12, 2024
2d2dfdc
Merge branch 'master' into gpestana/epm-multi-block
gpestana Jan 15, 2024
e115cf7
Fix integration tests mock after merging master
gpestana Jan 15, 2024
d0db405
stakes-based bounded supports (solution) paging working
gpestana Jan 15, 2024
8c3165b
[squash]
gpestana Jan 17, 2024
40da0fc
[squash] target and voter idx etc
gpestana Jan 17, 2024
c76f36f
[squash] integrates staking MB
gpestana Jan 17, 2024
70f43ad
[squash]: fixes multi page election data provider
gpestana Jan 18, 2024
3a8a5fb
Merge branch 'gpestana/epm-multi-block' into gpestana/epm-multi-block…
gpestana Jan 18, 2024
37af6e4
squash
gpestana Jan 18, 2024
7c83ba7
[squash] collect exposures paged elect
gpestana Jan 21, 2024
47a7ccb
remove uncessary printlns
gpestana Jan 21, 2024
ca3d9b1
target helpers
gpestana Jan 29, 2024
9a8b690
Removes target snapsho pagination
gpestana Jan 29, 2024
3ea6b51
Removes support to multi-block target snapshot fetching; EPM-MB <> St…
gpestana Jan 29, 2024
9f0ee12
Adds export phase limit
gpestana Jan 29, 2024
35c3828
builds the target snapshot only once per round
gpestana Jan 29, 2024
683f88a
Adds the LockableElectionDataProvider trait and implements it for sta…
gpestana Jan 29, 2024
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
46 changes: 46 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ members = [
"substrate/frame/conviction-voting",
"substrate/frame/core-fellowship",
"substrate/frame/democracy",
"substrate/frame/election-provider-multi-block",
"substrate/frame/election-provider-multi-block/integration-tests",
"substrate/frame/election-provider-multi-phase",
"substrate/frame/election-provider-multi-phase/test-staking-e2e",
"substrate/frame/election-provider-support",
Expand Down
61 changes: 61 additions & 0 deletions substrate/frame/election-provider-multi-block/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[package]
name = "pallet-election-provider-multi-block"
version = "4.0.0-dev"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
homepage = "https://substrate.dev"
repository.workspace = true
description = "FRAME pallet election provider multi-block"
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.10.0", default-features = false, features = [
"derive",
] }
log = { version = "0.4.17", default-features = false }

frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }

sp-io = { path = "../../primitives/io", default-features = false}
sp-std = { path = "../../primitives/std", default-features = false}
sp-core = { path = "../../primitives/core", default-features = false}
sp-runtime = { path = "../../primitives/runtime", default-features = false}

frame-election-provider-support = { default-features = false, path = "../election-provider-support" }
sp-npos-elections = { default-features = false, path = "../../primitives/npos-elections" }

[dev-dependencies]
sp-tracing = { path = "../../primitives/tracing" }
pallet-balances = { path = "../balances", default-features = false}

[features]
default = [ "std" ]
std = [
"codec/std",
"scale-info/std",
"log/std",
"frame-support/std",
"frame-system/std",
"sp-std/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"frame-election-provider-support/std",
"sp-npos-elections/std",
"pallet-balances/std",
]
try-runtime = [
"frame-election-provider-support/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
]
1 change: 1 addition & 0 deletions substrate/frame/election-provider-multi-block/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Election Provider multi-block
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "pallet-election-tests"
version = "1.0.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
homepage = "https://substrate.io"
repository.workspace = true
description = "FRAME election provider multi block pallet tests with staking pallet, bags-list and session pallets"
publish = false

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dev-dependencies]
parking_lot = "0.12.1"
codec = { package = "parity-scale-codec", version = "3.6.1", features = ["derive"] }
scale-info = { version = "2.10.0", features = ["derive"] }
log = { version = "0.4.17", default-features = false }
substrate-test-utils = { path = "../../../test-utils" }

sp-runtime = { path = "../../../primitives/runtime" }
sp-io = { path = "../../../primitives/io" }
sp-std = { path = "../../../primitives/std" }
sp-staking = { path = "../../../primitives/staking" }
sp-core = { path = "../../../primitives/core" }
sp-npos-elections = { path = "../../../primitives/npos-elections", default-features = false}
sp-tracing = { path = "../../../primitives/tracing" }

frame-system = { path = "../../system" }
frame-support = { path = "../../support" }
frame-election-provider-support = { path = "../../election-provider-support" }

pallet-election-provider-multi-block = { path = ".." }
pallet-staking = { path = "../../staking" }
pallet-bags-list = { path = "../../bags-list" }
pallet-balances = { path = "../../balances" }
pallet-timestamp = { path = "../../timestamp" }
pallet-session = { path = "../../session" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg(test)]
mod mock;

pub(crate) const LOG_TARGET: &str = "integration-tests::epm-staking";

use mock::*;

use frame_election_provider_support::{bounds::ElectionBoundsBuilder, ElectionDataProvider};

use frame_support::assert_ok;

// syntactic sugar for logging.
#[macro_export]
macro_rules! log {
($level:tt, $patter:expr $(, $values:expr)* $(,)?) => {
log::$level!(
target: crate::LOG_TARGET,
concat!("🛠️ ", $patter) $(, $values)*
)
};
}

fn log_current_time() {
log!(
info,
"block: {:?}, session: {:?}, era: {:?}, EPM phase: {:?} ts: {:?}",
System::block_number(),
Session::current_index(),
Staking::current_era(),
ElectionProvider::current_phase(),
Timestamp::now()
);
}

#[test]
fn block_progression_works() {
let (mut ext, _pool_state, _) = ExtBuilder::default().build_offchainify();
ext.execute_with(|| {})
}

#[test]
fn verify_snapshot() {
ExtBuilder::default().build_and_execute(|| {
assert_eq!(Pages::get(), 3);

// manually get targets and voters from staking to see the inspect the issue with the
// DataProvider.
let bounds = ElectionBoundsBuilder::default()
.targets_count((TargetSnapshotPerBlock::get() as u32).into())
.voters_count((VoterSnapshotPerBlock::get() as u32).into())
.build();

assert_ok!(<Staking as ElectionDataProvider>::electable_targets(bounds.targets, 2));
assert_ok!(<Staking as ElectionDataProvider>::electing_voters(bounds.voters, 2));
})
}

mod staking_integration {
use super::*;

#[test]
fn call_elect_multi_block() {
ExtBuilder::default().build_and_execute(|| {
assert_eq!(Pages::get(), 3);
assert_eq!(ElectionProvider::current_round(), 0);
assert_eq!(Staking::current_era(), Some(0));

// staking prepares first page of exposures.
roll_to(election_prediction() - 3, false);

// staking prepares second page of exposures.
roll_to(election_prediction() - 2, false);

// staking prepares third page of exposures.
roll_to(election_prediction() - 1, false);

// election successfully, round & era progressed.
//assert_eq!(ElectionProvider::current_phase(), Phase::Off);
//assert_eq!(ElectionProvider::current_round(), 1);
//assert_eq!(Staking::current_era(), Some(1));
})
}
}
Loading
Loading