Compact the event log into per-account snapshots

Once the log grows past ~3x the account count it is rewritten to one
AccountRegistered per account (churned cert events dropped), via a temp
file and rename. Cert replay is now idempotent, so a snapshot plus
re-delivered events converge and a peer syncing from a compacted node
still gets every account. Runs on a 30m timer.
This commit is contained in:
Jean Chevronnet 2026-07-12 07:24:44 +00:00
parent df7b413862
commit cc0265548f
No known key found for this signature in database
3 changed files with 127 additions and 1 deletions

View file

@ -104,6 +104,16 @@ impl Engine {
self.db.ingest(entry)
}
// Compact the log if it has grown past the live account count. Returns
// whether it rewrote anything.
pub fn maybe_compact(&mut self) -> std::io::Result<bool> {
if self.db.should_compact() {
self.db.compact()?;
return Ok(true);
}
Ok(false)
}
#[cfg(test)]
pub(crate) fn test_register(&mut self, name: &str) {
self.db.register(name, "pw", None).unwrap();