Compute the new Merkle state after unrecording changes. This recomputes the state by re-hashing the remaining changes. # Arguments `txn` - Read transaction `view` - View being modified `removed` - Set of change hashes being removed # Returns The new Merkle state after removal.
(
txn: &T,
view: &ViewState,
removed: &HashSet<Hash>,
)
| 566 | /// |
| 567 | /// The new Merkle state after removal. |
| 568 | pub fn compute_state_after_unrecord<T: ViewTxnT>( |
| 569 | txn: &T, |
| 570 | view: &ViewState, |
| 571 | removed: &HashSet<Hash>, |
| 572 | ) -> UnrecordResult<Merkle> { |
| 573 | let mut state = Merkle::ZERO; |
| 574 | |
| 575 | // Iterate through all changes and recompute state without the removed ones |
| 576 | let iter = txn |
| 577 | .iter_changes(view, 0) |
| 578 | .map_err(|e| UnrecordError::Database(e.to_string()))?; |
| 579 | |
| 580 | for result in iter { |
| 581 | let (_, change_id, _) = result.map_err(|e| UnrecordError::Database(e.to_string()))?; |
| 582 | |
| 583 | // Get external hash |
| 584 | let hash = txn |
| 585 | .get_external(change_id) |
| 586 | .map_err(|e| UnrecordError::Database(e.to_string()))? |
| 587 | .ok_or_else(|| UnrecordError::ChangeNotFound { |
| 588 | hash: format!("{:?}", change_id), |
| 589 | })?; |
| 590 | |
| 591 | // Skip removed changes |
| 592 | if removed.contains(&hash) { |
| 593 | continue; |
| 594 | } |
| 595 | |
| 596 | // Update state |
| 597 | state = state.next(&hash); |
| 598 | } |
| 599 | |
| 600 | Ok(state) |
| 601 | } |
| 602 | |
| 603 | /// Preview what would be unrecorded without actually doing it. |
| 604 | /// |
no test coverage detected