Skip to content

Commit 96daffa

Browse files
Improve documentation for InboundHTLCState enum states.
1 parent f08d610 commit 96daffa

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

lightning/src/ln/channel.rs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,43 @@ enum InboundHTLCRemovalReason {
5353
}
5454

5555
enum InboundHTLCState {
56-
/// Added by remote, to be included in next local commitment tx.
56+
/// Offered by remote, to be included in next local commitment tx. I.e., the remote sent an
57+
/// update_add_htlc message for this HTLC.
5758
RemoteAnnounced(PendingHTLCStatus),
58-
/// Included in a received commitment_signed message (implying we've revoke_and_ack'ed it), but
59-
/// the remote side hasn't yet revoked their previous state, which we need them to do before we
60-
/// accept this HTLC. Implies AwaitingRemoteRevoke.
61-
/// We also have not yet included this HTLC in a commitment_signed message, and are waiting on
62-
/// a remote revoke_and_ack on a previous state before we can do so.
59+
/// Included in a received commitment_signed message (implying we've
60+
/// revoke_and_ack'd it), but the remote hasn't yet revoked their previous
61+
/// state (see the example below). We have not yet included this HTLC in a
62+
/// commitment_signed message because we are waiting on the remote's
63+
/// aforementioned state revocation. One reason this missing remote RAA
64+
/// (revoke_and_ack) blocks us from constructing a commitment_signed message
65+
/// is because every time we create a new "state", i.e. every time we sign a
66+
/// new commitment tx (see [BOLT #2]), we need a new per_commitment_point,
67+
/// which are provided one-at-a-time in each RAA. E.g., the last RAA they
68+
/// sent provided the per_commitment_point for our current commitment tx.
69+
/// The other reason we should not send a commitment_signed without their RAA
70+
/// is because their RAA serves to ACK our previous commitment_signed.
71+
///
72+
/// Here's an example of how an HTLC could come to be in this state:
73+
/// remote --> update_add_htlc(prev_htlc) --> local
74+
/// remote --> commitment_signed(prev_htlc) --> local
75+
/// remote <-- revoke_and_ack <-- local
76+
/// remote <-- commitment_signed(prev_htlc) <-- local
77+
/// [note that here, the remote does not respond with a RAA]
78+
/// remote --> update_add_htlc(this_htlc) --> local
79+
/// remote --> commitment_signed(prev_htlc, this_htlc) --> local
80+
/// Now `this_htlc` will be assigned this state. It's unable to be officially
81+
/// accepted, i.e. included in a commitment_signed, because we're missing the
82+
/// RAA that provides our next per_commitment_point. The per_commitment_point
83+
/// is used to derive commitment keys, which are used to construct the
84+
/// signatures in a commitment_signed message.
85+
/// Implies AwaitingRemoteRevoke.
86+
/// [BOLT #2]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md
6387
AwaitingRemoteRevokeToAnnounce(PendingHTLCStatus),
64-
/// Included in a received commitment_signed message (implying we've revoke_and_ack'ed it), but
65-
/// the remote side hasn't yet revoked their previous state, which we need them to do before we
66-
/// accept this HTLC. Implies AwaitingRemoteRevoke.
67-
/// We have included this HTLC in our latest commitment_signed and are now just waiting on a
68-
/// revoke_and_ack.
88+
/// Included in a received commitment_signed message (implying we've revoke_and_ack'd it).
89+
/// We have also included this HTLC in our latest commitment_signed and are now just waiting
90+
/// on the remote's revoke_and_ack to make this HTLC an irrevocable part of the state of the
91+
/// channel (before it can then get forwarded and/or removed).
92+
/// Implies AwaitingRemoteRevoke.
6993
AwaitingAnnouncedRemoteRevoke(PendingHTLCStatus),
7094
Committed,
7195
/// Removed by us and a new commitment_signed was sent (if we were AwaitingRemoteRevoke when we

0 commit comments

Comments
 (0)