Skip to content

Commit

Permalink
style(GlobalState): Rename criterion function
Browse files Browse the repository at this point in the history
`should_enter_into_sync_mode` -> `sync_mode_criterion`

The function evaluates a criterion. This criterion is the
antecedent. Entering into sync mode is the consequence, and not
a necessary one.

This particular antecedent can be evaluated and even satisfied
independently of the consequence being activated. The new name
communicates that while the consequence is linked, it does not
necessarily follow from the antecedent.
  • Loading branch information
aszepieniec committed Jan 19, 2025
1 parent e26ba39 commit 2dd639c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ impl MainLoopHandler {
// mode.
let mut global_state_mut = self.global_state_lock.lock_guard_mut().await;
if global_state_mut
.should_enter_sync_mode(claimed_max_height, claimed_max_accumulative_pow)
.sync_mode_criterion(claimed_max_height, claimed_max_accumulative_pow)
{
info!(
"Entering synchronization mode due to peer {} indicating tip height {}; pow family: {:?}",
Expand Down
13 changes: 11 additions & 2 deletions src/models/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,17 @@ impl GlobalState {
height
}

/// Return a boolean indicating if synchronization mode should be entered
pub(crate) fn should_enter_sync_mode(
/// Determine whether the conditions are met to enter into sync mode.
///
/// Specifically, compute a boolean value based on
/// - whether the foreign cumulative proof-of-work exceeds that of our own;
/// - whether the foreign block has a bigger block height and the height
/// difference exceeds the threshold set by the CLI.
///
/// The main loop relies on this criterion to decide whether to enter sync
/// mode. If the main loop activates sync mode, it affects the entire
/// application.
pub(crate) fn sync_mode_criterion(
&self,
max_height: BlockHeight,
cumulative_pow: ProofOfWork,
Expand Down
2 changes: 1 addition & 1 deletion src/peer_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ impl PeerLoopHandler {
block_notification.height
);
let state = self.global_state_lock.lock_guard().await;
if state.should_enter_sync_mode(
if state.sync_mode_criterion(
block_notification.height,
block_notification.cumulative_proof_of_work,
) {
Expand Down

0 comments on commit 2dd639c

Please sign in to comment.