Skip to content

Commit

Permalink
Add extrinsic notifications (paritytech#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
gguoss committed Sep 14, 2018
1 parent 55d372c commit fa416d4
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use substrate_client::BlockchainEvents;

use chainx_network::consensus::ConsensusNetwork;
use chainx_pool::{PoolApi, TransactionPool};
use chainx_primitives::{Block, Hash};
use chainx_primitives::{Block, Hash, BlockId};
use chainx_api::TClient;
use cli::ChainSpec;

Expand Down Expand Up @@ -119,16 +119,36 @@ fn main() {
{
// block notifications
let network = network.clone();
let txpool = extrinsic_pool.clone();

let events = client
.import_notification_stream()
.for_each(move |notification| {
network.on_block_imported(notification.hash, &notification.header);
txpool.inner().cull(&BlockId::hash(notification.hash))
.map_err(|e| warn!("Error removing extrinsics: {:?}", e))?;
Ok(())
}).select(exit.clone())
.then(|_| Ok(()));
task_executor.spawn(events);
}

{
// extrinsic notifications
let network = network.clone();
let txpool = extrinsic_pool.clone();
let events = txpool.inner().import_notification_stream()
// TODO [ToDr] Consider throttling?
.for_each(move |_| {
network.trigger_repropagate();
Ok(())
})
.select(exit.clone())
.then(|_| Ok(()));

task_executor.spawn(events);
}

let _consensus = if validator_mode {
let key = match matches
.subcommand_matches("validator")
Expand Down

0 comments on commit fa416d4

Please sign in to comment.