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

FRAME: Meta Transaction (pallet based version) #4122

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e7c6f57
Fixes and refactoring after tx ext introduction
georgepisaltu Mar 8, 2024
2fa52c8
Remove bench helper trait from claims
georgepisaltu Mar 8, 2024
90819a5
Rename `additional_signed` to `implicit` in IR
georgepisaltu Mar 8, 2024
9206bea
Fix imports
georgepisaltu Mar 8, 2024
611c165
Fix metadata test
georgepisaltu Mar 8, 2024
6fd6b25
Fix unchecked extrinsic signing in tests
georgepisaltu Mar 8, 2024
53c0379
Revert "Revert "FRAME: Create `TransactionExtension` as a replacement…
georgepisaltu Mar 13, 2024
ed40294
Merge branch 'tx-ext-fixes' into george-tx-ext
georgepisaltu Mar 13, 2024
b6fba4a
Add docs for `impl_tx_ext_default`
georgepisaltu Mar 14, 2024
455b762
Remove `TransactionExtensionInterior`
georgepisaltu Mar 14, 2024
5f6f63b
Merge remote-tracking branch 'origin/master' into george/restore-gav-…
georgepisaltu Mar 14, 2024
a896a50
Minor fixes for `TransactionExtensionInterior`
georgepisaltu Mar 14, 2024
26ea26f
Fix metadata test
georgepisaltu Mar 14, 2024
cde2b1e
Bump tx version in bridges
georgepisaltu Mar 14, 2024
4c6f654
Missed file in previous commit
georgepisaltu Mar 14, 2024
c4b522b
Merge remote-tracking branch 'origin' into george/restore-gav-tx-ext
georgepisaltu Mar 18, 2024
fabd306
Merge remote-tracking branch 'origin/master' into george/restore-gav-…
georgepisaltu Mar 25, 2024
ea5c623
Merge remote-tracking branch 'origin/master' into george/restore-gav-…
georgepisaltu Mar 25, 2024
c67cff2
Run zepter
georgepisaltu Mar 25, 2024
0699023
meta tx pallet gen
muharem Apr 10, 2024
4e0fa2d
resolve todos and docs
muharem May 7, 2024
7a104ef
fix
muharem May 7, 2024
59a66fa
include meta-tx instance into kitchensink runtime
muharem May 7, 2024
ec0d668
clippy fixes
muharem May 7, 2024
8407cd0
remove unnecessary fmt
muharem May 7, 2024
6bf6b24
Merge remote-tracking branch 'origin/master' into muharem-meta-tx-pallet
muharem Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
54 changes: 42 additions & 12 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ members = [
"substrate/frame/membership",
"substrate/frame/merkle-mountain-range",
"substrate/frame/message-queue",
"substrate/frame/meta-tx",
"substrate/frame/migrations",
"substrate/frame/mixnet",
"substrate/frame/multisig",
Expand Down
1 change: 1 addition & 0 deletions bridges/bin/runtime-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ runtime-benchmarks = [
"pallet-bridge-messages/runtime-benchmarks",
"pallet-bridge-parachains/runtime-benchmarks",
"pallet-bridge-relayers/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
Expand Down
72 changes: 41 additions & 31 deletions bridges/bin/runtime-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,43 +105,48 @@ macro_rules! generate_bridge_reject_obsolete_headers_and_messages {
($call:ty, $account_id:ty, $($filter_call:ty),*) => {
#[derive(Clone, codec::Decode, Default, codec::Encode, Eq, PartialEq, sp_runtime::RuntimeDebug, scale_info::TypeInfo)]
pub struct BridgeRejectObsoleteHeadersAndMessages;
impl sp_runtime::traits::SignedExtension for BridgeRejectObsoleteHeadersAndMessages {
impl sp_runtime::traits::TransactionExtensionBase for BridgeRejectObsoleteHeadersAndMessages {
const IDENTIFIER: &'static str = "BridgeRejectObsoleteHeadersAndMessages";
type AccountId = $account_id;
type Call = $call;
type AdditionalSigned = ();
type Implicit = ();
}
impl<Context> sp_runtime::traits::TransactionExtension<$call, Context> for BridgeRejectObsoleteHeadersAndMessages {
type Pre = ();

fn additional_signed(&self) -> sp_std::result::Result<
(),
sp_runtime::transaction_validity::TransactionValidityError,
> {
Ok(())
}
type Val = ();

fn validate(
&self,
_who: &Self::AccountId,
call: &Self::Call,
_info: &sp_runtime::traits::DispatchInfoOf<Self::Call>,
origin: <$call as sp_runtime::traits::Dispatchable>::RuntimeOrigin,
call: &$call,
_info: &sp_runtime::traits::DispatchInfoOf<$call>,
_len: usize,
) -> sp_runtime::transaction_validity::TransactionValidity {
let valid = sp_runtime::transaction_validity::ValidTransaction::default();
_context: &mut Context,
_self_implicit: Self::Implicit,
_inherited_implication: &impl codec::Encode,
) -> Result<
(
sp_runtime::transaction_validity::ValidTransaction,
Self::Val,
<$call as sp_runtime::traits::Dispatchable>::RuntimeOrigin,
), sp_runtime::transaction_validity::TransactionValidityError
> {
let tx_validity = sp_runtime::transaction_validity::ValidTransaction::default();
$(
let valid = valid
.combine_with(<$filter_call as $crate::BridgeRuntimeFilterCall<$call>>::validate(call)?);
let call_filter_validity = <$filter_call as $crate::BridgeRuntimeFilterCall<$call>>::validate(call)?;
let tx_validity = tx_validity.combine_with(call_filter_validity);
)*
Ok(valid)
Ok((tx_validity, (), origin))
}

fn pre_dispatch(
fn prepare(
self,
who: &Self::AccountId,
call: &Self::Call,
info: &sp_runtime::traits::DispatchInfoOf<Self::Call>,
len: usize,
_val: Self::Val,
_origin: &<$call as sp_runtime::traits::Dispatchable>::RuntimeOrigin,
_call: &$call,
_info: &sp_runtime::traits::DispatchInfoOf<$call>,
_len: usize,
_context: &Context,
) -> Result<Self::Pre, sp_runtime::transaction_validity::TransactionValidityError> {
self.validate(who, call, info, len).map(drop)
Ok(())
}
}
};
Expand All @@ -150,12 +155,14 @@ macro_rules! generate_bridge_reject_obsolete_headers_and_messages {
#[cfg(test)]
mod tests {
use crate::BridgeRuntimeFilterCall;
use frame_support::{assert_err, assert_ok};
use codec::Encode;
use frame_support::assert_err;
use sp_runtime::{
traits::SignedExtension,
traits::DispatchTransaction,
transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction},
};

#[derive(Encode)]
pub struct MockCall {
data: u32,
}
Expand Down Expand Up @@ -206,17 +213,20 @@ mod tests {
);

assert_err!(
BridgeRejectObsoleteHeadersAndMessages.validate(&(), &MockCall { data: 1 }, &(), 0),
BridgeRejectObsoleteHeadersAndMessages.validate_only((), &MockCall { data: 1 }, &(), 0),
InvalidTransaction::Custom(1)
);

assert_err!(
BridgeRejectObsoleteHeadersAndMessages.validate(&(), &MockCall { data: 2 }, &(), 0),
BridgeRejectObsoleteHeadersAndMessages.validate_only((), &MockCall { data: 2 }, &(), 0),
InvalidTransaction::Custom(2)
);

assert_ok!(
BridgeRejectObsoleteHeadersAndMessages.validate(&(), &MockCall { data: 3 }, &(), 0),
assert_eq!(
BridgeRejectObsoleteHeadersAndMessages
.validate_only((), &MockCall { data: 3 }, &(), 0)
.unwrap()
.0,
ValidTransaction { priority: 3, ..Default::default() }
)
}
Expand Down
1 change: 0 additions & 1 deletion bridges/bin/runtime-common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ impl pallet_transaction_payment::Config for TestRuntime {
MinimumMultiplier,
MaximumMultiplier,
>;
type RuntimeEvent = RuntimeEvent;
}

impl pallet_bridge_grandpa::Config for TestRuntime {
Expand Down
11 changes: 7 additions & 4 deletions bridges/bin/runtime-common/src/priority_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,23 @@ mod integrity_tests {
// nodes to the proof (x0.5 because we expect some nodes to be reused)
let estimated_message_size = 512;
// let's say all our messages have the same dispatch weight
let estimated_message_dispatch_weight =
Runtime::WeightInfo::message_dispatch_weight(estimated_message_size);
let estimated_message_dispatch_weight = <Runtime as pallet_bridge_messages::Config<
MessagesInstance,
>>::WeightInfo::message_dispatch_weight(
estimated_message_size
);
// messages proof argument size is (for every message) messages size + some additional
// trie nodes. Some of them are reused by different messages, so let's take 2/3 of default
// "overhead" constant
let messages_proof_size = Runtime::WeightInfo::expected_extra_storage_proof_size()
let messages_proof_size = <Runtime as pallet_bridge_messages::Config<MessagesInstance>>::WeightInfo::expected_extra_storage_proof_size()
.saturating_mul(2)
.saturating_div(3)
.saturating_add(estimated_message_size)
.saturating_mul(messages as _);

// finally we are able to estimate transaction size and weight
let transaction_size = base_tx_size.saturating_add(messages_proof_size);
let transaction_weight = Runtime::WeightInfo::receive_messages_proof_weight(
let transaction_weight = <Runtime as pallet_bridge_messages::Config<MessagesInstance>>::WeightInfo::receive_messages_proof_weight(
&PreComputedSize(transaction_size as _),
messages as _,
estimated_message_dispatch_weight.saturating_mul(messages),
Expand Down
Loading
Loading