Skip to content

Commit

Permalink
optional "failure_onion" in reply to htlc_accepted hook.
Browse files Browse the repository at this point in the history
Changelog-Added: `htlc_accepted` hook can now return custom `failure_onion`.
  • Loading branch information
fiatjaf committed Nov 9, 2020
1 parent 5a87e88 commit 2b38eb7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
19 changes: 18 additions & 1 deletion doc/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,23 @@ onion fields which a plugin doesn't want lightningd to consider.
```

`fail` will tell `lightningd` to fail the HTLC with a given hex-encoded
`failure_message` (please refer to the [spec][bolt4-failure-messages] for details: `incorrect_or_unknown_payment_details` is the most common).
`failure_message` (please refer to the [spec][bolt4-failure-messages] for
details: `incorrect_or_unknown_payment_details` is the most common).


```json
{
"result": "fail",
"failure_onion": "[292bytes of a serialized error packet]"
}
```

If instead of `failure_message` the response contain a hex-encoded
`failure_onion` that will be used instead (please refer to the
[spec][bolt4-failure-onion] for details). Note that `lightningd` will
apply the obfuscation step to the value retrned here with its own shared
secret (and key type `ammag`) before returning it to the previous hop.


```json
{
Expand Down Expand Up @@ -1211,6 +1227,7 @@ The plugin must broadcast it and respond with the following fields:
[jsonrpc-notification-spec]: https://www.jsonrpc.org/specification#notification
[bolt4]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md
[bolt4-failure-messages]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md#failure-messages
[bolt4-failure-onion]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md#returning-errors
[bolt2-open-channel]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md#the-open_channel-message
[sendcustommsg]: lightning-dev-sendcustommsg.7.html
[oddok]: https://github.com/lightningnetwork/lightning-rfc/blob/master/00-introduction.md#its-ok-to-be-odd
Expand Down
14 changes: 12 additions & 2 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,8 @@ static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *re
struct htlc_in *hin = request->hin;
struct lightningd *ld = request->ld;
struct preimage payment_preimage;
const jsmntok_t *resulttok, *paykeytok, *payloadtok;
u8 *payload;
const jsmntok_t *resulttok, *paykeytok, *payloadtok, *failoniontok;
u8 *payload, *failonion;

if (!toks || !buffer)
return true;
Expand Down Expand Up @@ -940,6 +940,16 @@ static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *re
" hook: %.*s",
failmsgtok->end - failmsgtok->start,
buffer + failmsgtok->start);
} else if ((failoniontok = json_get_member(buffer, toks,
"failure_onion"))) {
failonion = json_tok_bin_from_hex(NULL, 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)));
return false;
} else if (deprecated_apis
&& (failcodetok = json_get_member(buffer, toks,
"failure_code"))) {
Expand Down

0 comments on commit 2b38eb7

Please sign in to comment.