From cefb64cd683ff4a4b5b1f30624c0a9068dc4daa5 Mon Sep 17 00:00:00 2001 From: niftynei Date: Tue, 10 Nov 2020 13:42:38 -0600 Subject: [PATCH] htlc_accepted: log BROKEN if both 'failure_msg' + 'failure_onion' Log an error for incorrect use of API Suggested-By: @cdecker --- lightningd/peer_htlcs.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 6ae548e08..9ce592c8a 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -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)