Skip to main content

aa_core/storage/
audit_sink.rs

1//! [`AuditSink`] — append-only emission of audit entries.
2
3use super::{AuditEntry, Result};
4use async_trait::async_trait;
5
6/// Append-only sink for governance [`AuditEntry`] records.
7///
8/// Every governance decision produces one entry. The sink is write-only from the
9/// runtime's perspective: it persists entries in order so the hash-chained audit
10/// log stays verifiable. Backends may batch or buffer internally, but
11/// [`emit`](AuditSink::emit) must not reorder entries relative to the calls.
12///
13/// # Example
14///
15/// ```
16/// use aa_core::storage::{AuditEntry, AuditSink, Result};
17/// use async_trait::async_trait;
18///
19/// /// A sink that discards every entry (useful as a test double).
20/// struct NullAuditSink;
21///
22/// #[async_trait]
23/// impl AuditSink for NullAuditSink {
24///     async fn emit(&self, _event: AuditEntry) -> Result<()> {
25///         Ok(())
26///     }
27/// }
28/// ```
29#[async_trait]
30pub trait AuditSink: Send + Sync {
31    /// Persist a single audit entry.
32    ///
33    /// Takes ownership of `event` because the sink is the entry's final
34    /// destination. Returns [`StorageError::Backend`](super::StorageError::Backend)
35    /// when the entry could not be durably recorded.
36    async fn emit(&self, event: AuditEntry) -> Result<()>;
37}