Skip to main content

PoolLedger

Struct PoolLedger 

Source
pub struct PoolLedger { /* private fields */ }
Expand description

One lane’s live voucher ledger, shared by every concurrent stream that draws on it. Voucher issuance is serialized through the async issuance mutex — held across compute → sign → send so vouchers reach the node in strict cumulative order — and released the instant the send returns, because there is no ack to wait for (implicit acceptance, ADR 005). The committed watermark advances the moment a send succeeds; a mid-stream VoucherRejected rewinds it through resolve_reject.

Implementations§

Source§

impl PoolLedger

Source

pub fn new(seed: Cumulative) -> Self

Build a ledger seeded from the lane’s persisted cumulative state (the last voucher issued on earlier streams/invocations). Pass Cumulative::default() for a brand-new lane, and for the unpaid legs — the node’s own-origin BackendSource quotes rate 0, so it never prices, signs, or meters anything.

The cumulative is the only seed there is. A chain draws its own secret at open and is never resumed across a restart, so this constructor takes no lane identity and no key material: what the ledger inherits from a previous process is the money it owes, never the chain it owed it under.

Source

pub fn committed(&self) -> Cumulative

Read the committed cumulative WITHOUT awaiting — the drop-safe reader, and the only one a Drop impl can call. It is the highest voucher whose send succeeded (implicit acceptance) or that a terminal StreamEnd confirmed (confirm_armed_stamped), plus the accrual since, so it is exactly what a completed pull persists.

Source

pub fn paid_bytes(&self) -> U256

The lane bytes this ledger paid for since its seed: how far it grew the cumulative claim the node can redeem. Each voucher and hash-chain reveal adds the bytes it pays for, and a rejection of that same proof takes them back. Content delivered twice is paid for twice and counts twice.

A Self::reseed jump is payment this ledger did not make, so it does not count. A rebase drops claims the node never accepted, so they do not count either; claims below the seed that this ledger signs again after a rebase do count.

An armed voucher whose send did not confirm counts only once a later voucher builds on it, a StreamEnd confirms it, or a retired chain’s fold commits it. Self::settlement counts it from the start.

Source

pub fn settlement(&self) -> Cumulative

The cumulative a cancelled pull must PERSIST — the drop-path counterpart of Self::committed, and what a Drop guard should actually write (#1122).

It is Self::committed, except when a voucher is still armed with its send unconfirmed, in which case it is the HIGHER of the two by amount (the monotone key). Settling high is the safe direction and it is correct: an armed voucher pays for bytes the upstream ALREADY DELIVERED, and the upstream persists a voucher before it would reject it, so an ambiguous failure may leave the upstream holding it — under-reporting would strand the deposit. A voucher the upstream explicitly REJECTED is never here — resolve_reject clears armed and rewinds committed — so this cannot inflate our cumulative for bytes the upstream declined.

Source

pub fn take_unsaved_rebase(&self) -> Option<Cumulative>

Take the watermark the latest rebase moved to, if no persist has recorded it yet. The caller overwrites the lane record with it once and advances from there; every later persist is a monotone advance again. Taking it clears it, so a second persist sees None.

Trait Implementations§

Source§

impl Debug for PoolLedger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more