Skip to content

Commit

Permalink
minor potential bug fix in floresta-wire/chain-selector
Browse files Browse the repository at this point in the history
  • Loading branch information
lla-dane committed Jun 21, 2024
1 parent de32ff6 commit ae85b49
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/floresta-wire/src/p2p_wire/chain_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ where
}
}

self.request_headers(headers.last().unwrap().block_hash())
self.request_headers(headers.last().unwrap().block_hash(), peer)
.await
}

Expand Down Expand Up @@ -546,12 +546,12 @@ where
/// peer is following a chain with `tip` inside it. We use this in case some of
/// our peer is in a fork, so we can learn about all blocks in that fork and
/// compare the candidate chains to pick the best one.
async fn request_headers(&mut self, tip: BlockHash) -> Result<(), WireError> {
async fn request_headers(&mut self, tip: BlockHash, peer: PeerId) -> Result<(), WireError> {
let locator = self
.chain
.get_block_locator_for_tip(tip)
.unwrap_or_default();
self.send_to_peer(self.1.sync_peer, NodeRequest::GetHeaders(locator))
self.send_to_peer(peer, NodeRequest::GetHeaders(locator))
.await?;

let peer = self.1.sync_peer;
Expand Down Expand Up @@ -622,7 +622,10 @@ where
let new_sync_peer = rand::random::<usize>() % self.peer_ids.len();
self.1.sync_peer = *self.peer_ids.get(new_sync_peer).unwrap();

try_and_log!(self.request_headers(self.chain.get_best_block()?.1).await);
try_and_log!(
self.request_headers(self.chain.get_best_block()?.1, self.1.sync_peer)
.await
);

self.1.state = ChainSelectorState::DownloadingHeaders;
}
Expand Down

0 comments on commit ae85b49

Please sign in to comment.