-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add remote proxy support to AH Kusama (#535)
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
1 parent
80ee7dc
commit 6b85bf6
Showing
33 changed files
with
1,937 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.