Skip to content

Commit

Permalink
Rework user warning (to update its node software)
Browse files Browse the repository at this point in the history
  • Loading branch information
sydhds committed Jul 4, 2023
1 parent 9292dbb commit 97a683f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
2 changes: 2 additions & 0 deletions massa-models/src/config/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ pub const MAX_LISTENERS_PER_PEER: u64 = 100;
pub const VERSIONING_THRESHOLD_TRANSITION_ACCEPTED: Ratio<u64> = Ratio::new_raw(75, 100);
/// Block count to process in MipStoreStats (for state change threshold)
pub const MIP_STORE_STATS_BLOCK_CONSIDERED: usize = 1000;
/// Warn user to update its node if we reach this ratio for announced network versions
pub const MIP_STATS_RATIO_WARN_ANNOUNCED_VERSION: Ratio<u64> = Ratio::new_raw(30, 100);

//
// Constants for denunciation factory
Expand Down
5 changes: 0 additions & 5 deletions massa-protocol-exports/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ pub enum ProtocolError {
/// received announced network version
announced_received: u32,
},
/// Invalid announced network version (expected None)
InvalidAnnouncedNetworkVersion {
/// received announced network version
announced_received: u32,
},
/// Versioned factory error: {0}
FactoryError(#[from] FactoryError),
/// PoS error: {0}
Expand Down
17 changes: 1 addition & 16 deletions massa-protocol-worker/src/handlers/block_handler/retrieval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,27 +466,12 @@ impl RetrievalThread {
} else {
if let Some(announced_version) = header.content.announced_version {
if announced_version <= current_version {
// Received block, announced an old version (already accepted)
// Received an announced network version that is already known
return Err(ProtocolError::OutdatedAnnouncedNetworkVersion {
local: current_version,
announced_received: announced_version,
});
}

match self.mip_store.get_network_version_to_announce() {
Some(version_to_announce) => {
// Unknown/new announced version -> user might need to upgrade
if announced_version > version_to_announce {
warn!("Please update your node if you want to support this update (new network version: {})", announced_version);
}
}
None => {
// Received an announced version but none should be announced
return Err(ProtocolError::InvalidAnnouncedNetworkVersion {
announced_received: announced_version,
});
}
};
}

Ok(())
Expand Down
32 changes: 29 additions & 3 deletions massa-versioning/src/versioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ use num::{rational::Ratio, Zero};
use num_enum::{FromPrimitive, IntoPrimitive, TryFromPrimitive};
use parking_lot::RwLock;
use thiserror::Error;
use tracing::debug;
use tracing::{debug, warn};

use massa_db_exports::{
DBBatch, ShareableMassaDBController, MIP_STORE_PREFIX, MIP_STORE_STATS_PREFIX, STATE_CF,
VERSIONING_CF,
};
use massa_models::config::MIP_STORE_STATS_BLOCK_CONSIDERED;
use massa_models::config::VERSIONING_THRESHOLD_TRANSITION_ACCEPTED;
use massa_models::config::{
MIP_STATS_RATIO_WARN_ANNOUNCED_VERSION, MIP_STORE_STATS_BLOCK_CONSIDERED,
};
use massa_models::error::ModelsError;
use massa_models::slot::Slot;
use massa_models::timeslots::get_block_slot_timestamp;
Expand Down Expand Up @@ -890,7 +892,8 @@ impl MipStoreRaw {
.push_back(announced_network_version);

// We update the count of the received version (example: update counter for version 1)
self.stats
let mut network_version_count = *self
.stats
.network_version_counters
.entry(announced_network_version)
.and_modify(|v| *v = v.saturating_add(1))
Expand All @@ -905,11 +908,32 @@ impl MipStoreRaw {
{
let entry_value = e.get_mut();
*entry_value = entry_value.saturating_sub(1);
network_version_count = *entry_value;
if *entry_value == 0 {
self.stats.network_version_counters.remove(&removed_version);
}
}
}

if announced_network_version != 0 {
let vote_ratio = Ratio::new(
network_version_count,
self.stats.config.block_count_considered as u64,
);

if vote_ratio > MIP_STATS_RATIO_WARN_ANNOUNCED_VERSION {
let last_key_value = self.store.last_key_value();
if let Some((mi, _ms)) = last_key_value {
if announced_network_version > mi.version {
// Vote ratio is > 30%
// announced version is not known (not in MIP store)
// announced version is > to the last known network version in MIP store
// -> Warn the user to update
warn!("Please update your node if you want to support this update (new network version: {})", announced_network_version);
}
}
}
}
}

debug!(
Expand Down Expand Up @@ -983,6 +1007,8 @@ impl MipStoreRaw {
version
}

// fn contains_network_version(&self, current_network_version: u32, announced)

// Network restart

/// Check if store is coherent with given last network shutdown
Expand Down

0 comments on commit 97a683f

Please sign in to comment.