Enum diem_types::trusted_state::TrustedState [−][src]
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.
Tuple Fields of EpochWaypoint
0: Waypoint
The current trusted state is inside a verified epoch (which includes the validator set inside that epoch).
Fields of EpochState
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.
Implementations
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<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 verify_and_ratchet<'a>(
&self,
state_proof: &'a StateProof,
initial_accumulator: Option<&'a TransactionAccumulatorSummary>
) -> Result<TrustedStateChange<'a>>
pub fn verify_and_ratchet<'a>(
&self,
state_proof: &'a StateProof,
initial_accumulator: Option<&'a TransactionAccumulatorSummary>
) -> 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 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>>
Trait Implementations
type Hasher = TrustedStateHasher
type Hasher = TrustedStateHasher
The associated Hasher
type which comes with a unique salt for this type.
fn 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
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Verify if the ledger_info is trust worthy.
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
Returns true if the given LedgerInfo
is stale and probably in our
trusted prefix. Read more
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
Mutably borrows from an owned value. Read more
Generates a hash used only for tests.