pub struct LightClient { /* private fields */ }unstable only.Expand description
A light client that authenticates state against a trusted validator committee.
LightClient owns a Client for talking to a Sui gRPC endpoint and
an EpochCache seeded with a starting committee. Each verification
call advances the cache forward as far as needed (BLS-verifying each
epoch transition along the way), verifies the response’s checkpoint
summary against the now-cached committee, and finally verifies the
returned proof against the trusted summary.
Implementations§
Source§impl LightClient
impl LightClient
Sourcepub fn new(rpc: Client, starting_committee: ValidatorCommittee) -> Self
pub fn new(rpc: Client, starting_committee: ValidatorCommittee) -> Self
Build a new LightClient seeded with starting_committee.
The starting committee must be obtained out of band (e.g. baked
into the application, or read from a trusted source). It need
not be the genesis committee — a client that only cares about
recent state can seed the cache with a known-trusted committee
at a later epoch (see the bundled-trust-anchors feature) and
skip ratcheting through every prior epoch.
Sourcepub fn with_ratchet_config(self, config: RatchetConfig) -> Self
pub fn with_ratchet_config(self, config: RatchetConfig) -> Self
Override the RatchetConfig used when this client advances its
epoch cache. Defaults to RatchetConfig::default.
Sourcepub fn with_archive(self, archive: Client) -> Self
pub fn with_archive(self, archive: Client) -> Self
Attach an archive endpoint. The ratchet driver will prefer the
archive for historical reads (GetEpoch during discovery and
GetCheckpoint for end-of-epoch summaries) and fall back to
the fullnode on any archive miss or error.
Archives serve historical data with higher availability and tighter latency than typical fullnodes; misses (newer checkpoints not yet archived) transparently fall back to the fullnode. Both clients are used read-only by the ratchet — nothing in the cache becomes trustworthy solely because the archive served it; every end-of-epoch summary is still BLS-verified against the cache’s current committee.
Sourcepub fn epoch_cache(&self) -> &EpochCache
pub fn epoch_cache(&self) -> &EpochCache
Read-only access to the client’s epoch cache, for inspection.
Sourcepub fn rpc(&mut self) -> &mut Client
pub fn rpc(&mut self) -> &mut Client
Mutable access to the underlying RPC client, for callers that want to issue additional gRPC requests through the same channel.
Sourcepub async fn latest_checkpoint_seq(&mut self) -> Result<u64, LightClientError>
pub async fn latest_checkpoint_seq(&mut self) -> Result<u64, LightClientError>
Return the sequence number of the network’s most recent
checkpoint, as reported by LedgerService.GetCheckpoint(latest).
The result is not trust-anchored — it’s a single read from
the server with no signature verification. Streaming clients use
it as a starting cursor (e.g., “begin reading events from the
checkpoint after this one”); any subsequent claim about an
object’s state at this checkpoint must still flow through
Self::prove_object_at_checkpoint for cryptographic
authentication.
Sourcepub async fn prove_object_at_checkpoint(
&mut self,
object_id: &Address,
checkpoint_seq: u64,
) -> Result<CheckpointObjectProof, LightClientError>
pub async fn prove_object_at_checkpoint( &mut self, object_id: &Address, checkpoint_seq: u64, ) -> Result<CheckpointObjectProof, LightClientError>
Prove what (if anything) the checkpoint at checkpoint_seq did
to object_id, returning a CheckpointObjectProof that
distinguishes the four cases (created/mutated/unwrapped,
deleted/wrapped, or not modified at all).
The full chain of trust:
- Call the alpha
ProofService.GetCheckpointObjectProofRPC with(object_id, checkpoint_seq). - Ratchet the epoch cache forward to cover the checkpoint whose summary the server returned, BLS-verifying each intervening end-of-epoch summary along the way.
- BCS-decode the returned
SignedCheckpointSummary, sanity-check that itssequence_numbermatchescheckpoint_seq, and BLS-verify its aggregate signature against the now-trusted committee for that epoch. - Dispatch on the response’s
proofoneof:- Inclusion: sanity-check the returned
ObjectReference’s object id matches the request, verify the OCS inclusion proof against the trusted summary, and (whenobject_datais present) BCS-decode it and confirm its(id, version, digest)match the authenticated leaf. Absentobject_datasignals a deletion or wrap, in which caseobjectis returned asNone. - NonInclusion: verify the OCS non-inclusion proof
against the trusted summary for
object_id. The proof’s id-strict-bracketing rules out any leaf withobject_id, proving the checkpoint did not modify it.
- Inclusion: sanity-check the returned
This method does not answer “what is the state of object_id
at checkpoint checkpoint_seq?” — that question requires
walking back to the most recent modification or an entirely
different commitment scheme. See CheckpointObjectProof’s
type-level documentation for details.
Auto Trait Implementations§
impl !Freeze for LightClient
impl !RefUnwindSafe for LightClient
impl Send for LightClient
impl Sync for LightClient
impl Unpin for LightClient
impl UnsafeUnpin for LightClient
impl !UnwindSafe for LightClient
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§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<T> Conv for T
impl<T> Conv for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.