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

Function htlc_out_check

lightningd/htlc_end.c:167–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167struct htlc_out *htlc_out_check(const struct htlc_out *hout,
168 const char *abortstr)
169{
170 if (htlc_state_owner(hout->hstate) != LOCAL)
171 return corrupt(abortstr, "invalid state %s",
172 htlc_state_name(hout->hstate));
173 else if (hout->failonion && hout->preimage)
174 return corrupt(abortstr, "Both failed and succeeded");
175
176 if (hout->am_origin && hout->in)
177 return corrupt(abortstr, "Both origin and incoming");
178
179 if (hout->in) {
180 if (amount_msat_less(hout->in->msat, hout->msat))
181 return corrupt(abortstr, "Input amount %s"
182 " less than %s",
183 fmt_amount_msat(tmpctx, hout->in->msat),
184 fmt_amount_msat(tmpctx, hout->msat));
185 if (hout->in->cltv_expiry <= hout->cltv_expiry)
186 return corrupt(abortstr, "Input cltv_expiry %u"
187 " less than %u",
188 hout->in->cltv_expiry, hout->cltv_expiry);
189 if (!sha256_eq(&hout->in->payment_hash, &hout->payment_hash))
190 return corrupt(abortstr, "Input hash != output hash");
191 /* If output is resolved, input must be resolved same
192 * way (or not resolved yet). */
193 if (hout->failonion) {
194 if (hout->in->badonion)
195 return corrupt(abortstr,
196 "Output failmsg, input badonion");
197 if (hout->in->preimage)
198 return corrupt(abortstr,
199 "Output failmsg, input preimage");
200 } else if (hout->failmsg) {
201 if (hout->in->preimage)
202 return corrupt(abortstr,
203 "Output failmsg, input preimage");
204 } else if (hout->preimage) {
205 /* If we abandoned the HTLC to save the incoming channel,
206 * (see consider_failing_incoming), hout->in->failonion
207 * will be set! */
208 if (hout->in->badonion)
209 return corrupt(abortstr,
210 "Output preimage, input badonion");
211 } else {
212 if (hout->in->preimage)
213 return corrupt(abortstr,
214 "Output unresolved, input preimage");
215 if (hout->in->failonion)
216 return corrupt(abortstr,
217 "Output unresovled, input failmsg");
218 if (hout->in->badonion)
219 return corrupt(abortstr,
220 "Output unresolved, input badonion");
221 }
222 }
223
224 /* Can't have a resolution while still being added. */

Callers 7

fail_out_htlcFunction · 0.85
fulfill_our_htlc_outFunction · 0.85
peer_failed_our_htlcFunction · 0.85
check_already_failedFunction · 0.85
onchain_failed_our_htlcFunction · 0.85
remove_htlc_outFunction · 0.85
new_htlc_outFunction · 0.85

Calls 5

htlc_state_ownerFunction · 0.85
corruptFunction · 0.70
htlc_state_nameFunction · 0.50
amount_msat_lessFunction · 0.50
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected