Save an attestation to the repository. Serializes the attestation to disk and registers it in the graph with `node_type::ATTESTATION`. Also registers dependencies from `changes_covered` in the DEPS table so the graph knows which changes this attestation covers. # Arguments `attestation` - The attestation to save # Returns The content hash of the saved attestation.
(
&self,
attestation: &atomic_core::change::Attestation,
)
| 481 | /// |
| 482 | /// The content hash of the saved attestation. |
| 483 | pub fn save_attestation( |
| 484 | &self, |
| 485 | attestation: &atomic_core::change::Attestation, |
| 486 | ) -> Result<Hash, RepositoryError> { |
| 487 | self.ensure_project_identity(atomic_core::kg::project_id::MintReason::Upgrade)?; |
| 488 | use atomic_core::pristine::MutTxnT; |
| 489 | |
| 490 | // Save to disk |
| 491 | let hash = self |
| 492 | .change_store |
| 493 | .save_attestation(attestation) |
| 494 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 495 | |
| 496 | // Register in the graph |
| 497 | let mut txn = self |
| 498 | .pristine |
| 499 | .write_txn() |
| 500 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 501 | |
| 502 | let attest_id = txn |
| 503 | .register_attestation(&hash) |
| 504 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 505 | |
| 506 | // Register dependencies: attestation → covered changes. A downloaded |
| 507 | // change may not have been inserted into a view yet (`--download-only`), |
| 508 | // but it still needs an internal ID so this relationship is durable. |
| 509 | // Insertion reuses the same content-addressed registration later. |
| 510 | for change_hash in &attestation.changes_covered { |
| 511 | let change_id = txn |
| 512 | .register_change(change_hash) |
| 513 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 514 | txn.put_dep(attest_id, change_id) |
| 515 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 516 | } |
| 517 | |
| 518 | // If chained, register dependency on previous attestation too |
| 519 | if let Some(ref prev_hash) = attestation.previous_attestation { |
| 520 | if let Ok(Some(prev_id)) = txn.get_internal(prev_hash) { |
| 521 | txn.put_dep(attest_id, prev_id) |
| 522 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | txn.commit() |
| 527 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 528 | |
| 529 | self.refresh_session_kg()?; |
| 530 | Ok(hash) |
| 531 | } |
| 532 | |
| 533 | /// Build and persist the latest content-addressed manifest for a session. |
| 534 | /// |