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

Add a wrapper to waive tx fee for batch-call from worker #3110

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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 parachain/Cargo.lock

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

3 changes: 3 additions & 0 deletions parachain/pallets/teebag/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-balances = { workspace = true, optional = true }
pallet-timestamp = { workspace = true }
pallet-utility = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
Expand Down Expand Up @@ -62,12 +63,14 @@ std = [
"sp-std/std",
"pallet-timestamp/std",
"pallet-balances?/std",
"pallet-utility/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"pallet-balances?/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
# workaround to cross crate boundary, see https://github.com/rust-lang/cargo/issues/8379
Expand Down
36 changes: 35 additions & 1 deletion parachain/pallets/teebag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ pub mod pallet {
pub struct Pallet<T>(PhantomData<T>);

#[pallet::config]
pub trait Config: frame_system::Config + pallet_timestamp::Config {
pub trait Config:
frame_system::Config + pallet_timestamp::Config + pallet_utility::Config
{
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
Expand Down Expand Up @@ -668,6 +670,38 @@ pub mod pallet {
Self::finalize_block(sender, shard, confirmation);
Ok(Pays::No.into())
}

// A wrapper to utility.call to waive the tx fee if the caller is tee-worker
// the weight is copied from pallet_utility
#[pallet::call_index(23)]
#[pallet::weight({
use pallet_utility::WeightInfo;
let dispatch_infos = calls.iter().map(|call| call.get_dispatch_info()).collect::<Vec<_>>();
let dispatch_weight = dispatch_infos.iter()
.map(|di| di.weight)
.fold(Weight::zero(), |total: Weight, weight: Weight| total.saturating_add(weight))
.saturating_add(<T as pallet_utility::Config>::WeightInfo::batch(calls.len() as u32));
let dispatch_class = {
let all_operational = dispatch_infos.iter()
.map(|di| di.class)
.all(|class| class == DispatchClass::Operational);
if all_operational {
DispatchClass::Operational
} else {
DispatchClass::Normal
}
};
(dispatch_weight, dispatch_class)
})]
pub fn batch(
origin: OriginFor<T>,
calls: Vec<<T as pallet_utility::Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
let sender = ensure_signed(origin.clone())?;
let _ = EnclaveRegistry::<T>::get(&sender).ok_or(Error::<T>::EnclaveNotExist)?;
let _ = pallet_utility::Pallet::<T>::batch(origin, calls)?;
Ok(Pays::No.into())
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion parachain/runtime/litentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("litentry-parachain"),
authoring_version: 1,
// same versioning-mechanism as polkadot: use last digit for minor updates
spec_version: 9200,
spec_version: 9201,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtime/paseo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("paseo-parachain"),
authoring_version: 1,
// same versioning-mechanism as polkadot: use last digit for minor updates
spec_version: 9200,
spec_version: 9201,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("rococo-parachain"),
authoring_version: 1,
// same versioning-mechanism as polkadot: use last digit for minor updates
spec_version: 9200,
spec_version: 9201,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ where
(metadata.clone(), m.get_runtime_version(), m.get_runtime_transaction_version())
})?;
let batch_call =
OpaqueCall::from_tuple(&compose_call!(node_metadata, "Utility", "batch", calls));
OpaqueCall::from_tuple(&compose_call!(node_metadata, "Teebag", "batch", calls));

let mut nonce_lock = self.nonce_cache.load_for_mutation()?;
let mut nonce_value = nonce_lock.0;
Expand Down
Loading