MCPcopy Create free account
hub / github.com/ElementsProject/lightning / htlc_in_commitment

Function htlc_in_commitment

lightningd/onchain_control.c:138–211  ·  view source on GitHub ↗

Is this HTLC in the commitment tx which went onchain? * * The stubs cover a range of commitment numbers, so they include HTLCs * removed just before this commitment: those can be indistinguishable * onchain from a live HTLC with the same payment hash, amount and cltv. * We know the exact state of every HTLC we still track, so we can tell * onchaind which stubs are really in this tx (as best

Source from the content-addressed store, hash-verified

136 * We know the exact state of every HTLC we still track, so we can tell
137 * onchaind which stubs are really in this tx (as best we know). */
138static bool htlc_in_commitment(const struct channel *channel,
139 const struct htlc_stub *stub,
140 u64 commit_num,
141 bool our_commitment)
142{
143 enum htlc_state hstate;
144 int flags;
145 enum side side;
146 bool current;
147
148 if (stub->owner == LOCAL) {
149 const struct htlc_out *hout;
150 hout = find_htlc_out(channel->peer->ld->htlcs_out, channel,
151 stub->id);
152 if (!hout)
153 return false;
154 hstate = hout->hstate;
155 } else {
156 const struct htlc_in *hin;
157 hin = find_htlc_in(channel->peer->ld->htlcs_in, channel,
158 stub->id);
159 if (!hin)
160 return false;
161 hstate = hin->hstate;
162 }
163
164 /* The only commitment of ours we ever broadcast is the latest. */
165 if (our_commitment) {
166 side = LOCAL;
167 current = true;
168 } else {
169 u64 nrev;
170
171 side = REMOTE;
172 nrev = revocations_received(&channel->their_shachain.chain);
173 /* next_index[REMOTE] advances when we send commitment_signed,
174 * so next_index - 2 is their previous commitment. That one
175 * is still unrevoked only while we're waiting for
176 * revoke_and_ack (revocations_received == next_index - 2).
177 * Once they have revoked it, onchaind takes the cheat path
178 * and sweeps every output, so the present bit doesn't matter. */
179 if (commit_num + 1 == channel->next_index[REMOTE])
180 current = true;
181 else if (nrev + 2 == channel->next_index[REMOTE]
182 && commit_num + 2 == channel->next_index[REMOTE])
183 current = false;
184 else
185 /* A revoked (or unknown) commitment: we take
186 * everything anyway, so being here is good enough. */
187 return true;
188 }
189
190 flags = htlc_state_flags(hstate);
191
192 /* HTLC_F_COMMITTED/HTLC_F_REVOKED refer to the change in progress
193 * (adding or removing), not to the HTLC itself. */
194 if (flags & HTLC_ADDING) {
195 if (current)

Callers 1

Calls 4

find_htlc_outFunction · 0.85
find_htlc_inFunction · 0.85
revocations_receivedFunction · 0.85
htlc_state_flagsFunction · 0.50

Tested by

no test coverage detected