Skip to content

Commit

Permalink
Kusama AH implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr committed Jan 16, 2025
1 parent bc69dde commit 55f69b1
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 45 deletions.
5 changes: 4 additions & 1 deletion Cargo.lock

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

6 changes: 6 additions & 0 deletions relay/kusama/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@ license.workspace = true

[dependencies]
smallvec = { workspace = true }
codec = { workspace = true }
scale-info = { workspace = true }

frame-support = { workspace = true }
polkadot-primitives = { workspace = true }
polkadot-runtime-common = { workspace = true }
sp-runtime = { workspace = true }
sp-weights = { workspace = true }
sp-core = { workspace = true }
pallet-remote-proxy = { workspace = true }

xcm-builder = { workspace = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"pallet-remote-proxy/std",
"polkadot-primitives/std",
"polkadot-runtime-common/std",
"scale-info/std",
"sp-core/std",
"sp-runtime/std",
"sp-weights/std",
Expand Down
91 changes: 91 additions & 0 deletions relay/kusama/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,97 @@ pub mod system_parachain {
/// Kusama Treasury pallet instance.
pub const TREASURY_PALLET_ID: u8 = 18;

pub mod proxy {
use pallet_remote_proxy::ProxyDefinition;
use polkadot_primitives::{AccountId, BlakeTwo256, BlockNumber, Hash};
use sp_runtime::traits::Convert;

/// The type used to represent the kinds of proxying allowed.
#[derive(
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
codec::Encode,
codec::Decode,
codec::MaxEncodedLen,
core::fmt::Debug,
scale_info::TypeInfo,
Default,
)]
pub enum ProxyType {
#[codec(index = 0)]
#[default]
Any,
#[codec(index = 1)]
NonTransfer,
#[codec(index = 2)]
Governance,
#[codec(index = 3)]
Staking,
// Index 4 skipped. Formerly `IdentityJudgement`.
#[codec(index = 5)]
CancelProxy,
#[codec(index = 6)]
Auction,
#[codec(index = 7)]
Society,
#[codec(index = 8)]
NominationPools,
#[codec(index = 9)]
Spokesperson,
#[codec(index = 10)]
ParaRegistration,
}

/// Remote proxy interface that uses the relay chain as remote location.
pub struct RemoteProxyInterface<LocalProxyType, ProxyDefinitionConverter>(
core::marker::PhantomData<(LocalProxyType, ProxyDefinitionConverter)>,
);

impl<
LocalProxyType,
ProxyDefinitionConverter: Convert<
ProxyDefinition<AccountId, ProxyType, BlockNumber>,
Option<ProxyDefinition<AccountId, LocalProxyType, BlockNumber>>,
>,
> pallet_remote_proxy::RemoteProxyInterface<AccountId, LocalProxyType, BlockNumber>
for RemoteProxyInterface<LocalProxyType, ProxyDefinitionConverter>
{
type RemoteAccountId = AccountId;

type RemoteProxyType = ProxyType;

type RemoteBlockNumber = BlockNumber;

type Hash = Hash;

type Hasher = BlakeTwo256;

fn block_to_storage_root(
validation_data: &polkadot_primitives::PersistedValidationData,
) -> Option<(Self::RemoteBlockNumber, <Self::Hasher as sp_core::Hasher>::Out)> {
Some((validation_data.relay_parent_number, validation_data.relay_parent_storage_root))
}

fn local_to_remote_account_id(local: &AccountId) -> Option<Self::RemoteAccountId> {
Some(local.clone())
}

fn remote_to_local_proxy_defintion(
remote: ProxyDefinition<
Self::RemoteAccountId,
Self::RemoteProxyType,
Self::RemoteBlockNumber,
>,
) -> Option<ProxyDefinition<AccountId, LocalProxyType, BlockNumber>> {
ProxyDefinitionConverter::convert(remote)
}
}
}

#[cfg(test)]
mod tests {
use super::{
Expand Down
51 changes: 17 additions & 34 deletions relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use frame_support::{
traits::EnsureOriginWithArg,
weights::constants::{WEIGHT_PROOF_SIZE_PER_KB, WEIGHT_REF_TIME_PER_MICROS},
};
use kusama_runtime_constants::system_parachain::coretime::TIMESLICE_PERIOD;
use kusama_runtime_constants::{proxy::ProxyType, system_parachain::coretime::TIMESLICE_PERIOD};
use pallet_nis::WithMaximumOf;
use polkadot_primitives::{
slashing, AccountId, AccountIndex, ApprovalVotingParams, Balance, BlockNumber, CandidateEvent,
Expand Down Expand Up @@ -1109,7 +1109,10 @@ parameter_types! {
pub const MaxPending: u16 = 32;
}

/// The type used to represent the kinds of proxying allowed.
/// Transparent wrapper around the actual [`ProxyType`].
///
/// This is done to have [`ProxyType`] declared in a different crate (constants) and being able to
/// implement [`InstanceFilter`] in this crate.
#[derive(
Copy,
Clone,
Expand All @@ -1121,41 +1124,21 @@ parameter_types! {
Decode,
RuntimeDebug,
MaxEncodedLen,
TypeInfo,
Default,
)]
pub enum ProxyType {
#[codec(index = 0)]
Any,
#[codec(index = 1)]
NonTransfer,
#[codec(index = 2)]
Governance,
#[codec(index = 3)]
Staking,
// Index 4 skipped. Formerly `IdentityJudgement`.
#[codec(index = 5)]
CancelProxy,
#[codec(index = 6)]
Auction,
#[codec(index = 7)]
Society,
#[codec(index = 8)]
NominationPools,
#[codec(index = 9)]
Spokesperson,
#[codec(index = 10)]
ParaRegistration,
}

impl Default for ProxyType {
fn default() -> Self {
Self::Any
pub struct TransparentProxyType(ProxyType);

impl scale_info::TypeInfo for TransparentProxyType {
type Identity = <ProxyType as TypeInfo>::Identity;

fn type_info() -> scale_info::Type {
ProxyType::type_info()
}
}

impl InstanceFilter<RuntimeCall> for ProxyType {
impl InstanceFilter<RuntimeCall> for TransparentProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
match self.0 {
ProxyType::Any => true,
ProxyType::NonTransfer => matches!(
c,
Expand Down Expand Up @@ -1261,7 +1244,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
}
}
fn is_superset(&self, o: &Self) -> bool {
match (self, o) {
match (self.0, o.0) {
(x, y) if x == y => true,
(ProxyType::Any, _) => true,
(_, ProxyType::Any) => false,
Expand All @@ -1275,7 +1258,7 @@ impl pallet_proxy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Currency = Balances;
type ProxyType = ProxyType;
type ProxyType = TransparentProxyType;
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type MaxProxies = MaxProxies;
Expand Down
2 changes: 1 addition & 1 deletion relay/polkadot/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub mod proxy {
PartialOrd,
codec::Encode,
codec::Decode,
sp_runtime::RuntimeDebug,
core::fmt::Debug,
codec::MaxEncodedLen,
scale_info::TypeInfo,
Default,
Expand Down
3 changes: 1 addition & 2 deletions system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bp-asset-hub-polkadot = { workspace = true }
bp-bridge-hub-kusama = { workspace = true }
bp-bridge-hub-polkadot = { workspace = true }
kusama-runtime-constants = { workspace = true }
polkadot-runtime-constants = { workspace = true }
pallet-remote-proxy = { workspace = true }

# Substrate
frame-benchmarking = { optional = true, workspace = true }
Expand Down Expand Up @@ -246,7 +246,6 @@ std = [
"polkadot-core-primitives/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"polkadot-runtime-constants/std",
"primitive-types/std",
"scale-info/std",
"serde_json/std",
Expand Down
59 changes: 53 additions & 6 deletions system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ use assets_common::{
};
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use kusama_runtime_constants::time::MINUTES;
use pallet_proxy::ProxyDefinition;
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto, Verify,
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Convert, ConvertInto,
Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill, Permill,
Expand Down Expand Up @@ -519,9 +522,11 @@ parameter_types! {
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
Default,
)]
pub enum ProxyType {
/// Fully permissioned proxy. Can execute any call on behalf of _proxied_.
#[default]
Any,
/// Can execute any call that does not transfer funds or assets.
NonTransfer,
Expand All @@ -536,11 +541,6 @@ pub enum ProxyType {
/// Collator selection proxy. Can execute calls related to collator selection mechanism.
Collator,
}
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}

impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
Expand Down Expand Up @@ -964,6 +964,52 @@ impl pallet_xcm_bridge_hub_router::Config<ToPolkadotXcmRouterInstance> for Runti
cumulus_pallet_xcmp_queue::bridging::InAndOutXcmpChannelStatusProvider<Runtime>;
}

/// Converts from the relay chain proxy type to the local proxy type.
pub struct RelayChainToLocalProxyTypeConverter;

impl
Convert<
ProxyDefinition<AccountId, kusama_runtime_constants::proxy::ProxyType, BlockNumber>,
Option<ProxyDefinition<AccountId, ProxyType, BlockNumber>>,
> for RelayChainToLocalProxyTypeConverter
{
fn convert(
a: ProxyDefinition<AccountId, kusama_runtime_constants::proxy::ProxyType, BlockNumber>,
) -> Option<ProxyDefinition<AccountId, ProxyType, BlockNumber>> {
let proxy_type = match a.proxy_type {
kusama_runtime_constants::proxy::ProxyType::Any => ProxyType::Any,
kusama_runtime_constants::proxy::ProxyType::NonTransfer => ProxyType::NonTransfer,
kusama_runtime_constants::proxy::ProxyType::CancelProxy => ProxyType::CancelProxy,
// Proxy types that are not supported on AH.
kusama_runtime_constants::proxy::ProxyType::Governance |
kusama_runtime_constants::proxy::ProxyType::Staking |
kusama_runtime_constants::proxy::ProxyType::Auction |
kusama_runtime_constants::proxy::ProxyType::Spokesperson |
kusama_runtime_constants::proxy::ProxyType::NominationPools |
kusama_runtime_constants::proxy::ProxyType::Society |
kusama_runtime_constants::proxy::ProxyType::ParaRegistration => return None,
};

Some(ProxyDefinition {
delegate: a.delegate,
proxy_type,
// Delays are currently not supported by the remote proxy pallet, but should be
// converted in the future to the block time used by the local proxy pallet.
delay: a.delay,
})
}
}

impl pallet_remote_proxy::Config for Runtime {
type MaxStorageRootsToKeep = ConstU32<{ MINUTES * 20 }>;
type RemoteProxy = kusama_runtime_constants::proxy::RemoteProxyInterface<
ProxyType,
RelayChainToLocalProxyTypeConverter,
>;
//TODO: Run benchmarks and replace.
type WeightInfo = ();
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime
Expand Down Expand Up @@ -1000,6 +1046,7 @@ construct_runtime!(
Utility: pallet_utility = 40,
Multisig: pallet_multisig = 41,
Proxy: pallet_proxy = 42,
RemoteProxyRelayChain: pallet_remote_proxy = 43,

// The main stage.
Assets: pallet_assets::<Instance1> = 50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ pub mod bridging {
2,
[
GlobalConsensus(PolkadotNetwork::get()),
Parachain(polkadot_runtime_constants::system_parachain::ASSET_HUB_ID),
Parachain(kusama_runtime_constants::system_parachain::ASSET_HUB_ID),
],
);

Expand Down

0 comments on commit 55f69b1

Please sign in to comment.