pub enum TrustedState {
    EpochWaypoint(Waypoint),
    EpochState {
        waypoint: Waypoint,
        epoch_state: EpochState,
        accumulator: TransactionAccumulatorSummary,
    },
}
Expand description

TrustedState keeps track of light clients’ latest, trusted view of the ledger state. Light clients can use proofs from a state proof to “ratchet” their view forward to a newer state.

Variants§

§

EpochWaypoint(Waypoint)

The current trusted state is an epoch waypoint, which is a commitment to an epoch change ledger info. Most light clients will start here when syncing for the first time.

§

EpochState

Fields

§waypoint: Waypoint

The current trusted version and a commitment to a ledger info inside the current trusted epoch.

§epoch_state: EpochState

The current epoch and validator set inside that epoch.

§accumulator: TransactionAccumulatorSummary

The current verified view of the transaction accumulator. Note that this is not the complete accumulator; rather, it is a summary containing only the frozen subtrees at the currently verified state version. We use the accumulator summary to verify accumulator consistency proofs when applying state proofs.

The current trusted state is inside a verified epoch (which includes the validator set inside that epoch).

Implementations§

§

impl TrustedState

pub fn from_epoch_waypoint(epoch_waypoint: Waypoint) -> TrustedState

Create an initial trusted state from a trusted epoch waypoint constructed from an epoch-change ledger info.

Note: we can’t actually guarantee this waypoint is actually an epoch waypoint, but the sync will always fail to verify it’s not.

pub fn try_from_epoch_change_li( epoch_change_li: &LedgerInfo, accumulator: TransactionAccumulatorSummary ) -> Result<TrustedState, Error>

Try to create a trusted state from an epoch-change ledger info and an accumulator summary at the same version.

Fails if the ledger info is not actually an epoch-change ledger info or if the accumulator summary is not consistent with the ledger info.

pub fn is_epoch_waypoint(&self) -> bool

pub fn version(&self) -> u64

pub fn waypoint(&self) -> Waypoint

pub fn accumulator_root_hash(&self) -> Option<HashValue>

pub fn accumulator_summary(&self) -> Option<&TransactionAccumulatorSummary>

pub fn need_accumulator(&self) -> bool

pub fn verify_and_ratchet<'a>( &self, state_proof: &'a StateProof, initial_accumulator: Option<&'a TransactionAccumulatorSummary> ) -> Result<TrustedStateChange<'a>, Error>

Verify and ratchet forward our trusted state using an EpochChangeProof (that moves us into the latest epoch), a LedgerInfoWithSignatures inside that epoch, and an AccumulatorConsistencyProof from our current version to that last verifiable ledger info.

If our current trusted state doesn’t have an accumulator summary yet (for example, a client may be starting with an epoch waypoint), then an initial accumulator summary must be provided.

For example, a client sends a GetStateProof request to an upstream FullNode and receives some epoch change proof along with a latest ledger info inside the StateProof response. This function verifies the change proof and ratchets the trusted state version forward if the response successfully moves us into a new epoch or a new latest ledger info within our current epoch.

  • If there was a validation error, e.g., the epoch change proof was invalid, we return an Err.

  • If the message was well formed but stale (i.e., the returned latest ledger is behind our trusted version), we also return an Err since stale responses should always be rejected.

  • If the response is fresh and there is no epoch change, we just ratchet our trusted version to the latest ledger info and return Ok(TrustedStateChange::Version { .. }).

  • If there is a new epoch and the server provides a correct proof, we ratchet our trusted version forward, update our verifier to contain the new validator set, and return Ok(TrustedStateChange::Epoch { .. }).

pub fn verify_and_ratchet_inner<'a>( &self, latest_li: &'a LedgerInfoWithSignatures, epoch_change_proof: &'a EpochChangeProof, consistency_proof: &'a AccumulatorConsistencyProof, initial_accumulator: Option<&'a TransactionAccumulatorSummary> ) -> Result<TrustedStateChange<'a>, Error>

Trait Implementations§

§

impl Arbitrary for TrustedState

§

type Parameters = (<Waypoint as Arbitrary>::Parameters, (<Waypoint as Arbitrary>::Parameters, <EpochState as Arbitrary>::Parameters, <TransactionAccumulatorSummary as Arbitrary>::Parameters))

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default.
§

type Strategy = TupleUnion<((u32, Arc<Map<<Waypoint as Arbitrary>::Strategy, fn(_: Waypoint) -> TrustedState>>), (u32, Arc<Map<(<Waypoint as Arbitrary>::Strategy, <EpochState as Arbitrary>::Strategy, <TransactionAccumulatorSummary as Arbitrary>::Strategy), fn(_: (Waypoint, EpochState, TransactionAccumulatorSummary)) -> TrustedState>>))>

The type of Strategy used to generate values of type Self.
§

fn arbitrary_with( _top: <TrustedState as Arbitrary>::Parameters ) -> <TrustedState as Arbitrary>::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args. Read more
§

fn arbitrary() -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). Read more
§

impl Clone for TrustedState

§

fn clone(&self) -> TrustedState

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl CryptoHash for TrustedState

§

type Hasher = TrustedStateHasher

The associated Hasher type which comes with a unique salt for this type.
§

fn hash(&self) -> HashValue

Hashes the object and produces a HashValue.
§

impl Debug for TrustedState

§

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

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for TrustedState

§

fn deserialize<__D>( __deserializer: __D ) -> Result<TrustedState, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl PartialEq<TrustedState> for TrustedState

§

fn eq(&self, other: &TrustedState) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for TrustedState

§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Verifier for TrustedState

§

fn verify(&self, ledger_info: &LedgerInfoWithSignatures) -> Result<(), Error>

Verify if the ledger_info is trust worthy.
§

fn epoch_change_verification_required(&self, epoch: u64) -> bool

Returns true in case the given epoch is larger than the existing verifier can support. In this case the EpochChangeProof should be verified and the verifier updated.
§

fn is_ledger_info_stale(&self, ledger_info: &LedgerInfo) -> bool

Returns true if the given LedgerInfo is stale and probably in our trusted prefix. Read more
§

impl Eq for TrustedState

§

impl StructuralEq for TrustedState

§

impl StructuralPartialEq for TrustedState

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
§

impl<T> TestOnlyHash for Twhere T: Serialize + ?Sized,

§

fn test_only_hash(&self) -> HashValue

Generates a hash used only for tests.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

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
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,