Skip to content

Commit

Permalink
Reverse heartbeat order
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Dec 2, 2021
1 parent 6aba524 commit 825ecef
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/network/peers.rs
Original file line number Diff line number Diff line change
@@ -1131,11 +1131,11 @@ impl<N: Network, E: Environment> Peer<N, E> {
peer.seen_inbound_blocks.insert(block_hash, SystemTime::now());

// Ensure the unconfirmed block is at least within 2 blocks of the latest block height,
// and no more that 3 blocks ahead of the latest block height.
// and no more that 2 blocks ahead of the latest block height.
// If it is stale, skip the routing of this unconfirmed block to the ledger.
let latest_block_height = ledger_reader.latest_block_height();
let lower_bound = latest_block_height.saturating_sub(2);
let upper_bound = latest_block_height.saturating_add(3);
let upper_bound = latest_block_height.saturating_add(2);
let is_within_range = block_height >= lower_bound && block_height <= upper_bound;

// Ensure the node is not peering.
8 changes: 4 additions & 4 deletions src/network/server.rs
Original file line number Diff line number Diff line change
@@ -258,15 +258,15 @@ impl<N: Network, E: Environment> Server<N, E> {
// Notify the outer function that the task is ready.
let _ = router.send(());
loop {
// Transmit a heartbeat request to the ledger.
if let Err(error) = ledger_router.send(LedgerRequest::Heartbeat(prover_router.clone())).await {
error!("Failed to send heartbeat to ledger: {}", error)
}
// Transmit a heartbeat request to the peers.
let request = PeersRequest::Heartbeat(ledger_reader.clone(), ledger_router.clone(), prover_router.clone());
if let Err(error) = peers_router.send(request).await {
error!("Failed to send heartbeat to peers: {}", error)
}
// Transmit a heartbeat request to the ledger.
if let Err(error) = ledger_router.send(LedgerRequest::Heartbeat(prover_router.clone())).await {
error!("Failed to send heartbeat to ledger: {}", error)
}
// Sleep for `E::HEARTBEAT_IN_SECS` seconds.
tokio::time::sleep(Duration::from_secs(E::HEARTBEAT_IN_SECS)).await;
}

0 comments on commit 825ecef

Please sign in to comment.