pub struct RecentProvers { /* private fields */ }Expand description
Per-key cache of recent provers, capped at MAX_PROVERS_PER_KEY.
Implementations§
Source§impl RecentProvers
impl RecentProvers
Sourcepub fn record_proof(
&mut self,
key: XorName,
peer_id: PeerId,
commitment_hash: [u8; 32],
proved_at: Instant,
)
pub fn record_proof( &mut self, key: XorName, peer_id: PeerId, commitment_hash: [u8; 32], proved_at: Instant, )
Record that peer_id proved storage of key under commitment
commitment_hash at proved_at.
If the same (peer_id, commitment_hash) is already cached for
this key, the entry is updated in place (refreshes proved_at).
Otherwise a new entry is appended, evicting the oldest entry if
the per-key cap would be exceeded.
Sourcepub fn is_credited_holder(
&self,
key: &XorName,
peer_id: &PeerId,
current_commitment_hash: &[u8; 32],
) -> bool
pub fn is_credited_holder( &self, key: &XorName, peer_id: &PeerId, current_commitment_hash: &[u8; 32], ) -> bool
Is peer_id currently credited as a holder of key?
Returns true iff there is a non-stale cached entry with peer_id
and commitment_hash == current_commitment_hash.
“Non-stale” means now - proved_at < PROVER_ENTRY_TTL. The hash
binding is the v12 §6 lever: a peer that rotates their commitment
must re-prove every key they want credit for. The TTL is a
secondary safety net that revokes credit even if the hash
happens to match (e.g. a peer who proved long ago but has been
silent or offline since).
Sourcepub fn sweep_expired(&mut self, now: Instant) -> usize
pub fn sweep_expired(&mut self, now: Instant) -> usize
Sweep entries older than PROVER_ENTRY_TTL across all keys.
Returns the number of entries dropped. Intended for periodic
invocation by a background task; is_credited_holder already
honours the TTL on read, so the sweep only reclaims memory.
Sourcepub fn forget_peer(&mut self, peer_id: &PeerId)
pub fn forget_peer(&mut self, peer_id: &PeerId)
Drop every cached entry for peer_id across all keys.
Called when a peer leaves the routing table (RT-only invariant) or on explicit eviction.
Sourcepub fn forget_commitment(&mut self, stale_hash: &[u8; 32])
pub fn forget_commitment(&mut self, stale_hash: &[u8; 32])
Drop every entry whose commitment_hash matches stale_hash
(used when the auditor invalidates a peer’s last_commitment —
e.g. on UnknownCommitmentHash rejection — to remove the cached
proofs against that no-longer-valid commitment).
Sourcepub fn provers_for(&self, key: &XorName) -> usize
pub fn provers_for(&self, key: &XorName) -> usize
Number of cached entries for key. Test/observability helper.
Sourcepub fn total_entries(&self) -> usize
pub fn total_entries(&self) -> usize
Total number of cached entries across all keys.
Trait Implementations§
Source§impl Clone for RecentProvers
impl Clone for RecentProvers
Source§fn clone(&self) -> RecentProvers
fn clone(&self) -> RecentProvers
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RecentProvers
impl Debug for RecentProvers
Source§impl Default for RecentProvers
impl Default for RecentProvers
Source§fn default() -> RecentProvers
fn default() -> RecentProvers
Auto Trait Implementations§
impl Freeze for RecentProvers
impl RefUnwindSafe for RecentProvers
impl Send for RecentProvers
impl Sync for RecentProvers
impl Unpin for RecentProvers
impl UnsafeUnpin for RecentProvers
impl UnwindSafe for RecentProvers
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more