Skip to content

Commit fa416d4

Browse files
committed
Add extrinsic notifications (paritytech#29)
1 parent 55d372c commit fa416d4

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/main.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use substrate_client::BlockchainEvents;
5252

5353
use chainx_network::consensus::ConsensusNetwork;
5454
use chainx_pool::{PoolApi, TransactionPool};
55-
use chainx_primitives::{Block, Hash};
55+
use chainx_primitives::{Block, Hash, BlockId};
5656
use chainx_api::TClient;
5757
use cli::ChainSpec;
5858

@@ -119,16 +119,36 @@ fn main() {
119119
{
120120
// block notifications
121121
let network = network.clone();
122+
let txpool = extrinsic_pool.clone();
123+
122124
let events = client
123125
.import_notification_stream()
124126
.for_each(move |notification| {
125127
network.on_block_imported(notification.hash, &notification.header);
128+
txpool.inner().cull(&BlockId::hash(notification.hash))
129+
.map_err(|e| warn!("Error removing extrinsics: {:?}", e))?;
126130
Ok(())
127131
}).select(exit.clone())
128132
.then(|_| Ok(()));
129133
task_executor.spawn(events);
130134
}
131135

136+
{
137+
// extrinsic notifications
138+
let network = network.clone();
139+
let txpool = extrinsic_pool.clone();
140+
let events = txpool.inner().import_notification_stream()
141+
// TODO [ToDr] Consider throttling?
142+
.for_each(move |_| {
143+
network.trigger_repropagate();
144+
Ok(())
145+
})
146+
.select(exit.clone())
147+
.then(|_| Ok(()));
148+
149+
task_executor.spawn(events);
150+
}
151+
132152
let _consensus = if validator_mode {
133153
let key = match matches
134154
.subcommand_matches("validator")

0 commit comments

Comments
 (0)