Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
24 changes: 12 additions & 12 deletions .github/scripts/cmd/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@
subparsers = parser.add_subparsers(help='a command to run', dest='command')

"""
BENCH
BENCH
"""

bench_example = '''**Examples**:

> runs all benchmarks

%(prog)s

> runs benchmarks for pallet_balances and pallet_multisig for all runtimes which have these pallets
> --quiet makes it to output nothing to PR but reactions

%(prog)s --pallet pallet_balances pallet_xcm_benchmarks::generic --quiet

> runs bench for all pallets for polkadot runtime and continues even if some benchmarks fail
%(prog)s --runtime polkadot --continue-on-fail
> does not output anything and cleans up the previous bot's & author command triggering comments in PR
%(prog)s --runtime polkadot kusama --pallet pallet_balances pallet_multisig --quiet --clean

%(prog)s --runtime polkadot --continue-on-fail

> does not output anything and cleans up the previous bot's & author command triggering comments in PR

%(prog)s --runtime polkadot kusama --pallet pallet_balances pallet_multisig --quiet --clean

'''

Expand All @@ -62,7 +62,7 @@
parser_bench.add_argument('--pallet', help='Pallet(s) space separated', nargs='*', default=[])

"""
FMT
FMT
"""
parser_fmt = subparsers.add_parser('fmt', help='Formats code')
for arg, config in common_args.items():
Expand Down
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.

47 changes: 32 additions & 15 deletions relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ pub use sp_runtime::BuildStorage;
use sp_runtime::{
generic, impl_opaque_keys,
traits::{
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto, Get,
IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion, Saturating, Verify,
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Convert, ConvertInto,
Get, IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion, Saturating, Verify,
},
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedU128, KeyTypeId, OpaqueValue, Perbill, Percent, Permill,
Expand Down Expand Up @@ -485,6 +485,7 @@ impl pallet_timestamp::Config for Runtime {

impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
// Era points are now reported to ah-client, to be sent to AH on next session.
type EventHandler = StakingAhClient;
}

Expand All @@ -510,6 +511,8 @@ impl pallet_session::Config for Runtime {
type ValidatorIdOf = ConvertInto;
type ShouldEndSession = Babe;
type NextSessionRotation = Babe;
// Sessions are now managed by the staking-ah client, giving us validator sets, and sending
// session report.
type SessionManager = session_historical::NoteHistoricalRoot<Self, StakingAhClient>;
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
Expand All @@ -522,6 +525,10 @@ impl pallet_session::Config for Runtime {

impl pallet_session::historical::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// Note: while the identification of each validators for historical reasons is still an
// exposure, we actually don't need this data, and `DefaultExposureOf` always uses
// `Default::default`. Retaining this type + keeping a default value is only for historical
// reasons and backwards compatibility.
type FullIdentification = pallet_staking::Exposure<AccountId, Balance>;
type FullIdentificationOf = pallet_staking::DefaultExposureOf<Runtime>;
}
Expand Down Expand Up @@ -803,7 +810,7 @@ impl pallet_staking::EraPayout<Balance> for EraPayout {

let params = relay_common::EraPayoutParams {
total_staked,
total_stakable: 0, // TODO: double check
total_stakable: Balances::total_issuance(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this used to be Nis total issuance

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

correct, and NIS is not part of KAH anymore. Balances TI is the right alternative, and what we have been using in Polkadot all the while.

ideal_stake: dynamic_params::inflation::IdealStake::get(),
max_annual_inflation: dynamic_params::inflation::MaxInflation::get(),
min_annual_inflation: dynamic_params::inflation::MinInflation::get(),
Expand Down Expand Up @@ -1030,6 +1037,8 @@ impl pallet_child_bounties::Config for Runtime {
impl pallet_offences::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
// Offences are now reported to ah-client, to be forwarded to AH, after potentially disabling
// validators.
type OnOffenceHandler = StakingAhClient;
}

Expand Down Expand Up @@ -1340,8 +1349,7 @@ impl InstanceFilter<RuntimeCall> for TransparentProxyType {
matches!(
c,
RuntimeCall::Staking(..) |
RuntimeCall::Session(..) |
RuntimeCall::Utility(..) |
RuntimeCall::Session(..) | RuntimeCall::Utility(..) |
RuntimeCall::FastUnstake(..) |
RuntimeCall::VoterList(..) |
RuntimeCall::NominationPools(..)
Expand Down Expand Up @@ -1426,6 +1434,7 @@ impl parachains_session_info::Config for Runtime {
impl parachains_inclusion::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type DisputesHandler = ParasDisputes;
// parachain consensus points are now reported to ah-client, to be sent to AH on next session.
type RewardValidators =
parachains_reward_points::RewardValidatorsWithEraPoints<Runtime, StakingAhClient>;
type MessageQueue = MessageQueue;
Expand Down Expand Up @@ -1712,6 +1721,8 @@ impl pallet_nomination_pools::Config for Runtime {
parameter_types! {
pub const DelegatedStakingPalletId: PalletId = PalletId(*b"py/dlstk");
pub const SlashRewardFraction: Perbill = Perbill::from_percent(1);
// Kusama always wants 1000 validators, we reject anything smaller than that.
pub storage MinimumValidatorSetSize: u32 = 1000;
}

impl pallet_delegated_staking::Config for Runtime {
Expand All @@ -1732,9 +1743,10 @@ impl pallet_staking_async_ah_client::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
type SessionInterface = Self;
type SendToAssetHub = StakingXcmToAssetHub;
type MinimumValidatorSetSize = ConstU32<400>;
type MinimumValidatorSetSize = MinimumValidatorSetSize;
type UnixTime = Timestamp;
type PointsPerBlock = ConstU32<20>;
// TODO @kianenigma
type MaxOffenceBatchSize = ConstU32<50>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

.

type Fallback = Staking;
type WeightInfo = pallet_staking_async_ah_client::weights::SubstrateWeight<Runtime>;
Expand Down Expand Up @@ -1762,6 +1774,7 @@ impl frame_support::traits::EnsureOrigin<RuntimeOrigin> for EnsureAssetHub {

#[derive(Encode, Decode)]
enum AssetHubRuntimePallets<AccountId> {
// index of the rc-client pallet in ksm-ah.
#[codec(index = 84)]
RcClient(RcClientCalls<AccountId>),
}
Expand Down Expand Up @@ -1802,12 +1815,12 @@ impl pallet_staking_async_ah_client::SendToAssetHub for StakingXcmToAssetHub {
fn relay_session_report(
session_report: pallet_staking_async_rc_client::SessionReport<Self::AccountId>,
) {
pallet_staking_async_rc_client::XCMSender::<
xcm_config::XcmRouter,
AssetHubLocation,
pallet_staking_async_rc_client::SessionReport<AccountId>,
SessionReportToXcm,
>::split_then_send(session_report, Some(8));
// TODO: after https://github.com/paritytech/polkadot-sdk/pull/9619, use `XCMSender::send` and handle error
let message = SessionReportToXcm::convert(session_report);
let dest = AssetHubLocation::get();
let _ = xcm::prelude::send_xcm::<xcm_config::XcmRouter>(dest, message).inspect_err(|err| {
log::error!(target: "runtime::ah-client", "Failed to send relay session report: {:?}", err);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is defensive or not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can't handle the error before paritytech/polkadot-sdk#9619

We might be able to merge it next week, let's see.

});
}

fn relay_new_offence(
Expand All @@ -1830,9 +1843,12 @@ impl pallet_staking_async_ah_client::SendToAssetHub for StakingXcmToAssetHub {
.into(),
},
]);
if let Err(err) = send_xcm::<xcm_config::XcmRouter>(AssetHubLocation::get(), message) {
log::error!(target: "runtime::ah-client", "Failed to send relay offence message: {:?}", err);
}
// TODO: after https://github.com/paritytech/polkadot-sdk/pull/9619, use `XCMSender::send` and handle error
let _ = send_xcm::<xcm_config::XcmRouter>(AssetHubLocation::get(), message).inspect_err(
|err| {
log::error!(target: "runtime::ah-client", "Failed to send relay offence message: {:?}", err);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can't handle the error before paritytech/polkadot-sdk#9619

We might be able to merge it next week, let's see.

},
);
}
}

Expand Down Expand Up @@ -2005,6 +2021,7 @@ construct_runtime! {
// Staking extension for delegation
DelegatedStaking: pallet_delegated_staking = 47,

// staking client to communicate with AH.
StakingAhClient: pallet_staking_async_ah_client = 48,

// Parachains pallets. Start indices at 50 to leave room.
Expand Down
1 change: 1 addition & 0 deletions system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ snowbridge-inbound-queue-primitives = { workspace = true }
asset-test-utils = { workspace = true }
parachains-runtimes-test-utils = { workspace = true }
sp-io = { workspace = true, default-features = true }
sp-tracing = { workspace = true, default-features = true }

[build-dependencies]
substrate-wasm-builder = { optional = true, workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn asset_hub_kusama_genesis(
},
"staking": {
"validatorCount": 1000,
"devStakers": Some((2_000, 25_000)),
"devStakers": Some((4_000, 15_000)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I had some TODO in a checklist for you to set some Genesis config values for Kusama, is this it? Can i Check that off?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is correct now and no benchmarks shoulf fail.

},
"foreignAssets": ForeignAssetsConfig {
assets: foreign_assets
Expand Down
43 changes: 34 additions & 9 deletions system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ use sp_runtime::{
generic, impl_opaque_keys,
traits::{
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Convert, ConvertInto,
Verify,
Get, Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill, Permill, RuntimeDebug,
ApplyExtrinsicResult, Perbill, Permill, Perquintill, RuntimeDebug,
};
#[cfg(feature = "std")]
use sp_version::NativeVersion;
Expand Down Expand Up @@ -661,8 +661,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. } |
RuntimeCall::NftFractionalization { .. } |
RuntimeCall::Nfts { .. } |
RuntimeCall::Uniques { .. }
RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. }
)
},
ProxyType::AssetOwner => matches!(
Expand Down Expand Up @@ -750,8 +749,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
matches!(
c,
RuntimeCall::Staking(..) |
RuntimeCall::Session(..) |
RuntimeCall::Utility(..) |
RuntimeCall::Session(..) | RuntimeCall::Utility(..) |
RuntimeCall::NominationPools(..) |
RuntimeCall::VoterList(..)
)
Expand Down Expand Up @@ -1345,6 +1343,8 @@ impl EnsureOriginWithArg<RuntimeOrigin, RuntimeParametersKey> for DynamicParamet
use crate::RuntimeParametersKey::*;

match key {
// TODO: @kianenigma/!bkontur - do we want to allow StakingAdmin here?
Inflation(_) => frame_system::ensure_root(origin.clone()),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// TODO: @kianenigma/!bkontur - do we want to allow StakingAdmin here?
Inflation(_) => frame_system::ensure_root(origin.clone()),
Inflation(_) => frame_system::ensure_root(origin.clone()),

I think root is okay, there should only be changes needed to this rarely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True, inflation should be root-only, will fix.

Treasury(_) => {
EitherOf::<EnsureRoot<AccountId>, GeneralAdmin>::ensure_origin(origin.clone())
},
Expand All @@ -1371,6 +1371,27 @@ impl pallet_parameters::Config for Runtime {
pub mod dynamic_params {
use super::*;

/// Parameters used to calculate staking era payouts.
#[dynamic_pallet_params]
#[codec(index = 0)]
pub mod inflation {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure if you saw Gavs recent interview, but he basically argued that Inflation is not the right terminology, but rather Interest or Issuance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

noted and fixed.

/// Minimum inflation rate used to calculate era payouts.
#[codec(index = 0)]
pub static MinInflation: Perquintill = Perquintill::from_rational(25u64, 1000);

/// Maximum inflation rate used to calculate era payouts.
#[codec(index = 1)]
pub static MaxInflation: Perquintill = Perquintill::from_percent(10);

/// Ideal stake ratio used to calculate era payouts.
#[codec(index = 2)]
pub static IdealStake: Perquintill = Perquintill::from_percent(75);

/// Falloff used to calculate era payouts.
#[codec(index = 3)]
pub static Falloff: Perquintill = Perquintill::from_percent(5);
}

/// Parameters used by `pallet-treasury` to handle the burn process.
#[dynamic_pallet_params]
#[codec(index = 1)]
Expand All @@ -1386,9 +1407,10 @@ pub mod dynamic_params {
#[cfg(feature = "runtime-benchmarks")]
impl Default for RuntimeParameters {
fn default() -> Self {
RuntimeParameters::Treasury(dynamic_params::treasury::Parameters::BurnPortion(
dynamic_params::treasury::BurnPortion,
Some(Permill::from_percent(0)),
// TODO: @kianenigma/!bkontur - is this ok?
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why is this needed to begin with? some benchmarks fail without it? I though the default for MinInflation is already defined above in all cases.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this needed to begin with? some benchmarks fail without it? I though the default for MinInflation is already defined above in all cases.

I don't know, this impl Default is kind of confusing, but something on the way requires that.
I just copy this according to actual relay/kusama: https://github.com/polkadot-fellows/runtimes/blob/main/relay/kusama/src/lib.rs#L753-L756

Copy link
Copy Markdown
Member

@ggwpez ggwpez Sep 5, 2025

Choose a reason for hiding this comment

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

Benchmarks have a where bound for RuntimeParameters: Default. So you just return any variant, does not matter which. Otherwise the benchmark would have no way to construct this opaque type.

RuntimeParameters::Inflation(dynamic_params::inflation::Parameters::MinInflation(
dynamic_params::inflation::MinInflation,
Some(Perquintill::from_rational(25u64, 1000u64)),
))
}
}
Expand Down Expand Up @@ -1571,6 +1593,9 @@ pub type Migrations = (
pallet_session::migrations::v1::InitOffenceSeverity<Runtime>,
>,
cumulus_pallet_aura_ext::migration::MigrateV0ToV1<Runtime>,
// TODO: maybe rewrite this to execute if the storage items are not set, relying on the spec
// version might be flaky.
staking::InitiateStakingAsync<1_008_000>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
Expand Down
Loading
Loading