Skip to content
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
82f9339
allow and test staking-async xcm messages to be splitted
kianenigma May 5, 2025
2d0f7be
Update substrate/frame/staking-async/runtimes/parachain/src/staking.rs
kianenigma May 5, 2025
6da3b99
Update substrate/frame/staking-async/runtimes/parachain/src/staking.rs
kianenigma May 5, 2025
03ace80
Apply suggestions from code review
kianenigma May 5, 2025
35b8e05
Merge branch 'master' of github.com:paritytech/polkadot-sdk into kiz-…
kianenigma May 5, 2025
ee701f5
fmt
kianenigma May 5, 2025
669ef3e
Update from github-actions[bot] running command 'prdoc --bump minor'
github-actions[bot] May 5, 2025
88096fd
small fixes, waiting for 8409 to be merged
kianenigma May 5, 2025
cca3008
Merge branch 'master' of github.com:paritytech/polkadot-sdk into kiz-…
kianenigma May 14, 2025
b82ea6c
make paged solution unbounded -- but not tested yet with ZN, it shoul…
kianenigma May 14, 2025
9c1c6f4
ErasClaimedRewards -> ClaimedRewards
kianenigma May 20, 2025
d5de81c
fix epmb solution duplicate issue + add remote mining apparatus to epm
kianenigma May 20, 2025
1e98f35
Master.into()
kianenigma May 20, 2025
641015f
feature-gate it
kianenigma May 20, 2025
1c24d17
fix test ordering
kianenigma May 21, 2025
10a0869
fmt
kianenigma May 21, 2025
d70ba72
refactor XCM stuff
kianenigma May 22, 2025
6a682fc
Master.into()
kianenigma May 22, 2025
971b9e9
add Justfile
kianenigma May 22, 2025
8b79b0a
clippy
kianenigma May 22, 2025
1325913
taplo
kianenigma May 22, 2025
f9f7995
make names be like westend
kianenigma May 27, 2025
75c7dae
Update prdoc/pr_8422.prdoc
kianenigma May 29, 2025
11aa855
Update prdoc/pr_8422.prdoc
kianenigma May 29, 2025
35683a9
small improvement in chunk_size
kianenigma May 29, 2025
d54db21
Merge branch 'master' of github.com:paritytech/polkadot-sdk into kiz-…
kianenigma May 29, 2025
d2b84df
fmt
kianenigma May 29, 2025
3451ade
Merge branch 'kiz-staking-async-xcm-weight' of github.com:paritytech/…
kianenigma May 29, 2025
c3d0a8f
zepter
kianenigma May 29, 2025
3d2e865
fix prdoc
kianenigma May 29, 2025
9ab18e7
taplo
kianenigma May 29, 2025
c161aeb
staking-async: rename relay and parachain version runtimes
sigurpol May 30, 2025
caf5024
rename SessionsPerEra back
kianenigma May 30, 2025
0c266f6
prdoc
kianenigma May 30, 2025
83586c9
Merge branch 'master' of github.com:paritytech/polkadot-sdk into kiz-…
kianenigma May 30, 2025
0ea8d91
taplo
kianenigma May 30, 2025
e9ed85d
fmt
kianenigma May 30, 2025
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
1 change: 1 addition & 0 deletions Cargo.lock

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

24 changes: 24 additions & 0 deletions prdoc/pr_8422.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
title: '[AHM] Staking async fixes for XCM and election planning'
doc:
- audience: Runtime Dev
description: |-
This PR brings a few small fixes related to the XCM messages of stkaing-async, among other small fixes:


* [x] Allows `xcm::validate` to check the message size, and we actually now act upon it in the `staking-async-rc/parachain-runtime`s. The code is a bit duplicate now, and there is a TOOD about how to better refactor it later.
* [x] Part of this work is backported separately as https://github.com/paritytech/polkadot-sdk/pull/8409
* [x] It brings a default `EraElectionPlannerOf` which should be the right tool to use to ensure elections always happen in time, with an educated guess based on `ElectionProvider::duration` rather than a random number.
* [x] It adds a few unit tests about the above
* [x] It silences some logs that were needlessly `INFO`, and makes the printing of some types a bit more CLI friendly.
* [x] Renames `type SessionDuration` in `staking-async` to `type RelaySessionDuration` for better clarity.
crates:
- name: pallet-staking-async-ah-client
bump: patch
- name: pallet-staking-async-rc-client
bump: minor
- name: pallet-staking-async-parachain-runtime
bump: minor
- name: pallet-staking-async-rc-runtime
bump: major
- name: pallet-staking-async
bump: major
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ use crate::{
};
use frame_election_provider_support::PageIndex;
use frame_support::{
assert_ok, dispatch::PostDispatchInfo, parameter_types, traits::EstimateCallFee, BoundedVec,
assert_ok, dispatch::PostDispatchInfo, parameter_types, traits::EstimateCallFee,
};
use sp_npos_elections::ElectionScore;
use sp_runtime::{traits::Zero, Perbill};

parameter_types! {
pub static MockSignedNextSolution: Option<BoundedVec<SolutionOf<Runtime>, Pages>> = None;
pub static MockSignedNextSolution: Option<Vec<SolutionOf<Runtime>>> = None;
pub static MockSignedNextScore: Option<ElectionScore> = Default::default();
pub static MockSignedResults: Vec<VerificationResult> = Default::default();
}
Expand Down
34 changes: 22 additions & 12 deletions substrate/frame/election-provider-multi-block/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ pub type AssignmentOf<T> =
CloneNoBound,
EqNoBound,
PartialEqNoBound,
MaxEncodedLen,
DefaultNoBound,
)]
#[codec(mel_bound(T: crate::Config))]
#[scale_info(skip_type_params(T))]
pub struct PagedRawSolution<T: MinerConfig> {
/// The individual pages.
pub solution_pages: BoundedVec<SolutionOf<T>, <T as MinerConfig>::Pages>,
pub solution_pages: Vec<SolutionOf<T>>,
/// The final claimed score post feasibility and concatenation of all pages.
pub score: ElectionScore,
/// The designated round.
Expand Down Expand Up @@ -165,6 +164,23 @@ pub trait PadSolutionPages: Sized {
fn pad_solution_pages(self, desired_pages: PageIndex) -> Self;
}

impl<T: Default + Clone + Debug> PadSolutionPages for Vec<T> {
fn pad_solution_pages(self, desired_pages: PageIndex) -> Self {
let desired_pages_usize = desired_pages as usize;
debug_assert!(self.len() <= desired_pages_usize);
if self.len() == desired_pages_usize {
return self
}

// we basically need to prepend the list with this many items.
let empty_slots = desired_pages_usize.saturating_sub(self.len());
sp_std::iter::repeat(Default::default())
.take(empty_slots)
.chain(self.into_iter())
.collect::<Vec<_>>()
}
}

impl<T: Default + Clone + Debug, Bound: frame_support::traits::Get<u32>> PadSolutionPages
for BoundedVec<T, Bound>
{
Expand Down Expand Up @@ -391,8 +407,6 @@ impl<T: crate::Config> Phase<T> {
#[cfg(test)]
mod pagify {
use super::{PadSolutionPages, Pagify};
use frame_support::{traits::ConstU32, BoundedVec};
use sp_core::bounded_vec;

#[test]
fn pagify_works() {
Expand All @@ -410,15 +424,11 @@ mod pagify {
#[test]
fn pad_solution_pages_works() {
// noop if the solution is complete, as with pagify.
let solution: BoundedVec<_, ConstU32<3>> = bounded_vec![1u32, 2, 3];
assert_eq!(solution.pad_solution_pages(3).into_inner(), vec![1, 2, 3]);
let solution = vec![1u32, 2, 3];
assert_eq!(solution.pad_solution_pages(3), vec![1, 2, 3]);

// pads the solution with default if partial..
let solution: BoundedVec<_, ConstU32<3>> = bounded_vec![2, 3];
assert_eq!(solution.pad_solution_pages(3).into_inner(), vec![0, 2, 3]);

// behaves the same as `pad_solution_pages(3)`.
let solution: BoundedVec<_, ConstU32<3>> = bounded_vec![2, 3];
assert_eq!(solution.pad_solution_pages(4).into_inner(), vec![0, 2, 3]);
let solution = vec![2, 3];
assert_eq!(solution.pad_solution_pages(3), vec![0, 2, 3]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl<T: MinerConfig> BaseMiner<T> {
}

// convert each page to a compact struct -- no more change allowed.
let solution_pages: BoundedVec<SolutionOf<T>, T::Pages> = paged_assignments
let mut solution_pages: Vec<SolutionOf<T>> = paged_assignments
.into_iter()
.enumerate()
.map(|(page_index, assignment_page)| {
Expand All @@ -382,12 +382,11 @@ impl<T: MinerConfig> BaseMiner<T> {
.ok_or(MinerError::SnapshotUnAvailable(SnapshotType::Voters(page)))?;

// one last trimming -- `MaxBackersPerWinner`, the per-page variant.
let trimmed_assignment_page =
Self::trim_supports_max_backers_per_winner_per_page(
assignment_page,
voter_snapshot_page,
page_index as u32,
)?;
let trimmed_assignment_page = Self::trim_supports_max_backers_per_winner_per_page(
assignment_page,
voter_snapshot_page,
page_index as u32,
)?;

let voter_index_fn = {
let cache = helpers::generate_voter_cache::<T, _>(&voter_snapshot_page);
Expand All @@ -401,17 +400,11 @@ impl<T: MinerConfig> BaseMiner<T> {
)
.map_err::<MinerError<T>, _>(Into::into)
})
.collect::<Result<Vec<_>, _>>()?
.try_into()
.expect("`paged_assignments` is bound by `T::Pages`; length cannot change in iter chain; qed");
.collect::<Result<Vec<_>, _>>()?;

// now do the length trim.
let mut solution_pages_unbounded = solution_pages.into_inner();
let _trim_length_weight =
Self::maybe_trim_weight_and_len(&mut solution_pages_unbounded, &voter_pages)?;
let solution_pages = solution_pages_unbounded
.try_into()
.expect("maybe_trim_weight_and_len cannot increase the length of its input; qed.");
Self::maybe_trim_weight_and_len(&mut solution_pages, &voter_pages)?;
miner_log!(debug, "trimmed {} voters due to length restriction.", _trim_length_weight);

// finally, wrap everything up. Assign a fake score here, since we might need to re-compute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ mod pallet {
// we select the most significant pages, based on `T::MinerPages`.
let page_indices = crate::Pallet::<T>::msp_range_for(T::MinerPages::get() as usize);
<T::Verifier as Verifier>::verify_synchronous_multi(
paged_solution.solution_pages.into_inner(),
paged_solution.solution_pages,
page_indices,
claimed_score,
)
Expand Down Expand Up @@ -235,7 +235,12 @@ mod pallet {
assert!(
UnsignedWeightsOf::<T>::submit_unsigned().all_lte(T::BlockWeights::get().max_block),
"weight of `submit_unsigned` is too high"
)
);
assert!(
<T as Config>::MinerPages::get() as usize <=
<T as crate::Config>::Pages::get() as usize,
"number of pages in the unsigned phase is too high"
);
}

#[cfg(feature = "try-runtime")]
Expand Down Expand Up @@ -333,6 +338,10 @@ mod pallet {
paged_solution.solution_pages.len() == T::MinerPages::get() as usize,
CommonError::WrongPageCount
);
ensure!(
paged_solution.solution_pages.len() <= <T as crate::Config>::Pages::get() as usize,
CommonError::WrongPageCount
);

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ mod multi_page_sync_verification {
assert_eq!(<VerifierPallet as Verifier>::queued_score(), None);

let _ = <VerifierPallet as Verifier>::verify_synchronous_multi(
paged.solution_pages.clone().into_inner(),
paged.solution_pages.clone(),
MultiBlock::msp_range_for(2),
paged.score,
)
Expand Down Expand Up @@ -955,7 +955,7 @@ mod multi_page_sync_verification {
assert_eq!(<VerifierPallet as Verifier>::queued_score(), None);

let _ = <VerifierPallet as Verifier>::verify_synchronous_multi(
paged.solution_pages.clone().into_inner(),
paged.solution_pages.clone(),
MultiBlock::msp_range_for(3),
paged.score,
)
Expand Down Expand Up @@ -987,7 +987,7 @@ mod multi_page_sync_verification {

assert_eq!(
<VerifierPallet as Verifier>::verify_synchronous_multi(
paged.solution_pages.clone().into_inner(),
paged.solution_pages.clone(),
MultiBlock::msp_range_for(2),
paged.score,
)
Expand Down Expand Up @@ -1021,7 +1021,7 @@ mod multi_page_sync_verification {

assert_eq!(
<VerifierPallet as Verifier>::verify_synchronous_multi(
paged.solution_pages.clone().into_inner(),
paged.solution_pages.clone(),
MultiBlock::msp_range_for(2),
paged.score,
)
Expand Down Expand Up @@ -1055,7 +1055,7 @@ mod multi_page_sync_verification {

hypothetically!({
assert_ok!(<VerifierPallet as Verifier>::verify_synchronous_multi(
paged.solution_pages.clone().into_inner(),
paged.solution_pages.clone(),
MultiBlock::msp_range_for(2),
paged.score,
));
Expand Down Expand Up @@ -1098,7 +1098,7 @@ mod multi_page_sync_verification {

assert_eq!(
<VerifierPallet as Verifier>::verify_synchronous_multi(
paged.solution_pages.clone().into_inner(),
paged.solution_pages.clone(),
MultiBlock::msp_range_for(2),
paged.score,
)
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/staking-async/ah-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ pub mod pallet {
report: rc_client::ValidatorSetReport<T::AccountId>,
) -> DispatchResult {
// Ensure the origin is one of Root or whatever is representing AssetHub.
log!(info, "Received new validator set report {:?}", report);
log!(debug, "Received new validator set report {}", report);
T::AssetHubOrigin::ensure_origin_or_root(origin)?;

// Check the operating mode.
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/staking-async/ahm-test/src/ah/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ impl multi_block::signed::Config for Runtime {
parameter_types! {
pub static BondingDuration: u32 = 3;
pub static SlashDeferredDuration: u32 = 2;
pub static SessionsPerEra: u32 = 6;
pub static PlanningEraOffset: u32 = 1;
pub static RelaySessionsPerEra: u32 = 6;
pub static PlanningEraOffset: u32 = 2;
}

impl pallet_staking_async::Config for Runtime {
Expand All @@ -326,7 +326,7 @@ impl pallet_staking_async::Config for Runtime {

type AdminOrigin = EnsureRoot<AccountId>;
type BondingDuration = BondingDuration;
type SessionsPerEra = SessionsPerEra;
type RelaySessionsPerEra = RelaySessionsPerEra;
type PlanningEraOffset = PlanningEraOffset;

type Currency = Balances;
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/staking-async/ahm-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ mod tests {
rc::roll_until_matches(
|| {
pallet_session::CurrentIndex::<rc::Runtime>::get() ==
current_session + ah::SessionsPerEra::get() + 1
current_session + ah::RelaySessionsPerEra::get() + 1
},
true,
);
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/staking-async/rc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ scale-info = { workspace = true, features = ["derive"] }
sp-core = { workspace = true }
sp-runtime = { features = ["serde"], workspace = true }
sp-staking = { features = ["serde"], workspace = true }
xcm = { workspace = true }

[features]
default = ["std"]
Expand All @@ -29,12 +30,14 @@ std = [
"sp-core/std",
"sp-runtime/std",
"sp-staking/std",
"xcm/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
"xcm/runtime-benchmarks"
]
try-runtime = [
"frame-support/try-runtime",
Expand Down
Loading
Loading