Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MipStoreRaw::update_with now return enum #3675

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion massa-versioning-worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! # Note on MipInfo versions
//!
//! There is 2 different versions:
//! * version -> Network version -> This is the network version to announce and thus to store in block header
//! * version == Network version -> This is the network version to announce and thus to store in block header
//! * component_version -> This is the version for the associated component and is used in VersioningFactory
//!
//! # Note on MipState
Expand Down
28 changes: 17 additions & 11 deletions massa-versioning-worker/src/versioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,15 @@ pub struct MipStoreRaw(pub(crate) BTreeMap<MipInfo, MipState>);

impl MipStoreRaw {
/// Update our store with another (usually after a bootstrap where we received another store)
/// Return true if update is successful, false if something is wrong on given store raw
fn update_with(&mut self, store_raw: &MipStoreRaw) -> bool {
/// Return list of updated / added if update is successful
fn update_with(&mut self, store_raw: &MipStoreRaw) -> Result<(Vec<MipInfo>, Vec<MipInfo>), ()> {
// iter over items in given store:
// -> 2 cases: VersioningInfo is already in self store -> add to 'to_update' list
// VersioningInfo is not in self.store -> add to 'to_add' list
//
// -> 2 cases:
// * MipInfo is already in self store -> add to 'to_update' list
// * MipInfo is not in self.store -> We received a new MipInfo so we are running an out dated version
// of the software
// We then return the list of new MipInfo so we can warn and ask
// to update the software

let mut component_versions: HashMap<MipComponent, u32> = self
.0
Expand Down Expand Up @@ -551,11 +554,14 @@ impl MipStoreRaw {

// Return false is there is nothing to merge - maybe we could make a distinction here?
if should_merge && (!to_update.is_empty() || !to_add.is_empty()) {
let added = to_add.keys().cloned().collect();
let updated = to_update.keys().cloned().collect();

self.0.append(&mut to_update);
self.0.append(&mut to_add);
true
Ok((updated, added))
} else {
false
Err(())
}
}
}
Expand All @@ -572,8 +578,8 @@ impl<const N: usize> TryFrom<[(MipInfo, MipState); N]> for MipStoreRaw {

// Use update_with ensuring that we have no overlapping time range, unique names & ...
match store.update_with(&other_store) {
true => Ok(store),
false => Err(()),
Ok(_) => Ok(store),
Err(_) => Err(()),
}
}
}
Expand Down Expand Up @@ -1052,7 +1058,7 @@ mod test {
]);
assert_eq!(_vs_raw_2_.is_err(), true);

assert_eq!(vs_raw_1.update_with(&vs_raw_2), false);
assert_eq!(vs_raw_1.update_with(&vs_raw_2), Err(()));
assert_eq!(vs_raw_1.0.get(&vi_1).unwrap().inner, vs_1.inner);
assert_eq!(vs_raw_1.0.get(&vi_2).unwrap().inner, vs_2.inner);

Expand All @@ -1070,6 +1076,6 @@ mod test {
(vi_2_2.clone(), vs_2_2.clone()),
]));

assert_eq!(vs_raw_1.update_with(&vs_raw_2), false);
assert_eq!(vs_raw_1.update_with(&vs_raw_2), Err(()));
}
}