Add get_state_for_commitment_root
This commit is contained in:
parent
6cf9752b4c
commit
9c52241e90
@ -256,6 +256,25 @@ impl Process {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_state_for_commitments_root(&mut self, merkle_root: [u8; 32]) -> anyhow::Result<&mut ProcessState> {
|
||||
if self.get_number_of_states() == 0 {
|
||||
// This should never happen, but we better get rid of it now
|
||||
return Err(anyhow::Error::msg("process is empty".to_owned()));
|
||||
}
|
||||
|
||||
for p in self.get_latest_concurrent_states_mut()? {
|
||||
if p.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let root = <Value as Pcd>::create_merkle_tree(&p.pcd_commitment).unwrap().root().unwrap();
|
||||
if merkle_root == root {
|
||||
return Ok(p);
|
||||
}
|
||||
}
|
||||
|
||||
return Err(anyhow::Error::msg("No state for this merkle root"));
|
||||
}
|
||||
|
||||
/// This is useful when multiple unvalidated states are pending waiting for enough validations
|
||||
/// It returns the latest state and all the previous states that have the same commited_in
|
||||
/// It means that all the returned states are unvalidated and except for the one that get validated they will be pruned
|
||||
|
Loading…
x
Reference in New Issue
Block a user