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

[stable2407] Backport #6323 #6471

Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,31 @@ macro_rules! generate_bridge_reject_obsolete_headers_and_messages {
)* ),
);

<<<<<<< HEAD:bridges/bin/runtime-common/src/extensions/check_obsolete_extension.rs
fn additional_signed(&self) -> sp_std::result::Result<
(),
sp_runtime::transaction_validity::TransactionValidityError,
=======
fn weight(&self, _: &$call) -> frame_support::pallet_prelude::Weight {
frame_support::pallet_prelude::Weight::zero()
}

fn validate(
&self,
origin: <$call as sp_runtime::traits::Dispatchable>::RuntimeOrigin,
call: &$call,
_info: &sp_runtime::traits::DispatchInfoOf<$call>,
_len: usize,
_self_implicit: Self::Implicit,
_inherited_implication: &impl codec::Encode,
_source: sp_runtime::transaction_validity::TransactionSource,
) -> Result<
(
sp_runtime::transaction_validity::ValidTransaction,
Self::Val,
<$call as sp_runtime::traits::Dispatchable>::RuntimeOrigin,
), sp_runtime::transaction_validity::TransactionValidityError
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323)):bridges/bin/runtime-common/src/extensions.rs
> {
Ok(())
}
Expand Down Expand Up @@ -371,6 +393,7 @@ mod tests {
},
RefundableParachain,
},
<<<<<<< HEAD:bridges/bin/runtime-common/src/extensions/check_obsolete_extension.rs
mock::*,
};
use bp_polkadot_core::parachains::ParaId;
Expand All @@ -379,6 +402,11 @@ mod tests {
use sp_runtime::{
traits::{ConstU64, SignedExtension},
transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction},
=======
transaction_validity::{
InvalidTransaction, TransactionSource::External, TransactionValidity, ValidTransaction,
},
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323)):bridges/bin/runtime-common/src/extensions.rs
DispatchError,
};

Expand Down Expand Up @@ -466,7 +494,17 @@ mod tests {

run_test(|| {
assert_err!(
<<<<<<< HEAD:bridges/bin/runtime-common/src/extensions/check_obsolete_extension.rs
BridgeRejectObsoleteHeadersAndMessages.validate(&42, &MockCall { data: 1 }, &(), 0),
=======
BridgeRejectObsoleteHeadersAndMessages.validate_only(
42u64.into(),
&MockCall { data: 1 },
&(),
0,
External,
),
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323)):bridges/bin/runtime-common/src/extensions.rs
InvalidTransaction::Custom(1)
);
assert_err!(
Expand All @@ -480,7 +518,17 @@ mod tests {
);

assert_err!(
<<<<<<< HEAD:bridges/bin/runtime-common/src/extensions/check_obsolete_extension.rs
BridgeRejectObsoleteHeadersAndMessages.validate(&42, &MockCall { data: 2 }, &(), 0),
=======
BridgeRejectObsoleteHeadersAndMessages.validate_only(
42u64.into(),
&MockCall { data: 2 },
&(),
0,
External,
),
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323)):bridges/bin/runtime-common/src/extensions.rs
InvalidTransaction::Custom(2)
);
assert_err!(
Expand All @@ -495,8 +543,14 @@ mod tests {

assert_eq!(
BridgeRejectObsoleteHeadersAndMessages
<<<<<<< HEAD:bridges/bin/runtime-common/src/extensions/check_obsolete_extension.rs
.validate(&42, &MockCall { data: 3 }, &(), 0)
.unwrap(),
=======
.validate_only(42u64.into(), &MockCall { data: 3 }, &(), 0, External)
.unwrap()
.0,
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323)):bridges/bin/runtime-common/src/extensions.rs
ValidTransaction { priority: 3, ..Default::default() },
);
assert_eq!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ use bp_relayers::{ExplicitOrAccountParams, RewardsAccountOwner, RewardsAccountPa
use bp_runtime::{Chain, Parachain, RangeInclusiveExt, StaticStrProvider};
use codec::{Codec, Decode, Encode};
use frame_support::{
<<<<<<< HEAD:bridges/bin/runtime-common/src/extensions/refund_relayer_extension.rs
dispatch::{CallableCallFor, DispatchInfo, PostDispatchInfo},
traits::IsSubType,
=======
dispatch::{DispatchInfo, PostDispatchInfo},
pallet_prelude::TransactionSource,
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323)):bridges/modules/relayers/src/extension/mod.rs
weights::Weight,
CloneNoBound, DefaultNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound,
};
Expand Down Expand Up @@ -450,13 +455,27 @@ where
call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
<<<<<<< HEAD:bridges/bin/runtime-common/src/extensions/refund_relayer_extension.rs
) -> TransactionValidity {
// this is the only relevant line of code for the `pre_dispatch`
//
// we're not calling `validate` from `pre_dispatch` directly because of performance
// reasons, so if you're adding some code that may fail here, please check if it needs
// to be added to the `pre_dispatch` as well
let parsed_call = T::parse_and_check_for_obsolete_call(call)?;
=======
_self_implicit: Self::Implicit,
_inherited_implication: &impl Encode,
_source: TransactionSource,
) -> ValidateResult<Self::Val, R::RuntimeCall> {
// Prepare relevant data for `prepare`
let parsed_call = match C::parse_and_check_for_obsolete_call(call)? {
Some(parsed_call) => parsed_call,
None => return Ok((Default::default(), None, origin)),
};
// Those calls are only for signed transactions.
let relayer = origin.as_system_origin_signer().ok_or(InvalidTransaction::BadSigner)?;
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323)):bridges/modules/relayers/src/extension/mod.rs

// the following code just plays with transaction priority and never returns an error

Expand Down Expand Up @@ -962,8 +981,15 @@ pub(crate) mod tests {
Call as ParachainsCall, Pallet as ParachainsPallet, RelayBlockHash,
};
use sp_runtime::{
<<<<<<< HEAD:bridges/bin/runtime-common/src/extensions/refund_relayer_extension.rs
traits::{ConstU64, Header as HeaderT},
transaction_validity::{InvalidTransaction, ValidTransaction},
=======
traits::{ConstU64, DispatchTransaction, Header as HeaderT},
transaction_validity::{
InvalidTransaction, TransactionSource::External, TransactionValidity, ValidTransaction,
},
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323)):bridges/modules/relayers/src/extension/mod.rs
DispatchError,
};

Expand Down Expand Up @@ -1545,6 +1571,7 @@ pub(crate) mod tests {
}

fn run_validate(call: RuntimeCall) -> TransactionValidity {
<<<<<<< HEAD:bridges/bin/runtime-common/src/extensions/refund_relayer_extension.rs
let extension: TestExtension =
RefundSignedExtensionAdapter(RefundBridgedParachainMessages(PhantomData));
extension.validate(&relayer_account_at_this_chain(), &call, &DispatchInfo::default(), 0)
Expand All @@ -1560,6 +1587,44 @@ pub(crate) mod tests {
let extension: TestMessagesExtension =
RefundSignedExtensionAdapter(RefundBridgedMessages(PhantomData));
extension.validate(&relayer_account_at_this_chain(), &call, &DispatchInfo::default(), 0)
=======
let extension: TestExtension = BridgeRelayersTransactionExtension(PhantomData);
extension
.validate_only(
Some(relayer_account_at_this_chain()).into(),
&call,
&DispatchInfo::default(),
0,
External,
)
.map(|t| t.0)
}

fn run_grandpa_validate(call: RuntimeCall) -> TransactionValidity {
let extension: TestGrandpaExtension = BridgeRelayersTransactionExtension(PhantomData);
extension
.validate_only(
Some(relayer_account_at_this_chain()).into(),
&call,
&DispatchInfo::default(),
0,
External,
)
.map(|t| t.0)
}

fn run_messages_validate(call: RuntimeCall) -> TransactionValidity {
let extension: TestMessagesExtension = BridgeRelayersTransactionExtension(PhantomData);
extension
.validate_only(
Some(relayer_account_at_this_chain()).into(),
&call,
&DispatchInfo::default(),
0,
External,
)
.map(|t| t.0)
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323)):bridges/modules/relayers/src/extension/mod.rs
}

fn ignore_priority(tx: TransactionValidity) -> TransactionValidity {
Expand Down
34 changes: 33 additions & 1 deletion polkadot/runtime/common/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256};
use sp_runtime::{
traits::{CheckedSub, DispatchInfoOf, SignedExtension, Zero},
transaction_validity::{
InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction,
InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError,
ValidTransaction,
},
RuntimeDebug,
};
Expand Down Expand Up @@ -650,6 +651,7 @@ where
call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
<<<<<<< HEAD
) -> TransactionValidity {
if let Some(local_call) = call.is_sub_type() {
if let Call::attest { statement: attested_statement } = local_call {
Expand All @@ -659,6 +661,22 @@ where
let e = InvalidTransaction::Custom(ValidityError::InvalidStatement.into());
ensure!(&attested_statement[..] == s.to_text(), e);
}
=======
_self_implicit: Self::Implicit,
_inherited_implication: &impl Encode,
_source: TransactionSource,
) -> Result<
(ValidTransaction, Self::Val, <T::RuntimeCall as Dispatchable>::RuntimeOrigin),
TransactionValidityError,
> {
if let Some(Call::attest { statement: attested_statement }) = call.is_sub_type() {
let who = origin.as_system_origin_signer().ok_or(InvalidTransaction::BadSigner)?;
let signer = Preclaims::<T>::get(who)
.ok_or(InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()))?;
if let Some(s) = Signing::<T>::get(signer) {
let e = InvalidTransaction::Custom(ValidityError::InvalidStatement.into());
ensure!(&attested_statement[..] == s.to_text(), e);
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323))
}
}
Ok(ValidTransaction::default())
Expand Down Expand Up @@ -699,6 +717,7 @@ mod tests {
use super::*;
use hex_literal::hex;
use secp_utils::*;
use sp_runtime::transaction_validity::TransactionSource::External;

use codec::Encode;
// The testing primitives are very useful for avoiding having to work with signatures
Expand Down Expand Up @@ -1055,8 +1074,13 @@ mod tests {
});
let di = c.get_dispatch_info();
assert_eq!(di.pays_fee, Pays::No);
<<<<<<< HEAD
let r = p.validate(&42, &c, &di, 20);
assert_eq!(r, TransactionValidity::Ok(ValidTransaction::default()));
=======
let r = p.validate_only(Some(42).into(), &c, &di, 20, External);
assert_eq!(r.unwrap().0, ValidTransaction::default());
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323))
});
}

Expand All @@ -1068,13 +1092,21 @@ mod tests {
statement: StatementKind::Regular.to_text().to_vec(),
});
let di = c.get_dispatch_info();
<<<<<<< HEAD
let r = p.validate(&42, &c, &di, 20);
=======
let r = p.validate_only(Some(42).into(), &c, &di, 20, External);
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323))
assert!(r.is_err());
let c = RuntimeCall::Claims(ClaimsCall::attest {
statement: StatementKind::Saft.to_text().to_vec(),
});
let di = c.get_dispatch_info();
<<<<<<< HEAD
let r = p.validate(&69, &c, &di, 20);
=======
let r = p.validate_only(Some(69).into(), &c, &di, 20, External);
>>>>>>> 8e3d9296 ([Tx ext stage 2: 1/4] Add `TransactionSource` as argument in `TransactionExtension::validate` (#6323))
assert!(r.is_err());
});
}
Expand Down
32 changes: 32 additions & 0 deletions prdoc/pr_6323.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
title: add `TransactionSource` to `TransactionExtension::validate`
doc:
- audience: Runtime Dev
description: |
Add a the source of the extrinsic as an argument in `TransactionExtension::validate`.
The transaction source can be useful for transactions that should only be valid if it comes from the node. For example from offchain worker.
To update the current code. The transaction source can simply be ignored: `_source: TransactionSource`


crates:
- name: sp-runtime
bump: major
- name: bridge-runtime-common
bump: patch
- name: frame-system
bump: patch
- name: pallet-transaction-payment
bump: patch
- name: polkadot-runtime-common
bump: patch
- name: pallet-sudo
bump: patch
- name: pallet-verify-signature
bump: patch
- name: pallet-asset-tx-payment
bump: patch
- name: pallet-bridge-relayers
bump: patch
- name: pallet-asset-conversion-tx-payment
bump: patch
- name: pallet-skip-feeless-payment
bump: patch
Loading
Loading