Verify one ref update: resolve the projection state at the new tip, compute the view's change delta, and run the trusted provenance gate.
(
repo: &Repository,
git_repo: &GitRepository,
old: git2::Oid,
new: git2::Oid,
ref_name: &str,
)
| 180 | /// Verify one ref update: resolve the projection state at the new tip, |
| 181 | /// compute the view's change delta, and run the trusted provenance gate. |
| 182 | fn verify_ref_update( |
| 183 | repo: &Repository, |
| 184 | git_repo: &GitRepository, |
| 185 | old: git2::Oid, |
| 186 | new: git2::Oid, |
| 187 | ref_name: &str, |
| 188 | ) -> Result<usize, String> { |
| 189 | let (view, new_merkle) = resolve_projection_state(git_repo, new).ok_or_else(|| { |
| 190 | format!( |
| 191 | "new tip {new} carries no Atomic-View/Atomic-State projection trailers; the \ |
| 192 | receiving boundary cannot verify it (deploy an Atomic-controlled remote so every \ |
| 193 | protected ref update is a verified projection)" |
| 194 | ) |
| 195 | })?; |
| 196 | |
| 197 | // The state must be ingested on the receiving side before verification. |
| 198 | let view_id = { |
| 199 | use atomic_core::pristine::ViewTxnT; |
| 200 | let txn = repo |
| 201 | .pristine() |
| 202 | .read_txn() |
| 203 | .map_err(|error| format!("cannot open the receiving pristine: {error}"))?; |
| 204 | txn.get_view(&view) |
| 205 | .map_err(|error| format!("cannot read view '{view}': {error}"))? |
| 206 | .map(|view_state| view_state.id) |
| 207 | .ok_or_else(|| { |
| 208 | format!( |
| 209 | "view '{view}' from projection trailers is not present on this boundary; \ |
| 210 | deploy the Atomic repository that owns this view" |
| 211 | ) |
| 212 | })? |
| 213 | }; |
| 214 | let seq_new = state_seq(repo, view_id, &new_merkle).ok_or_else(|| { |
| 215 | format!( |
| 216 | "state {} for view '{view}' is not ingested on this boundary; refusing ahead of \ |
| 217 | ingestion is fail-closed, never waved through", |
| 218 | new_merkle.to_base32() |
| 219 | ) |
| 220 | })?; |
| 221 | |
| 222 | let seq_old = if old.is_zero() { |
| 223 | None |
| 224 | } else { |
| 225 | let old_merkle = resolve_projection_state(git_repo, old) |
| 226 | .map(|(old_view, old_merkle)| { |
| 227 | if old_view == view { |
| 228 | Ok(old_merkle) |
| 229 | } else { |
| 230 | Err(format!( |
| 231 | "old tip {old} projects view '{old_view}' but the update targets \ |
| 232 | '{view}'; refusing the boundary crossing" |
| 233 | )) |
| 234 | } |
| 235 | }) |
| 236 | .transpose()? |
| 237 | .ok_or_else(|| { |
| 238 | format!("old tip {old} carries no projection trailers; cannot compute the delta") |
| 239 | })?; |
no test coverage detected