The packet
A packet is one unit of information a relayer carries from one chain to another. It holds what an application wants to send, together with the routing information IBC needs to deliver it and verify it.sequence: the packet’s number on its source client. It comes from a counter that starts at 1 and increments by one with every send, so both chains can refer to the same packet.sourceClientanddestClient: the two ends of the route.sourceClientis the source chain’s light client of the destination;destClientis the destination chain’s client of the source.timeoutTimestamp: the deadline in unix seconds, after which the packet can no longer be received. The timestamp represents the destination chain’s block time, and a relayer times it out on the source chain. On send the router requires it to be in the future and no more than one day out.payloads: the application’s content.
The payload
A payload is an application’s message as raw bytes, plus information naming the application at each end and saying how to read those bytes.sourcePortanddestPort: the ports of the sending and the receiving application.version: the version of the application protocol thatvaluefollows.encoding: the format the value bytes are written in.value: the message itself, opaque to IBC, the way a network carries a TCP payload without reading it.
value but never interprets it. The application registered on destPort is what gives those bytes their meaning.
An application also decides which versions and encodings it answers to.
Applications
Applications are the business logic that give meaning to packets. They are the logic at each end of an IBC connection that wants to communicate. An application owns thevalue field of the payload: what goes in, how it is encoded, and what happens at each step of the packet’s life. IBC core delivers packets but never interprets them, so the application is responsible for the meaning.
Sending an IBC packet begins inside the application. An application runs its own logic, then hands the router a send message with its source client, a timeout, and its payload.
Sending a packet
An application does not build a full packet. It submits a smaller message to the router on the source chain and the router completes the rest.destClient from the source client’s counterparty, assigns the next sequence, assembles the Packet, and commits it. The application owns its data and the route it wants; the router owns sequence numbering and the destination side of the route.
Ports and registration
An application is registered with the IBC router on its chain, under a port. Each port identifies one application, and ports are how the router knows which application a packet is for and how to route it. A port is either the application’s own address as a hex string or a readable name like GMP’sgmpport. The access manager decides who may register each kind. Once registered, the port identifier remains with that application permanently.
Every payload names two ports:
destPortsays which application the payload is for.sourcePortsays who sent it, and only the application registered there may send on it.
Application callbacks
Applications can register callbacks that the router executes at different stages of the packet lifecycle.onRecvPacketruns on the destination chain when a packet arrives. The application decodes the payload, acts on it, and returns an acknowledgement. If it reverts with a reason, the router writes a universal error acknowledgement in its place and the packet still settles. If it reverts with no reason (like running out of gas), the whole receive fails and the packet stays undelivered.onAcknowledgementPacketruns on the source chain once the destination’s acknowledgement is proven. The application reads the result and settles accordingly.onTimeoutPacketruns on the source chain when a packet’s deadline passes without delivery. The application releases or reverses whatever it staged on send, or tells the sender so it can.
- Sending: encode
valueand set the version and encoding. - On receipt: validate the version and encoding, decode
value, act, and return an acknowledgement. - On the return leg: handle either the acknowledgement or the timeout of the packet.