Skip to main content

WitnessLog

Struct WitnessLog 

Source
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

Source

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).

Source

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.

Source

pub fn len(&self) -> usize

Number of recorded events currently in the log.

Source

pub fn is_empty(&self) -> bool

Whether the log contains no records.

Source

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.

Source

pub fn all(&self) -> &[WitnessRecord]

Get all records currently in the log.

Source

pub fn clear(&mut self)

Clear all records from the log.

Source

pub fn count_tier_changes(&self) -> usize

Count the number of WitnessEvent::TierChange records.

Source

pub fn count_evictions(&self) -> usize

Count the number of WitnessEvent::Eviction records.

Source

pub fn count_checksum_failures(&self) -> usize

Count the number of WitnessEvent::ChecksumFailure records.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.