From 2f6f7e5063b4661cc0db55c32e9fd884c79ed03c Mon Sep 17 00:00:00 2001 From: Davidson Souza <40968167+Davidson-Souza@users.noreply.github.com> Date: Wed, 3 May 2023 19:30:35 -0300 Subject: [PATCH] Ask for headers only once (#40) In some cases, we might ask for headers twice, downloading duplicated headers during ibd. This commit fixes it --- src/blockchain/p2p_blockchain/node.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/blockchain/p2p_blockchain/node.rs b/src/blockchain/p2p_blockchain/node.rs index 5b833c5..c693a23 100644 --- a/src/blockchain/p2p_blockchain/node.rs +++ b/src/blockchain/p2p_blockchain/node.rs @@ -445,16 +445,20 @@ impl UtreexoNode { if version.services.has(ServiceFlags::NODE_UTREEXO) { if let NodeState::WaitingPeer = self.state { - try_and_log!( - self.send_to_random_peer( - NodeRequest::GetHeaders( - self.chain.get_block_locator().expect("Can get locators"), - ), - ServiceFlags::NONE - ) - .await - ); - self.state = NodeState::DownloadHeaders; + if !self.inflight.contains_key(&InflightRequests::Headers) { + try_and_log!( + self.send_to_random_peer( + NodeRequest::GetHeaders( + self.chain + .get_block_locator() + .expect("Can get locators"), + ), + ServiceFlags::NONE + ) + .await + ); + self.state = NodeState::DownloadHeaders; + } } } }