Skip to content

Commit

Permalink
Update status
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Dec 1, 2021
1 parent 3887237 commit 9c1f22f
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions src/network/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,34 +518,26 @@ impl<N: Network, E: Environment> Ledger<N, E> {
_ => State::Ready,
};

if E::NODE_TYPE == NodeType::Miner {
// Retrieve the latest cumulative weight of this node.
let latest_cumulative_weight = self.canon.latest_cumulative_weight();
// Iterate through the connected peers, to determine if the ledger state is out of date.
for (_, peer_state) in self.peers_state.read().await.iter() {
if let Some((_, _, is_fork, block_height, block_locators)) = peer_state {
// Retrieve the cumulative weight, defaulting to the block height if it does not exist.
let cumulative_weight = match block_locators.get_cumulative_weight(*block_height) {
Some(cumulative_weight) => cumulative_weight,
None => *block_height as u128,
};
// If the cumulative weight is more, set the status to `Syncing`.
if cumulative_weight > latest_cumulative_weight && is_fork.is_some() {
// Sync if this difference in cumulative weight is greater than 2.
if cumulative_weight - latest_cumulative_weight > 2 {
// Set the status to `Syncing`.
status = State::Syncing;
break;
}
// Retrieve the latest cumulative weight of this node.
let latest_cumulative_weight = self.canon.latest_cumulative_weight();
// Iterate through the connected peers, to determine if the ledger state is out of date.
for (_, peer_state) in self.peers_state.read().await.iter() {
if let Some((_, _, is_fork, block_height, block_locators)) = peer_state {
// Retrieve the cumulative weight, defaulting to the block height if it does not exist.
let cumulative_weight = match block_locators.get_cumulative_weight(*block_height) {
Some(cumulative_weight) => cumulative_weight,
None => *block_height as u128,
};
// If the cumulative weight is more, set the status to `Syncing`.
if cumulative_weight > latest_cumulative_weight && is_fork.is_some() {
// Sync if this difference in cumulative weight is greater than 2.
if cumulative_weight - latest_cumulative_weight > 2 {
// Set the status to `Syncing`.
status = State::Syncing;
break;
}
}
}
} else {
// If there are pending block requests, set the status to `Syncing`.
if self.number_of_block_requests().await > 0 {
// Set the status to `Syncing`.
status = State::Syncing;
}
}
}

Expand Down

0 comments on commit 9c1f22f

Please sign in to comment.