Skip to content

Commit c6a65dd

Browse files
committed
one big round of refactors and tests, a lot left to do.
1 parent 26ceaf0 commit c6a65dd

32 files changed

+2619
-4003
lines changed

Cargo.lock

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/frame/election-provider-multi-block/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ pub mod pallet {
520520
/// The origin that can perform administration operations on this pallet.
521521
type AdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;
522522

523-
/// An indicator of whether we should move to do the [`crate::types::Done`] or not? This is
524-
/// called at the end of the election process.
523+
/// An indicator of whether we should move to do the [`crate::types::Phase::Done`] or not?
524+
/// This is called at the end of the election process.
525525
///
526526
/// Common implementation is [`ProceedRegardlessOf`] or [`RevertToSignedIfNotQueuedOf`].
527527
type AreWeDone: Get<Phase<Self>>;

substrate/frame/election-provider-multi-block/src/verifier/benchmarking.rs

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ use sp_std::prelude::*;
2828
mod benchmarks {
2929
use super::*;
3030

31-
// TODO: this is the epitome of bad DevEx because of generics.. create a nice one that works in
32-
// frame_system.
3331
fn events_for<T: Config>() -> Vec<Event<T>> {
3432
frame_system::Pallet::<T>::events()
3533
.into_iter()

substrate/frame/staking-next/Cargo.toml

+1-18
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,11 @@ workspace = true
1616
targets = ["x86_64-unknown-linux-gnu"]
1717

1818
[dependencies]
19-
codec = { features = [
20-
"derive",
21-
], workspace = true }
19+
codec = { features = [ "derive" ], workspace = true }
2220
frame-election-provider-support = { workspace = true }
2321
frame-support = { workspace = true }
2422
frame-system = { workspace = true }
2523
log = { workspace = true }
26-
pallet-authorship = { workspace = true }
27-
# Should be removed after `pallet_session::migrations::v1::MigrateDisabledValidators` and
28-
# `MigrateV14ToV15` are executed
29-
pallet-session = { features = [
30-
"historical",
31-
], workspace = true }
3224
pallet-staking-next-rc-client = { workspace = true }
3325
rand = { features = ["alloc"], workspace = true }
3426
rand_chacha = { workspace = true }
@@ -45,12 +37,10 @@ frame-benchmarking = { optional = true, workspace = true }
4537

4638
[dev-dependencies]
4739
frame-benchmarking = { workspace = true, default-features = true }
48-
frame-election-provider-support = { workspace = true, default-features = true }
4940
frame-support = { features = ["experimental"], workspace = true, default-features = true }
5041
pallet-bags-list = { workspace = true, default-features = true }
5142
pallet-balances = { workspace = true, default-features = true }
5243
pallet-staking-next-reward-curve = { workspace = true, default-features = true }
53-
pallet-timestamp = { workspace = true, default-features = true }
5444
rand_chacha = { workspace = true, default-features = true }
5545
sp-npos-elections = { workspace = true, default-features = true }
5646
sp-tracing = { workspace = true, default-features = true }
@@ -65,12 +55,9 @@ std = [
6555
"frame-support/std",
6656
"frame-system/std",
6757
"log/std",
68-
"pallet-authorship/std",
6958
"pallet-bags-list/std",
7059
"pallet-balances/std",
71-
"pallet-session/std",
7260
"pallet-staking-next-rc-client/std",
73-
"pallet-timestamp/std",
7461
"rand/std",
7562
"rand_chacha/std",
7663
"scale-info/std",
@@ -92,19 +79,15 @@ runtime-benchmarks = [
9279
"pallet-bags-list/runtime-benchmarks",
9380
"pallet-balances/runtime-benchmarks",
9481
"pallet-staking-next-rc-client/runtime-benchmarks",
95-
"pallet-timestamp/runtime-benchmarks",
9682
"sp-runtime/runtime-benchmarks",
9783
"sp-staking/runtime-benchmarks",
9884
]
9985
try-runtime = [
10086
"frame-election-provider-support/try-runtime",
10187
"frame-support/try-runtime",
10288
"frame-system/try-runtime",
103-
"pallet-authorship/try-runtime",
10489
"pallet-bags-list/try-runtime",
10590
"pallet-balances/try-runtime",
106-
"pallet-session/try-runtime",
10791
"pallet-staking-next-rc-client/try-runtime",
108-
"pallet-timestamp/try-runtime",
10992
"sp-runtime/try-runtime",
11093
]

substrate/frame/staking-next/ahm-test/src/ah/mock.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ impl multi_block::Config for Runtime {
169169
type TargetSnapshotPerBlock = TargetSnapshotPerBlock;
170170
type VoterSnapshotPerBlock = VoterSnapshotPerBlock;
171171
type Verifier = MultiBlockVerifier;
172+
type AreWeDone = multi_block::ProceedRegardlessOf<Self>;
172173
type WeightInfo = multi_block::weights::AllZeroWeights;
173174
}
174175

@@ -219,7 +220,7 @@ parameter_types! {
219220
pub static BondingDuration: u32 = 3;
220221
pub static SlashDeferredDuration: u32 = 2;
221222
pub static SessionsPerEra: u32 = 6;
222-
pub static ElectionOffset: u32 = 1;
223+
pub static PlanningEraOffset: u32 = 1;
223224
}
224225

225226
impl pallet_staking_next::Config for Runtime {
@@ -231,7 +232,7 @@ impl pallet_staking_next::Config for Runtime {
231232
type BenchmarkingConfig = pallet_staking_next::TestBenchmarkingConfig;
232233
type BondingDuration = BondingDuration;
233234
type SessionsPerEra = SessionsPerEra;
234-
type ElectionOffset = ElectionOffset;
235+
type PlanningEraOffset = PlanningEraOffset;
235236

236237
type Currency = Balances;
237238
type OldCurrency = Balances;
@@ -263,9 +264,6 @@ impl pallet_staking_next::Config for Runtime {
263264

264265
type RcClientInterface = RcClient;
265266

266-
// TODO
267-
type NextNewSession = ();
268-
269267
type WeightInfo = ();
270268
}
271269

@@ -331,7 +329,7 @@ impl ExtBuilder {
331329

332330
let validators = vec![1, 2, 3, 4, 5, 6, 7, 8]
333331
.into_iter()
334-
.map(|x| (x, x, INITIAL_STAKE, pallet_staking_next::StakerStatus::Validator));
332+
.map(|x| (x, INITIAL_STAKE, pallet_staking_next::StakerStatus::Validator));
335333

336334
let nominators = vec![
337335
(100, vec![1, 2]),
@@ -351,14 +349,14 @@ impl ExtBuilder {
351349
.into_iter()
352350
.map(|(x, y)| {
353351
let y = y.into_iter().map(|x| x).collect::<Vec<_>>();
354-
(x, x, INITIAL_STAKE, pallet_staking_next::StakerStatus::Nominator(y))
352+
(x, INITIAL_STAKE, pallet_staking_next::StakerStatus::Nominator(y))
355353
});
356354

357355
let stakers = validators.chain(nominators).collect::<Vec<_>>();
358356
let balances = stakers
359357
.clone()
360358
.into_iter()
361-
.map(|(x, _, _, _)| (x, INITIAL_BALANCE))
359+
.map(|(x, _, _)| (x, INITIAL_BALANCE))
362360
.collect::<Vec<_>>();
363361

364362
pallet_balances::GenesisConfig::<Runtime> { balances, ..Default::default() }

substrate/frame/staking-next/ahm-test/src/ah/test.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::ah::mock::*;
33
use frame_support::assert_ok;
44
use pallet_election_provider_multi_block::{Event as ElectionEvent, Phase};
55
use pallet_staking_next::{
6-
ActiveEra, ActiveEraInfo, CurrentEra, CurrentPlannedSession, Event as StakingEvent,
6+
ActiveEra, ActiveEraInfo, CurrentEra, Event as StakingEvent,
77
};
88
use pallet_staking_next_rc_client as rc_client;
99
use pallet_staking_next_rc_client::ValidatorSetReport;
@@ -14,7 +14,6 @@ fn on_receive_session_report() {
1414
ExtBuilder::default().local_queue().build().execute_with(|| {
1515
// GIVEN genesis state of ah
1616
assert_eq!(System::block_number(), 1);
17-
assert_eq!(CurrentPlannedSession::<T>::get(), 0);
1817
assert_eq!(CurrentEra::<T>::get(), Some(0));
1918
assert_eq!(pallet_staking_next::ErasStartSessionIndex::<T>::get(0), Some(0));
2019
assert_eq!(ActiveEra::<T>::get(), Some(ActiveEraInfo { index: 0, start: Some(0) }));
@@ -33,7 +32,6 @@ fn on_receive_session_report() {
3332
));
3433

3534
// THEN end 0, start 1, plan 2
36-
assert_eq!(CurrentPlannedSession::<T>::get(), 2);
3735
let era_points = pallet_staking_next::ErasRewardPoints::<T>::get(&0);
3836
assert_eq!(era_points.total, 360);
3937
assert_eq!(era_points.individual.get(&1), Some(&10));
@@ -87,9 +85,6 @@ fn on_receive_session_report() {
8785
);
8886
}
8987

90-
// current planned session is 4 (ongoing 3, last ended 2)
91-
assert_eq!(CurrentPlannedSession::<T>::get(), 4);
92-
9388
// Next session we will begin election.
9489
assert_ok!(rc_client::Pallet::<T>::relay_session_report(
9590
RuntimeOrigin::root(),
@@ -212,8 +207,6 @@ fn roll_many_eras() {
212207
leftover: false,
213208
}
214209
));
215-
// planned session is two ahead of end session.
216-
assert_eq!(CurrentPlannedSession::<T>::get(), session_counter + 2);
217210

218211
// increment session for the next iteration.
219212
session_counter += 1;
@@ -256,6 +249,21 @@ fn roll_many_eras() {
256249
});
257250
}
258251

252+
#[test]
253+
fn receives_too_many_session_reports_at_once() {
254+
todo!()
255+
}
256+
257+
#[test]
258+
fn receives_session_old_session_report() {
259+
todo!()
260+
}
261+
262+
#[test]
263+
fn receives_session_report_in_future() {
264+
todo!()
265+
}
266+
259267
#[test]
260268
fn on_new_offence() {
261269
// todo(ank4n):

substrate/frame/staking-next/ahm-test/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ mod tests {
2323
// initial state of ah
2424
shared::in_ah(|| {
2525
assert_eq!(frame_system::Pallet::<ah::Runtime>::block_number(), 1);
26-
assert_eq!(pallet_staking_next::CurrentPlannedSession::<ah::Runtime>::get(), 0);
2726
assert_eq!(pallet_staking_next::CurrentEra::<ah::Runtime>::get(), Some(0));
2827
assert_eq!(
2928
ActiveEra::<ah::Runtime>::get(),
@@ -57,7 +56,6 @@ mod tests {
5756
shared::in_ah(|| {
5857
// ah's rc-client has also progressed some blocks, equal to 4 sessions
5958
assert_eq!(frame_system::Pallet::<ah::Runtime>::block_number(), 121);
60-
assert_eq!(pallet_staking_next::CurrentPlannedSession::<ah::Runtime>::get(), 5);
6159
// election is ongoing, and has just started
6260
assert!(matches!(
6361
multi_block::CurrentPhase::<ah::Runtime>::get(),

substrate/frame/staking-next/runtimes/parachain/src/staking.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ impl pallet_staking_next::Config for Runtime {
260260
type AdminOrigin = EitherOf<EnsureRoot<AccountId>, StakingAdmin>;
261261
type EraPayout = EraPayout;
262262
type MaxExposurePageSize = MaxExposurePageSize;
263-
type NextNewSession = Session;
264263
type ElectionProvider = MultiBlock;
265264
type GenesisElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
266265
type VoterList = VoterList;
@@ -275,7 +274,7 @@ impl pallet_staking_next::Config for Runtime {
275274
type WeightInfo = weights::pallet_staking_next::WeightInfo<Runtime>;
276275
type MaxInvulnerables = frame_support::traits::ConstU32<20>;
277276
type MaxDisabledValidators = ConstU32<100>;
278-
type ElectionOffset = ConstU32<2>;
277+
type PlanningEraOffset = ConstU32<2>;
279278
type RcClientInterface = StakingRcClient;
280279
}
281280

substrate/frame/staking-next/src/benchmarking.rs

-6
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ pub fn create_validator_with_nominators<T: Config>(
115115
MinimumValidatorCount::<T>::put(1);
116116

117117
// Start a new (genesis) Era
118-
// populate electable stashes as it gets read within `try_plan_new_era`
119-
120-
// ElectableStashes::<T>::put(
121-
// BoundedBTreeSet::try_from(vec![v_stash.clone()].into_iter().collect::<BTreeSet<_>>())
122-
// .unwrap(),
123-
// );
124118
let new_validators = Staking::<T>::try_plan_new_era(SessionIndex::one(), true).unwrap();
125119

126120
assert_eq!(new_validators.len(), 1);

0 commit comments

Comments
 (0)