Skip to content

Commit

Permalink
Now update main MIP store with what is received from bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
sydhds committed Apr 5, 2023
1 parent d4a17e7 commit 5a726ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions massa-bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct GlobalBootstrapState {
/// list of network peers
pub peers: Option<BootstrapPeers>,

/// versioning info state
pub mip_store: Option<MipStore>,
}

Expand Down
8 changes: 7 additions & 1 deletion massa-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,13 @@ async fn launch(
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
counters_max: MIP_STORE_STATS_COUNTERS_MAX,
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();
let mut mip_store =
MipStore::try_from(([], mip_stats_config)).expect("Cannot create an empty MIP store");
if let Some(bootstrap_mip_store) = bootstrap_state.mip_store {
mip_store
.update_with(&bootstrap_mip_store)
.expect("Cannot update MIP store with bootstrap mip store");
}

// launch execution module
let execution_config = ExecutionConfig {
Expand Down
16 changes: 15 additions & 1 deletion massa-versioning-worker/src/versioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,16 @@ impl MipStore {
let mut lock = self.0.write();
lock.update_network_version_stats(slot_timestamp, network_versions);
}

#[allow(clippy::result_unit_err)]
pub fn update_with(
&mut self,
mip_store: &MipStore,
) -> Result<(Vec<MipInfo>, Vec<MipInfo>), ()> {
let mut lock = self.0.write();
let lock_other = mip_store.0.read();
lock.update_with(lock_other.deref())
}
}

impl<const N: usize> TryFrom<([(MipInfo, MipState); N], MipStatsConfig)> for MipStore {
Expand Down Expand Up @@ -514,7 +524,11 @@ pub struct MipStoreRaw {
impl MipStoreRaw {
/// Update our store with another (usually after a bootstrap where we received another store)
/// Return list of updated / added if update is successful
fn update_with(&mut self, store_raw: &MipStoreRaw) -> Result<(Vec<MipInfo>, Vec<MipInfo>), ()> {
#[allow(clippy::result_unit_err)]
pub fn update_with(
&mut self,
store_raw: &MipStoreRaw,
) -> Result<(Vec<MipInfo>, Vec<MipInfo>), ()> {
// iter over items in given store:
// -> 2 cases:
// * MipInfo is already in self store -> add to 'to_update' list
Expand Down

0 comments on commit 5a726ad

Please sign in to comment.