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

[Tx ext stage 2: 2/4] Introduce #[pallet::authorize(...)] macro attribute and AuthorizeCall system transaction extension #6324

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cfe8667
add source to transaction extension
gui1117 Nov 1, 2024
f84192b
impl authorize
gui1117 Nov 1, 2024
f14e5ca
fix
gui1117 Nov 1, 2024
16d691b
prdoc
gui1117 Nov 1, 2024
ab46f1b
fmt
gui1117 Nov 1, 2024
93d9ed3
fmt
gui1117 Nov 1, 2024
241817e
Merge branch 'gui-tx-ext-stage-2-part-1' into gui-tx-ext-stage-2-part-2
gui1117 Nov 1, 2024
de1d4f4
improve code gen
gui1117 Nov 1, 2024
baa6fc5
prdoc
gui1117 Nov 20, 2024
ffe33de
apply suggestions
gui1117 Nov 20, 2024
461059a
Merge remote-tracking branch 'origin/master' into gui-tx-ext-stage-2-…
gui1117 Nov 20, 2024
7862970
use AsTransctionAuthorizedOrigin::is_transaction_authorized
gui1117 Nov 20, 2024
3dd50ca
test for call without authorization
gui1117 Nov 20, 2024
ec1b263
do not force std in test
gui1117 Nov 20, 2024
25691b8
add authorize call tx ext everywhere
gui1117 Nov 20, 2024
acd4282
update doc + example weight is zero
gui1117 Nov 22, 2024
6b65245
fmt
gui1117 Dec 2, 2024
71ca562
Merge remote-tracking branch 'origin/master' into gui-tx-ext-stage-2-…
gui1117 Dec 4, 2024
743835c
do not leak runtime-benchmark feature in dev build
gui1117 Dec 4, 2024
7d08985
minor
gui1117 Dec 4, 2024
83873c6
taplo
gui1117 Dec 4, 2024
f62152a
cannot link to dev dependencies
gui1117 Dec 4, 2024
33646e7
clippy
gui1117 Dec 4, 2024
2bc6d0c
fix tests and doc
gui1117 Dec 5, 2024
62c9e6e
Merge branch 'master' into gui-tx-ext-stage-2-part-2
gui1117 Dec 5, 2024
d040d4f
rustdoc
gui1117 Dec 5, 2024
e538e29
rustdoc
gui1117 Dec 5, 2024
3a757e8
fix span for split feature
gui1117 Dec 5, 2024
0946d79
Update from gui1117 running command 'update-ui'
actions-user Dec 5, 2024
d60e170
keep same error message as before
gui1117 Dec 5, 2024
f9cde01
fix test
gui1117 Dec 5, 2024
2c905e3
prdoc bump versions
gui1117 Dec 5, 2024
4bc94dd
Update from gui1117 running command 'update-ui'
actions-user Dec 5, 2024
a4452bc
Merge branch 'master' into gui-tx-ext-stage-2-part-2
gui1117 Dec 5, 2024
1566519
Merge branch 'master' into gui-tx-ext-stage-2-part-2
gui1117 Dec 5, 2024
2e756bc
ui test
gui1117 Dec 5, 2024
c002f10
remove non deterministic UI test
gui1117 Dec 6, 2024
36620e1
Update substrate/frame/support/src/traits/tasks.rs
gui1117 Dec 8, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ pub type SignedBlock = generic::SignedBlock<Block>;
pub type BlockId = generic::BlockId<Block>;
/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ pub type SignedBlock = generic::SignedBlock<Block>;
pub type BlockId = generic::BlockId<Block>;
/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand All @@ -1075,6 +1076,7 @@ impl EthExtra for EthExtraImpl {

fn get_eth_extension(nonce: u32, tip: Balance) -> Self::Extension {
(
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ pub type BlockId = generic::BlockId<Block>;

/// The TransactionExtension to the basic transaction logic.
pub type TxExtension = (
frame_system::CheckNonZeroSender<Runtime>,
// `Debug` is implemented for tuple of at most 12 elements, so we group extensions.
(frame_system::AuthorizeCall<Runtime>, frame_system::CheckNonZeroSender<Runtime>),
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
frame_system::CheckGenesis<Runtime>,
Expand Down Expand Up @@ -1559,7 +1560,10 @@ mod tests {
sp_io::TestExternalities::default().execute_with(|| {
frame_system::BlockHash::<Runtime>::insert(BlockNumber::zero(), Hash::default());
let payload: TxExtension = (
frame_system::CheckNonZeroSender::new(),
(
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::new(),
),
frame_system::CheckSpecVersion::new(),
frame_system::CheckTxVersion::new(),
frame_system::CheckGenesis::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ fn construct_extrinsic(
) -> UncheckedExtrinsic {
let account_id = AccountId32::from(sender.public());
let tx_ext: TxExtension = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
(
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::<Runtime>::new(),
),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ fn construct_extrinsic(
) -> UncheckedExtrinsic {
let account_id = AccountId32::from(sender.public());
let tx_ext: TxExtension = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
(
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::<Runtime>::new(),
),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ pub type BlockId = generic::BlockId<Block>;

/// The TransactionExtension to the basic transaction logic.
pub type TxExtension = (
frame_system::CheckNonZeroSender<Runtime>,
// `Debug` is implemented for tuple of at most 12 elements, so we group extensions.
(frame_system::AuthorizeCall<Runtime>, frame_system::CheckNonZeroSender<Runtime>),
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
frame_system::CheckGenesis<Runtime>,
Expand Down Expand Up @@ -1381,7 +1382,10 @@ mod tests {
sp_io::TestExternalities::default().execute_with(|| {
frame_system::BlockHash::<Runtime>::insert(BlockNumber::zero(), Hash::default());
let payload: TxExtension = (
frame_system::CheckNonZeroSender::new(),
(
frame_system::AuthorizeCall::new(),
frame_system::CheckNonZeroSender::new(),
),
frame_system::CheckSpecVersion::new(),
frame_system::CheckTxVersion::new(),
frame_system::CheckGenesis::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ fn construct_extrinsic(
) -> UncheckedExtrinsic {
let account_id = AccountId32::from(sender.public());
let extra: TxExtension = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
(
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::<Runtime>::new(),
),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ fn construct_extrinsic(
) -> UncheckedExtrinsic {
let account_id = AccountId32::from(sender.public());
let tx_ext: TxExtension = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
(
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::<Runtime>::new(),
),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ pub type SignedBlock = generic::SignedBlock<Block>;
pub type BlockId = generic::BlockId<Block>;
/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub type SignedBlock = generic::SignedBlock<Block>;
pub type BlockId = generic::BlockId<Block>;
/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub type BlockId = generic::BlockId<Block>;
/// The TransactionExtension to the basic transaction logic.
pub type TxExtension = (
frame_system::CheckNonZeroSender<Runtime>,
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
frame_system::CheckGenesis<Runtime>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub type BlockId = generic::BlockId<Block>;

/// The TransactionExtension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ pub type SignedBlock = generic::SignedBlock<Block>;
pub type BlockId = generic::BlockId<Block>;
/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
pallet_sudo::CheckOnlySudoAccount<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub type BlockId = generic::BlockId<Block>;

/// The TransactionExtension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub type BlockId = generic::BlockId<Block>;

/// The transactionExtension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand Down
1 change: 1 addition & 0 deletions cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub type AssetId = u32;

/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ pub type SignedBlock = generic::SignedBlock<Block>;
pub type BlockId = generic::BlockId<Block>;
/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand Down
3 changes: 2 additions & 1 deletion cumulus/test/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ pub fn generate_extrinsic_with_pair(
BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
let tip = 0;
let tx_ext: TxExtension = (
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
Expand All @@ -152,7 +153,7 @@ pub fn generate_extrinsic_with_pair(
let raw_payload = SignedPayload::from_raw(
function.clone(),
tx_ext.clone(),
((), VERSION.spec_version, genesis_block, current_block_hash, (), (), (), ()),
((), (), VERSION.spec_version, genesis_block, current_block_hash, (), (), (), ()),
);
let signature = raw_payload.using_encoded(|e| origin.sign(e));

Expand Down
1 change: 1 addition & 0 deletions cumulus/test/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ pub type SignedBlock = generic::SignedBlock<Block>;
pub type BlockId = generic::BlockId<Block>;
/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckGenesis<Runtime>,
Expand Down
3 changes: 2 additions & 1 deletion cumulus/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ pub fn construct_extrinsic(
.unwrap_or(2) as u64;
let tip = 0;
let tx_ext: runtime::TxExtension = (
frame_system::AuthorizeCall::<runtime::Runtime>::new(),
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
frame_system::CheckGenesis::<runtime::Runtime>::new(),
Expand All @@ -974,7 +975,7 @@ pub fn construct_extrinsic(
let raw_payload = runtime::SignedPayload::from_raw(
function.clone(),
tx_ext.clone(),
((), runtime::VERSION.spec_version, genesis_block, current_block_hash, (), (), (), ()),
((), (), runtime::VERSION.spec_version, genesis_block, current_block_hash, (), (), (), ()),
);
let signature = raw_payload.using_encoded(|e| caller.sign(e));
runtime::UncheckedExtrinsic::new_signed(
Expand Down
4 changes: 4 additions & 0 deletions polkadot/node/service/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ fn westend_sign_call(
use westend_runtime as runtime;

let tx_ext: runtime::TxExtension = (
frame_system::AuthorizeCall::<runtime::Runtime>::new(),
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
Expand All @@ -162,6 +163,7 @@ fn westend_sign_call(
call.clone(),
tx_ext.clone(),
(
(),
(),
runtime::VERSION.spec_version,
runtime::VERSION.transaction_version,
Expand Down Expand Up @@ -198,6 +200,7 @@ fn rococo_sign_call(
use sp_core::Pair;

let tx_ext: runtime::TxExtension = (
frame_system::AuthorizeCall::<runtime::Runtime>::new(),
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
Expand All @@ -217,6 +220,7 @@ fn rococo_sign_call(
call.clone(),
tx_ext.clone(),
(
(),
(),
runtime::VERSION.spec_version,
runtime::VERSION.transaction_version,
Expand Down
2 changes: 2 additions & 0 deletions polkadot/node/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ pub fn construct_extrinsic(
BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
let tip = 0;
let tx_ext: TxExtension = (
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
Expand All @@ -429,6 +430,7 @@ pub fn construct_extrinsic(
function.clone(),
tx_ext.clone(),
(
(),
(),
VERSION.spec_version,
VERSION.transaction_version,
Expand Down
22 changes: 22 additions & 0 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ where
.saturating_sub(1);
let tip = 0;
let tx_ext: TxExtension = (
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
Expand Down Expand Up @@ -698,6 +699,26 @@ where
}
}

impl<LocalCall> frame_system::offchain::CreateAuthorizedTransaction<LocalCall> for Runtime
where
RuntimeCall: From<LocalCall>,
{
fn create_extension() -> Self::Extension {
(
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckMortality::<Runtime>::from(generic::Era::Immortal),
frame_system::CheckNonce::<Runtime>::from(0),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(0),
frame_metadata_hash_extension::CheckMetadataHash::new(false),
)
}
}

parameter_types! {
pub Prefix: &'static [u8] = b"Pay ROCs to the Rococo account:";
}
Expand Down Expand Up @@ -1596,6 +1617,7 @@ pub type SignedBlock = generic::SignedBlock<Block>;
pub type BlockId = generic::BlockId<Block>;
/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand Down
21 changes: 21 additions & 0 deletions polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ where
}
}

impl<C> frame_system::offchain::CreateAuthorizedTransaction<C> for Runtime
where
RuntimeCall: From<C>,
{
fn create_extension() -> Self::Extension {
(
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckMortality::<Runtime>::from(generic::Era::Immortal),
frame_system::CheckNonce::<Runtime>::from(0),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(0),
)
}
}

parameter_types! {
pub storage EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS as u64;
pub storage ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
Expand Down Expand Up @@ -432,6 +451,7 @@ where
let current_block = System::block_number().saturated_into::<u64>().saturating_sub(1);
let tip = 0;
let tx_ext: TxExtension = (
frame_system::AuthorizeCall::<Runtime>::new(),
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
Expand Down Expand Up @@ -826,6 +846,7 @@ pub type SignedBlock = generic::SignedBlock<Block>;
pub type BlockId = generic::BlockId<Block>;
/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::AuthorizeCall<Runtime>,
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
Expand Down
Loading
Loading