Struct ibc_relayer::foreign_client::ForeignClient
source · [−]pub struct ForeignClient<DstChain: ChainHandle, SrcChain: ChainHandle> {
pub id: ClientId,
pub dst_chain: DstChain,
pub src_chain: SrcChain,
}Fields
id: ClientIdThe identifier of this client. The host chain determines this id upon client creation, so we may be using the default value temporarily.
dst_chain: DstChainA handle to the chain hosting this client, i.e., destination chain.
src_chain: SrcChainA handle to the chain whose headers this client is verifying, aka the source chain.
Implementations
sourceimpl<DstChain: ChainHandle, SrcChain: ChainHandle> ForeignClient<DstChain, SrcChain>
impl<DstChain: ChainHandle, SrcChain: ChainHandle> ForeignClient<DstChain, SrcChain>
sourcepub fn new(
dst_chain: DstChain,
src_chain: SrcChain
) -> Result<ForeignClient<DstChain, SrcChain>, ForeignClientError>
pub fn new(
dst_chain: DstChain,
src_chain: SrcChain
) -> Result<ForeignClient<DstChain, SrcChain>, ForeignClientError>
Creates a new foreign client on dst_chain. Blocks until the client is created, or
an error occurs.
Post-condition: dst_chain hosts an IBC client for src_chain.
pub fn restore(
id: ClientId,
dst_chain: DstChain,
src_chain: SrcChain
) -> ForeignClient<DstChain, SrcChain>
sourcepub fn find(
expected_target_chain: SrcChain,
host_chain: DstChain,
client_id: &ClientId
) -> Result<ForeignClient<DstChain, SrcChain>, ForeignClientError>
pub fn find(
expected_target_chain: SrcChain,
host_chain: DstChain,
client_id: &ClientId
) -> Result<ForeignClient<DstChain, SrcChain>, ForeignClientError>
Queries host_chain to verify that a client with identifier client_id exists.
If the client does not exist, returns an error. If the client exists, cross-checks that the
identifier for the target chain of this client (i.e., the chain whose headers this client is
verifying) is consistent with expected_target_chain, and if so, return a new
ForeignClient representing this client.
pub fn upgrade(&self) -> Result<Vec<IbcEvent>, ForeignClientError>
sourcepub fn src_chain(&self) -> SrcChain
pub fn src_chain(&self) -> SrcChain
Returns a handle to the chain whose headers this client is sourcing (the source chain).
pub fn id(&self) -> &ClientId
sourcepub fn build_create_client(
&self,
options: CreateOptions
) -> Result<MsgCreateAnyClient, ForeignClientError>
pub fn build_create_client(
&self,
options: CreateOptions
) -> Result<MsgCreateAnyClient, ForeignClientError>
Lower-level interface for preparing a message to create a client.
sourcepub fn build_create_client_and_send(
&self,
options: CreateOptions
) -> Result<IbcEvent, ForeignClientError>
pub fn build_create_client_and_send(
&self,
options: CreateOptions
) -> Result<IbcEvent, ForeignClientError>
Returns the identifier of the newly created client.
pub fn validated_client_state(
&self
) -> Result<(AnyClientState, Option<Duration>), ForeignClientError>
pub fn is_expired_or_frozen(&self) -> bool
pub fn refresh(&mut self) -> Result<Option<Vec<IbcEvent>>, ForeignClientError>
sourcepub fn build_update_client(
&self,
target_height: Height
) -> Result<Vec<Any>, ForeignClientError>
pub fn build_update_client(
&self,
target_height: Height
) -> Result<Vec<Any>, ForeignClientError>
Wrapper for build_update_client_with_trusted.
sourcepub fn build_update_client_with_trusted(
&self,
target_height: Height,
trusted_height: Height
) -> Result<Vec<Any>, ForeignClientError>
pub fn build_update_client_with_trusted(
&self,
target_height: Height,
trusted_height: Height
) -> Result<Vec<Any>, ForeignClientError>
Returns a vector with a message for updating the client to height target_height.
If the client already stores a consensus state for this height, returns an empty vector.
pub fn build_latest_update_client_and_send(
&self
) -> Result<Vec<IbcEvent>, ForeignClientError>
pub fn build_update_client_and_send(
&self,
height: Height,
trusted_height: Height
) -> Result<Vec<IbcEvent>, ForeignClientError>
sourcepub fn update(&self) -> Result<(), ForeignClientError>
pub fn update(&self) -> Result<(), ForeignClientError>
Attempts to update a client using header from the latest height of its source chain.
sourcepub fn update_client_event(
&self,
consensus_height: Height
) -> Result<Option<UpdateClient>, ForeignClientError>
pub fn update_client_event(
&self,
consensus_height: Height
) -> Result<Option<UpdateClient>, ForeignClientError>
Retrieves the client update event that was emitted when a consensus state at the specified height was created on chain. It is possible that the event cannot be retrieved if the information is not yet available on the full node. To handle this the query is retried a few times.
sourcepub fn detect_misbehaviour(
&self,
update: Option<UpdateClient>
) -> Result<Option<MisbehaviourEvidence>, ForeignClientError>
pub fn detect_misbehaviour(
&self,
update: Option<UpdateClient>
) -> Result<Option<MisbehaviourEvidence>, ForeignClientError>
Checks for evidence of misbehaviour.
The check starts with and update_event emitted by chain B (dst_chain) for a client update
with a header from chain A (src_chain). The algorithm goes backwards through the headers
until it gets to the first misbehaviour.
The following cases are covered:
1 - fork:
Assumes at least one consensus state before the fork point exists.
Let existing consensus states on chain B be: [Sn,.., Sf, Sf-1, S0] with Sf-1 being
the most recent state before fork.
Chain A is queried for a header Hf' at Sf.height and if it is different than the Hf
in the event for the client update (the one that has generated Sf on chain), then the two
headers are included in the evidence and submitted.
Note that in this case the headers are different but have the same height.
2 - BFT time violation for unavailable header (a.k.a. Future Lunatic Attack or FLA):
Some header with a height that is higher than the latest
height on A has been accepted and a consensus state was created on B. Note that this implies
that the timestamp of this header must be within the clock_drift of the client.
Assume the client on B has been updated with h2(not present on/ produced by chain A)
and it has a timestamp of t2 that is at most clock_drift in the future.
Then the latest header from A is fetched, let it be h1, with a timestamp of t1.
If t1 >= t2 then evidence of misbehavior is submitted to A.
3 - BFT time violation for existing headers (TODO): Ensure that consensus state times are monotonically increasing with height.
Other notes:
- the algorithm builds misbehavior at each consensus height, starting with the highest height assuming the previous one is trusted. It submits the first constructed evidence (the one with the highest height)
- a lot of the logic here is derived from the behavior of the only implemented client (ics07-tendermint) and might not be general enough.
pub fn detect_misbehaviour_and_submit_evidence(
&self,
update_event: Option<UpdateClient>
) -> MisbehaviourResults
pub fn map_chain<DstChain2: ChainHandle, SrcChain2: ChainHandle>(
self,
map_dst: impl Fn(DstChain) -> DstChain2,
map_src: impl Fn(SrcChain) -> SrcChain2
) -> ForeignClient<DstChain2, SrcChain2>
Trait Implementations
sourceimpl<DstChain: Clone + ChainHandle, SrcChain: Clone + ChainHandle> Clone for ForeignClient<DstChain, SrcChain>
impl<DstChain: Clone + ChainHandle, SrcChain: Clone + ChainHandle> Clone for ForeignClient<DstChain, SrcChain>
sourcefn clone(&self) -> ForeignClient<DstChain, SrcChain>
fn clone(&self) -> ForeignClient<DstChain, SrcChain>
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<DstChain: Debug + ChainHandle, SrcChain: Debug + ChainHandle> Debug for ForeignClient<DstChain, SrcChain>
impl<DstChain: Debug + ChainHandle, SrcChain: Debug + ChainHandle> Debug for ForeignClient<DstChain, SrcChain>
sourceimpl<DstChain: ChainHandle, SrcChain: ChainHandle> Display for ForeignClient<DstChain, SrcChain>
impl<DstChain: ChainHandle, SrcChain: ChainHandle> Display for ForeignClient<DstChain, SrcChain>
Used in Output messages.
Provides a concise description of a ForeignClient,
using the format:
{CHAIN-ID} -> {CHAIN-ID}:{CLIENT}
where the first chain identifier is for the source
chain, and the second chain identifier is the
destination (which hosts the client) chain.
Auto Trait Implementations
impl<DstChain, SrcChain> RefUnwindSafe for ForeignClient<DstChain, SrcChain> where
DstChain: RefUnwindSafe,
SrcChain: RefUnwindSafe,
impl<DstChain, SrcChain> Send for ForeignClient<DstChain, SrcChain>
impl<DstChain, SrcChain> Sync for ForeignClient<DstChain, SrcChain>
impl<DstChain, SrcChain> Unpin for ForeignClient<DstChain, SrcChain> where
DstChain: Unpin,
SrcChain: Unpin,
impl<DstChain, SrcChain> UnwindSafe for ForeignClient<DstChain, SrcChain> where
DstChain: UnwindSafe,
SrcChain: UnwindSafe,
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
impl<T> FutureExt for T
impl<T> FutureExt for T
fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message T in a tonic::Request
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more
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