Struct tendermint_light_client::light_client::LightClient
source · pub struct LightClient {
pub peer: PeerId,
pub options: Options,
/* private fields */
}Expand description
The light client implements a read operation of a header from the blockchain, by communicating with full nodes. As full nodes may be faulty, it cannot trust the received information, but the light client has to check whether the header it receives coincides with the one generated by Tendermint consensus.
In the Tendermint blockchain, the validator set may change with every new block. The staking and unbonding mechanism induces a security model: starting at time of the header, more than two-thirds of the next validators of a new block are correct for the duration of the trusted period. The fault-tolerant read operation is designed for this security model.
Fields§
§peer: PeerIdThe peer id of the peer this client is connected to
options: OptionsOptions for this light client
Implementations§
source§impl LightClient
impl LightClient
sourcepub fn new(
peer: PeerId,
options: Options,
clock: impl Clock + 'static,
scheduler: impl Scheduler + 'static,
verifier: impl Verifier + 'static,
io: impl Io + 'static
) -> Self
pub fn new( peer: PeerId, options: Options, clock: impl Clock + 'static, scheduler: impl Scheduler + 'static, verifier: impl Verifier + 'static, io: impl Io + 'static ) -> Self
Constructs a new light client
sourcepub fn from_boxed(
peer: PeerId,
options: Options,
clock: Box<dyn Clock>,
scheduler: Box<dyn Scheduler>,
verifier: Box<dyn Verifier>,
io: Box<dyn Io>
) -> Self
pub fn from_boxed( peer: PeerId, options: Options, clock: Box<dyn Clock>, scheduler: Box<dyn Scheduler>, verifier: Box<dyn Verifier>, io: Box<dyn Io> ) -> Self
Constructs a new light client from boxed components
sourcepub fn verify_to_highest(
&mut self,
state: &mut State
) -> Result<LightBlock, Error>
pub fn verify_to_highest( &mut self, state: &mut State ) -> Result<LightBlock, Error>
Attempt to update the light client to the highest block of the primary node.
Note: This function delegates the actual work to verify_to_target.
sourcepub fn verify_to_target(
&self,
target_height: Height,
state: &mut State
) -> Result<LightBlock, Error>
pub fn verify_to_target( &self, target_height: Height, state: &mut State ) -> Result<LightBlock, Error>
Update the light client to a block of the primary node at the given height.
This is the main function and uses the following components:
- The I/O component is called to fetch the next light block. It is the only component that communicates with other nodes.
- The Verifier component checks whether a header is valid and checks if a new light block should be trusted based on a previously verified light block.
- When doing forward verification, the Scheduler component decides which height to try to verify next, in case the current block pass verification but cannot be trusted yet.
- When doing backward verification, the Hasher component is used to determine whether the
last_block_idhash of a block matches the hash of the block right below it.
Implements
- [LCV-DIST-SAFE.1]
- [LCV-DIST-LIFE.1]
- [LCV-PRE-TP.1]
- [LCV-POST-LS.1]
- [LCV-INV-TP.1]
Postcondition
- The light store contains a light block that corresponds to a block of the blockchain of
height
target_height[LCV-POST-LS.1]
Error conditions
- The light store does not contains a trusted light block within the trusting period [LCV-PRE-TP.1]
- If the core verification loop invariant is violated [LCV-INV-TP.1]
- If verification of a light block fails
- If the fetching a light block from the primary node fails
Contracts
Post-condition: ret.is_ok() -> trusted_store_contains_block_at_target_height(state.light_store.as_ref(), target_height,)
sourcepub fn get_or_fetch_block(
&self,
height: Height,
state: &mut State
) -> Result<(LightBlock, Status), Error>
pub fn get_or_fetch_block( &self, height: Height, state: &mut State ) -> Result<(LightBlock, Status), Error>
Look in the light store for a block from the given peer at the given height,
which has not previously failed verification (ie. its status is not Failed).
If one cannot be found, fetch the block from the given peer and store
it in the light store with Unverified status.
Postcondition
- The provider of block that is returned matches the given peer.
Contracts
Post-condition: ret.as_ref().map(| (lb, _) | lb.provider == self.peer).unwrap_or(true)
sourcepub fn get_target_block_or_latest(
&mut self,
height: Height,
state: &mut State
) -> Result<TargetOrLatest, Error>
pub fn get_target_block_or_latest( &mut self, height: Height, state: &mut State ) -> Result<TargetOrLatest, Error>
Get the block at the given height or the latest block from the chain if the given height is lower than the latest height.