From 38ccc02eaa1665a52b41aa1f69521f3880d313fa Mon Sep 17 00:00:00 2001 From: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com> Date: Thu, 20 Feb 2020 14:38:58 +0100 Subject: [PATCH] Quick subscribe (#232) * feat: Send chain head ahead of node list * feat: Partition node list into batches of 32 --- backend/src/chain.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/src/chain.rs b/backend/src/chain.rs index 425ac5f..7cb8d92 100644 --- a/backend/src/chain.rs +++ b/backend/src/chain.rs @@ -392,7 +392,15 @@ impl Handler for Chain { )); self.serializer.push(feed::BestFinalized(self.finalized.height, self.finalized.hash)); - for (nid, node) in self.nodes.iter() { + for (idx, (nid, node)) in self.nodes.iter().enumerate() { + // Send subscribtion confirmation and chain head before doing all the nodes, + // and continue sending batches of 32 nodes a time over the wire subsequently + if idx % 32 == 0 { + if let Some(serialized) = self.serializer.finalize() { + feed.do_send(serialized); + } + } + self.serializer.push(feed::AddedNode(nid, node)); self.serializer.push(feed::FinalizedBlock(nid, node.finalized().height, node.finalized().hash)); if node.stale() {