Skip to content

Commit

Permalink
Add more documentation
Browse files Browse the repository at this point in the history
sydhds committed Jan 27, 2025
1 parent 2bef24c commit d008658
Showing 2 changed files with 42 additions and 40 deletions.
4 changes: 3 additions & 1 deletion massa-versioning/src/lib.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@
//! # General description
//! MIP = Massa Improvement proposal (similar to Bitcoin Improvement Proposal - BIP or Ethereum - EIP)
//!
//! MIPInfo -> represent a MIP (name, versions, time ranges)
//! MipComponent -> A component that is going to be updated (e.g. Address v2)
//! MIPInfo -> represent a MIP (name, versions, time ranges, components)
//! MIPState -> Deployment state of a MIPInfo
//! MIPStore -> A map of MIPInfo -> MipState
//!
@@ -45,6 +46,7 @@
//!
//! MipState has:
//! * A state machine (stores the current state of deployment for a MipInfo)
//! * Usual state changes: Defined -> Started -> LockedIn -> Active
//! * A history (stores a list of `Advance` message that 'really' updated the state machine)
//!
//! An auto generated graph of the state machine can be found here:
78 changes: 39 additions & 39 deletions massa-versioning/src/versioning.rs
Original file line number Diff line number Diff line change
@@ -198,44 +198,6 @@ impl PartialEq for Advance {

impl Eq for Advance {}

// A Lightweight version of 'Advance' (used in MipState history)
#[derive(Clone, Debug)]
pub struct AdvanceLW {
/// % of past blocks with this version
pub threshold: Ratio<u64>,
/// Current time (timestamp)
pub now: MassaTime,
}

impl From<&Advance> for AdvanceLW {
fn from(value: &Advance) -> Self {
Self {
threshold: value.threshold,
now: value.now,
}
}
}

impl Ord for AdvanceLW {
fn cmp(&self, other: &Self) -> Ordering {
(self.now, self.threshold).cmp(&(other.now, other.threshold))
}
}

impl PartialOrd for AdvanceLW {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl PartialEq for AdvanceLW {
fn eq(&self, other: &Self) -> bool {
self.threshold == other.threshold && self.now == other.now
}
}

impl Eq for AdvanceLW {}

transitions!(ComponentState,
[
(Defined, Advance) => [Defined, Started, Failed],
@@ -299,6 +261,44 @@ impl Failed {
}
}

// A Lightweight version of 'Advance' (used in MipState history)
#[derive(Clone, Debug)]
pub struct AdvanceLW {
/// % of past blocks with this version
pub threshold: Ratio<u64>,
/// Current time (timestamp)
pub now: MassaTime,
}

impl From<&Advance> for AdvanceLW {
fn from(value: &Advance) -> Self {
Self {
threshold: value.threshold,
now: value.now,
}
}
}

impl Ord for AdvanceLW {
fn cmp(&self, other: &Self) -> Ordering {
(self.now, self.threshold).cmp(&(other.now, other.threshold))
}
}

impl PartialOrd for AdvanceLW {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl PartialEq for AdvanceLW {
fn eq(&self, other: &Self) -> bool {
self.threshold == other.threshold && self.now == other.now
}
}

impl Eq for AdvanceLW {}

/// Error returned by `MipState::is_consistent_with`
#[derive(Error, Debug, PartialEq)]
pub enum IsConsistentError {
@@ -1170,7 +1170,7 @@ impl MipStoreRaw {
// Network restart

/// Check if store is consistent with given last network shutdown
/// On a network shutdown, the MIP infos will be edited but we still need to check if this is consistent
/// On a network shutdown, the MIP infos will be edited, but we still need to check if this is consistent
fn is_consistent_with_shutdown_period(
&self,
shutdown_start: Slot,

0 comments on commit d008658

Please sign in to comment.