Skip to content

Commit

Permalink
Skip computing block locators if peer is disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Dec 5, 2022
1 parent 8124f74 commit 886ea8a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
13 changes: 8 additions & 5 deletions node/src/beacon/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,14 @@ impl<N: Network, C: ConsensusStorage<N>> Inbound<N> for Beacon<N, C> {
tokio::spawn(async move {
// Sleep for the preset time before sending a `Ping` request.
tokio::time::sleep(Duration::from_secs(Self::PING_SLEEP_IN_SECS)).await;
// Retrieve the block locators.
match crate::helpers::get_block_locators(&self_clone.ledger) {
// Send a `Ping` message to the peer.
Ok(block_locators) => self_clone.send_ping(peer_ip, Some(block_locators)),
Err(e) => error!("Failed to get block locators: {e}"),
// Check that the peer is still connected.
if self_clone.router().is_connected(&peer_ip) {
// Retrieve the block locators.
match crate::helpers::get_block_locators(&self_clone.ledger) {
// Send a `Ping` message to the peer.
Ok(block_locators) => self_clone.send_ping(peer_ip, Some(block_locators)),
Err(e) => error!("Failed to get block locators: {e}"),
}
}
});
true
Expand Down
7 changes: 5 additions & 2 deletions node/src/client/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ impl<N: Network, C: ConsensusStorage<N>> Inbound<N> for Client<N, C> {
tokio::spawn(async move {
// Sleep for the preset time before sending a `Ping` request.
tokio::time::sleep(Duration::from_secs(Self::PING_SLEEP_IN_SECS)).await;
// Send a `Ping` message to the peer.
self_clone.send_ping(peer_ip, None);
// Check that the peer is still connected.
if self_clone.router().is_connected(&peer_ip) {
// Send a `Ping` message to the peer.
self_clone.send_ping(peer_ip, None);
}
});
true
}
Expand Down
7 changes: 5 additions & 2 deletions node/src/prover/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ impl<N: Network, C: ConsensusStorage<N>> Inbound<N> for Prover<N, C> {
tokio::spawn(async move {
// Sleep for the preset time before sending a `Ping` request.
tokio::time::sleep(Duration::from_secs(Self::PING_SLEEP_IN_SECS)).await;
// Send a `Ping` message to the peer.
self_clone.send_ping(peer_ip, None);
// Check that the peer is still connected.
if self_clone.router().is_connected(&peer_ip) {
// Send a `Ping` message to the peer.
self_clone.send_ping(peer_ip, None);
}
});
true
}
Expand Down
13 changes: 8 additions & 5 deletions node/src/validator/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,14 @@ impl<N: Network, C: ConsensusStorage<N>> Inbound<N> for Validator<N, C> {
tokio::spawn(async move {
// Sleep for the preset time before sending a `Ping` request.
tokio::time::sleep(Duration::from_secs(Self::PING_SLEEP_IN_SECS)).await;
// Retrieve the block locators.
match crate::helpers::get_block_locators(&self_clone.ledger) {
// Send a `Ping` message to the peer.
Ok(block_locators) => self_clone.send_ping(peer_ip, Some(block_locators)),
Err(e) => error!("Failed to get block locators: {e}"),
// Check that the peer is still connected.
if self_clone.router().is_connected(&peer_ip) {
// Retrieve the block locators.
match crate::helpers::get_block_locators(&self_clone.ledger) {
// Send a `Ping` message to the peer.
Ok(block_locators) => self_clone.send_ping(peer_ip, Some(block_locators)),
Err(e) => error!("Failed to get block locators: {e}"),
}
}
});
true
Expand Down

0 comments on commit 886ea8a

Please sign in to comment.