Skip to content

Zero next_commitment_number does not immediately fail channel #9425

Description

@tankyleo

Core Lightning does not immediately fail an established channel when receiving channel_reestablish with next_commitment_number = 0. On master at f80895bac, CLN instead sends a warning for the stale next_revocation_number, records a transient failure, and does not broadcast its commitment.

BOLT #2 states:

if next_commitment_number is zero: MUST immediately fail the channel and broadcast any relevant latest commitment transaction.

BOLT #2 requirements

In channeld.c, next_revocation_number is evaluated first. A sufficiently stale value calls peer_failed_warn_nodisconnect, so the commitment-number validation is never reached.

The existing zero check is nested under:

next_commitment_number == peer->next_index[REMOTE] - 1

which does not cover an advanced channel receiving zero.

Moving that check immediately after parsing and validating channel_reestablish, before other reconnect processing, was validated end to end on regtest with CLN master and unmodified LDK Server main: CLN immediately failed the channel, broadcast its latest commitment, and the recovering peer swept its output:

diff --git a/channeld/channeld.c b/channeld/channeld.c
index 3848f0d2..6b64f807 100644
--- a/channeld/channeld.c
+++ b/channeld/channeld.c
@@ -5890,6 +5890,12 @@ static void peer_reconnect(struct peer *peer,
                     next_revocation_number,
                     tal_count(peer->splice_state->inflights),
                     peer->splice_state->count);
+       if (next_commitment_number == 0)
+               peer_failed_err(peer->pps,
+                                &peer->channel_id,
+                                "bad reestablish commitment_number: %"
+                                PRIu64,
+                                next_commitment_number);

        local_next_funding = (send_tlvs ? send_tlvs->next_funding : NULL);
        remote_next_funding = (recv_tlvs ? recv_tlvs->next_funding : NULL);
@@ -6102,14 +6108,6 @@ static void peer_reconnect(struct peer *peer,
         *       `commitment_signed`.
         */
        if (next_commitment_number == peer->next_index[REMOTE] - 1) {
-               /* We completed opening, we don't re-transmit that one! */
-               if (next_commitment_number == 0)
-                       peer_failed_err(peer->pps,
-                                        &peer->channel_id,
-                                        "bad reestablish commitment_number: %"
-                                        PRIu64,
-                                        next_commitment_number);
-
                if (!recv_tlvs || !recv_tlvs->next_funding)
                        retransmit_commitment_signed = true;
                else

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions