pub struct ChainVerifier { /* private fields */ }Expand description
Incremental, O(1)-memory chain verifier: folds one entry at a time, carrying forward only the last verified hash (NFR-002’s “carry forward only the last verified hash as state” shape, reused here for the JSONL adapters even though NFR-002 itself was written for durable’s segment reads).
Implementations§
Source§impl ChainVerifier
impl ChainVerifier
Sourcepub fn new(key: ChainKey, genesis: ChainHash) -> Self
pub fn new(key: ChainKey, genesis: ChainHash) -> Self
Start a verifier at genesis (or at the last verified head, when resuming mid-file).
Sourcepub fn verify_next(
&mut self,
content: &[u8],
stored: &ChainHash,
) -> Result<(), ChainError>
pub fn verify_next( &mut self, content: &[u8], stored: &ChainHash, ) -> Result<(), ChainError>
Verify one more entry against the running chain state, advancing it on success.
§Errors
Returns ChainError::Mismatch if the recomputed hash does not equal stored.
Sourcepub fn peek_next(&self, content: &[u8]) -> ChainHash
pub fn peek_next(&self, content: &[u8]) -> ChainHash
Compute the next link without advancing state — used by writers to compute the hash to
store for a new append, immediately followed by a manual Self::advance once the write
is known to have succeeded.
Sourcepub fn advance(&mut self, head: ChainHash)
pub fn advance(&mut self, head: ChainHash)
Advance the running state to head after a write using Self::peek_next’s result has
been durably committed.