Skip to content

Commit ed8dbff

Browse files
authored
Add a wrapper to waive tx fee for batch-call from worker (#3110)
* Add a wrapper to waive tx fee for batch-call from worker * fix ci
1 parent 19eedae commit ed8dbff

File tree

12 files changed

+72
-6
lines changed

12 files changed

+72
-6
lines changed

parachain/Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parachain/pallets/identity-management/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pallet-timestamp = { workspace = true, features = ["std"] }
2626
sp-io = { workspace = true, features = ["std"] }
2727
pallet-teebag = { workspace = true, features = ["std", "test-util"] }
2828
pallet-group = { workspace = true, features = ["std"] }
29+
pallet-utility = { workspace = true, features = ["std"] }
2930

3031
[features]
3132
default = ["std"]

parachain/pallets/identity-management/src/mock.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ frame_support::construct_runtime!(
8181
Timestamp: pallet_timestamp,
8282
IdentityManagement: pallet_identity_management,
8383
IMPExtrinsicWhitelist: pallet_group,
84+
Utility: pallet_utility,
8485
}
8586
);
8687

@@ -164,6 +165,13 @@ impl pallet_group::Config for Test {
164165
type GroupManagerOrigin = frame_system::EnsureRoot<Self::AccountId>;
165166
}
166167

168+
impl pallet_utility::Config for Test {
169+
type RuntimeEvent = RuntimeEvent;
170+
type RuntimeCall = RuntimeCall;
171+
type PalletsOrigin = OriginCaller;
172+
type WeightInfo = ();
173+
}
174+
167175
pub fn new_test_ext() -> sp_io::TestExternalities {
168176
use pallet_teebag::test_util::{
169177
get_signer, TEST8_CERT, TEST8_SIGNER_PUB, TEST8_TIMESTAMP, URL,

parachain/pallets/teebag/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ frame-support = { workspace = true }
2828
frame-system = { workspace = true }
2929
pallet-balances = { workspace = true, optional = true }
3030
pallet-timestamp = { workspace = true }
31+
pallet-utility = { workspace = true }
3132
sp-core = { workspace = true }
3233
sp-io = { workspace = true }
3334
sp-runtime = { workspace = true }
@@ -62,12 +63,14 @@ std = [
6263
"sp-std/std",
6364
"pallet-timestamp/std",
6465
"pallet-balances?/std",
66+
"pallet-utility/std",
6567
]
6668
runtime-benchmarks = [
6769
"frame-support/runtime-benchmarks",
6870
"frame-benchmarking/runtime-benchmarks",
6971
"pallet-balances?/runtime-benchmarks",
7072
"pallet-timestamp/runtime-benchmarks",
73+
"pallet-utility/runtime-benchmarks",
7174
]
7275
try-runtime = ["frame-support/try-runtime"]
7376
# workaround to cross crate boundary, see https://github.com/rust-lang/cargo/issues/8379

parachain/pallets/teebag/src/lib.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ pub mod pallet {
6565
pub struct Pallet<T>(PhantomData<T>);
6666

6767
#[pallet::config]
68-
pub trait Config: frame_system::Config + pallet_timestamp::Config {
68+
pub trait Config:
69+
frame_system::Config + pallet_timestamp::Config + pallet_utility::Config
70+
{
6971
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
7072
/// Weight information for extrinsics in this pallet.
7173
type WeightInfo: WeightInfo;
@@ -668,6 +670,38 @@ pub mod pallet {
668670
Self::finalize_block(sender, shard, confirmation);
669671
Ok(Pays::No.into())
670672
}
673+
674+
// A wrapper to utility.call to waive the tx fee if the caller is tee-worker
675+
// the weight is copied from pallet_utility
676+
#[pallet::call_index(23)]
677+
#[pallet::weight({
678+
use pallet_utility::WeightInfo;
679+
let dispatch_infos = calls.iter().map(|call| call.get_dispatch_info()).collect::<Vec<_>>();
680+
let dispatch_weight = dispatch_infos.iter()
681+
.map(|di| di.weight)
682+
.fold(Weight::zero(), |total: Weight, weight: Weight| total.saturating_add(weight))
683+
.saturating_add(<T as pallet_utility::Config>::WeightInfo::batch(calls.len() as u32));
684+
let dispatch_class = {
685+
let all_operational = dispatch_infos.iter()
686+
.map(|di| di.class)
687+
.all(|class| class == DispatchClass::Operational);
688+
if all_operational {
689+
DispatchClass::Operational
690+
} else {
691+
DispatchClass::Normal
692+
}
693+
};
694+
(dispatch_weight, dispatch_class)
695+
})]
696+
pub fn batch(
697+
origin: OriginFor<T>,
698+
calls: Vec<<T as pallet_utility::Config>::RuntimeCall>,
699+
) -> DispatchResultWithPostInfo {
700+
let sender = ensure_signed(origin.clone())?;
701+
let _ = EnclaveRegistry::<T>::get(&sender).ok_or(Error::<T>::EnclaveNotExist)?;
702+
let _ = pallet_utility::Pallet::<T>::batch(origin, calls)?;
703+
Ok(Pays::No.into())
704+
}
671705
}
672706
}
673707

parachain/pallets/teebag/src/mock.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ construct_runtime!(
4949
Balances: pallet_balances,
5050
Timestamp: pallet_timestamp,
5151
Teebag: pallet_teebag,
52+
Utility: pallet_utility,
5253
}
5354
);
5455

@@ -129,6 +130,13 @@ impl pallet_teebag::Config for Test {
129130
type WeightInfo = ();
130131
}
131132

133+
impl pallet_utility::Config for Test {
134+
type RuntimeEvent = RuntimeEvent;
135+
type RuntimeCall = RuntimeCall;
136+
type PalletsOrigin = OriginCaller;
137+
type WeightInfo = ();
138+
}
139+
132140
// This function basically just builds a genesis storage key/value store according to
133141
// our desired mockup. RA from enclave compiled in debug mode is allowed
134142
pub fn new_test_ext(is_dev_mode: bool) -> sp_io::TestExternalities {

parachain/pallets/vc-management/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pallet-timestamp = { workspace = true, features = ["std"] }
2727
sp-io = { workspace = true, features = ["std"] }
2828
pallet-group = { workspace = true, features = ["std"] }
2929
pallet-teebag = { workspace = true, features = ["std", "test-util"] }
30-
30+
pallet-utility = { workspace = true, features = ["std"] }
3131

3232
[features]
3333
default = ["std"]
@@ -52,5 +52,6 @@ std = [
5252
"pallet-teebag/std",
5353
"pallet-balances/std",
5454
"pallet-group/std",
55+
"pallet-utility/std",
5556
]
5657
try-runtime = ["frame-support/try-runtime"]

parachain/pallets/vc-management/src/mock.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ frame_support::construct_runtime!(
7878
Balances: pallet_balances,
7979
Teebag: pallet_teebag,
8080
Timestamp: pallet_timestamp,
81+
Utility: pallet_utility,
8182
VCManagement: pallet_vc_management,
8283
VCMPExtrinsicWhitelist: pallet_group,
8384
}
@@ -163,6 +164,13 @@ impl pallet_group::Config for Test {
163164
type GroupManagerOrigin = frame_system::EnsureRoot<Self::AccountId>;
164165
}
165166

167+
impl pallet_utility::Config for Test {
168+
type RuntimeEvent = RuntimeEvent;
169+
type RuntimeCall = RuntimeCall;
170+
type PalletsOrigin = OriginCaller;
171+
type WeightInfo = ();
172+
}
173+
166174
pub fn new_test_ext() -> sp_io::TestExternalities {
167175
use pallet_teebag::test_util::{
168176
get_signer, TEST8_CERT, TEST8_SIGNER_PUB, TEST8_TIMESTAMP, URL,

parachain/runtime/litentry/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
221221
impl_name: create_runtime_str!("litentry-parachain"),
222222
authoring_version: 1,
223223
// same versioning-mechanism as polkadot: use last digit for minor updates
224-
spec_version: 9200,
224+
spec_version: 9201,
225225
impl_version: 0,
226226
apis: RUNTIME_API_VERSIONS,
227227
transaction_version: 1,

parachain/runtime/paseo/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
227227
impl_name: create_runtime_str!("paseo-parachain"),
228228
authoring_version: 1,
229229
// same versioning-mechanism as polkadot: use last digit for minor updates
230-
spec_version: 9200,
230+
spec_version: 9201,
231231
impl_version: 0,
232232
apis: RUNTIME_API_VERSIONS,
233233
transaction_version: 1,

0 commit comments

Comments
 (0)