pub struct WitnessLog { /* private fields */ }Expand description
Append-only witness log with configurable capacity.
When the log reaches capacity, the oldest records are dropped to make room for new ones, giving ring-buffer semantics. This bounds memory usage while preserving the most recent history for audit trails and flip-rate calculations.
Implementations§
Source§impl WitnessLog
impl WitnessLog
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new witness log with the given maximum capacity.
A capacity of zero is treated as one (at least one record can be stored).
Sourcepub fn record(&mut self, timestamp: u64, event: WitnessEvent)
pub fn record(&mut self, timestamp: u64, event: WitnessEvent)
Record a witness event at the given timestamp.
If the log is at capacity, the oldest record is removed first.
Sourcepub fn recent(&self, n: usize) -> &[WitnessRecord]
pub fn recent(&self, n: usize) -> &[WitnessRecord]
Get the most recent n records.
Returns fewer than n if the log does not contain that many records.
Sourcepub fn all(&self) -> &[WitnessRecord]
pub fn all(&self) -> &[WitnessRecord]
Get all records currently in the log.
Sourcepub fn count_tier_changes(&self) -> usize
pub fn count_tier_changes(&self) -> usize
Count the number of WitnessEvent::TierChange records.
Sourcepub fn count_evictions(&self) -> usize
pub fn count_evictions(&self) -> usize
Count the number of WitnessEvent::Eviction records.
Sourcepub fn count_checksum_failures(&self) -> usize
pub fn count_checksum_failures(&self) -> usize
Count the number of WitnessEvent::ChecksumFailure records.
Sourcepub fn tier_flip_rate(&self, window_ticks: u64, num_blocks: u64) -> f32
pub fn tier_flip_rate(&self, window_ticks: u64, num_blocks: u64) -> f32
Compute tier flip rate: tier changes per block per minute.
window_ticks is the size of the time window to consider (only records
whose timestamp is >= max_timestamp - window_ticks are counted).
num_blocks is the current total block count (used as the denominator).
Returns 0.0 when num_blocks is zero or when no tier changes fall
within the window.