Enum aptos_types::trusted_state::TrustedState
source · [−]pub enum TrustedState {
EpochWaypoint(Waypoint),
EpochState {
waypoint: Waypoint,
epoch_state: EpochState,
},
}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: WaypointThe current trusted version and a commitment to a ledger info inside the current trusted epoch.
epoch_state: EpochStateThe current epoch and validator set inside that epoch.
The current trusted state is inside a verified epoch (which includes the validator set inside that epoch).
Implementations
sourceimpl TrustedState
impl TrustedState
sourcepub fn from_epoch_waypoint(epoch_waypoint: Waypoint) -> Self
pub fn from_epoch_waypoint(epoch_waypoint: Waypoint) -> Self
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.
sourcepub fn try_from_epoch_change_li(
epoch_change_li: &LedgerInfo,
accumulator: TransactionAccumulatorSummary
) -> Result<Self>
pub fn try_from_epoch_change_li(
epoch_change_li: &LedgerInfo,
accumulator: TransactionAccumulatorSummary
) -> Result<Self>
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) -> Version
pub fn waypoint(&self) -> Waypoint
sourcepub fn verify_and_ratchet<'a>(
&self,
state_proof: &'a StateProof
) -> Result<TrustedStateChange<'a>>
pub fn verify_and_ratchet<'a>(
&self,
state_proof: &'a StateProof
) -> Result<TrustedStateChange<'a>>
Verify and ratchet forward our trusted state using an EpochChangeProof
(that moves us into the latest epoch), a LedgerInfoWithSignatures
inside that epoch, and an crate::proof::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
Errsince 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
) -> Result<TrustedStateChange<'a>>
Trait Implementations
sourceimpl Clone for TrustedState
impl Clone for TrustedState
sourcefn clone(&self) -> TrustedState
fn clone(&self) -> TrustedState
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl CryptoHash for TrustedState
impl CryptoHash for TrustedState
type Hasher = TrustedStateHasher
type Hasher = TrustedStateHasher
The associated Hasher type which comes with a unique salt for this type.
sourceimpl Debug for TrustedState
impl Debug for TrustedState
sourceimpl<'de> Deserialize<'de> for TrustedState
impl<'de> Deserialize<'de> for TrustedState
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl PartialEq<TrustedState> for TrustedState
impl PartialEq<TrustedState> for TrustedState
sourcefn eq(&self, other: &TrustedState) -> bool
fn eq(&self, other: &TrustedState) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &TrustedState) -> bool
fn ne(&self, other: &TrustedState) -> bool
This method tests for !=.
sourceimpl Serialize for TrustedState
impl Serialize for TrustedState
sourceimpl Verifier for TrustedState
impl Verifier for TrustedState
sourcefn verify(&self, ledger_info: &LedgerInfoWithSignatures) -> Result<()>
fn verify(&self, ledger_info: &LedgerInfoWithSignatures) -> Result<()>
Verify if the ledger_info is trust worthy.
sourcefn epoch_change_verification_required(&self, epoch: u64) -> bool
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. Read more
sourcefn is_ledger_info_stale(&self, ledger_info: &LedgerInfo) -> bool
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
impl RefUnwindSafe for TrustedState
impl Send for TrustedState
impl Sync for TrustedState
impl Unpin for TrustedState
impl UnwindSafe for TrustedState
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key and return true if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> TestOnlyHash for T where
T: Serialize + ?Sized,
impl<T> TestOnlyHash for T where
T: Serialize + ?Sized,
sourcefn test_only_hash(&self) -> HashValue
fn test_only_hash(&self) -> HashValue
Generates a hash used only for tests.
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more