pub struct EventNumbers { /* private fields */ }Expand description
The node’s event-number counter (§7.14.1.1).
Hands out numbers from RAM and tells the caller when to persist the next reservation, so that monotonicity survives a restart without a flash write per event.
Implementations§
Source§impl EventNumbers
impl EventNumbers
Sourcepub const fn restore(persisted: u64) -> Self
pub const fn restore(persisted: u64) -> Self
Resumes from the value that was last persisted.
§7.14.1.1’s step 1 and 2: “Read the counter value at start-up. Before processing any
message, write counter + N to storage.” So a fresh boot starts at the persisted value
and immediately owes a write of persisted + N — which EventNumbers::reservation
reports.
Sourcepub const fn reservation(&self) -> Option<u64>
pub const fn reservation(&self) -> Option<u64>
The value the node must persist before handing out any more numbers.
None when the current reservation still has room. A caller that ignores this breaks
the monotonicity guarantee only across a restart — which is exactly the kind of bug
that never shows up in testing.
Sourcepub const fn next(&mut self) -> Option<u64>
pub const fn next(&mut self) -> Option<u64>
Takes the next event number.
Returns None while a reservation is owed: handing out a number the node has not
reserved is precisely how a restart rewinds the counter, and a record with a reused
number tells a client that nothing happened when something did.