Skip to content

Commit

Permalink
Add a wrapper to waive tx fee for batch-call from worker (#3110)
Browse files Browse the repository at this point in the history
* Add a wrapper to waive tx fee for batch-call from worker

* fix ci
  • Loading branch information
Kailai-Wang authored Oct 1, 2024
1 parent 19eedae commit ed8dbff
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 6 deletions.
3 changes: 3 additions & 0 deletions parachain/Cargo.lock

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

1 change: 1 addition & 0 deletions parachain/pallets/identity-management/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pallet-timestamp = { workspace = true, features = ["std"] }
sp-io = { workspace = true, features = ["std"] }
pallet-teebag = { workspace = true, features = ["std", "test-util"] }
pallet-group = { workspace = true, features = ["std"] }
pallet-utility = { workspace = true, features = ["std"] }

[features]
default = ["std"]
Expand Down
8 changes: 8 additions & 0 deletions parachain/pallets/identity-management/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ frame_support::construct_runtime!(
Timestamp: pallet_timestamp,
IdentityManagement: pallet_identity_management,
IMPExtrinsicWhitelist: pallet_group,
Utility: pallet_utility,
}
);

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

impl pallet_utility::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PalletsOrigin = OriginCaller;
type WeightInfo = ();
}

pub fn new_test_ext() -> sp_io::TestExternalities {
use pallet_teebag::test_util::{
get_signer, TEST8_CERT, TEST8_SIGNER_PUB, TEST8_TIMESTAMP, URL,
Expand Down
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
8 changes: 8 additions & 0 deletions parachain/pallets/teebag/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ construct_runtime!(
Balances: pallet_balances,
Timestamp: pallet_timestamp,
Teebag: pallet_teebag,
Utility: pallet_utility,
}
);

Expand Down Expand Up @@ -129,6 +130,13 @@ impl pallet_teebag::Config for Test {
type WeightInfo = ();
}

impl pallet_utility::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PalletsOrigin = OriginCaller;
type WeightInfo = ();
}

// This function basically just builds a genesis storage key/value store according to
// our desired mockup. RA from enclave compiled in debug mode is allowed
pub fn new_test_ext(is_dev_mode: bool) -> sp_io::TestExternalities {
Expand Down
3 changes: 2 additions & 1 deletion parachain/pallets/vc-management/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pallet-timestamp = { workspace = true, features = ["std"] }
sp-io = { workspace = true, features = ["std"] }
pallet-group = { workspace = true, features = ["std"] }
pallet-teebag = { workspace = true, features = ["std", "test-util"] }

pallet-utility = { workspace = true, features = ["std"] }

[features]
default = ["std"]
Expand All @@ -52,5 +52,6 @@ std = [
"pallet-teebag/std",
"pallet-balances/std",
"pallet-group/std",
"pallet-utility/std",
]
try-runtime = ["frame-support/try-runtime"]
8 changes: 8 additions & 0 deletions parachain/pallets/vc-management/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ frame_support::construct_runtime!(
Balances: pallet_balances,
Teebag: pallet_teebag,
Timestamp: pallet_timestamp,
Utility: pallet_utility,
VCManagement: pallet_vc_management,
VCMPExtrinsicWhitelist: pallet_group,
}
Expand Down Expand Up @@ -163,6 +164,13 @@ impl pallet_group::Config for Test {
type GroupManagerOrigin = frame_system::EnsureRoot<Self::AccountId>;
}

impl pallet_utility::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PalletsOrigin = OriginCaller;
type WeightInfo = ();
}

pub fn new_test_ext() -> sp_io::TestExternalities {
use pallet_teebag::test_util::{
get_signer, TEST8_CERT, TEST8_SIGNER_PUB, TEST8_TIMESTAMP, URL,
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

0 comments on commit ed8dbff

Please sign in to comment.