mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 04:07:57 +00:00
Adds syntax for marking calls feeless (#1926)
Fixes https://github.com/paritytech/polkadot-sdk/issues/1725 This PR adds the following changes: 1. An attribute `pallet::feeless_if` that can be optionally attached to a call like so: ```rust #[pallet::feeless_if(|_origin: &OriginFor<T>, something: &u32| -> bool { *something == 0 })] pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResult { .... } ``` The closure passed accepts references to arguments as specified in the call fn. It returns a boolean that denotes the conditions required for this call to be "feeless". 2. A signed extension `SkipCheckIfFeeless<T: SignedExtension>` that wraps a transaction payment processor such as `pallet_transaction_payment::ChargeTransactionPayment`. It checks for all calls annotated with `pallet::feeless_if` to see if the conditions are met. If so, the wrapped signed extension is not called, essentially making the call feeless. In order to use this, you can simply replace your existing signed extension that manages transaction payment like so: ```diff - pallet_transaction_payment::ChargeTransactionPayment<Runtime>, + pallet_skip_feeless_payment::SkipCheckIfFeeless< + Runtime, + pallet_transaction_payment::ChargeTransactionPayment<Runtime>, + >, ``` ### Todo - [x] Tests - [x] Docs - [x] Prdoc --------- Co-authored-by: Nikhil Gupta <> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com> Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
This commit is contained in:
@@ -129,6 +129,7 @@ pallet-transaction-payment = { path = "../../../frame/transaction-payment", defa
|
||||
pallet-transaction-payment-rpc-runtime-api = { path = "../../../frame/transaction-payment/rpc/runtime-api", default-features = false}
|
||||
pallet-asset-conversion-tx-payment = { path = "../../../frame/transaction-payment/asset-conversion-tx-payment", default-features = false}
|
||||
pallet-asset-tx-payment = { path = "../../../frame/transaction-payment/asset-tx-payment", default-features = false}
|
||||
pallet-skip-feeless-payment = { path = "../../../frame/transaction-payment/skip-feeless-payment", default-features = false}
|
||||
pallet-transaction-storage = { path = "../../../frame/transaction-storage", default-features = false}
|
||||
pallet-uniques = { path = "../../../frame/uniques", default-features = false}
|
||||
pallet-vesting = { path = "../../../frame/vesting", default-features = false}
|
||||
@@ -212,6 +213,7 @@ std = [
|
||||
"pallet-scheduler/std",
|
||||
"pallet-session-benchmarking?/std",
|
||||
"pallet-session/std",
|
||||
"pallet-skip-feeless-payment/std",
|
||||
"pallet-society/std",
|
||||
"pallet-staking-runtime-api/std",
|
||||
"pallet-staking/std",
|
||||
@@ -308,6 +310,7 @@ runtime-benchmarks = [
|
||||
"pallet-salary/runtime-benchmarks",
|
||||
"pallet-scheduler/runtime-benchmarks",
|
||||
"pallet-session-benchmarking/runtime-benchmarks",
|
||||
"pallet-skip-feeless-payment/runtime-benchmarks",
|
||||
"pallet-society/runtime-benchmarks",
|
||||
"pallet-staking/runtime-benchmarks",
|
||||
"pallet-state-trie-migration/runtime-benchmarks",
|
||||
@@ -381,6 +384,7 @@ try-runtime = [
|
||||
"pallet-salary/try-runtime",
|
||||
"pallet-scheduler/try-runtime",
|
||||
"pallet-session/try-runtime",
|
||||
"pallet-skip-feeless-payment/try-runtime",
|
||||
"pallet-society/try-runtime",
|
||||
"pallet-staking/try-runtime",
|
||||
"pallet-state-trie-migration/try-runtime",
|
||||
|
||||
@@ -569,6 +569,10 @@ impl pallet_asset_conversion_tx_payment::Config for Runtime {
|
||||
pallet_asset_conversion_tx_payment::AssetConversionAdapter<Balances, AssetConversion>;
|
||||
}
|
||||
|
||||
impl pallet_skip_feeless_payment::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MinimumPeriod: Moment = SLOT_DURATION / 2;
|
||||
}
|
||||
@@ -1394,7 +1398,11 @@ where
|
||||
frame_system::CheckEra::<Runtime>::from(era),
|
||||
frame_system::CheckNonce::<Runtime>::from(nonce),
|
||||
frame_system::CheckWeight::<Runtime>::new(),
|
||||
pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::<Runtime>::from(tip, None),
|
||||
pallet_skip_feeless_payment::SkipCheckIfFeeless::from(
|
||||
pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::<Runtime>::from(
|
||||
tip, None,
|
||||
),
|
||||
),
|
||||
);
|
||||
let raw_payload = SignedPayload::new(call, extra)
|
||||
.map_err(|e| {
|
||||
@@ -2134,6 +2142,7 @@ construct_runtime!(
|
||||
Statement: pallet_statement,
|
||||
Broker: pallet_broker,
|
||||
Mixnet: pallet_mixnet,
|
||||
SkipFeelessPayment: pallet_skip_feeless_payment,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -2160,7 +2169,10 @@ pub type SignedExtra = (
|
||||
frame_system::CheckEra<Runtime>,
|
||||
frame_system::CheckNonce<Runtime>,
|
||||
frame_system::CheckWeight<Runtime>,
|
||||
pallet_asset_conversion_tx_payment::ChargeAssetTxPayment<Runtime>,
|
||||
pallet_skip_feeless_payment::SkipCheckIfFeeless<
|
||||
Runtime,
|
||||
pallet_asset_conversion_tx_payment::ChargeAssetTxPayment<Runtime>,
|
||||
>,
|
||||
);
|
||||
|
||||
/// Unchecked extrinsic type as expected by this runtime.
|
||||
|
||||
Reference in New Issue
Block a user