Skip to content

Commit d1cf73a

Browse files
muharemshawntabrizigui1117
authored
FRAME: Meta Transaction (#6428)
Meta transactions implementation. The meta transaction follows a layout similar to that of a regular transaction and can leverage the same extensions implementing the `TransactionExtension` trait. Once signed and shared by the signer, the relayer may submit a regular transaction with the `pallet_meta_tx::dispatch` call, passing the signed meta transaction as an argument. To see an example, refer to the mock setup and the `sign_and_execute_meta_tx` test case in `substrate/frame/meta-tx/src/tests.rs` file. RFC: #4123 --------- Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: command-bot <> Co-authored-by: Guillaume Thiolliere <[email protected]>
1 parent 5f44a77 commit d1cf73a

File tree

20 files changed

+1396
-35
lines changed

20 files changed

+1396
-35
lines changed

Cargo.lock

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ members = [
379379
"substrate/frame/membership",
380380
"substrate/frame/merkle-mountain-range",
381381
"substrate/frame/message-queue",
382+
"substrate/frame/meta-tx",
382383
"substrate/frame/metadata-hash-extension",
383384
"substrate/frame/migrations",
384385
"substrate/frame/mixnet",
@@ -962,6 +963,7 @@ pallet-insecure-randomness-collective-flip = { path = "substrate/frame/insecure-
962963
pallet-lottery = { default-features = false, path = "substrate/frame/lottery" }
963964
pallet-membership = { path = "substrate/frame/membership", default-features = false }
964965
pallet-message-queue = { path = "substrate/frame/message-queue", default-features = false }
966+
pallet-meta-tx = { path = "substrate/frame/meta-tx", default-features = false }
965967
pallet-migrations = { path = "substrate/frame/migrations", default-features = false }
966968
pallet-minimal-template = { path = "templates/minimal/pallets/template", default-features = false }
967969
pallet-mixnet = { default-features = false, path = "substrate/frame/mixnet" }

polkadot/runtime/westend/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pallet-identity = { workspace = true }
7070
pallet-indices = { workspace = true }
7171
pallet-membership = { workspace = true }
7272
pallet-message-queue = { workspace = true }
73+
pallet-meta-tx = { workspace = true }
7374
pallet-migrations = { workspace = true }
7475
pallet-mmr = { workspace = true }
7576
pallet-multisig = { workspace = true }
@@ -94,6 +95,7 @@ pallet-transaction-payment = { workspace = true }
9495
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
9596
pallet-treasury = { workspace = true }
9697
pallet-utility = { workspace = true }
98+
pallet-verify-signature = { workspace = true }
9799
pallet-vesting = { workspace = true }
98100
pallet-whitelist = { workspace = true }
99101
pallet-xcm = { workspace = true }
@@ -168,6 +170,7 @@ std = [
168170
"pallet-indices/std",
169171
"pallet-membership/std",
170172
"pallet-message-queue/std",
173+
"pallet-meta-tx/std",
171174
"pallet-migrations/std",
172175
"pallet-mmr/std",
173176
"pallet-multisig/std",
@@ -195,6 +198,7 @@ std = [
195198
"pallet-transaction-payment/std",
196199
"pallet-treasury/std",
197200
"pallet-utility/std",
201+
"pallet-verify-signature/std",
198202
"pallet-vesting/std",
199203
"pallet-whitelist/std",
200204
"pallet-xcm-benchmarks?/std",
@@ -257,6 +261,7 @@ runtime-benchmarks = [
257261
"pallet-indices/runtime-benchmarks",
258262
"pallet-membership/runtime-benchmarks",
259263
"pallet-message-queue/runtime-benchmarks",
264+
"pallet-meta-tx/runtime-benchmarks",
260265
"pallet-migrations/runtime-benchmarks",
261266
"pallet-mmr/runtime-benchmarks",
262267
"pallet-multisig/runtime-benchmarks",
@@ -279,6 +284,7 @@ runtime-benchmarks = [
279284
"pallet-transaction-payment/runtime-benchmarks",
280285
"pallet-treasury/runtime-benchmarks",
281286
"pallet-utility/runtime-benchmarks",
287+
"pallet-verify-signature/runtime-benchmarks",
282288
"pallet-vesting/runtime-benchmarks",
283289
"pallet-whitelist/runtime-benchmarks",
284290
"pallet-xcm-benchmarks/runtime-benchmarks",
@@ -319,6 +325,7 @@ try-runtime = [
319325
"pallet-indices/try-runtime",
320326
"pallet-membership/try-runtime",
321327
"pallet-message-queue/try-runtime",
328+
"pallet-meta-tx/try-runtime",
322329
"pallet-migrations/try-runtime",
323330
"pallet-mmr/try-runtime",
324331
"pallet-multisig/try-runtime",
@@ -340,6 +347,7 @@ try-runtime = [
340347
"pallet-transaction-payment/try-runtime",
341348
"pallet-treasury/try-runtime",
342349
"pallet-utility/try-runtime",
350+
"pallet-verify-signature/try-runtime",
343351
"pallet-vesting/try-runtime",
344352
"pallet-whitelist/try-runtime",
345353
"pallet-xcm/try-runtime",

polkadot/runtime/westend/src/lib.rs

+38-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ use sp_runtime::{
104104
OpaqueKeys, SaturatedConversion, Verify,
105105
},
106106
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
107-
ApplyExtrinsicResult, FixedU128, KeyTypeId, Percent, Permill,
107+
ApplyExtrinsicResult, FixedU128, KeyTypeId, MultiSignature, MultiSigner, Percent, Permill,
108108
};
109109
use sp_staking::SessionIndex;
110110
#[cfg(any(feature = "std", test))]
@@ -1616,6 +1616,35 @@ impl OnSwap for SwapLeases {
16161616
}
16171617
}
16181618

1619+
pub type MetaTxExtension = (
1620+
pallet_verify_signature::VerifySignature<Runtime>,
1621+
pallet_meta_tx::MetaTxMarker<Runtime>,
1622+
frame_system::CheckNonZeroSender<Runtime>,
1623+
frame_system::CheckSpecVersion<Runtime>,
1624+
frame_system::CheckTxVersion<Runtime>,
1625+
frame_system::CheckGenesis<Runtime>,
1626+
frame_system::CheckMortality<Runtime>,
1627+
frame_system::CheckNonce<Runtime>,
1628+
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
1629+
);
1630+
1631+
impl pallet_meta_tx::Config for Runtime {
1632+
type WeightInfo = weights::pallet_meta_tx::WeightInfo<Runtime>;
1633+
type RuntimeEvent = RuntimeEvent;
1634+
#[cfg(not(feature = "runtime-benchmarks"))]
1635+
type Extension = MetaTxExtension;
1636+
#[cfg(feature = "runtime-benchmarks")]
1637+
type Extension = pallet_meta_tx::WeightlessExtension<Runtime>;
1638+
}
1639+
1640+
impl pallet_verify_signature::Config for Runtime {
1641+
type Signature = MultiSignature;
1642+
type AccountIdentifier = MultiSigner;
1643+
type WeightInfo = weights::pallet_verify_signature::WeightInfo<Runtime>;
1644+
#[cfg(feature = "runtime-benchmarks")]
1645+
type BenchmarkHelper = ();
1646+
}
1647+
16191648
#[frame_support::runtime(legacy_ordering)]
16201649
mod runtime {
16211650
#[runtime::runtime]
@@ -1809,6 +1838,12 @@ mod runtime {
18091838
#[runtime::pallet_index(102)]
18101839
pub type RootTesting = pallet_root_testing;
18111840

1841+
#[runtime::pallet_index(103)]
1842+
pub type MetaTx = pallet_meta_tx::Pallet<Runtime>;
1843+
1844+
#[runtime::pallet_index(104)]
1845+
pub type VerifySignature = pallet_verify_signature::Pallet<Runtime>;
1846+
18121847
// BEEFY Bridges support.
18131848
#[runtime::pallet_index(200)]
18141849
pub type Beefy = pallet_beefy;
@@ -1959,6 +1994,8 @@ mod benches {
19591994
[pallet_vesting, Vesting]
19601995
[pallet_whitelist, Whitelist]
19611996
[pallet_asset_rate, AssetRate]
1997+
[pallet_meta_tx, MetaTx]
1998+
[pallet_verify_signature, VerifySignature]
19621999
// XCM
19632000
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
19642001
// NOTE: Make sure you point to the individual modules below.

polkadot/runtime/westend/src/weights/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub mod pallet_fast_unstake;
2828
pub mod pallet_identity;
2929
pub mod pallet_indices;
3030
pub mod pallet_message_queue;
31+
pub mod pallet_meta_tx;
3132
pub mod pallet_migrations;
3233
pub mod pallet_mmr;
3334
pub mod pallet_multisig;
@@ -44,6 +45,7 @@ pub mod pallet_timestamp;
4445
pub mod pallet_transaction_payment;
4546
pub mod pallet_treasury;
4647
pub mod pallet_utility;
48+
pub mod pallet_verify_signature;
4749
pub mod pallet_vesting;
4850
pub mod pallet_whitelist;
4951
pub mod pallet_xcm;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (C) Parity Technologies (UK) Ltd.
2+
// This file is part of Polkadot.
3+
4+
// Polkadot is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Polkadot is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! Autogenerated weights for `pallet_meta_tx`
18+
//!
19+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
20+
//! DATE: 2024-11-08, STEPS: `50`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]`
21+
//! WORST CASE MAP SIZE: `1000000`
22+
//! HOSTNAME: `cob`, CPU: `<UNKNOWN>`
23+
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("westend-dev")`, DB CACHE: 1024
24+
25+
// Executed Command:
26+
// ./target/debug/polkadot
27+
// benchmark
28+
// pallet
29+
// --chain=westend-dev
30+
// --steps=50
31+
// --repeat=2
32+
// --pallet=pallet-meta-tx
33+
// --extrinsic=*
34+
// --wasm-execution=compiled
35+
// --heap-pages=4096
36+
// --output=./polkadot/runtime/westend/src/weights/
37+
38+
#![cfg_attr(rustfmt, rustfmt_skip)]
39+
#![allow(unused_parens)]
40+
#![allow(unused_imports)]
41+
#![allow(missing_docs)]
42+
43+
use frame_support::{traits::Get, weights::Weight};
44+
use core::marker::PhantomData;
45+
46+
/// Weight functions for `pallet_meta_tx`.
47+
pub struct WeightInfo<T>(PhantomData<T>);
48+
impl<T: frame_system::Config> pallet_meta_tx::WeightInfo for WeightInfo<T> {
49+
fn bare_dispatch() -> Weight {
50+
// Proof Size summary in bytes:
51+
// Measured: `0`
52+
// Estimated: `0`
53+
// Minimum execution time: 138_000_000 picoseconds.
54+
Weight::from_parts(140_000_000, 0)
55+
.saturating_add(Weight::from_parts(0, 0))
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (C) Parity Technologies (UK) Ltd.
2+
// This file is part of Polkadot.
3+
4+
// Polkadot is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Polkadot is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! Autogenerated weights for `pallet_verify_signature`
18+
//!
19+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
20+
//! DATE: 2025-01-14, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
21+
//! WORST CASE MAP SIZE: `1000000`
22+
//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
23+
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("westend-dev")`, DB CACHE: 1024
24+
25+
// Executed Command:
26+
// target/production/polkadot
27+
// benchmark
28+
// pallet
29+
// --steps=50
30+
// --repeat=20
31+
// --extrinsic=*
32+
// --wasm-execution=compiled
33+
// --heap-pages=4096
34+
// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json
35+
// --pallet=pallet_verify_signature
36+
// --chain=westend-dev
37+
// --header=./polkadot/file_header.txt
38+
// --output=./polkadot/runtime/westend/src/weights/
39+
40+
#![cfg_attr(rustfmt, rustfmt_skip)]
41+
#![allow(unused_parens)]
42+
#![allow(unused_imports)]
43+
#![allow(missing_docs)]
44+
45+
use frame_support::{traits::Get, weights::Weight};
46+
use core::marker::PhantomData;
47+
48+
/// Weight functions for `pallet_verify_signature`.
49+
pub struct WeightInfo<T>(PhantomData<T>);
50+
impl<T: frame_system::Config> pallet_verify_signature::WeightInfo for WeightInfo<T> {
51+
fn verify_signature() -> Weight {
52+
// Proof Size summary in bytes:
53+
// Measured: `0`
54+
// Estimated: `0`
55+
// Minimum execution time: 42_915_000 picoseconds.
56+
Weight::from_parts(43_522_000, 0)
57+
.saturating_add(Weight::from_parts(0, 0))
58+
}
59+
}

prdoc/pr_6428.prdoc

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: "FRAME: Meta Transaction"
5+
6+
doc:
7+
- audience: Runtime Dev
8+
description: |
9+
Introduces the meta-tx pallet that implements Meta Transactions.
10+
11+
The meta transaction follows a layout similar to that of a regular transaction and can
12+
leverage the same extensions that implement the `TransactionExtension` trait. Once signed and
13+
shared by the signer, it can be relayed by a relayer. The relayer then submits a regular
14+
transaction with the `meta-tx::dispatch` call, passing the signed meta transaction as an
15+
argument.
16+
17+
To see an example, refer to the mock setup and the `sign_and_execute_meta_tx` test case within
18+
the pallet.
19+
20+
crates:
21+
- name: pallet-meta-tx
22+
bump: major
23+
- name: westend-runtime
24+
bump: major
25+
- name: kitchensink-runtime
26+
bump: major
27+
- name: polkadot-sdk
28+
bump: major
29+
- name: pallet-verify-signature
30+
bump: patch
31+
- name: pallet-example-authorization-tx-extension
32+
bump: major

0 commit comments

Comments
 (0)