[bug] remove_all_concurrent_states won't panic if there's no concurrent states

This commit is contained in:
NicolasCantu 2025-01-24 16:00:21 +01:00
parent a4a81f42f1
commit 079156d86a

View File

@ -169,7 +169,6 @@ impl ProcessState {
}
};
// Check if each modified field satisfies at least one applicable rule across all roles
let all_fields_validated = modified_fields.iter().all(|field| {
// Collect applicable rules from all roles for the current field
@ -450,14 +449,19 @@ impl Process {
let empty_state = self.states.pop().unwrap();
let last_commitment_outpoint = empty_state.commited_in;
let split_index = self.states.iter().position(|state| state.commited_in == last_commitment_outpoint).unwrap();
if let Some(split_index) = self.states.iter().position(|state| state.commited_in == last_commitment_outpoint) {
let removed = self.states.split_off(split_index);
let removed = self.states.split_off(split_index);
// We make sure we always have an empty state at the end
self.states.push(empty_state);
// We make sure we always have an empty state at the end
self.states.push(empty_state);
Ok(removed)
Ok(removed)
} else {
// This could happen if we weren't aware there was pending concurrent updates
// We push the empty state back and return an empty vec
self.states.push(empty_state);
Ok(vec![])
}
}
pub fn get_latest_commited_state(&self) -> Option<&ProcessState> {