Skip to content

Commit

Permalink
htlc_accepted: log BROKEN if both 'failure_msg' + 'failure_onion'
Browse files Browse the repository at this point in the history
Log an error for incorrect use of API

Suggested-By: @cdecker
  • Loading branch information
niftynei committed Nov 11, 2020
1 parent 65cdb78 commit cefb64c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,17 +931,28 @@ static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *re
u8 *failmsg;
const jsmntok_t *failoniontok, *failmsgtok, *failcodetok;

if ((failoniontok = json_get_member(buffer, toks, "failure_onion"))) {
failonion = json_tok_bin_from_hex(NULL, buffer, failoniontok);
failoniontok = json_get_member(buffer, toks, "failure_onion");
failmsgtok = json_get_member(buffer, toks, "failure_message");

if (failoniontok) {
failonion = json_tok_bin_from_hex(tmpctx, buffer,
failoniontok);
if (!failonion)
fatal("Bad failure_onion for htlc_accepted"
" hook: %.*s",
failoniontok->end - failoniontok->start,
buffer + failoniontok->start);
fail_in_htlc(hin, take(new_onionreply(tmpctx, failonion)));

if (failmsgtok)
log_broken(ld->log, "Both 'failure_onion' and"
"'failure_message' provided."
" Ignoring 'failure_message'.");

fail_in_htlc(hin, take(new_onionreply(NULL,
failonion)));
return false;
}
if ((failmsgtok = json_get_member(buffer, toks, "failure_message"))) {
if (failmsgtok) {
failmsg = json_tok_bin_from_hex(NULL, buffer,
failmsgtok);
if (!failmsg)
Expand Down

0 comments on commit cefb64c

Please sign in to comment.