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 remote proxy pallet #535

Open
wants to merge 14 commits into
base: main
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
30 changes: 29 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.0.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.0.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.1", 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
60 changes: 60 additions & 0 deletions pallets/remote-proxy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[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",
]

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",
]
133 changes: 133 additions & 0 deletions pallets/remote-proxy/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// 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};

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>::insert(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>::insert(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>::insert(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
Loading