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

Add pallet-staking-ah-client to Westend and use it instead of pallet-staking #7658

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion Cargo.lock

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

4 changes: 0 additions & 4 deletions polkadot/runtime/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pallet-broker = { workspace = true }
pallet-message-queue = { workspace = true }
pallet-mmr = { workspace = true, optional = true }
pallet-session = { workspace = true }
pallet-staking = { workspace = true }
pallet-timestamp = { workspace = true }

polkadot-primitives = { workspace = true }
Expand Down Expand Up @@ -93,7 +92,6 @@ std = [
"pallet-message-queue/std",
"pallet-mmr?/std",
"pallet-session/std",
"pallet-staking/std",
"pallet-timestamp/std",
"polkadot-core-primitives/std",
"polkadot-parachain-primitives/std",
Expand Down Expand Up @@ -127,7 +125,6 @@ runtime-benchmarks = [
"pallet-broker/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-mmr/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
Expand All @@ -151,7 +148,6 @@ try-runtime = [
"pallet-message-queue/try-runtime",
"pallet-mmr/try-runtime",
"pallet-session/try-runtime",
"pallet-staking/try-runtime",
"pallet-timestamp/try-runtime",
"sp-runtime/try-runtime",
]
Expand Down
5 changes: 5 additions & 0 deletions polkadot/runtime/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ pub trait FeeTracker {
fn decrease_fee_factor(id: Self::Id) -> FixedU128;
}

/// Trait for reporting rewards for processing parachains blocks
pub trait RewardsReporter<C> {
fn reward_by_ids(validators_points: impl IntoIterator<Item = (C, u32)>);
}

/// Schedule a para to be initialized at the start of the next session with the given genesis data.
pub fn schedule_para_initialize<T: paras::Config>(
id: ParaId,
Expand Down
24 changes: 15 additions & 9 deletions polkadot/runtime/parachains/src/reward_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! which doesn't currently mention availability bitfields. As such, we don't reward them
//! for the time being, although we will build schemes to do so in the future.

use crate::{session_info, shared};
use crate::{session_info, shared, RewardsReporter};
use alloc::collections::btree_set::BTreeSet;
use frame_support::traits::{Defensive, ValidatorSet};
use polkadot_primitives::{SessionIndex, ValidatorIndex};
Expand All @@ -32,12 +32,16 @@ pub const BACKING_POINTS: u32 = 20;
pub const DISPUTE_STATEMENT_POINTS: u32 = 20;

/// Rewards validators for participating in parachains with era points in pallet-staking.
pub struct RewardValidatorsWithEraPoints<C>(core::marker::PhantomData<C>);
pub struct RewardValidatorsWithEraPoints<C, R>(
core::marker::PhantomData<C>,
core::marker::PhantomData<R>,
);

impl<C> RewardValidatorsWithEraPoints<C>
impl<C, R> RewardValidatorsWithEraPoints<C, R>
where
C: pallet_staking::Config + session_info::Config,
C: session_info::Config,
C::ValidatorSet: ValidatorSet<C::AccountId, ValidatorId = C::AccountId>,
R: RewardsReporter<C::AccountId>,
{
/// Reward validators in session with points, but only if they are in the active set.
fn reward_only_active(
Expand All @@ -61,14 +65,15 @@ where
.filter(|v| active_set.contains(v))
.map(|v| (v, points));

<pallet_staking::Pallet<C>>::reward_by_ids(rewards);
R::reward_by_ids(rewards);
}
}

impl<C> crate::inclusion::RewardValidators for RewardValidatorsWithEraPoints<C>
impl<C, R> crate::inclusion::RewardValidators for RewardValidatorsWithEraPoints<C, R>
where
C: pallet_staking::Config + shared::Config + session_info::Config,
C: shared::Config + session_info::Config,
C::ValidatorSet: ValidatorSet<C::AccountId, ValidatorId = C::AccountId>,
R: RewardsReporter<C::AccountId>,
{
fn reward_backing(indices: impl IntoIterator<Item = ValidatorIndex>) {
let session_index = shared::CurrentSessionIndex::<C>::get();
Expand All @@ -78,10 +83,11 @@ where
fn reward_bitfields(_validators: impl IntoIterator<Item = ValidatorIndex>) {}
}

impl<C> crate::disputes::RewardValidators for RewardValidatorsWithEraPoints<C>
impl<C, R> crate::disputes::RewardValidators for RewardValidatorsWithEraPoints<C, R>
where
C: pallet_staking::Config + session_info::Config,
C: session_info::Config,
C::ValidatorSet: ValidatorSet<C::AccountId, ValidatorId = C::AccountId>,
R: RewardsReporter<C::AccountId>,
{
fn reward_dispute_statement(
session: SessionIndex,
Expand Down
4 changes: 4 additions & 0 deletions polkadot/runtime/westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pallet-scheduler = { workspace = true }
pallet-session = { workspace = true }
pallet-society = { workspace = true }
pallet-staking = { workspace = true }
pallet-staking-ah-client = { workspace = true }
pallet-staking-runtime-api = { workspace = true }
pallet-state-trie-migration = { workspace = true }
pallet-sudo = { workspace = true }
Expand Down Expand Up @@ -186,6 +187,7 @@ std = [
"pallet-session-benchmarking?/std",
"pallet-session/std",
"pallet-society/std",
"pallet-staking-ah-client/std",
"pallet-staking-runtime-api/std",
"pallet-staking/std",
"pallet-state-trie-migration/std",
Expand Down Expand Up @@ -273,6 +275,7 @@ runtime-benchmarks = [
"pallet-session-benchmarking/runtime-benchmarks",
"pallet-society/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-staking-ah-client/runtime-benchmarks",
"pallet-state-trie-migration/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
Expand Down Expand Up @@ -334,6 +337,7 @@ try-runtime = [
"pallet-session/try-runtime",
"pallet-society/try-runtime",
"pallet-staking/try-runtime",
"pallet-staking-ah-client/try-runtime",
"pallet-state-trie-migration/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
Expand Down
44 changes: 36 additions & 8 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub use sp_runtime::BuildStorage;
use westend_runtime_constants::{
currency::*,
fee::*,
system_parachain::{coretime::TIMESLICE_PERIOD, BROKER_ID},
system_parachain::{coretime::TIMESLICE_PERIOD, ASSET_HUB_ID, BROKER_ID},
time::*,
};

Expand Down Expand Up @@ -504,7 +504,7 @@ impl pallet_timestamp::Config for Runtime {

impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
type EventHandler = Staking;
type EventHandler = AssetHubStakingClient;
}

parameter_types! {
Expand All @@ -529,16 +529,25 @@ impl pallet_session::Config for Runtime {
type ValidatorIdOf = pallet_staking::StashOf<Self>;
type ShouldEndSession = Babe;
type NextSessionRotation = Babe;
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
type SessionManager =
pallet_session::historical::NoteHistoricalRoot<Self, AssetHubStakingClient>;
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type DisablingStrategy = pallet_session::disabling::UpToLimitWithReEnablingDisablingStrategy;
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
}

// Dummy implementation which returns `Some(())`
pub struct FullIdentificationOf;
impl sp_runtime::traits::Convert<AccountId, Option<()>> for FullIdentificationOf {
fn convert(_: AccountId) -> Option<()> {
Some(Default::default())
}
}

impl pallet_session::historical::Config for Runtime {
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
type FullIdentification = ();
type FullIdentificationOf = FullIdentificationOf;
}

pub struct MaybeSignedPhase;
Expand Down Expand Up @@ -774,6 +783,13 @@ impl pallet_staking::Config for Runtime {
type MaxDisabledValidators = ConstU32<100>;
}

impl pallet_staking_ah_client::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type CurrencyBalance = Balance;
type AssetHubId = AssetHubId;
type SendXcm = crate::xcm_config::XcmRouter;
}

impl pallet_fast_unstake::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
Expand Down Expand Up @@ -848,7 +864,7 @@ impl pallet_treasury::Config for Runtime {
impl pallet_offences::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
type OnOffenceHandler = AssetHubStakingClient;
}

impl pallet_authority_discovery::Config for Runtime {
Expand Down Expand Up @@ -1250,10 +1266,18 @@ impl parachains_session_info::Config for Runtime {
type ValidatorSet = Historical;
}

pub struct RewardsHandler;
impl polkadot_runtime_parachains::RewardsReporter<AccountId> for RewardsHandler {
fn reward_by_ids(validators_points: impl IntoIterator<Item = (AccountId, u32)>) {
<pallet_staking_ah_client::Pallet<Runtime>>::handle_parachain_rewards(validators_points);
}
}

impl parachains_inclusion::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type DisputesHandler = ParasDisputes;
type RewardValidators = parachains_reward_points::RewardValidatorsWithEraPoints<Runtime>;
type RewardValidators =
parachains_reward_points::RewardValidatorsWithEraPoints<Runtime, RewardsHandler>;
type MessageQueue = MessageQueue;
type WeightInfo = weights::polkadot_runtime_parachains_inclusion::WeightInfo<Runtime>;
}
Expand Down Expand Up @@ -1353,6 +1377,7 @@ impl parachains_scheduler::Config for Runtime {

parameter_types! {
pub const BrokerId: u32 = BROKER_ID;
pub const AssetHubId: u32 = ASSET_HUB_ID; // TODO: replace with ASSET_HUB_NEXT_ID
pub const BrokerPalletId: PalletId = PalletId(*b"py/broke");
pub MaxXcmTransactWeight: Weight = Weight::from_parts(200_000_000, 20_000);
}
Expand Down Expand Up @@ -1425,7 +1450,8 @@ impl assigned_slots::Config for Runtime {

impl parachains_disputes::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RewardValidators = parachains_reward_points::RewardValidatorsWithEraPoints<Runtime>;
type RewardValidators =
parachains_reward_points::RewardValidatorsWithEraPoints<Runtime, RewardsHandler>;
type SlashingHandler = parachains_slashing::SlashValidatorsForDisputes<ParasSlashing>;
type WeightInfo = weights::polkadot_runtime_parachains_disputes::WeightInfo<Runtime>;
}
Expand Down Expand Up @@ -1785,6 +1811,8 @@ mod runtime {
pub type AssignedSlots = assigned_slots;
#[runtime::pallet_index(66)]
pub type Coretime = coretime;
#[runtime::pallet_index(67)]
pub type AssetHubStakingClient = pallet_staking_ah_client;

// Migrations pallet
#[runtime::pallet_index(98)]
Expand Down
6 changes: 6 additions & 0 deletions substrate/frame/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }
pallet-authorship = { workspace = true }
# Should be removed after `pallet_session::migrations::v1::MigrateDisabledValidators` and
# `MigrateV14ToV15` are executed
pallet-session = { features = [
"historical",
], workspace = true }
pallet-staking-rc-client = { workspace = true }
rand = { features = ["alloc"], workspace = true }
rand_chacha = { workspace = true }
scale-info = { features = ["derive", "serde"], workspace = true }
Expand Down Expand Up @@ -66,6 +69,7 @@ std = [
"pallet-bags-list/std",
"pallet-balances/std",
"pallet-session/std",
"pallet-staking-rc-client/std",
"pallet-timestamp/std",
"rand/std",
"rand_chacha/std",
Expand All @@ -87,6 +91,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-bags-list/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-staking-rc-client/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
Expand All @@ -99,6 +104,7 @@ try-runtime = [
"pallet-bags-list/try-runtime",
"pallet-balances/try-runtime",
"pallet-session/try-runtime",
"pallet-staking-rc-client/try-runtime",
"pallet-timestamp/try-runtime",
"sp-runtime/try-runtime",
]
Loading