-
Notifications
You must be signed in to change notification settings - Fork 332
/
light_client.rs
54 lines (45 loc) · 1.75 KB
/
light_client.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use ibc::core::ics02_client::client_state::AnyClientState;
use ibc::core::ics02_client::misbehaviour::MisbehaviourEvidence;
use crate::chain::ChainEndpoint;
use crate::error;
use ibc::core::ics02_client::events::UpdateClient;
pub mod tendermint;
#[cfg(test)]
pub mod mock;
/// Defines a light block from the point of view of the relayer.
pub trait LightBlock<C: ChainEndpoint>: Send + Sync {
fn signed_header(&self) -> &C::Header;
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Verified<H> {
/// Verified target
pub target: H,
/// Supporting headers needed to verify `target`
pub supporting: Vec<H>,
}
/// Defines a client from the point of view of the relayer.
pub trait LightClient<C: ChainEndpoint>: Send + Sync {
/// Fetch and verify a header, and return its minimal supporting set.
fn header_and_minimal_set(
&mut self,
trusted: ibc::Height,
target: ibc::Height,
client_state: &AnyClientState,
) -> Result<Verified<C::Header>, error::Error>;
/// Fetch a header from the chain at the given height and verify it.
fn verify(
&mut self,
trusted: ibc::Height,
target: ibc::Height,
client_state: &AnyClientState,
) -> Result<Verified<C::LightBlock>, error::Error>;
/// Given a client update event that includes the header used in a client update,
/// look for misbehaviour by fetching a header at same or latest height.
fn check_misbehaviour(
&mut self,
update: UpdateClient,
client_state: &AnyClientState,
) -> Result<Option<MisbehaviourEvidence>, error::Error>;
/// Fetch a header from the chain at the given height, without verifying it
fn fetch(&mut self, height: ibc::Height) -> Result<C::LightBlock, error::Error>;
}