Unverified Commit 035d1a58 authored by Tomasz Drwięga's avatar Tomasz Drwięga Committed by GitHub
Browse files

Transaction source (#5366) companion PR (#938)

* Add transaction source.

* Bump substrate.

* Fix tests.
parent 710f4cae
Pipeline #84886 passed with stages
in 24 minutes and 28 seconds
This diff is collapsed.
......@@ -29,8 +29,9 @@ use serde::{self, Serialize, Deserialize, Serializer, Deserializer};
use sp_runtime::traits::Zero;
use sp_runtime::traits::CheckedSub;
use sp_runtime::{
RuntimeDebug, transaction_validity::{
TransactionLongevity, TransactionValidity, ValidTransaction, InvalidTransaction
RuntimeDebug,
transaction_validity::{
TransactionLongevity, TransactionValidity, ValidTransaction, InvalidTransaction, TransactionSource,
},
};
use primitives::ValidityError;
......@@ -288,7 +289,7 @@ impl<T: Trait> Module<T> {
impl<T: Trait> sp_runtime::traits::ValidateUnsigned for Module<T> {
type Call = Call<T>;
fn validate_unsigned(call: &Self::Call) -> TransactionValidity {
fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
const PRIORITY: u64 = 100;
match call {
......@@ -607,10 +608,11 @@ mod tests {
#[test]
fn validate_unsigned_works() {
use sp_runtime::traits::ValidateUnsigned;
let source = sp_runtime::transaction_validity::TransactionSource::External;
new_test_ext().execute_with(|| {
assert_eq!(
<Module<Test>>::validate_unsigned(&Call::claim(1, sig::<Test>(&alice(), &1u64.encode()))),
<Module<Test>>::validate_unsigned(source, &Call::claim(1, sig::<Test>(&alice(), &1u64.encode()))),
Ok(ValidTransaction {
priority: 100,
requires: vec![],
......@@ -620,15 +622,15 @@ mod tests {
})
);
assert_eq!(
<Module<Test>>::validate_unsigned(&Call::claim(0, EcdsaSignature([0; 65]))),
<Module<Test>>::validate_unsigned(source, &Call::claim(0, EcdsaSignature([0; 65]))),
InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()).into(),
);
assert_eq!(
<Module<Test>>::validate_unsigned(&Call::claim(1, sig::<Test>(&bob(), &1u64.encode()))),
<Module<Test>>::validate_unsigned(source, &Call::claim(1, sig::<Test>(&bob(), &1u64.encode()))),
InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(),
);
assert_eq!(
<Module<Test>>::validate_unsigned(&Call::claim(0, sig::<Test>(&bob(), &1u64.encode()))),
<Module<Test>>::validate_unsigned(source, &Call::claim(0, sig::<Test>(&bob(), &1u64.encode()))),
InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(),
);
});
......@@ -690,8 +692,9 @@ mod benchmarking {
let account: T::AccountId = account("user", c, SEED);
let signature = sig::<T>(&secret_key, &account.encode());
let call = Call::<T>::claim(account, signature);
let source = sp_runtime::transaction_validity::TransactionSource::External;
}: {
super::Module::<T>::validate_unsigned(&call)?
super::Module::<T>::validate_unsigned(source, &call)?
}
// Benchmark the time it takes to do `repeat` number of keccak256 hashes
......
......@@ -35,7 +35,9 @@ use runtime_common::{attestations, claims, parachains, registrar, slots,
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, RuntimeDebug,
transaction_validity::{TransactionValidity, InvalidTransaction, TransactionValidityError},
transaction_validity::{
TransactionValidity, InvalidTransaction, TransactionValidityError, TransactionSource,
},
curve::PiecewiseLinear,
traits::{BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto, IdentityLookup},
};
......@@ -772,8 +774,11 @@ sp_api::impl_runtime_apis! {
}
impl tx_pool_api::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity {
Executive::validate_transaction(tx)
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
) -> TransactionValidity {
Executive::validate_transaction(source, tx)
}
}
......
......@@ -36,7 +36,9 @@ use primitives::{
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, RuntimeDebug,
transaction_validity::{TransactionValidity, InvalidTransaction, TransactionValidityError},
transaction_validity::{
TransactionValidity, InvalidTransaction, TransactionValidityError, TransactionSource,
},
curve::PiecewiseLinear,
traits::{
BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto,
......@@ -694,8 +696,11 @@ sp_api::impl_runtime_apis! {
}
impl tx_pool_api::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity {
Executive::validate_transaction(tx)
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
) -> TransactionValidity {
Executive::validate_transaction(source, tx)
}
}
......
......@@ -35,7 +35,9 @@ use runtime_common::{attestations, claims, parachains, registrar, slots,
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, Perbill, RuntimeDebug, KeyTypeId,
transaction_validity::{TransactionValidity, InvalidTransaction, TransactionValidityError},
transaction_validity::{
TransactionValidity, InvalidTransaction, TransactionValidityError, TransactionSource,
},
curve::PiecewiseLinear,
traits::{BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension, OpaqueKeys, ConvertInto},
};
......@@ -498,8 +500,11 @@ sp_api::impl_runtime_apis! {
}
impl tx_pool_api::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity {
Executive::validate_transaction(tx)
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
) -> TransactionValidity {
Executive::validate_transaction(source, tx)
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment