Fix quadratic iterations over transaction pool (#4736)

* transaction pool changes

* service & network changes

* address review

* reduce future pool
This commit is contained in:
Nikolay Volf
2020-01-27 09:26:42 -08:00
committed by Gavin Wood
parent 76acc96f3a
commit ed3da9f903
12 changed files with 102 additions and 37 deletions
+25 -5
View File
@@ -1135,18 +1135,26 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
}
}
/// Call when we must propagate ready extrinsics to peers.
pub fn propagate_extrinsics(
/// Propagate one extrinsic.
pub fn propagate_extrinsic(
&mut self,
hash: &H,
) {
debug!(target: "sync", "Propagating extrinsics");
debug!(target: "sync", "Propagating extrinsic [{:?}]", hash);
// Accept transactions only when fully synced
if self.sync.status().state != SyncState::Idle {
return;
}
if let Some(extrinsic) = self.transaction_pool.transaction(hash) {
let propagated_to = self.do_propagate_extrinsics(&[(hash.clone(), extrinsic)]);
self.transaction_pool.on_broadcasted(propagated_to);
}
}
let extrinsics = self.transaction_pool.transactions();
fn do_propagate_extrinsics(
&mut self,
extrinsics: &[(H, B::Extrinsic)],
) -> HashMap<H, Vec<String>> {
let mut propagated_to = HashMap::new();
for (who, peer) in self.context_data.peers.iter_mut() {
// never send extrinsics to the light node
@@ -1177,6 +1185,18 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
}
}
propagated_to
}
/// Call when we must propagate ready extrinsics to peers.
pub fn propagate_extrinsics(&mut self) {
debug!(target: "sync", "Propagating extrinsics");
// Accept transactions only when fully synced
if self.sync.status().state != SyncState::Idle {
return;
}
let extrinsics = self.transaction_pool.transactions();
let propagated_to = self.do_propagate_extrinsics(&extrinsics);
self.transaction_pool.on_broadcasted(propagated_to);
}