Skip to content

Commit 4351d8d

Browse files
Improve documentation for InboundHTLCState enum states.
1 parent f08d610 commit 4351d8d

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

lightning/src/ln/channel.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,37 @@ 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 revoke_and_ack'd it), but
60+
/// the remote hasn't yet revoked their previous state (see the example below). We have not yet
61+
/// included this HTLC in a commitment_signed message because we are waiting on the remote's
62+
/// aforementioned state revocation. The reason we need this remote RAA (revoke_and_ack) is
63+
/// because every time we create a new "state", i.e. every time we create our next
64+
/// per_commitment_point (see [BOLT #2]), we consume a prior revocation point (aka the
65+
/// per_commitment_secret in the revoke_and_ack message (see BOLT #2)).
66+
///
67+
/// Here's an example of how an HTLC could come to be in this state:
68+
/// remote --> update_add_htlc(prev_htlc) --> local
69+
/// remote --> commitment_signed(prev_htlc) --> local
70+
/// remote <-- revoke_and_ack <-- local
71+
/// remote <-- commitment_signed(prev_htlc) <-- local
72+
/// [note that here, the remote does not respond with a RAA]
73+
/// remote --> update_add_htlc(this_htlc) --> local
74+
/// remote --> commitment_signed(prev_htlc, this_htlc) --> local
75+
/// Now `this_htlc` will be assigned this state. It's unable to be officially accepted, i.e.
76+
/// included in a commitment_signed, because we're missing the RAA that would let us construct
77+
/// our next per_commitment_point, which is used to derive commitment keys, which are used
78+
/// to construct the signatures in a commitment_signed message.
79+
/// Implies AwaitingRemoteRevoke.
80+
/// [BOLT #2]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md
6381
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.
82+
/// Included in a received commitment_signed message (implying we've revoke_and_ack'd it).
83+
/// We have also included this HTLC in our latest commitment_signed and are now just waiting
84+
/// on the remote's revoke_and_ack to make this HTLC an irrevocable part of the state of the
85+
/// channel (before it can then get forwarded and/or removed).
86+
/// Implies AwaitingRemoteRevoke.
6987
AwaitingAnnouncedRemoteRevoke(PendingHTLCStatus),
7088
Committed,
7189
/// Removed by us and a new commitment_signed was sent (if we were AwaitingRemoteRevoke when we

0 commit comments

Comments
 (0)