Verify every causal-frontier root and its complete transitive dependency index. A frontier root is not causal proof by itself. This verifier requires each root to be registered locally, then reuses the same cycle- and completeness-checked closure builder used by view materialization. The resulting value is the only frontier membership accepted by conflict detection.
(
txn: &T,
change: &Change,
)
| 86 | /// resulting value is the only frontier membership accepted by conflict |
| 87 | /// detection. |
| 88 | pub fn verify_causal_frontier<T: GraphTxnT>( |
| 89 | txn: &T, |
| 90 | change: &Change, |
| 91 | ) -> Result<VerifiedCausalFrontier, LocalApplyError> { |
| 92 | let frontier = change.causal_frontier(); |
| 93 | if frontier.is_empty() { |
| 94 | return Ok(VerifiedCausalFrontier::empty()); |
| 95 | } |
| 96 | |
| 97 | let mut root_ids = Vec::with_capacity(frontier.roots().len()); |
| 98 | for root in frontier.roots() { |
| 99 | let root_id = txn |
| 100 | .get_internal(root) |
| 101 | .map_err(|error| LocalApplyError::CausalFrontierInvalid { |
| 102 | reason: format!("failed to resolve frontier root {root}: {error}"), |
| 103 | })? |
| 104 | .ok_or_else(|| LocalApplyError::CausalFrontierInvalid { |
| 105 | reason: format!("frontier root {root} is not registered locally"), |
| 106 | })?; |
| 107 | root_ids.push(root_id); |
| 108 | } |
| 109 | |
| 110 | let membership = ViewMembershipSet::from_ordered(root_ids); |
| 111 | let closure = |
| 112 | GraphVisibilityClosure::try_from_membership(txn, &membership).map_err(|error| { |
| 113 | LocalApplyError::CausalFrontierInvalid { |
| 114 | reason: format!("frontier dependency closure is incomplete or invalid: {error}"), |
| 115 | } |
| 116 | })?; |
| 117 | |
| 118 | let mut known = BTreeSet::new(); |
| 119 | for change_id in closure.iter_dependency_first() { |
| 120 | let hash = txn |
| 121 | .get_external(*change_id) |
| 122 | .map_err(|error| LocalApplyError::CausalFrontierInvalid { |
| 123 | reason: format!( |
| 124 | "failed to resolve verified frontier change {change_id:?}: {error}" |
| 125 | ), |
| 126 | })? |
| 127 | .ok_or_else(|| LocalApplyError::CausalFrontierInvalid { |
| 128 | reason: format!("verified frontier change {change_id:?} has no external hash"), |
| 129 | })?; |
| 130 | known.insert(hash); |
| 131 | } |
| 132 | |
| 133 | Ok(VerifiedCausalFrontier::from_verified( |
| 134 | frontier.clone(), |
| 135 | known, |
| 136 | )) |
| 137 | } |
| 138 | |
| 139 | /// Check if a change has already been applied to a view. |
| 140 | /// |