pub struct PaymentVerifier { /* private fields */ }Expand description
Main payment verifier for ant-node.
Uses:
- LRU cache for fast lookups of previously verified
XorNamevalues - EVM payment verification for new data (always required)
- Pool-level cache for merkle batch payments (avoids repeated on-chain queries)
Implementations§
Source§impl PaymentVerifier
impl PaymentVerifier
Sourcepub fn new(config: PaymentVerifierConfig) -> Self
pub fn new(config: PaymentVerifierConfig) -> Self
Create a new payment verifier.
Sourcepub fn attach_p2p_node(&self, node: Arc<P2PNode>)
pub fn attach_p2p_node(&self, node: Arc<P2PNode>)
Attach the node’s P2PNode handle so merkle-payment verification can
check candidate pub_keys against the DHT’s actual closest peers to the
pool midpoint.
Production startup MUST call this once the P2PNode exists. Without
it, the closeness check fails CLOSED in release builds (rejects the
PUT with a visible error) and fails open in test builds. Idempotent:
calling twice replaces the handle.
Sourcepub fn attach_storage(&self, storage: Arc<LmdbStorage>)
pub fn attach_storage(&self, storage: Arc<LmdbStorage>)
Attach the node’s LmdbStorage handle so storage-delta freshness
checks can query the authoritative on-disk record count.
Production startup MUST call this once the storage exists; otherwise
validate_quote_freshness falls back to treating the current count as
zero, which will reject all non-trivial quotes. Idempotent: calling
twice replaces the handle.
Sourcepub fn check_payment_required(
&self,
xorname: &XorName,
context: VerificationContext,
) -> PaymentStatus
pub fn check_payment_required( &self, xorname: &XorName, context: VerificationContext, ) -> PaymentStatus
Check if payment is required for the given XorName.
This is the main entry point for payment verification:
- Check LRU cache (fast path)
- If not cached, payment is required
The fast path is context-aware: a ClientPut lookup is satisfied only
by an entry whose verification ran the full client-PUT check set. An
entry inserted by a Replication verification (which skips the
storer-being-paid-now checks) must not let a later client PUT bypass
those checks. A Replication lookup accepts either kind of entry.
§Arguments
xorname- The content-addressed name of the datacontext- The verification context of the caller
§Returns
PaymentStatus::CachedAsVerified- Found in local cache (previously paid)PaymentStatus::PaymentRequired- Not cached (payment required)
Sourcepub async fn verify_payment(
&self,
xorname: &XorName,
payment_proof: Option<&[u8]>,
context: VerificationContext,
) -> Result<PaymentStatus>
pub async fn verify_payment( &self, xorname: &XorName, payment_proof: Option<&[u8]>, context: VerificationContext, ) -> Result<PaymentStatus>
Verify that a PUT request has valid payment.
This is the complete payment verification flow:
- Check if data is in cache (previously paid)
- If not, verify the provided payment proof
§Arguments
xorname- The content-addressed name of the datapayment_proof- Optional payment proof (required if not in cache)context- Whether the proof backs a live client PUT or an already-settled receipt presented during replication — seeVerificationContextfor which checks each context runs
§Returns
Ok(PaymentStatus)- Verification succeededErr(Error::Payment)- No payment and not cached, or payment invalid
§Errors
Returns an error if payment is required but not provided, or if payment is invalid.
Sourcepub fn cache_stats(&self) -> CacheStats
pub fn cache_stats(&self) -> CacheStats
Get cache statistics.
Auto Trait Implementations§
impl !Freeze for PaymentVerifier
impl !RefUnwindSafe for PaymentVerifier
impl !UnwindSafe for PaymentVerifier
impl Send for PaymentVerifier
impl Sync for PaymentVerifier
impl Unpin for PaymentVerifier
impl UnsafeUnpin for PaymentVerifier
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> 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