mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
Revert "prune finalized transactions from the pool"
This reverts commit 7ab024ceb65c31edcf6414f98a31dd7a29688c96.
This commit is contained in:
@@ -53,8 +53,8 @@ use futures::prelude::*;
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use tokio_core::reactor::Core;
|
use tokio_core::reactor::Core;
|
||||||
use codec::Slicable;
|
use codec::Slicable;
|
||||||
use primitives::block::{Id as BlockId, Extrinsic, ExtrinsicHash, HeaderHash};
|
use runtime_io::with_externalities;
|
||||||
use primitives::hashing;
|
use primitives::block::{Id as BlockId, TransactionHash};
|
||||||
use transaction_pool::TransactionPool;
|
use transaction_pool::TransactionPool;
|
||||||
use substrate_executor::NativeExecutor;
|
use substrate_executor::NativeExecutor;
|
||||||
use polkadot_executor::Executor as LocalDispatch;
|
use polkadot_executor::Executor as LocalDispatch;
|
||||||
@@ -71,6 +71,7 @@ pub use config::{Configuration, Role, ChainSpec};
|
|||||||
|
|
||||||
type Client = client::Client<InMemory, NativeExecutor<LocalDispatch>>;
|
type Client = client::Client<InMemory, NativeExecutor<LocalDispatch>>;
|
||||||
|
|
||||||
|
|
||||||
/// Polkadot service.
|
/// Polkadot service.
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
thread: Option<thread::JoinHandle<()>>,
|
thread: Option<thread::JoinHandle<()>>,
|
||||||
@@ -86,7 +87,7 @@ struct TransactionPoolAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl network::TransactionPool for TransactionPoolAdapter {
|
impl network::TransactionPool for TransactionPoolAdapter {
|
||||||
fn transactions(&self) -> Vec<(ExtrinsicHash, Vec<u8>)> {
|
fn transactions(&self) -> Vec<(TransactionHash, Vec<u8>)> {
|
||||||
let best_block = match self.client.info() {
|
let best_block = match self.client.info() {
|
||||||
Ok(info) => info.chain.best_hash,
|
Ok(info) => info.chain.best_hash,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -103,7 +104,7 @@ impl network::TransactionPool for TransactionPoolAdapter {
|
|||||||
}).collect()
|
}).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn import(&self, transaction: &[u8]) -> Option<ExtrinsicHash> {
|
fn import(&self, transaction: &[u8]) -> Option<TransactionHash> {
|
||||||
if let Some(tx) = codec::Slicable::decode(&mut &transaction[..]) {
|
if let Some(tx) = codec::Slicable::decode(&mut &transaction[..]) {
|
||||||
match self.pool.lock().import(tx) {
|
match self.pool.lock().import(tx) {
|
||||||
Ok(t) => Some(t.hash()[..].into()),
|
Ok(t) => Some(t.hash()[..].into()),
|
||||||
@@ -298,14 +299,11 @@ impl Service {
|
|||||||
|
|
||||||
let thread_client = client.clone();
|
let thread_client = client.clone();
|
||||||
let thread_network = network.clone();
|
let thread_network = network.clone();
|
||||||
let thread_txpool = transaction_pool.clone();
|
|
||||||
let thread = thread::spawn(move || {
|
let thread = thread::spawn(move || {
|
||||||
thread_network.start_network();
|
thread_network.start_network();
|
||||||
let mut core = Core::new().expect("tokio::Core could not be created");
|
let mut core = Core::new().expect("tokio::Core could not be created");
|
||||||
let events = thread_client.import_notification_stream().for_each(|notification| {
|
let events = thread_client.import_notification_stream().for_each(|notification| {
|
||||||
thread_network.on_block_imported(notification.hash, ¬ification.header);
|
thread_network.on_block_imported(notification.hash, ¬ification.header);
|
||||||
prune_imported(&*thread_client, &*thread_txpool, notification.hash);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
if let Err(e) = core.run(events) {
|
if let Err(e) = core.run(events) {
|
||||||
@@ -338,23 +336,6 @@ impl Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prune_transactions(pool: &mut TransactionPool, extrinsics: &[Extrinsic]) {
|
|
||||||
for extrinsic in extrinsics {
|
|
||||||
let hash: _ = hashing::blake2_256(&extrinsic.encode()).into();
|
|
||||||
pool.remove(&hash, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Produce a task which prunes any finalized transactions from the pool.
|
|
||||||
pub fn prune_imported(client: &Client, pool: &Mutex<TransactionPool>, hash: HeaderHash) {
|
|
||||||
let id = BlockId::Hash(hash);
|
|
||||||
match client.body(&id) {
|
|
||||||
Ok(Some(body)) => prune_transactions(&mut *pool.lock(), &body[..]),
|
|
||||||
Ok(None) => warn!("Missing imported block {:?}", hash),
|
|
||||||
Err(e) => warn!("Failed to fetch block: {:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Service {
|
impl Drop for Service {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.client.stop_notifications();
|
self.client.stop_notifications();
|
||||||
|
|||||||
Reference in New Issue
Block a user