Enum diem_sdk::types::trusted_state::TrustedState
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
impl TrustedState
pub fn from_epoch_waypoint(epoch_waypoint: Waypoint) -> 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>
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>
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
impl Arbitrary for TrustedState
§type Parameters = (<Waypoint as Arbitrary>::Parameters, (<Waypoint as Arbitrary>::Parameters, <EpochState as Arbitrary>::Parameters, <TransactionAccumulatorSummary as Arbitrary>::Parameters))
type Parameters = (<Waypoint as Arbitrary>::Parameters, (<Waypoint as Arbitrary>::Parameters, <EpochState as Arbitrary>::Parameters, <TransactionAccumulatorSummary as Arbitrary>::Parameters))
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>>))>
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>>))>
Strategy
used to generate values of type Self
.§fn arbitrary_with(
_top: <TrustedState as Arbitrary>::Parameters
) -> <TrustedState as Arbitrary>::Strategy
fn arbitrary_with( _top: <TrustedState as Arbitrary>::Parameters ) -> <TrustedState as Arbitrary>::Strategy
§impl Clone for TrustedState
impl Clone for TrustedState
§fn clone(&self) -> TrustedState
fn clone(&self) -> TrustedState
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl CryptoHash for TrustedState
impl CryptoHash for TrustedState
§impl Debug for TrustedState
impl Debug for TrustedState
§impl<'de> Deserialize<'de> for TrustedState
impl<'de> Deserialize<'de> for TrustedState
§fn deserialize<__D>(
__deserializer: __D
) -> Result<TrustedState, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>( __deserializer: __D ) -> Result<TrustedState, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,
§impl PartialEq<TrustedState> for TrustedState
impl PartialEq<TrustedState> for TrustedState
§fn eq(&self, other: &TrustedState) -> bool
fn eq(&self, other: &TrustedState) -> bool
self
and other
values to be equal, and is used
by ==
.§impl Serialize for TrustedState
impl Serialize for TrustedState
§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,
§impl Verifier for TrustedState
impl Verifier for TrustedState
§fn verify(&self, ledger_info: &LedgerInfoWithSignatures) -> Result<(), Error>
fn verify(&self, ledger_info: &LedgerInfoWithSignatures) -> Result<(), Error>
§fn epoch_change_verification_required(&self, epoch: u64) -> bool
fn epoch_change_verification_required(&self, epoch: u64) -> bool
§fn is_ledger_info_stale(&self, ledger_info: &LedgerInfo) -> bool
fn is_ledger_info_stale(&self, ledger_info: &LedgerInfo) -> bool
LedgerInfo
is stale and probably in our
trusted prefix. Read moreimpl 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§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.