Skip to content

Commit

Permalink
lightningd: beef up HTLC consistency checking.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
rustyrussell committed Oct 9, 2018
1 parent 123713f commit a516e26
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions lightningd/htlc_end.c
Original file line number Diff line number Diff line change
@@ -126,6 +126,55 @@ struct htlc_out *htlc_out_check(const struct htlc_out *hout,
else if (hout->failuremsg && hout->preimage)
return corrupt(abortstr, "Both failed and succeeded");

if (hout->in) {
if (hout->in->msatoshi < hout->msatoshi)
return corrupt(abortstr, "Input msatoshi %"PRIu64
" less than %"PRIu64,
hout->in->msatoshi, hout->msatoshi);
if (hout->in->cltv_expiry <= hout->cltv_expiry)
return corrupt(abortstr, "Input ctlv_expiry %u"
" less than %u",
hout->in->cltv_expiry, hout->cltv_expiry);
if (!sha256_eq(&hout->in->payment_hash, &hout->payment_hash))
return corrupt(abortstr, "Input hash != output hash");
/* If output is resolved, input must be resolved same
* way (or not resolved yet). */
if (hout->failuremsg) {
if (hout->in->failcode)
return corrupt(abortstr,
"Output failmsg, input failcode");
if (hout->in->preimage)
return corrupt(abortstr,
"Output failmsg, input preimage");
} else if (hout->failcode) {
if (hout->in->failuremsg)
return corrupt(abortstr,
"Output failcode, input failmsg");
if (hout->in->preimage)
return corrupt(abortstr,
"Output failcode, input preimage");
} else if (hout->preimage) {
if (hout->in->failuremsg)
return corrupt(abortstr,
"Output preimage, input failmsg");
if (hout->in->failcode)
return corrupt(abortstr,
"Output preimage, input failcode");
} else {
if (hout->in->preimage)
return corrupt(abortstr,
"Output unresolved, input preimage");
if (hout->in->failuremsg)
return corrupt(abortstr,
"Output unresovled, input failmsg");
if (hout->in->failcode)
return corrupt(abortstr,
"Output unresolved, input failcode");
}

/* FIXME: Check hout->in->hstate. */
}

return cast_const(struct htlc_out *, hout);
}

0 comments on commit a516e26

Please sign in to comment.