Introducing a new way to review your PRs.

Read the announcement

lfdt-ibc / ibc-go

Inter-Blockchain Communication Protocol (IBC) implementation in Golang.

View on GitHub

20 documents · Updated Nov 13, 2026

docs / channel-and-packet-lifecycle

Channel and packet lifecycle

The IBC transport layer creates a verified path between application modules on different chains. It opens paired channel ends, moves packets with proof-backed delivery, records acknowledgements, and recovers packets that cannot arrive. The layer supports the channel-based IBC v1 path and the client-based IBC v2 packet path.

Transport model

Channel ends

An IBC v1 channel is a pair of stateful channel ends. Each end binds an application port, its counterparty port and channel, one connection hop, an application version, and an ordering mode. Only an OPEN end can carry packets. The channel layer checks transport rules but leaves packet meaning and application state to the module behind the port.

Channel stateMeaning
INITOne chain has started the opening handshake.
TRYOPENThe other chain has proved the first opening step.
OPENThe channel can carry packets.
CLOSEDThe channel cannot carry new packets and cannot reopen.

References: modules/…/channel.pb.go• L103-117 modules/…/channel.go• L27-45 modules/…/doc.go• L3-17

Application boundary

The port router maps a port to an application callback set. Core IBC verifies channel and packet facts before it calls those callbacks. Applications use the ICS4 wrapper to send packets and write acknowledgements so middleware can inspect the traffic.

The main callback boundary has these responsibilities:

  • Channel callbacks check application parameters and choose a compatible version.
  • OnRecvPacket processes packet data and returns a success, error, or asynchronous acknowledgement.
  • OnAcknowledgementPacket finishes source-side state after the destination result is proved.
  • OnTimeoutPacket restores or releases source-side state after a timeout is proved.

References: modules/…/module.go• L13-18 modules/…/module.go• L26-117 modules/…/keeper.go• L33-48

Transport variants

IBC v1 identifies a packet by source and destination port-channel pairs. IBC v2 identifies a packet by source and destination client IDs and can carry several application payloads in one packet. An unordered v1 channel can provide a v2 client alias after it opens; an ordered channel cannot use that alias path.

PathDelivery identityTimeoutApplication unit
IBC v1Port, channel, and sequenceHeight, timestamp, or bothOne opaque data value
IBC v2Client IDs and sequenceTimestampOne or more typed payloads

References: modules/…/packet.go• L49-121 modules/…/packet.go• L14-89 modules/…/handshake.go• L225-258 modules/…/handshake.go• L313-343

Channel negotiation

Open handshake

The v1 channel open flow is a four-step proof exchange over an existing open connection. Each step verifies the remote channel state through the connection and its client. The application callback then checks module-specific rules and selects the version used by both ends.

The sequence below shows the state changes and proof direction.

sequenceDiagram
    participant A as Chain A
    participant B as Chain B
    A->>A: OpenInit: store INIT after callback
    A-->>B: OpenTry + proof of INIT
    B->>B: Verify proof and store TRYOPEN after callback
    B-->>A: OpenAck + proof of TRYOPEN
    A->>A: Verify proof and store OPEN
    A-->>B: OpenConfirm + proof of OPEN
    B->>B: Verify proof and store OPEN

The connection must be open and its client must be active. The negotiated ordering mode and opaque application version remain part of the channel identity. On successful open acknowledgement or confirmation, an unordered v1 channel also records the information needed to use its channel ID as a v2 client alias.

References: modules/…/handshake.go• L19-59 modules/…/handshake.go• L88-151 modules/…/handshake.go• L181-223 modules/…/handshake.go• L267-343 modules/…/msg_server.go• L212-355

Close handshake

Channel close is a two-step final exchange. Either application first accepts a close request, then its chain stores CLOSED; the counterparty proves that state and closes its own end. A closed channel cannot reopen, but a source can use timeout-on-close to recover a packet that the counterparty could not receive.

References: modules/…/handshake.go• L350-451 modules/…/msg_server.go• L358-409 modules/…/module.go• L71-81

Packet lifecycle

V1 packet send

An application sends a v1 packet through ICS4. Core IBC assigns the next send sequence, fills in the counterparty identifiers, checks the open channel and active client, checks the packet and timeout, and stores a commitment. The send event gives a relayer the information needed to submit the packet on the other chain.

The source commitment binds the timeout height, timeout timestamp, and data hash. This prevents a relayer from changing packet fields while reusing the source evidence.

flowchart LR
    App[Source application] --> Wrapper[ICS4 wrapper]
    Wrapper --> Checks[Channel, client, packet, and timeout checks]
    Checks --> State[Sequence advance + packet commitment]
    State --> Event[Send event]
    Event --> Relayer[Relayer]

References: modules/…/module.go• L120-142 modules/…/packet.go• L19-107 modules/…/packet.go• L19-47 modules/…/events.go• L124-149

V2 packet send

An IBC v2 send uses a source client ID and a destination found from the stored counterparty relation. The packet contains a timestamp deadline and one or more payloads. Core IBC validates the payload set, active client, deadline range, and client time before it advances the send sequence and stores a v2 commitment.

The v2 commitment binds the destination client, timestamp, and every payload. Each payload keeps its source and destination port, version, encoding, and value. The application receives a send callback for each payload after the commitment is stored.

References: modules/…/packet.go• L21-103 modules/…/msg_server.go• L22-47 modules/…/commitment.go• L11-52 modules/…/packet.go• L14-68

V1 packet receive

The destination accepts a v1 packet only when its channel is open, the source identifiers match the configured counterparty, the connection is open, the packet is not timed out, and a proof matches the source commitment. After those checks, replay protection records receipt before the application callback runs.

Unordered channels store one receipt per sequence. Ordered channels require the packet to equal the next receive sequence. The message handler uses a cached context so transport state is committed only after verification succeeds. A duplicate relay returns a no-op and does not call the application again.

References: modules/…/packet.go• L110-190 modules/…/packet.go• L192-264 modules/…/msg_server.go• L412-473

V2 packet receive

The v2 destination checks that the packet client IDs are counterparties, checks the timestamp, and verifies membership of the source commitment at the proof height. A receipt then marks the sequence as delivered. The router calls one destination application callback for each payload.

The v2 handler combines the callback results into one acknowledgement. A failed payload produces one shared error acknowledgement and discards application state from the receive batch. A successful packet needs one acknowledgement per payload. An asynchronous receive is limited to one payload and keeps the packet until the application writes its acknowledgement.

References: modules/…/packet.go• L105-175 modules/…/msg_server.go• L49-151 modules/…/acknowledgement.go• L21-63 modules/…/keeper.go• L169-199

Acknowledgement lifecycle

Acknowledgement write

An acknowledgement is the destination application's result for a received packet. Core IBC stores a hash rather than trusting the relayer's acknowledgement bytes. A synchronous receive writes this result during packet handling; an asynchronous application writes it later through ICS4 in v1 or through the saved packet flow in v2.

The acknowledgement can report success or failure. A packet receipt must already exist, and only one acknowledgement can be written for a packet. The write event tells a relayer that the result is ready to return to the source.

References: modules/…/packet.go• L266-335 modules/…/packet.go• L178-252 modules/…/events.go• L178-203

Acknowledgement relay

The source accepts an acknowledgement only when the packet commitment still matches the submitted packet and a proof matches the destination acknowledgement hash. For v1, core IBC also checks the canonical bytes of its own acknowledgement form while leaving application-defined bytes opaque. For v2, the proof commits to the combined acknowledgement values.

After verification, the source removes the packet commitment. An ordered v1 channel advances its next acknowledgement sequence and rejects later acknowledgements until earlier ones complete. The source application then receives OnAcknowledgementPacket for its final state change. A repeated relay is a no-op.

References: modules/…/packet.go• L338-463 modules/…/packet.go• L255-311 modules/…/msg_server.go• L576-623 modules/…/msg_server.go• L154-204

Timeout recovery

V1 timeout

A v1 timeout proves that a packet can no longer be received. The source checks that the deadline passed at the counterparty proof height and that the packet commitment still matches. It then proves non-receipt: an unordered channel needs receipt absence, while an ordered channel needs a next-receive sequence that has not passed the packet.

Timeout-on-close uses the same non-receipt proof and instead proves that the counterparty channel is closed. It can run before the packet deadline. After either path succeeds, core IBC deletes the packet commitment and calls OnTimeoutPacket. A timeout on an ordered channel closes the source channel because later packets cannot keep ordered delivery valid.

References: modules/…/timeout.go• L19-156 modules/…/timeout.go• L159-263 modules/…/msg_server.go• L476-573

V2 timeout

An IBC v2 timeout checks the counterparty timestamp at the proof height and verifies non-membership of the destination receipt. It also checks the source commitment before deleting it. The source then calls OnTimeoutPacket once for each payload.

References: modules/…/packet.go• L314-398 modules/…/msg_server.go• L207-248

Ordering and commitment state

Ordering and replay

Ordering determines which state proves that a packet was received. Unordered v1 channels keep independent receipts, so packets can arrive in any order. Ordered v1 channels keep one next-receive sequence and reject a packet that is not the next value. They also keep one next-acknowledgement sequence and require acknowledgements in send order. V2 packet handling uses receipt presence for replay protection rather than the v1 ordered-channel state.

The v1 receive-start sequence marks the first valid receive sequence after a channel upgrade. Packets below that boundary are rejected, which prevents old proofs from replaying an earlier channel lifecycle.

References: modules/…/packet.go• L192-264 modules/…/packet.go• L421-447 modules/…/keeper.go• L185-230 modules/…/keeper.go• L598-623 modules/…/packet.go• L135-143

Commitment records

Commitments are the cross-chain evidence that connects each packet stage. The source commitment remains while a packet is in flight. The destination receipt blocks a second receive. The destination acknowledgement hash lets the source verify the result. A packet ends when its commitment is removed by acknowledgement or timeout.

RecordLifecycle role
Next send sequenceNames the next packet and advances after a valid send.
Packet commitmentProves the source sent the exact packet and remains until completion.
Packet receiptProves delivery and blocks duplicate receive.
Acknowledgement hashProves the destination result without trusting the relayer.
Next receive sequenceEnforces ordered v1 delivery.
Next acknowledgement sequenceEnforces ordered v1 acknowledgement completion.
Async packetHolds a v2 packet until its delayed acknowledgement is written.

Both protocol versions expose state and events for relayers. Relayer reports are not proof; the destination or source verifies the corresponding membership or absence against its client.

References: modules/…/keeper.go• L150-321 modules/…/keeper.go• L61-199 modules/…/events.go• L124-269 modules/…/events.go• L11-25

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep v1 and v2 commitment inputs aligned with their proof paths. A change can make in-flight packets unverifiable by other implementations.
  • Keep ordered v1 receive and acknowledgement counters aligned with duplicate and timeout handling. A mismatch can block later packets or accept an invalid timeout.
  • Preserve the difference between a nil asynchronous acknowledgement, a failed acknowledgement, and an invalid acknowledgement. Each has a different state result.
  • Keep channel version selection consistent across all four v1 open callbacks and packet callbacks.
  • Keep ICS4 wrapper use intact for application sends and acknowledgement writes. A direct keeper call can bypass middleware.
  • Keep v2 payload and acknowledgement counts aligned. A successful multi-payload receive must return one application acknowledgement per payload.
  • Keep v1 unordered channel alias setup aligned with v2 client lookup. Removing it breaks v1-to-v2 packet paths.
  • Treat acknowledgement envelope and error text changes as state-machine changes because acknowledgement bytes are committed on chain.

Important failure modes

TriggerConsequenceGuard
A send uses an elapsed deadline or a v2 timeout outside the allowed windowNo packet commitment is created.Send compares the deadline with client or block time before storing state.
A packet commitment proof does not match the packetThe application callback is not called.The receiver recomputes the commitment and verifies membership.
A v1 packet arrives out of order on an ordered channelReceive fails and the next sequence does not advance.The receiver requires the packet sequence to equal the next receive sequence.
A v1 acknowledgement arrives out of orderThe commitment remains and later acknowledgements stay blocked.The source requires the next acknowledgement sequence.
A relayer repeats a completed receive, acknowledgement, or timeoutThe message returns a no-op instead of repeating application work.Receipt, sequence progress, or missing commitment is checked first.
A v1 ordered packet times out after non-receipt is provedThe packet commitment is removed and the source channel closes.Timeout verifies non-receipt before applying ordered-channel closure.
A v2 successful acknowledgement count differs from the payload countThe acknowledgement is rejected or cannot map results back to applications.V2 receive and acknowledgement handling enforce the payload/result relationship.
An application writes a second acknowledgementThe write fails and the first hash remains authoritative.The transport rejects an existing acknowledgement record.
A v1 ordered channel is used as a v2 aliasThe v2 counterparty relation is unavailable.Alias setup is limited to open unordered v1 channels.

Key files

FileWhy to read it
modules/…/doc.goStates the product role of channels and packets.
modules/…/channel.pb.goDefines v1 channel state, counterparty, ordering, connection, and version.
modules/…/handshake.goShows the v1 open and close lifecycle.
modules/…/msg_server.goShows how proof checks and application callbacks form one v1 message flow.
modules/…/packet.goShows v1 send, receive, acknowledgement, and replay behavior.
modules/…/timeout.goShows v1 deadline, non-receipt, and timeout-on-close recovery.
modules/…/packet.goDefines v1 packet validity and commitment inputs.
modules/…/module.goDefines application callbacks and the ICS4 boundary.
modules/…/keeper.goShows v1 sequence and packet evidence that persists across the lifecycle.
modules/…/packet.goDefines the v2 packet and multi-payload model.
modules/…/commitment.goDefines the v2 packet and acknowledgement evidence.
modules/…/packet.goShows v2 send, receive, acknowledgement, and timeout behavior.
modules/…/msg_server.goShows v2 routing, multi-payload results, asynchronous handling, and relayer flow.
modules/…/keeper.goShows v2 receipts, commitments, acknowledgements, sequences, and async packets.