# IBC Connection

## Overview

For a detailed overview, please refer to the [official documentation.](https://ibc.cosmos.network/)

The below diagram depicts the interaction between two Cosmos SDK-based chains, Osmosis and Landslide, through the IBC protocol. The IBC Relayer acts as a mediator between the two chains.

When a message transfer is initiated by Chain A (Osmosis), it generates a packet commitment (hash) and stores it in the KV store by key (port, channel, sequence). Then it emits a packet event and the IBC Relayer handles this event. The IBC Relayer queries for the packet commitment proof from Chain A (Osmosis), which is then returned by Chain A (Osmosis). The IBC Relayer creates a message to relay the packet to Chain B (Landslide).

After receiving the message, Chain B (Landslide) sends back a WriteAck result to the IBC Relayer. The IBC Relayer then queries for the acknowledgement proof from Chain B (Landslide), which is then returned by Chain B (Landslide). The IBC Relayer creates an acknowledgement message containing the packet, acknowledgement, and proofs, which is then sent to Chain A (Osmosis).

{% @mermaid/diagram content="sequenceDiagram

```
participant Chain A (Osmosis)
participant IBC Relayer
participant Chain B (Landslide)
Chain A (Osmosis)->>Chain A (Osmosis): Process MsgTransfer Message
Note left of Chain A (Osmosis): *Create IBC Packet <br>*Generate Packet<br>commitment (hash)<br>* Store Packet commitment<br>in KV Store by key<br>(port, channel, sequence)<br>* Emit Packet Event
```

Chain A (Osmosis)->>IBC Relayer: Handle Packet Event
IBC Relayer->>Chain A (Osmosis): Query Packet Commitment Proof
Chain A (Osmosis)-->>IBC Relayer: Returns Proof
Note over IBC Relayer: Create MsgRecvPacket<br/>with packet and proofs
IBC Relayer->>Chain B (Landslide): Relay Message
Chain B (Landslide)-->>IBC Relayer: Get WriteAck result
IBC Relayer->>Chain B (Landslide): Query Acknowledgement Proof
Chain B (Landslide)-->>IBC Relayer: Returns Proof
Note over IBC Relayer: Create MsgAcknowledgement<br/>with packet, ack, and proofs
IBC Relayer->>Chain A (Osmosis): Send Ack message
" %}

A more detailed view

{% @mermaid/diagram content="sequenceDiagram

participant Chain A
participant Relayer
participant Chain B

opt Setup Clients
Relayer->>Chain A: Create Client
Chain A-->>Relayer: Returns ClientID
Relayer->>Chain B: Create Client
Chain B-->>Relayer: Returns ClientID
end

opt Create Connections
Relayer->>Chain A: Calls ConnectionOpenInit
Chain A-->>Relayer: Returns ConnectionID
opt Query Proofs
Relayer->>Chain A: Query proof for the client state at latest height
Chain A-->>Relayer: Returns ProofClient and ProofHeight by ClientID
Relayer->>Chain A: Query proof for the consensus state at ProofHeight
Chain A-->>Relayer: Returns ProofConsensus
Relayer->>Chain A: Query proof for the connection at ProofHeight
Chain A-->>Relayer: Returns ProofConnection
end
note right of Relayer: with ProofClient, ProofConsensus, ProofConnection
Relayer->>Chain B: Calls ConnectionOpenTry
Chain B-->>Relayer: Returns ConnectionID
opt Query Proofs
Relayer->>Chain B: Query proof for the client state at latest height
Chain B-->>Relayer: Returns ProofClient and ProofHeight by ClientID
Relayer->>Chain B: Query proof for the consensus state at ProofHeight
Chain B-->>Relayer: Returns ProofConsensus
Relayer->>Chain B: Query proof for the connection at ProofHeight
Chain B-->>Relayer: Returns ProofConnection
end
note left of Relayer: with ProofClient, ProofConsensus, ProofConnection
Relayer->>Chain A: Calls ConnectionOpenAck
opt Query Proofs
Relayer->>Chain B: Query proof for the connection at latest height
Chain B-->>Relayer: Returns ProofConnection and ProofHeight
end
Relayer->>Chain B: Calls ConnectionOpenConfirm
Relayer->>Chain A: Update Client
end

opt Setup Channels
Relayer->>Chain A: Calls ChannelOpenInit
Chain A-->>Relayer: Returns ChannelID
opt Query Proofs
Relayer->>Chain A: Query channel proof
Chain A-->>Relayer: Returns proof and height
end
note right of Relayer: with ChannelProof
Relayer->>Chain B: Calls ChannelOpenTry
Chain B-->>Relayer: Returns ChannelID
opt Query Proofs
Relayer->>Chain B: Query channel proof
Chain B-->>Relayer: Returns proof and height
end
note left of Relayer: with ChannelProof
Relayer->>Chain A: Calls ChannelOpenAck
opt Query Proofs
Relayer->>Chain A: Query channel proof
Chain A-->>Relayer: Returns proof and height
end
note right of Relayer: with ChannelProof
Relayer->>Chain B: Calls ChannelOpenConfirm
end
" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.landslide.network/product-guides/ibc-light-client/ibc-connection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
