Skip to content

Commit

Permalink
Add remote proxy support to AH Kusama (#535)
Browse files Browse the repository at this point in the history
This adds remote proxy support to AssetHub on Polkadot and Kusama.
Currently it is configured only to support using proxies registered on
the relay chain to work on AssetHub. In the future this can be expanded.

---------

Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
4 people authored Feb 28, 2025
1 parent 80ee7dc commit 6b85bf6
Show file tree
Hide file tree
Showing 33 changed files with 1,937 additions and 97 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Delegate stake pools in Kusama ([polkadot-fellows/runtimes#540](https://github.com/polkadot-fellows/runtimes/pull/540))
- Snowbridge: Add support for bridging Ether ([polkadot-fellows/runtimes#548](https://github.com/polkadot-fellows/runtimes/pull/548))

- Adds support for remote proxies on AssetHub Polkadot and AssetHub Kusama. ‼️ Builders: Please read the docs and the implications around the lifetime of a proxy on a remote chain. ‼️ ([polkadot-fellows/runtimes#535](https://github.com/polkadot-fellows/runtimes/pull/535))

### Changed

- Kusama Treasury: remove funding to the Kappa Sigma Mu Society and disable burn ([polkadot-fellows/runtimes#507](https://github.com/polkadot-fellows/runtimes/pull/507))
Expand Down
32 changes: 31 additions & 1 deletion Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pallet-proxy = { version = "38.0.0", default-features = false }
pallet-ranked-collective = { version = "38.2.0", default-features = false }
pallet-recovery = { version = "38.0.0", default-features = false }
pallet-referenda = { version = "38.0.0", default-features = false }
pallet-remote-proxy = { path = "pallets/remote-proxy", default-features = false }
pallet-salary = { version = "23.2.0", default-features = false }
pallet-scheduler = { version = "39.0.0", default-features = false }
pallet-session = { version = "38.0.0", default-features = false }
Expand Down Expand Up @@ -229,11 +230,12 @@ sp-offchain = { version = "34.0.0", default-features = false }
sp-runtime = { version = "39.0.5", default-features = false }
sp-session = { version = "36.0.0", default-features = false }
sp-staking = { version = "36.0.0", default-features = false }
sp-state-machine = { version = "0.43.0", default-features = false }
sp-std = { version = "14.0.0", default-features = false }
sp-storage = { version = "21.0.0", default-features = false }
sp-tracing = { version = "17.0.1", default-features = false }
sp-transaction-pool = { version = "34.0.0", default-features = false }
sp-trie = { version = "37.0.0" }
sp-trie = { version = "37.0.0", default-features = false }
sp-version = { version = "37.0.0", default-features = false }
sp-weights = { version = "31.0.0", default-features = false }
static_assertions = { version = "1.1.0" }
Expand Down Expand Up @@ -284,6 +286,7 @@ members = [
"integration-tests/emulated/tests/people/people-kusama",
"integration-tests/emulated/tests/people/people-polkadot",
"integration-tests/zombienet",
"pallets/remote-proxy",
"relay/common",
"relay/kusama",
"relay/kusama/constants",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ xcm = { workspace = true, default-features = true }
# Runtimes
kusama-emulated-chain = { workspace = true }
polkadot-emulated-chain = { workspace = true }

[features]
runtime-benchmarks = [
"cumulus-primitives-core/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"penpal-runtime/runtime-benchmarks",
]
70 changes: 70 additions & 0 deletions pallets/remote-proxy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[package]
name = "pallet-remote-proxy"
version.workspace = true
authors.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]
codec = { features = ["derive", "max-encoded-len"], workspace = true }
scale-info = { features = ["derive"], workspace = true }

cumulus-pallet-parachain-system = { workspace = true }
cumulus-primitives-core = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-proxy = { workspace = true }
sp-core = { workspace = true }
sp-trie = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
pallet-balances = { workspace = true }
pallet-utility = { workspace = true }
sp-io = { workspace = true }
sp-state-machine = { workspace = true }

[features]
default = ["std"]

std = [
"codec/std",
"cumulus-pallet-parachain-system/std",
"cumulus-primitives-core/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"pallet-proxy/std",
"pallet-utility/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-state-machine/std",
"sp-trie/std",
]

try-runtime = [
"cumulus-pallet-parachain-system/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-balances/try-runtime",
"pallet-proxy/try-runtime",
"pallet-utility/try-runtime",
"sp-runtime/try-runtime",
]

runtime-benchmarks = [
"cumulus-pallet-parachain-system/runtime-benchmarks",
"cumulus-primitives-core/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
136 changes: 136 additions & 0 deletions pallets/remote-proxy/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Copyright (C) Polkadot Fellows.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Benchmarks for Remote Proxy Pallet

use super::*;
use crate::Pallet as RemoteProxy;
use alloc::{boxed::Box, vec};
use frame_benchmarking::v2::{
account, impl_test_function, instance_benchmarks, whitelisted_caller,
};
use frame_support::traits::Currency;
use frame_system::RawOrigin;
use sp_runtime::{
traits::{Bounded, StaticLookup},
BoundedVec,
};

const SEED: u32 = 0;

type BalanceOf<T> = <<T as pallet_proxy::Config>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::Balance;

fn assert_last_event<T: pallet_proxy::Config>(
generic_event: <T as pallet_proxy::Config>::RuntimeEvent,
) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}

#[instance_benchmarks]
mod benchmarks {
use super::*;
use frame_benchmarking::BenchmarkError;

#[benchmark]
fn remote_proxy() -> Result<(), BenchmarkError> {
// In this case the caller is the "target" proxy
let caller: T::AccountId = account("target", 0, SEED);
<T as pallet_proxy::Config>::Currency::make_free_balance_be(
&caller,
BalanceOf::<T>::max_value() / 2u32.into(),
);
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let real_lookup = T::Lookup::unlookup(real.clone());
let call: <T as pallet_proxy::Config>::RuntimeCall =
frame_system::Call::<T>::remark { remark: vec![] }.into();
let (proof, block_number, storage_root) =
T::RemoteProxy::create_remote_proxy_proof(&caller, &real);
BlockToRoot::<T, I>::set(BoundedVec::truncate_from(vec![(block_number, storage_root)]));

#[extrinsic_call]
_(RawOrigin::Signed(caller), real_lookup, None, Box::new(call), proof);

assert_last_event::<T>(pallet_proxy::Event::ProxyExecuted { result: Ok(()) }.into());

Ok(())
}

#[benchmark]
fn register_remote_proxy_proof() -> Result<(), BenchmarkError> {
// In this case the caller is the "target" proxy
let caller: T::AccountId = account("target", 0, SEED);
<T as pallet_proxy::Config>::Currency::make_free_balance_be(
&caller,
BalanceOf::<T>::max_value() / 2u32.into(),
);
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let (proof, block_number, storage_root) =
T::RemoteProxy::create_remote_proxy_proof(&caller, &real);
BlockToRoot::<T, I>::set(BoundedVec::truncate_from(vec![(block_number, storage_root)]));

#[extrinsic_call]
_(RawOrigin::Signed(caller), proof);

Ok(())
}

#[benchmark]
fn remote_proxy_with_registered_proof() -> Result<(), BenchmarkError> {
// In this case the caller is the "target" proxy
let caller: T::AccountId = account("target", 0, SEED);
<T as pallet_proxy::Config>::Currency::make_free_balance_be(
&caller,
BalanceOf::<T>::max_value() / 2u32.into(),
);
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = whitelisted_caller();
let real_lookup = T::Lookup::unlookup(real.clone());
let call: <T as pallet_proxy::Config>::RuntimeCall =
frame_system::Call::<T>::remark { remark: vec![] }.into();
let (proof, block_number, storage_root) =
T::RemoteProxy::create_remote_proxy_proof(&caller, &real);
BlockToRoot::<T, I>::set(BoundedVec::truncate_from(vec![(block_number, storage_root)]));

#[block]
{
frame_support::dispatch_context::run_in_context(|| {
frame_support::dispatch_context::with_context::<
crate::RemoteProxyContext<crate::RemoteBlockNumberOf<T, I>>,
_,
>(|context| {
context.or_default().proofs.push(proof.clone());
});

RemoteProxy::<T, I>::remote_proxy_with_registered_proof(
RawOrigin::Signed(caller).into(),
real_lookup,
None,
Box::new(call),
)
.unwrap()
})
}

assert_last_event::<T>(pallet_proxy::Event::ProxyExecuted { result: Ok(()) }.into());

Ok(())
}

impl_benchmark_test_suite!(RemoteProxy, crate::tests::new_test_ext(), crate::tests::Test);
}
Loading

0 comments on commit 6b85bf6

Please sign in to comment.