Make transaction pool prune transactions only of canonical blocks (#6123)

* Make tx pool aware of retracted fork blocks

* Make it compile

* Update client/transaction-pool/src/lib.rs

Co-authored-by: Nikolay Volf <nikvolf@gmail.com>

* Fix doc test

* Simplify the implementation

* Send tree route as arc to prevent heavy clones

* Switch to use `ExtrinsicHash` to make it more clear

* Fix benchmark

Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
Bastian Köcher
2020-06-05 23:12:00 +02:00
committed by GitHub
parent 8a8b4f99c3
commit d2846e2b9a
31 changed files with 808 additions and 359 deletions
@@ -331,15 +331,14 @@ mod tests {
use parking_lot::Mutex;
use sp_consensus::{BlockOrigin, Proposer};
use substrate_test_runtime_client::{
prelude::*,
runtime::{Extrinsic, Transfer},
prelude::*, TestClientBuilder, runtime::{Extrinsic, Transfer}, TestClientBuilderExt,
};
use sp_transaction_pool::{ChainEvent, MaintainedTransactionPool, TransactionSource};
use sc_transaction_pool::{BasicPool, FullChainApi};
use sp_api::Core;
use backend::Backend;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::NumberFor;
use sc_client_api::Backend;
const SOURCE: TransactionSource = TransactionSource::External;
@@ -357,7 +356,7 @@ mod tests {
{
ChainEvent::NewBlock {
id: BlockId::Number(block_number.into()),
retracted: vec![],
tree_route: None,
is_new_best: true,
header,
}
@@ -452,8 +451,7 @@ mod tests {
#[test]
fn proposed_storage_changes_should_match_execute_block_storage_changes() {
let (client, backend) = substrate_test_runtime_client::TestClientBuilder::new()
.build_with_backend();
let (client, backend) = TestClientBuilder::new().build_with_backend();
let client = Arc::new(client);
let txpool = Arc::new(
BasicPool::new(
@@ -473,7 +471,9 @@ mod tests {
futures::executor::block_on(
txpool.maintain(chain_event(
0,
client.header(&BlockId::Number(0u64)).expect("header get error").expect("there should be header")
client.header(&BlockId::Number(0u64))
.expect("header get error")
.expect("there should be header"),
))
);
@@ -500,8 +500,11 @@ mod tests {
backend.changes_trie_storage(),
).unwrap();
let storage_changes = api.into_storage_changes(&state, changes_trie_state.as_ref(), genesis_hash)
.unwrap();
let storage_changes = api.into_storage_changes(
&state,
changes_trie_state.as_ref(),
genesis_hash,
).unwrap();
assert_eq!(
proposal.storage_changes.transaction_storage_root,
+4 -1
View File
@@ -25,7 +25,10 @@
//! # use sp_consensus::{Environment, Proposer, RecordProof};
//! # use sp_runtime::generic::BlockId;
//! # use std::{sync::Arc, time::Duration};
//! # use substrate_test_runtime_client::{self, runtime::{Extrinsic, Transfer}, AccountKeyring};
//! # use substrate_test_runtime_client::{
//! # runtime::{Extrinsic, Transfer}, AccountKeyring,
//! # DefaultTestClientBuilderExt, TestClientBuilderExt,
//! # };
//! # use sc_transaction_pool::{BasicPool, FullChainApi};
//! # let client = Arc::new(substrate_test_runtime_client::new());
//! # let txpool = Arc::new(BasicPool::new(Default::default(), Arc::new(FullChainApi::new(client.clone())), None).0);