pub struct OpLog { /* private fields */ }Expand description
In-memory Merkle-DAG operation log.
Append-only: entries are content-addressed and linked to their causal
predecessors (the heads at time of write). The OpLog tracks heads,
supports delta computation (entries_since), and topological sorting.
Implementations§
Source§impl OpLog
impl OpLog
Sourcepub fn append(&mut self, entry: Entry) -> Result<bool, OpLogError>
pub fn append(&mut self, entry: Entry) -> Result<bool, OpLogError>
Append an entry to the log.
- Verifies the entry hash is valid.
- If the entry already exists (duplicate), returns false.
- Updates heads: the entry’s
nextlinks are no longer heads (they have a successor). - Returns true if the entry was newly inserted.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the log is empty (should never be — always has genesis).
Sourcepub fn estimated_memory_bytes(&self) -> usize
pub fn estimated_memory_bytes(&self) -> usize
Approximate heap memory used by the oplog (bytes). Uses serialized entry sizes + fixed overhead estimates per structure. Does not account for heap allocations behind String/Vec in property values or allocator fragmentation. Actual memory may be 2-3x higher for string-heavy graphs.
Sourcepub fn verify_integrity(&self) -> Vec<String>
pub fn verify_integrity(&self) -> Vec<String>
Verify structural integrity of the oplog (INV-6). Checks I-01 (hash integrity), I-02 (causal completeness), I-04 (heads accuracy). Returns a list of errors (empty = healthy).
Sourcepub fn entries_since(&self, known_hash: Option<&Hash>) -> Vec<&Entry>
pub fn entries_since(&self, known_hash: Option<&Hash>) -> Vec<&Entry>
Return all entries reachable from current heads that are NOT
reachable from (or equal to) known_hash.
This computes the delta a peer needs: “give me everything you have
that I don’t, given that I already have known_hash and its ancestors.”
If known_hash is None, returns all entries (the entire log).
Sourcepub fn topo_sort(&self, hashes: &HashSet<Hash>) -> Vec<&Entry>
pub fn topo_sort(&self, hashes: &HashSet<Hash>) -> Vec<&Entry>
Topological sort of the given set of entry hashes. Returns entries in causal order: parents before children.
Sourcepub fn entries_as_of(
&self,
cutoff_physical: u64,
cutoff_logical: u32,
) -> Vec<&Entry>
pub fn entries_as_of( &self, cutoff_physical: u64, cutoff_logical: u32, ) -> Vec<&Entry>
R-06: Get all entries with clock <= cutoff, in topological order. Returns a historical snapshot of the state at the given time.
Sourcepub fn replace_with_checkpoint(&mut self, checkpoint: Entry)
pub fn replace_with_checkpoint(&mut self, checkpoint: Entry)
R-08: Replace entire oplog with a single checkpoint entry. All previous entries are removed. The checkpoint becomes the sole entry. SAFETY: Only call after verifying ALL peers have synced past all current entries.