Skip to content

Commit

Permalink
FRAME: Create TransactionExtension as a replacement for `SignedExte…
Browse files Browse the repository at this point in the history
…nsion` (paritytech#2280)

Closes paritytech#2160

First part of [Extrinsic
Horizon](paritytech#2415)

Introduces a new trait `TransactionExtension` to replace
`SignedExtension`. Introduce the idea of transactions which obey the
runtime's extensions and have according Extension data (né Extra data)
yet do not have hard-coded signatures.

Deprecate the terminology of "Unsigned" when used for
transactions/extrinsics owing to there now being "proper" unsigned
transactions which obey the extension framework and "old-style" unsigned
which do not. Instead we have __*General*__ for the former and
__*Bare*__ for the latter. (Ultimately, the latter will be phased out as
a type of transaction, and Bare will only be used for Inherents.)

Types of extrinsic are now therefore:
- Bare (no hardcoded signature, no Extra data; used to be known as
"Unsigned")
- Bare transactions (deprecated): Gossiped, validated with
`ValidateUnsigned` (deprecated) and the `_bare_compat` bits of
`TransactionExtension` (deprecated).
  - Inherents: Not gossiped, validated with `ProvideInherent`.
- Extended (Extra data): Gossiped, validated via `TransactionExtension`.
  - Signed transactions (with a hardcoded signature).
  - General transactions (without a hardcoded signature).

`TransactionExtension` differs from `SignedExtension` because:
- A signature on the underlying transaction may validly not be present.
- It may alter the origin during validation.
- `pre_dispatch` is renamed to `prepare` and need not contain the checks
present in `validate`.
- `validate` and `prepare` is passed an `Origin` rather than a
`AccountId`.
- `validate` may pass arbitrary information into `prepare` via a new
user-specifiable type `Val`.
- `AdditionalSigned`/`additional_signed` is renamed to
`Implicit`/`implicit`. It is encoded *for the entire transaction* and
passed in to each extension as a new argument to `validate`. This
facilitates the ability of extensions to acts as underlying crypto.

There is a new `DispatchTransaction` trait which contains only default
function impls and is impl'ed for any `TransactionExtension` impler. It
provides several utility functions which reduce some of the tedium from
using `TransactionExtension` (indeed, none of its regular functions
should now need to be called directly).

Three transaction version discriminator ("versions") are now
permissible:
- 0b000000100: Bare (used to be called "Unsigned"): contains Signature
or Extra (extension data). After bare transactions are no longer
supported, this will strictly identify an Inherents only.
- 0b100000100: Old-school "Signed" Transaction: contains Signature and
Extra (extension data).
- 0b010000100: New-school "General" Transaction: contains Extra
(extension data), but no Signature.

For the New-school General Transaction, it becomes trivial for authors
to publish extensions to the mechanism for authorizing an Origin, e.g.
through new kinds of key-signing schemes, ZK proofs, pallet state,
mutations over pre-authenticated origins or any combination of the
above.

## Code Migration

### NOW: Getting it to build

Wrap your `SignedExtension`s in `AsTransactionExtension`. This should be
accompanied by renaming your aggregate type in line with the new
terminology. E.g. Before:

```rust
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
	/* snip */
	MySpecialSignedExtension,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
	generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
```

After:

```rust
/// The extension to the basic transaction logic.
pub type TxExtension = (
	/* snip */
	AsTransactionExtension<MySpecialSignedExtension>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
	generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
```

You'll also need to alter any transaction building logic to add a
`.into()` to make the conversion happen. E.g. Before:

```rust
fn construct_extrinsic(
		/* snip */
) -> UncheckedExtrinsic {
	let extra: SignedExtra = (
		/* snip */
		MySpecialSignedExtension::new(/* snip */),
	);
	let payload = SignedPayload::new(call.clone(), extra.clone()).unwrap();
	let signature = payload.using_encoded(|e| sender.sign(e));
	UncheckedExtrinsic::new_signed(
		/* snip */
		Signature::Sr25519(signature),
		extra,
	)
}
```

After:

```rust
fn construct_extrinsic(
		/* snip */
) -> UncheckedExtrinsic {
	let tx_ext: TxExtension = (
		/* snip */
		MySpecialSignedExtension::new(/* snip */).into(),
	);
	let payload = SignedPayload::new(call.clone(), tx_ext.clone()).unwrap();
	let signature = payload.using_encoded(|e| sender.sign(e));
	UncheckedExtrinsic::new_signed(
		/* snip */
		Signature::Sr25519(signature),
		tx_ext,
	)
}
```

### SOON: Migrating to `TransactionExtension`

Most `SignedExtension`s can be trivially converted to become a
`TransactionExtension`. There are a few things to know.

- Instead of a single trait like `SignedExtension`, you should now
implement two traits individually: `TransactionExtensionBase` and
`TransactionExtension`.
- Weights are now a thing and must be provided via the new function `fn
weight`.

#### `TransactionExtensionBase`

This trait takes care of anything which is not dependent on types
specific to your runtime, most notably `Call`.

- `AdditionalSigned`/`additional_signed` is renamed to
`Implicit`/`implicit`.
- Weight must be returned by implementing the `weight` function. If your
extension is associated with a pallet, you'll probably want to do this
via the pallet's existing benchmarking infrastructure.

#### `TransactionExtension`

Generally:
- `pre_dispatch` is now `prepare` and you *should not reexecute the
`validate` functionality in there*!
- You don't get an account ID any more; you get an origin instead. If
you need to presume an account ID, then you can use the trait function
`AsSystemOriginSigner::as_system_origin_signer`.
- You get an additional ticket, similar to `Pre`, called `Val`. This
defines data which is passed from `validate` into `prepare`. This is
important since you should not be duplicating logic from `validate` to
`prepare`, you need a way of passing your working from the former into
the latter. This is it.
- This trait takes two type parameters: `Call` and `Context`. `Call` is
the runtime call type which used to be an associated type; you can just
move it to become a type parameter for your trait impl. `Context` is not
currently used and you can safely implement over it as an unbounded
type.
- There's no `AccountId` associated type any more. Just remove it.

Regarding `validate`:
- You get three new parameters in `validate`; all can be ignored when
migrating from `SignedExtension`.
- `validate` returns a tuple on success; the second item in the tuple is
the new ticket type `Self::Val` which gets passed in to `prepare`. If
you use any information extracted during `validate` (off-chain and
on-chain, non-mutating) in `prepare` (on-chain, mutating) then you can
pass it through with this. For the tuple's last item, just return the
`origin` argument.

Regarding `prepare`:
- This is renamed from `pre_dispatch`, but there is one change:
- FUNCTIONALITY TO VALIDATE THE TRANSACTION NEED NOT BE DUPLICATED FROM
`validate`!!
- (This is different to `SignedExtension` which was required to run the
same checks in `pre_dispatch` as in `validate`.)

Regarding `post_dispatch`:
- Since there are no unsigned transactions handled by
`TransactionExtension`, `Pre` is always defined, so the first parameter
is `Self::Pre` rather than `Option<Self::Pre>`.

If you make use of `SignedExtension::validate_unsigned` or
`SignedExtension::pre_dispatch_unsigned`, then:
- Just use the regular versions of these functions instead.
- Have your logic execute in the case that the `origin` is `None`.
- Ensure your transaction creation logic creates a General Transaction
rather than a Bare Transaction; this means having to include all
`TransactionExtension`s' data.
- `ValidateUnsigned` can still be used (for now) if you need to be able
to construct transactions which contain none of the extension data,
however these will be phased out in stage 2 of the Transactions Horizon,
so you should consider moving to an extension-centric design.

## TODO

- [x] Introduce `CheckSignature` impl of `TransactionExtension` to
ensure it's possible to have crypto be done wholly in a
`TransactionExtension`.
- [x] Deprecate `SignedExtension` and move all uses in codebase to
`TransactionExtension`.
  - [x] `ChargeTransactionPayment`
  - [x] `DummyExtension`
  - [x] `ChargeAssetTxPayment` (asset-tx-payment)
  - [x] `ChargeAssetTxPayment` (asset-conversion-tx-payment)
  - [x] `CheckWeight`
  - [x] `CheckTxVersion`
  - [x] `CheckSpecVersion`
  - [x] `CheckNonce`
  - [x] `CheckNonZeroSender`
  - [x] `CheckMortality`
  - [x] `CheckGenesis`
  - [x] `CheckOnlySudoAccount`
  - [x] `WatchDummy`
  - [x] `PrevalidateAttests`
  - [x] `GenericSignedExtension`
  - [x] `SignedExtension` (chain-polkadot-bulletin)
  - [x] `RefundSignedExtensionAdapter`
- [x] Implement `fn weight` across the board.
- [ ] Go through all pre-existing extensions which assume an account
signer and explicitly handle the possibility of another kind of origin.
- [x] `CheckNonce` should probably succeed in the case of a non-account
origin.
- [x] `CheckNonZeroSender` should succeed in the case of a non-account
origin.
- [x] `ChargeTransactionPayment` and family should fail in the case of a
non-account origin.
  - [ ] 
- [x] Fix any broken tests.

---------

Signed-off-by: georgepisaltu <george.pisaltu@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Co-authored-by: Nikhil Gupta <17176722+gupnik@users.noreply.github.com>
Co-authored-by: georgepisaltu <52418509+georgepisaltu@users.noreply.github.com>
Co-authored-by: Chevdor <chevdor@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Maciej <maciej.zyszkiewicz@parity.io>
Co-authored-by: Javier Viola <javier@parity.io>
Co-authored-by: Marcin S. <marcin@realemail.net>
Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io>
Co-authored-by: Javier Bullrich <javier@bullrich.dev>
Co-authored-by: Koute <koute@users.noreply.github.com>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: Vladimir Istyufeev <vladimir@parity.io>
Co-authored-by: Ross Bulat <ross@parity.io>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Svyatoslav Nikolsky <svyatonik@gmail.com>
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com>
Co-authored-by: ordian <write@reusable.software>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com>
Co-authored-by: Dmitry Markin <dmitry@markin.tech>
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
Co-authored-by: Julian Eager <eagr@tutanota.com>
Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
Co-authored-by: Davide Galassi <davxy@datawok.net>
Co-authored-by: Dónal Murray <donal.murray@parity.io>
Co-authored-by: yjh <yjh465402634@gmail.com>
Co-authored-by: Tom Mi <tommi@niemi.lol>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Will | Paradox | ParaNodes.io <79228812+paradox-tt@users.noreply.github.com>
Co-authored-by: Bastian Köcher <info@kchr.de>
Co-authored-by: Joshy Orndorff <JoshOrndorff@users.noreply.github.com>
Co-authored-by: Joshy Orndorff <git-user-email.h0ly5@simplelogin.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Juan Girini <juangirini@gmail.com>
Co-authored-by: bader y <ibnbassem@gmail.com>
Co-authored-by: James Wilson <james@jsdw.me>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: asynchronous rob <rphmeier@gmail.com>
Co-authored-by: Parth <desaiparth08@gmail.com>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Jonathan Udd <jonathan@dwellir.com>
Co-authored-by: Serban Iorga <serban@parity.io>
Co-authored-by: Egor_P <egor@parity.io>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Evgeny Snitko <evgeny@parity.io>
Co-authored-by: Just van Stam <vstam1@users.noreply.github.com>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: gupnik <nikhilgupta.iitk@gmail.com>
Co-authored-by: dzmitry-lahoda <dzmitry@lahoda.pro>
Co-authored-by: zhiqiangxu <652732310@qq.com>
Co-authored-by: Nazar Mokrynskyi <nazar@mokrynskyi.com>
Co-authored-by: Anwesh <anweshknayak@gmail.com>
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
Co-authored-by: Sam Johnson <sam@durosoft.com>
Co-authored-by: kianenigma <kian@parity.io>
Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com>
Co-authored-by: Muharem <ismailov.m.h@gmail.com>
Co-authored-by: joepetrowski <joe@parity.io>
Co-authored-by: Alexandru Gheorghe <49718502+alexggh@users.noreply.github.com>
Co-authored-by: Gabriel Facco de Arruda <arrudagates@gmail.com>
Co-authored-by: Squirrel <gilescope@gmail.com>
Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
Co-authored-by: georgepisaltu <george.pisaltu@parity.io>
Co-authored-by: command-bot <>
  • Loading branch information
Show file tree
Hide file tree
Showing 181 changed files with 16,918 additions and 12,826 deletions.
2 changes: 1 addition & 1 deletion substrate/.maintain/frame-weight-template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub trait WeightInfo {

/// Weights for `{{pallet}}` using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
{{#if (eq pallet "frame_system")}}
{{#if (or (eq pallet "frame_system") (eq pallet "frame_system_extensions"))}}
impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
{{else}}
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
Expand Down
4 changes: 2 additions & 2 deletions substrate/bin/minimal/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}

type SignedExtra = (
type TxExtension = (
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand Down Expand Up @@ -104,7 +104,7 @@ impl pallet_transaction_payment::Config for Runtime {
type LengthToFee = FixedFee<1, <Self as pallet_balances::Config>::Balance>;
}

type Block = frame::runtime::types_common::BlockOf<Runtime, SignedExtra>;
type Block = frame::runtime::types_common::BlockOf<Runtime, TxExtension>;
type Header = HeaderFor<Runtime>;

type RuntimeExecutive =
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"node-template-runtime/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks",
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
Expand Down
9 changes: 5 additions & 4 deletions substrate/bin/node-template/node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn create_benchmark_extrinsic(
.checked_next_power_of_two()
.map(|c| c / 2)
.unwrap_or(2) as u64;
let extra: runtime::SignedExtra = (
let tx_ext: runtime::TxExtension = (
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
Expand All @@ -121,11 +121,12 @@ pub fn create_benchmark_extrinsic(
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
frame_system::CheckWeight::<runtime::Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
);
)
.into();

let raw_payload = runtime::SignedPayload::from_raw(
call.clone(),
extra.clone(),
tx_ext.clone(),
(
(),
runtime::VERSION.spec_version,
Expand All @@ -143,7 +144,7 @@ pub fn create_benchmark_extrinsic(
call,
sp_runtime::AccountId32::from(sender.public()).into(),
runtime::Signature::Sr25519(signature),
extra,
tx_ext,
)
}

Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node-template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ runtime-benchmarks = [
"pallet-sudo/runtime-benchmarks",
"pallet-template/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
Expand Down
12 changes: 8 additions & 4 deletions substrate/bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ impl pallet_transaction_payment::Config for Runtime {
type WeightToFee = IdentityFee<Balance>;
type LengthToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ConstFeeMultiplier<FeeMultiplier>;
type WeightInfo = pallet_transaction_payment::weights::SubstrateWeight<Runtime>;
}

impl pallet_sudo::Config for Runtime {
Expand Down Expand Up @@ -276,8 +277,8 @@ pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Block type as expected by this runtime.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand All @@ -296,9 +297,9 @@ type Migrations = ();

/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
pub type SignedPayload = generic::SignedPayload<RuntimeCall, TxExtension>;
/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Expand All @@ -314,6 +315,7 @@ mod benches {
frame_benchmarking::define_benchmarks!(
[frame_benchmarking, BaselineBench::<Runtime>]
[frame_system, SystemBench::<Runtime>]
[frame_system_extensions, SystemExtensionsBench::<Runtime>]
[pallet_balances, Balances]
[pallet_timestamp, Timestamp]
[pallet_sudo, Sudo]
Expand Down Expand Up @@ -498,6 +500,7 @@ impl_runtime_apis! {
use frame_benchmarking::{baseline, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use frame_system_benchmarking::Pallet as SystemBench;
use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
use baseline::Pallet as BaselineBench;

let mut list = Vec::<BenchmarkList>::new();
Expand All @@ -514,6 +517,7 @@ impl_runtime_apis! {
use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch};
use sp_storage::TrackedStorageKey;
use frame_system_benchmarking::Pallet as SystemBench;
use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
use baseline::Pallet as BaselineBench;

impl frame_system_benchmarking::Config for Runtime {}
Expand Down
2 changes: 2 additions & 0 deletions substrate/bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"kitchensink-runtime/runtime-benchmarks",
"node-inspect?/runtime-benchmarks",
"pallet-asset-conversion-tx-payment/runtime-benchmarks",
"pallet-asset-tx-payment/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
Expand All @@ -205,6 +206,7 @@ runtime-benchmarks = [
"pallet-skip-feeless-payment/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"sc-client-db/runtime-benchmarks",
"sc-service/runtime-benchmarks",
Expand Down
2 changes: 1 addition & 1 deletion substrate/bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {

fn extrinsic_set_time(now: u64) -> OpaqueExtrinsic {
kitchensink_runtime::UncheckedExtrinsic {
signature: None,
preamble: sp_runtime::generic::Preamble::Bare,
function: kitchensink_runtime::RuntimeCall::Timestamp(pallet_timestamp::Call::set { now }),
}
.into()
Expand Down
6 changes: 3 additions & 3 deletions substrate/bin/node/cli/benches/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use sp_core::{
storage::well_known_keys,
traits::{CallContext, CodeExecutor, RuntimeCode},
};
use sp_runtime::traits::BlakeTwo256;
use sp_runtime::{generic::ExtrinsicFormat, traits::BlakeTwo256};
use sp_state_machine::TestExternalities as CoreTestExternalities;
use staging_node_cli::service::RuntimeExecutor;

Expand Down Expand Up @@ -144,11 +144,11 @@ fn test_blocks(
) -> Vec<(Vec<u8>, Hash)> {
let mut test_ext = new_test_ext(genesis_config);
let mut block1_extrinsics = vec![CheckedExtrinsic {
signed: None,
format: ExtrinsicFormat::Bare,
function: RuntimeCall::Timestamp(pallet_timestamp::Call::set { now: 0 }),
}];
block1_extrinsics.extend((0..20).map(|i| CheckedExtrinsic {
signed: Some((alice(), signed_extra(i, 0))),
format: ExtrinsicFormat::Signed(alice(), tx_ext(i, 0)),
function: RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
dest: bob().into(),
value: 1 * DOLLARS,
Expand Down
77 changes: 44 additions & 33 deletions substrate/bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,21 @@ pub fn create_extrinsic(
.map(|c| c / 2)
.unwrap_or(2) as u64;
let tip = 0;
let extra: kitchensink_runtime::SignedExtra =
let tx_ext: kitchensink_runtime::TxExtension =
(
frame_system::CheckNonZeroSender::<kitchensink_runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<kitchensink_runtime::Runtime>::new(),
frame_system::CheckTxVersion::<kitchensink_runtime::Runtime>::new(),
frame_system::CheckGenesis::<kitchensink_runtime::Runtime>::new(),
frame_system::CheckEra::<kitchensink_runtime::Runtime>::from(generic::Era::mortal(
period,
best_block.saturated_into(),
)),
frame_system::CheckNonce::<kitchensink_runtime::Runtime>::from(nonce),
frame_system::CheckWeight::<kitchensink_runtime::Runtime>::new(),
(
frame_system::CheckNonZeroSender::<kitchensink_runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<kitchensink_runtime::Runtime>::new(),
frame_system::CheckTxVersion::<kitchensink_runtime::Runtime>::new(),
frame_system::CheckGenesis::<kitchensink_runtime::Runtime>::new(),
frame_system::CheckEra::<kitchensink_runtime::Runtime>::from(generic::Era::mortal(
period,
best_block.saturated_into(),
)),
frame_system::CheckNonce::<kitchensink_runtime::Runtime>::from(nonce),
frame_system::CheckWeight::<kitchensink_runtime::Runtime>::new(),
)
.into(),
pallet_skip_feeless_payment::SkipCheckIfFeeless::from(
pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::<
kitchensink_runtime::Runtime,
Expand All @@ -128,15 +131,17 @@ pub fn create_extrinsic(

let raw_payload = kitchensink_runtime::SignedPayload::from_raw(
function.clone(),
extra.clone(),
tx_ext.clone(),
(
(),
kitchensink_runtime::VERSION.spec_version,
kitchensink_runtime::VERSION.transaction_version,
genesis_hash,
best_hash,
(),
(),
(
(),
kitchensink_runtime::VERSION.spec_version,
kitchensink_runtime::VERSION.transaction_version,
genesis_hash,
best_hash,
(),
(),
),
(),
),
);
Expand All @@ -146,7 +151,7 @@ pub fn create_extrinsic(
function,
sp_runtime::AccountId32::from(sender.public()).into(),
kitchensink_runtime::Signature::Sr25519(signature),
extra,
tx_ext,
)
}

Expand Down Expand Up @@ -791,7 +796,7 @@ mod tests {
use codec::Encode;
use kitchensink_runtime::{
constants::{currency::CENTS, time::SLOT_DURATION},
Address, BalancesCall, RuntimeCall, UncheckedExtrinsic,
Address, BalancesCall, RuntimeCall, TxExtension, UncheckedExtrinsic,
};
use node_primitives::{Block, DigestItem, Signature};
use sc_client_api::BlockBackend;
Expand Down Expand Up @@ -993,25 +998,31 @@ mod tests {
let tx_payment = pallet_skip_feeless_payment::SkipCheckIfFeeless::from(
pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::from(0, None),
);
let extra = (
check_non_zero_sender,
check_spec_version,
check_tx_version,
check_genesis,
check_era,
check_nonce,
check_weight,
let tx_ext: TxExtension = (
(
check_non_zero_sender,
check_spec_version,
check_tx_version,
check_genesis,
check_era,
check_nonce,
check_weight,
)
.into(),
tx_payment,
);
let raw_payload = SignedPayload::from_raw(
function,
extra,
((), spec_version, transaction_version, genesis_hash, genesis_hash, (), (), ()),
tx_ext,
(
((), spec_version, transaction_version, genesis_hash, genesis_hash, (), ()),
(),
),
);
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
let (function, extra, _) = raw_payload.deconstruct();
let (function, tx_ext, _) = raw_payload.deconstruct();
index += 1;
UncheckedExtrinsic::new_signed(function, from.into(), signature.into(), extra)
UncheckedExtrinsic::new_signed(function, from.into(), signature.into(), tx_ext)
.into()
},
);
Expand Down
26 changes: 13 additions & 13 deletions substrate/bin/node/cli/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn transfer_fee<E: Encode>(extrinsic: &E) -> Balance {

fn xt() -> UncheckedExtrinsic {
sign(CheckedExtrinsic {
signed: Some((alice(), signed_extra(0, 0))),
format: sp_runtime::generic::ExtrinsicFormat::Signed(alice(), tx_ext(0, 0)),
function: RuntimeCall::Balances(default_transfer_call()),
})
}
Expand All @@ -84,11 +84,11 @@ fn changes_trie_block() -> (Vec<u8>, Hash) {
GENESIS_HASH.into(),
vec![
CheckedExtrinsic {
signed: None,
format: sp_runtime::generic::ExtrinsicFormat::Bare,
function: RuntimeCall::Timestamp(pallet_timestamp::Call::set { now: time }),
},
CheckedExtrinsic {
signed: Some((alice(), signed_extra(0, 0))),
format: sp_runtime::generic::ExtrinsicFormat::Signed(alice(), tx_ext(0, 0)),
function: RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
dest: bob().into(),
value: 69 * DOLLARS,
Expand All @@ -111,11 +111,11 @@ fn blocks() -> ((Vec<u8>, Hash), (Vec<u8>, Hash)) {
GENESIS_HASH.into(),
vec![
CheckedExtrinsic {
signed: None,
format: sp_runtime::generic::ExtrinsicFormat::Bare,
function: RuntimeCall::Timestamp(pallet_timestamp::Call::set { now: time1 }),
},
CheckedExtrinsic {
signed: Some((alice(), signed_extra(0, 0))),
format: sp_runtime::generic::ExtrinsicFormat::Signed(alice(), tx_ext(0, 0)),
function: RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
dest: bob().into(),
value: 69 * DOLLARS,
Expand All @@ -131,18 +131,18 @@ fn blocks() -> ((Vec<u8>, Hash), (Vec<u8>, Hash)) {
block1.1,
vec![
CheckedExtrinsic {
signed: None,
format: sp_runtime::generic::ExtrinsicFormat::Bare,
function: RuntimeCall::Timestamp(pallet_timestamp::Call::set { now: time2 }),
},
CheckedExtrinsic {
signed: Some((bob(), signed_extra(0, 0))),
format: sp_runtime::generic::ExtrinsicFormat::Signed(bob(), tx_ext(0, 0)),
function: RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
dest: alice().into(),
value: 5 * DOLLARS,
}),
},
CheckedExtrinsic {
signed: Some((alice(), signed_extra(1, 0))),
format: sp_runtime::generic::ExtrinsicFormat::Signed(alice(), tx_ext(1, 0)),
function: RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
dest: bob().into(),
value: 15 * DOLLARS,
Expand All @@ -166,11 +166,11 @@ fn block_with_size(time: u64, nonce: u32, size: usize) -> (Vec<u8>, Hash) {
GENESIS_HASH.into(),
vec![
CheckedExtrinsic {
signed: None,
format: sp_runtime::generic::ExtrinsicFormat::Bare,
function: RuntimeCall::Timestamp(pallet_timestamp::Call::set { now: time * 1000 }),
},
CheckedExtrinsic {
signed: Some((alice(), signed_extra(nonce, 0))),
format: sp_runtime::generic::ExtrinsicFormat::Signed(alice(), tx_ext(nonce, 0)),
function: RuntimeCall::System(frame_system::Call::remark { remark: vec![0; size] }),
},
],
Expand Down Expand Up @@ -677,11 +677,11 @@ fn deploying_wasm_contract_should_work() {
GENESIS_HASH.into(),
vec![
CheckedExtrinsic {
signed: None,
format: sp_runtime::generic::ExtrinsicFormat::Bare,
function: RuntimeCall::Timestamp(pallet_timestamp::Call::set { now: time }),
},
CheckedExtrinsic {
signed: Some((charlie(), signed_extra(0, 0))),
format: sp_runtime::generic::ExtrinsicFormat::Signed(charlie(), tx_ext(0, 0)),
function: RuntimeCall::Contracts(pallet_contracts::Call::instantiate_with_code::<
Runtime,
> {
Expand All @@ -694,7 +694,7 @@ fn deploying_wasm_contract_should_work() {
}),
},
CheckedExtrinsic {
signed: Some((charlie(), signed_extra(1, 0))),
format: sp_runtime::generic::ExtrinsicFormat::Signed(charlie(), tx_ext(1, 0)),
function: RuntimeCall::Contracts(pallet_contracts::Call::call::<Runtime> {
dest: sp_runtime::MultiAddress::Id(addr.clone()),
value: 10,
Expand Down
Loading

0 comments on commit d14b3b9

Please sign in to comment.