mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
Pass transaction source to validate_transaction (#5366)
* WiP * Support source in the runtime API. * Finish implementation in txpool. * Fix warning. * Fix tests. * Apply suggestions from code review Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-Authored-By: Nikolay Volf <nikvolf@gmail.com> * Extra changes. * Fix test and benches. * fix test * Fix test & benches again. * Fix tests. * Update bumpalo * Fix doc test. * Fix doctest. * Fix doctest. Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
@@ -33,6 +33,7 @@ use sp_runtime::transaction_validity::{
|
||||
TransactionTag as Tag,
|
||||
TransactionLongevity as Longevity,
|
||||
TransactionPriority as Priority,
|
||||
TransactionSource as Source,
|
||||
};
|
||||
use sp_transaction_pool::{error, PoolStatus, InPoolTransaction};
|
||||
|
||||
@@ -102,6 +103,8 @@ pub struct Transaction<Hash, Extrinsic> {
|
||||
pub provides: Vec<Tag>,
|
||||
/// Should that transaction be propagated.
|
||||
pub propagate: bool,
|
||||
/// Source of that transaction.
|
||||
pub source: Source,
|
||||
}
|
||||
|
||||
impl<Hash, Extrinsic> AsRef<Extrinsic> for Transaction<Hash, Extrinsic> {
|
||||
@@ -155,6 +158,7 @@ impl<Hash: Clone, Extrinsic: Clone> Transaction<Hash, Extrinsic> {
|
||||
bytes: self.bytes.clone(),
|
||||
hash: self.hash.clone(),
|
||||
priority: self.priority.clone(),
|
||||
source: self.source,
|
||||
valid_till: self.valid_till.clone(),
|
||||
requires: self.requires.clone(),
|
||||
provides: self.provides.clone(),
|
||||
@@ -185,6 +189,7 @@ impl<Hash, Extrinsic> fmt::Debug for Transaction<Hash, Extrinsic> where
|
||||
write!(fmt, "valid_till: {:?}, ", &self.valid_till)?;
|
||||
write!(fmt, "bytes: {:?}, ", &self.bytes)?;
|
||||
write!(fmt, "propagate: {:?}, ", &self.propagate)?;
|
||||
write!(fmt, "source: {:?}, ", &self.source)?;
|
||||
write!(fmt, "requires: [")?;
|
||||
print_tags(fmt, &self.requires)?;
|
||||
write!(fmt, "], provides: [")?;
|
||||
@@ -556,6 +561,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![vec![1]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
|
||||
// then
|
||||
@@ -578,6 +584,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![vec![1]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![1u8],
|
||||
@@ -588,6 +595,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![vec![1]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap_err();
|
||||
|
||||
// then
|
||||
@@ -611,6 +619,7 @@ mod tests {
|
||||
requires: vec![vec![0]],
|
||||
provides: vec![vec![1]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
assert_eq!(pool.ready().count(), 0);
|
||||
assert_eq!(pool.ready.len(), 0);
|
||||
@@ -623,6 +632,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![vec![0]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
|
||||
// then
|
||||
@@ -645,6 +655,7 @@ mod tests {
|
||||
requires: vec![vec![0]],
|
||||
provides: vec![vec![1]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![3u8],
|
||||
@@ -655,6 +666,7 @@ mod tests {
|
||||
requires: vec![vec![2]],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![2u8],
|
||||
@@ -665,6 +677,7 @@ mod tests {
|
||||
requires: vec![vec![1]],
|
||||
provides: vec![vec![3], vec![2]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![4u8],
|
||||
@@ -675,6 +688,7 @@ mod tests {
|
||||
requires: vec![vec![3], vec![4]],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
assert_eq!(pool.ready().count(), 0);
|
||||
assert_eq!(pool.ready.len(), 0);
|
||||
@@ -688,6 +702,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![vec![0], vec![4]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
|
||||
// then
|
||||
@@ -720,6 +735,7 @@ mod tests {
|
||||
requires: vec![vec![0]],
|
||||
provides: vec![vec![1]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![3u8],
|
||||
@@ -730,6 +746,7 @@ mod tests {
|
||||
requires: vec![vec![1]],
|
||||
provides: vec![vec![2]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
assert_eq!(pool.ready().count(), 0);
|
||||
assert_eq!(pool.ready.len(), 0);
|
||||
@@ -744,6 +761,7 @@ mod tests {
|
||||
requires: vec![vec![2]],
|
||||
provides: vec![vec![0]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
|
||||
// then
|
||||
@@ -764,6 +782,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![vec![0]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
let mut it = pool.ready().into_iter().map(|tx| tx.data[0]);
|
||||
assert_eq!(it.next(), Some(4));
|
||||
@@ -792,6 +811,7 @@ mod tests {
|
||||
requires: vec![vec![0]],
|
||||
provides: vec![vec![1]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![3u8],
|
||||
@@ -802,6 +822,7 @@ mod tests {
|
||||
requires: vec![vec![1]],
|
||||
provides: vec![vec![2]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
assert_eq!(pool.ready().count(), 0);
|
||||
assert_eq!(pool.ready.len(), 0);
|
||||
@@ -816,6 +837,7 @@ mod tests {
|
||||
requires: vec![vec![2]],
|
||||
provides: vec![vec![0]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
|
||||
// then
|
||||
@@ -836,6 +858,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![vec![0]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap_err();
|
||||
let mut it = pool.ready().into_iter().map(|tx| tx.data[0]);
|
||||
assert_eq!(it.next(), None);
|
||||
@@ -859,6 +882,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![vec![0], vec![4]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).expect("import 1 should be ok");
|
||||
pool.import(Transaction {
|
||||
data: vec![3u8; 1024],
|
||||
@@ -869,6 +893,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![vec![2], vec![7]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).expect("import 2 should be ok");
|
||||
|
||||
assert!(parity_util_mem::malloc_size(&pool) > 5000);
|
||||
@@ -887,6 +912,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![vec![0], vec![4]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![1u8],
|
||||
@@ -897,6 +923,7 @@ mod tests {
|
||||
requires: vec![vec![0]],
|
||||
provides: vec![vec![1]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![3u8],
|
||||
@@ -907,6 +934,7 @@ mod tests {
|
||||
requires: vec![vec![2]],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![2u8],
|
||||
@@ -917,6 +945,7 @@ mod tests {
|
||||
requires: vec![vec![1]],
|
||||
provides: vec![vec![3], vec![2]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![4u8],
|
||||
@@ -927,6 +956,7 @@ mod tests {
|
||||
requires: vec![vec![3], vec![4]],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
// future
|
||||
pool.import(Transaction {
|
||||
@@ -938,6 +968,7 @@ mod tests {
|
||||
requires: vec![vec![11]],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
assert_eq!(pool.ready().count(), 5);
|
||||
assert_eq!(pool.future.len(), 1);
|
||||
@@ -964,6 +995,7 @@ mod tests {
|
||||
requires: vec![vec![0]],
|
||||
provides: vec![vec![100]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
// ready
|
||||
pool.import(Transaction {
|
||||
@@ -975,6 +1007,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![vec![1]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![2u8],
|
||||
@@ -985,6 +1018,7 @@ mod tests {
|
||||
requires: vec![vec![2]],
|
||||
provides: vec![vec![3]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![3u8],
|
||||
@@ -995,6 +1029,7 @@ mod tests {
|
||||
requires: vec![vec![1]],
|
||||
provides: vec![vec![2]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
pool.import(Transaction {
|
||||
data: vec![4u8],
|
||||
@@ -1005,6 +1040,7 @@ mod tests {
|
||||
requires: vec![vec![3], vec![2]],
|
||||
provides: vec![vec![4]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
|
||||
assert_eq!(pool.ready().count(), 4);
|
||||
@@ -1040,10 +1076,11 @@ mod tests {
|
||||
requires: vec![vec![3], vec![2]],
|
||||
provides: vec![vec![4]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}),
|
||||
"Transaction { \
|
||||
hash: 4, priority: 1000, valid_till: 64, bytes: 1, propagate: true, \
|
||||
requires: [03,02], provides: [04], data: [4]}".to_owned()
|
||||
source: TransactionSource::External, requires: [03,02], provides: [04], data: [4]}".to_owned()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1058,6 +1095,7 @@ requires: [03,02], provides: [04], data: [4]}".to_owned()
|
||||
requires: vec![vec![3], vec![2]],
|
||||
provides: vec![vec![4]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}.is_propagable(), true);
|
||||
|
||||
assert_eq!(Transaction {
|
||||
@@ -1069,6 +1107,7 @@ requires: [03,02], provides: [04], data: [4]}".to_owned()
|
||||
requires: vec![vec![3], vec![2]],
|
||||
provides: vec![vec![4]],
|
||||
propagate: false,
|
||||
source: Source::External,
|
||||
}.is_propagable(), false);
|
||||
}
|
||||
|
||||
@@ -1090,6 +1129,7 @@ requires: [03,02], provides: [04], data: [4]}".to_owned()
|
||||
requires: vec![vec![0]],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
});
|
||||
|
||||
if let Err(error::Error::RejectedFutureTransaction) = err {
|
||||
@@ -1113,6 +1153,7 @@ requires: [03,02], provides: [04], data: [4]}".to_owned()
|
||||
requires: vec![vec![0]],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
|
||||
// then
|
||||
@@ -1142,6 +1183,7 @@ requires: [03,02], provides: [04], data: [4]}".to_owned()
|
||||
requires: vec![vec![0]],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}).unwrap();
|
||||
|
||||
flag
|
||||
|
||||
@@ -249,6 +249,7 @@ impl<Hash: hash::Hash + Eq + Clone, Ex> FutureTransactions<Hash, Ex> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sp_runtime::transaction_validity::TransactionSource;
|
||||
|
||||
#[test]
|
||||
fn can_track_heap_size() {
|
||||
@@ -263,6 +264,7 @@ mod tests {
|
||||
requires: vec![vec![1], vec![2]],
|
||||
provides: vec![vec![3], vec![4]],
|
||||
propagate: true,
|
||||
source: TransactionSource::External,
|
||||
}.into(),
|
||||
missing_tags: vec![vec![1u8], vec![2u8]].into_iter().collect(),
|
||||
imported_at: std::time::Instant::now(),
|
||||
|
||||
@@ -31,7 +31,9 @@ use futures::{
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{self, SaturatedConversion},
|
||||
transaction_validity::{TransactionValidity, TransactionTag as Tag, TransactionValidityError},
|
||||
transaction_validity::{
|
||||
TransactionValidity, TransactionTag as Tag, TransactionValidityError, TransactionSource,
|
||||
},
|
||||
};
|
||||
use sp_transaction_pool::error;
|
||||
use wasm_timer::Instant;
|
||||
@@ -76,6 +78,7 @@ pub trait ChainApi: Send + Sync {
|
||||
fn validate_transaction(
|
||||
&self,
|
||||
at: &BlockId<Self::Block>,
|
||||
source: TransactionSource,
|
||||
uxt: ExtrinsicFor<Self>,
|
||||
) -> Self::ValidationFuture;
|
||||
|
||||
@@ -144,12 +147,17 @@ impl<B: ChainApi> Pool<B> {
|
||||
}
|
||||
|
||||
/// Imports a bunch of unverified extrinsics to the pool
|
||||
pub async fn submit_at<T>(&self, at: &BlockId<B::Block>, xts: T, force: bool)
|
||||
-> Result<Vec<Result<ExHash<B>, B::Error>>, B::Error>
|
||||
where
|
||||
T: IntoIterator<Item=ExtrinsicFor<B>>
|
||||
pub async fn submit_at<T>(
|
||||
&self,
|
||||
at: &BlockId<B::Block>,
|
||||
source: TransactionSource,
|
||||
xts: T,
|
||||
force: bool,
|
||||
) -> Result<Vec<Result<ExHash<B>, B::Error>>, B::Error> where
|
||||
T: IntoIterator<Item=ExtrinsicFor<B>>,
|
||||
{
|
||||
let validated_pool = self.validated_pool.clone();
|
||||
let xts = xts.into_iter().map(|xt| (source, xt));
|
||||
self.verify(at, xts, force)
|
||||
.map(move |validated_transactions| validated_transactions
|
||||
.map(|validated_transactions| validated_pool.submit(validated_transactions
|
||||
@@ -162,9 +170,10 @@ impl<B: ChainApi> Pool<B> {
|
||||
pub async fn submit_one(
|
||||
&self,
|
||||
at: &BlockId<B::Block>,
|
||||
source: TransactionSource,
|
||||
xt: ExtrinsicFor<B>,
|
||||
) -> Result<ExHash<B>, B::Error> {
|
||||
self.submit_at(at, std::iter::once(xt), false)
|
||||
self.submit_at(at, source, std::iter::once(xt), false)
|
||||
.map(|import_result| import_result.and_then(|mut import_result| import_result
|
||||
.pop()
|
||||
.expect("One extrinsic passed; one result returned; qed")
|
||||
@@ -176,10 +185,13 @@ impl<B: ChainApi> Pool<B> {
|
||||
pub async fn submit_and_watch(
|
||||
&self,
|
||||
at: &BlockId<B::Block>,
|
||||
source: TransactionSource,
|
||||
xt: ExtrinsicFor<B>,
|
||||
) -> Result<Watcher<ExHash<B>, BlockHash<B>>, B::Error> {
|
||||
let block_number = self.resolve_block_number(at)?;
|
||||
let (_, tx) = self.verify_one(at, block_number, xt, false).await;
|
||||
let (_, tx) = self.verify_one(
|
||||
at, block_number, source, xt, false
|
||||
).await;
|
||||
self.validated_pool.submit_and_watch(tx)
|
||||
}
|
||||
|
||||
@@ -249,7 +261,7 @@ impl<B: ChainApi> Pool<B> {
|
||||
// to get validity info and tags that the extrinsic provides.
|
||||
None => {
|
||||
let validity = self.validated_pool.api()
|
||||
.validate_transaction(parent, extrinsic.clone())
|
||||
.validate_transaction(parent, TransactionSource::InBlock, extrinsic.clone())
|
||||
.await;
|
||||
|
||||
if let Ok(Ok(validity)) = validity {
|
||||
@@ -303,8 +315,12 @@ impl<B: ChainApi> Pool<B> {
|
||||
|
||||
// Try to re-validate pruned transactions since some of them might be still valid.
|
||||
// note that `known_imported_hashes` will be rejected here due to temporary ban.
|
||||
let pruned_hashes = prune_status.pruned.iter().map(|tx| tx.hash.clone()).collect::<Vec<_>>();
|
||||
let pruned_transactions = prune_status.pruned.into_iter().map(|tx| tx.data.clone());
|
||||
let pruned_hashes = prune_status.pruned
|
||||
.iter()
|
||||
.map(|tx| tx.hash.clone()).collect::<Vec<_>>();
|
||||
let pruned_transactions = prune_status.pruned
|
||||
.into_iter()
|
||||
.map(|tx| (tx.source, tx.data.clone()));
|
||||
|
||||
let reverified_transactions = self.verify(at, pruned_transactions, false).await?;
|
||||
|
||||
@@ -335,7 +351,7 @@ impl<B: ChainApi> Pool<B> {
|
||||
async fn verify(
|
||||
&self,
|
||||
at: &BlockId<B::Block>,
|
||||
xts: impl IntoIterator<Item=ExtrinsicFor<B>>,
|
||||
xts: impl IntoIterator<Item=(TransactionSource, ExtrinsicFor<B>)>,
|
||||
force: bool,
|
||||
) -> Result<HashMap<ExHash<B>, ValidatedTransactionFor<B>>, B::Error> {
|
||||
// we need a block number to compute tx validity
|
||||
@@ -345,7 +361,7 @@ impl<B: ChainApi> Pool<B> {
|
||||
for (hash, validated_tx) in
|
||||
futures::future::join_all(
|
||||
xts.into_iter()
|
||||
.map(|xt| self.verify_one(at, block_number, xt, force))
|
||||
.map(|(source, xt)| self.verify_one(at, block_number, source, xt, force))
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -360,6 +376,7 @@ impl<B: ChainApi> Pool<B> {
|
||||
&self,
|
||||
block_id: &BlockId<B::Block>,
|
||||
block_number: NumberFor<B>,
|
||||
source: TransactionSource,
|
||||
xt: ExtrinsicFor<B>,
|
||||
force: bool,
|
||||
) -> (ExHash<B>, ValidatedTransactionFor<B>) {
|
||||
@@ -371,7 +388,11 @@ impl<B: ChainApi> Pool<B> {
|
||||
)
|
||||
}
|
||||
|
||||
let validation_result = self.validated_pool.api().validate_transaction(block_id, xt.clone()).await;
|
||||
let validation_result = self.validated_pool.api().validate_transaction(
|
||||
block_id,
|
||||
source,
|
||||
xt.clone(),
|
||||
).await;
|
||||
|
||||
let status = match validation_result {
|
||||
Ok(status) => status,
|
||||
@@ -386,6 +407,7 @@ impl<B: ChainApi> Pool<B> {
|
||||
ValidatedTransaction::valid_at(
|
||||
block_number.saturated_into::<u64>(),
|
||||
hash.clone(),
|
||||
source,
|
||||
xt,
|
||||
bytes,
|
||||
validity,
|
||||
@@ -422,7 +444,7 @@ mod tests {
|
||||
use futures::executor::block_on;
|
||||
use super::*;
|
||||
use sp_transaction_pool::TransactionStatus;
|
||||
use sp_runtime::transaction_validity::{ValidTransaction, InvalidTransaction};
|
||||
use sp_runtime::transaction_validity::{ValidTransaction, InvalidTransaction, TransactionSource};
|
||||
use codec::Encode;
|
||||
use substrate_test_runtime::{Block, Extrinsic, Transfer, H256, AccountId};
|
||||
use assert_matches::assert_matches;
|
||||
@@ -430,6 +452,7 @@ mod tests {
|
||||
use crate::base_pool::Limit;
|
||||
|
||||
const INVALID_NONCE: u64 = 254;
|
||||
const SOURCE: TransactionSource = TransactionSource::External;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct TestApi {
|
||||
@@ -450,6 +473,7 @@ mod tests {
|
||||
fn validate_transaction(
|
||||
&self,
|
||||
at: &BlockId<Self::Block>,
|
||||
_source: TransactionSource,
|
||||
uxt: ExtrinsicFor<Self>,
|
||||
) -> Self::ValidationFuture {
|
||||
let hash = self.hash_and_length(&uxt).0;
|
||||
@@ -541,7 +565,7 @@ mod tests {
|
||||
let pool = pool();
|
||||
|
||||
// when
|
||||
let hash = block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
let hash = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -565,7 +589,7 @@ mod tests {
|
||||
|
||||
// when
|
||||
pool.validated_pool.rotator().ban(&Instant::now(), vec![pool.hash_of(&uxt)]);
|
||||
let res = block_on(pool.submit_one(&BlockId::Number(0), uxt));
|
||||
let res = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt));
|
||||
assert_eq!(pool.validated_pool().status().ready, 0);
|
||||
assert_eq!(pool.validated_pool().status().future, 0);
|
||||
|
||||
@@ -581,20 +605,20 @@ mod tests {
|
||||
let stream = pool.validated_pool().import_notification_stream();
|
||||
|
||||
// when
|
||||
let _hash = block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
let _hash = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
}))).unwrap();
|
||||
let _hash = block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
let _hash = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 1,
|
||||
}))).unwrap();
|
||||
// future doesn't count
|
||||
let _hash = block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
let _hash = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -617,19 +641,19 @@ mod tests {
|
||||
fn should_clear_stale_transactions() {
|
||||
// given
|
||||
let pool = pool();
|
||||
let hash1 = block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
let hash1 = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
}))).unwrap();
|
||||
let hash2 = block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
let hash2 = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 1,
|
||||
}))).unwrap();
|
||||
let hash3 = block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
let hash3 = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -653,7 +677,7 @@ mod tests {
|
||||
fn should_ban_mined_transactions() {
|
||||
// given
|
||||
let pool = pool();
|
||||
let hash1 = block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
let hash1 = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -680,7 +704,7 @@ mod tests {
|
||||
..Default::default()
|
||||
}, TestApi::default().into());
|
||||
|
||||
let hash1 = block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
let hash1 = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -689,7 +713,7 @@ mod tests {
|
||||
assert_eq!(pool.validated_pool().status().future, 1);
|
||||
|
||||
// when
|
||||
let hash2 = block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
let hash2 = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -716,7 +740,7 @@ mod tests {
|
||||
}, TestApi::default().into());
|
||||
|
||||
// when
|
||||
block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -734,7 +758,7 @@ mod tests {
|
||||
let pool = pool();
|
||||
|
||||
// when
|
||||
let err = block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
let err = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -754,7 +778,7 @@ mod tests {
|
||||
fn should_trigger_ready_and_finalized() {
|
||||
// given
|
||||
let pool = pool();
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), uxt(Transfer {
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -778,7 +802,7 @@ mod tests {
|
||||
fn should_trigger_ready_and_finalized_when_pruning_via_hash() {
|
||||
// given
|
||||
let pool = pool();
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), uxt(Transfer {
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -802,7 +826,7 @@ mod tests {
|
||||
fn should_trigger_future_and_ready_after_promoted() {
|
||||
// given
|
||||
let pool = pool();
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), uxt(Transfer {
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -812,7 +836,7 @@ mod tests {
|
||||
assert_eq!(pool.validated_pool().status().future, 1);
|
||||
|
||||
// when
|
||||
block_on(pool.submit_one(&BlockId::Number(0), uxt(Transfer {
|
||||
block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
@@ -836,7 +860,7 @@ mod tests {
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
});
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), uxt)).unwrap();
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), SOURCE, uxt)).unwrap();
|
||||
assert_eq!(pool.validated_pool().status().ready, 1);
|
||||
|
||||
// when
|
||||
@@ -860,7 +884,7 @@ mod tests {
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
});
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), uxt)).unwrap();
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), SOURCE, uxt)).unwrap();
|
||||
assert_eq!(pool.validated_pool().status().ready, 1);
|
||||
|
||||
// when
|
||||
@@ -895,7 +919,7 @@ mod tests {
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
});
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), xt)).unwrap();
|
||||
let watcher = block_on(pool.submit_and_watch(&BlockId::Number(0), SOURCE, xt)).unwrap();
|
||||
assert_eq!(pool.validated_pool().status().ready, 1);
|
||||
|
||||
// when
|
||||
@@ -905,7 +929,7 @@ mod tests {
|
||||
amount: 4,
|
||||
nonce: 1,
|
||||
});
|
||||
block_on(pool.submit_one(&BlockId::Number(1), xt)).unwrap();
|
||||
block_on(pool.submit_one(&BlockId::Number(1), SOURCE, xt)).unwrap();
|
||||
assert_eq!(pool.validated_pool().status().ready, 1);
|
||||
|
||||
// then
|
||||
@@ -934,7 +958,7 @@ mod tests {
|
||||
// This transaction should go to future, since we use `nonce: 1`
|
||||
let pool2 = pool.clone();
|
||||
std::thread::spawn(move || {
|
||||
block_on(pool2.submit_one(&BlockId::Number(0), xt)).unwrap();
|
||||
block_on(pool2.submit_one(&BlockId::Number(0), SOURCE, xt)).unwrap();
|
||||
ready.send(()).unwrap();
|
||||
});
|
||||
|
||||
@@ -948,7 +972,7 @@ mod tests {
|
||||
});
|
||||
// The tag the above transaction provides (TestApi is using just nonce as u8)
|
||||
let provides = vec![0_u8];
|
||||
block_on(pool.submit_one(&BlockId::Number(0), xt)).unwrap();
|
||||
block_on(pool.submit_one(&BlockId::Number(0), SOURCE, xt)).unwrap();
|
||||
assert_eq!(pool.validated_pool().status().ready, 1);
|
||||
|
||||
// Now block import happens before the second transaction is able to finish verification.
|
||||
|
||||
@@ -545,6 +545,7 @@ fn remove_item<T: PartialEq>(vec: &mut Vec<T>, item: &T) {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sp_runtime::transaction_validity::TransactionSource as Source;
|
||||
|
||||
fn tx(id: u8) -> Transaction<u64, Vec<u8>> {
|
||||
Transaction {
|
||||
@@ -556,6 +557,7 @@ mod tests {
|
||||
requires: vec![vec![1], vec![2]],
|
||||
provides: vec![vec![3], vec![4]],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,6 +658,7 @@ mod tests {
|
||||
requires: vec![tx1.provides[0].clone()],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
};
|
||||
|
||||
// when
|
||||
@@ -688,6 +691,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
};
|
||||
import(&mut ready, tx).unwrap();
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ impl<Hash: hash::Hash + Eq + Clone> PoolRotator<Hash> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sp_runtime::transaction_validity::TransactionSource;
|
||||
|
||||
type Hash = u64;
|
||||
type Ex = ();
|
||||
@@ -122,6 +123,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: TransactionSource::External,
|
||||
};
|
||||
|
||||
(hash, tx)
|
||||
@@ -188,6 +190,7 @@ mod tests {
|
||||
requires: vec![],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: TransactionSource::External,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ use parking_lot::{Mutex, RwLock};
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{self, SaturatedConversion},
|
||||
transaction_validity::{TransactionTag as Tag, ValidTransaction},
|
||||
transaction_validity::{TransactionTag as Tag, ValidTransaction, TransactionSource},
|
||||
};
|
||||
use sp_transaction_pool::{error, PoolStatus};
|
||||
use wasm_timer::Instant;
|
||||
@@ -58,6 +58,7 @@ impl<Hash, Ex, Error> ValidatedTransaction<Hash, Ex, Error> {
|
||||
pub fn valid_at(
|
||||
at: u64,
|
||||
hash: Hash,
|
||||
source: TransactionSource,
|
||||
data: Ex,
|
||||
bytes: usize,
|
||||
validity: ValidTransaction,
|
||||
@@ -66,6 +67,7 @@ impl<Hash, Ex, Error> ValidatedTransaction<Hash, Ex, Error> {
|
||||
data,
|
||||
bytes,
|
||||
hash,
|
||||
source,
|
||||
priority: validity.priority,
|
||||
requires: validity.requires,
|
||||
provides: validity.provides,
|
||||
|
||||
Reference in New Issue
Block a user