Merge Notifier and TransactionsPoolNotifier (#10591)

* Merge `Notifier` and `TransactionsPoolNotifier`

* fix tests
This commit is contained in:
Sfxdx
2019-06-04 18:35:33 +07:00
committed by Seun LanLege
parent 425dcd45c2
commit faf6f1f9ea
8 changed files with 138 additions and 139 deletions

View File

@@ -329,8 +329,9 @@ impl FullDependencies {
}
Api::EthPubSub => {
if !for_generic_pubsub {
let pool_receiver = self.miner.pending_transactions_receiver();
let mut client =
EthPubSubClient::new(self.client.clone(), self.executor.clone());
EthPubSubClient::new(self.client.clone(), self.executor.clone(), pool_receiver);
let weak_client = Arc::downgrade(&self.client);
client.add_sync_notifier(self.sync.sync_notification(), move |state| {
@@ -345,14 +346,6 @@ impl FullDependencies {
})
});
let h = client.handler();
self.miner
.add_transactions_listener(Box::new(move |hashes| {
if let Some(h) = h.upgrade() {
h.notify_new_transactions(hashes);
}
}));
if let Some(h) = client.handler().upgrade() {
self.client.add_notify(h);
}
@@ -361,7 +354,7 @@ impl FullDependencies {
}
Api::ParityTransactionsPool => {
if !for_generic_pubsub {
let receiver = self.miner.tx_pool_receiver();
let receiver = self.miner.full_transactions_receiver();
let client = TransactionsPoolClient::new(self.executor.clone(), receiver);
handler.extend_with(TransactionsPoolClient::to_delegate(client));
}
@@ -583,6 +576,8 @@ impl<C: LightChainClient + 'static> LightDependencies<C> {
}
}
Api::EthPubSub => {
let receiver = self.transaction_queue.write().pending_transactions_receiver();
let mut client = EthPubSubClient::light(
self.client.clone(),
self.on_demand.clone(),
@@ -590,6 +585,7 @@ impl<C: LightChainClient + 'static> LightDependencies<C> {
self.cache.clone(),
self.executor.clone(),
self.gas_price_percentile,
receiver
);
let weak_client = Arc::downgrade(&self.client);
@@ -607,19 +603,11 @@ impl<C: LightChainClient + 'static> LightDependencies<C> {
});
self.client.add_listener(client.handler() as Weak<_>);
let h = client.handler();
self.transaction_queue
.write()
.add_listener(Box::new(move |transactions| {
if let Some(h) = h.upgrade() {
h.notify_new_transactions(transactions);
}
}));
handler.extend_with(EthPubSub::to_delegate(client));
}
Api::ParityTransactionsPool => {
if !for_generic_pubsub {
let receiver = self.transaction_queue.write().tx_statuses_receiver();
let receiver = self.transaction_queue.write().full_transactions_receiver();
let client = TransactionsPoolClient::new(self.executor.clone(), receiver);
handler.extend_with(TransactionsPoolClient::to_delegate(client));
}

View File

@@ -30,7 +30,7 @@ use ethcore::verification::queue::VerifierSettings;
use ethcore_logger::{Config as LogConfig, RotatingLogger};
use ethcore_service::ClientService;
use ethereum_types::Address;
use futures::IntoFuture;
use futures::{IntoFuture, Stream};
use hash_fetch::{self, fetch};
use informant::{Informant, LightNodeInformantData, FullNodeInformantData};
use journaldb::Algorithm;
@@ -668,14 +668,19 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
// Propagate transactions as soon as they are imported.
let tx = ::parking_lot::Mutex::new(priority_tasks);
let is_ready = Arc::new(atomic::AtomicBool::new(true));
miner.add_transactions_listener(Box::new(move |_hashes| {
// we want to have only one PendingTransactions task in the queue.
if is_ready.compare_and_swap(true, false, atomic::Ordering::SeqCst) {
let task = ::sync::PriorityTask::PropagateTransactions(Instant::now(), is_ready.clone());
// we ignore error cause it means that we are closing
let _ = tx.lock().send(task);
}
}));
let executor = runtime.executor();
let pool_receiver = miner.pending_transactions_receiver();
executor.spawn(
pool_receiver.for_each(move |_hashes| {
// we want to have only one PendingTransactions task in the queue.
if is_ready.compare_and_swap(true, false, atomic::Ordering::SeqCst) {
let task = ::sync::PriorityTask::PropagateTransactions(Instant::now(), is_ready.clone());
// we ignore error cause it means that we are closing
let _ = tx.lock().send(task);
}
Ok(())
})
);
// provider not added to a notification center is effectively disabled
// TODO [debris] refactor it later on