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

Function htlc_out_check

lightningd/htlc_end.c:168–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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
amount_msat_lessFunction · 0.85
corruptFunction · 0.70
htlc_state_nameFunction · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected