Browse Source

optional "failure_onion" in reply to htlc_accepted hook.

Changelog-Added: `htlc_accepted` hook can now return custom `failure_onion`.
ppa-prep
fiatjaf 4 years ago
committed by neil saitug
parent
commit
9e4bed73d9
  1. 21
      doc/PLUGINS.md
  2. 14
      lightningd/peer_htlcs.c

21
doc/PLUGINS.md

@ -1053,7 +1053,25 @@ onion fields which a plugin doesn't want lightningd to consider.
``` ```
`fail` will tell `lightningd` to fail the HTLC with a given hex-encoded `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": "[serialized error packet]"
}
```
Instead of `failure_message` the response can contain a hex-encoded
`failure_onion` that will be used instead (please refer to the
[spec][bolt4-failure-onion] for details). This can be used, for example,
if you're writing a bridge between two Lightning Networks. Note that
`lightningd` will apply the obfuscation step to the value returned here
with its own shared secret (and key type `ammag`) before returning it to
the previous hop.
```json ```json
{ {
@ -1263,6 +1281,7 @@ The plugin must broadcast it and respond with the following fields:
[jsonrpc-notification-spec]: https://www.jsonrpc.org/specification#notification [jsonrpc-notification-spec]: https://www.jsonrpc.org/specification#notification
[bolt4]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md [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-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 [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 [sendcustommsg]: lightning-dev-sendcustommsg.7.html
[oddok]: https://github.com/lightningnetwork/lightning-rfc/blob/master/00-introduction.md#its-ok-to-be-odd [oddok]: https://github.com/lightningnetwork/lightning-rfc/blob/master/00-introduction.md#its-ok-to-be-odd

14
lightningd/peer_htlcs.c

@ -888,8 +888,8 @@ static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *re
struct htlc_in *hin = request->hin; struct htlc_in *hin = request->hin;
struct lightningd *ld = request->ld; struct lightningd *ld = request->ld;
struct preimage payment_preimage; struct preimage payment_preimage;
const jsmntok_t *resulttok, *paykeytok, *payloadtok; const jsmntok_t *resulttok, *paykeytok, *payloadtok, *failoniontok;
u8 *payload; u8 *payload, *failonion;
if (!toks || !buffer) if (!toks || !buffer)
return true; return true;
@ -940,6 +940,16 @@ static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *re
" hook: %.*s", " hook: %.*s",
failmsgtok->end - failmsgtok->start, failmsgtok->end - failmsgtok->start,
buffer + 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 } else if (deprecated_apis
&& (failcodetok = json_get_member(buffer, toks, && (failcodetok = json_get_member(buffer, toks,
"failure_code"))) { "failure_code"))) {

Loading…
Cancel
Save