Skip to content

Commit

Permalink
"createonion" to accept an optional custom onion_size.
Browse files Browse the repository at this point in the history
Changelog-Added: `createonion` RPC command now accepts an optional `onion_size`.
  • Loading branch information
fiatjaf committed May 12, 2021
1 parent ce1e5bd commit 2cf2a32
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
13 changes: 9 additions & 4 deletions doc/lightning-createonion.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions doc/lightning-createonion.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lightning-createonion -- Low-level command to create a custom onion
SYNOPSIS
--------

**createonion** *hops* *assocdata* \[*session_key*\]
**createonion** *hops* *assocdata* \[*session_key*\] \[*onion_size*\]

DESCRIPTION
-----------
Expand Down Expand Up @@ -68,10 +68,10 @@ which the above *hops* parameter was generated:

- Notice that the payload in the *hops* parameter is the hex-encoded version
of the parameters in the `getroute` response.
- The payloads are shifted left by one, i.e., payload 0 in `createonion`
corresponds to payload 1 from `getroute`.
- Except for the pubkey, the values are shifted left by one, i.e., the 1st
payload in `createonion` corresponds to the 2nd set of values from `getroute`.
- The final payload is a copy of the last payload sans `channel`

These rules are directly derived from the onion construction. Please refer
[BOLT 04][bolt04] for details and rationale.

Expand All @@ -85,6 +85,10 @@ should only be used for testing or if a specific shared secret is
important. If not specified it will be securely generated internally, and the
shared secrets will be returned.

The optional *onion_size* parameter specifies a size different from the default
payment onion (1300 bytes). May be used for custom protocols like trampoline
routing.

RETURN VALUE
------------

Expand Down Expand Up @@ -122,4 +126,3 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>

[bolt04]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md

6 changes: 4 additions & 2 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1670,13 +1670,15 @@ static struct command_result *json_createonion(struct command *cmd,
struct secret *session_key, *shared_secrets;
struct sphinx_path *sp;
u8 *assocdata, *serialized;
u32 *packet_size;
struct onionpacket *packet;
struct sphinx_hop *hops;

if (!param(cmd, buffer, params,
p_req("hops", param_hops_array, &hops),
p_req("assocdata", param_bin_from_hex, &assocdata),
p_opt("session_key", param_secret, &session_key),
p_opt_def("onion_size", param_number, &packet_size, ROUTING_INFO_SIZE),
NULL)) {
return command_param_failed();
}
Expand All @@ -1689,12 +1691,12 @@ static struct command_result *json_createonion(struct command *cmd,
for (size_t i=0; i<tal_count(hops); i++)
sphinx_add_hop(sp, &hops[i].pubkey, hops[i].raw_payload);

if (sphinx_path_payloads_size(sp) > ROUTING_INFO_SIZE)
if (sphinx_path_payloads_size(sp) > *packet_size)
return command_fail(
cmd, JSONRPC2_INVALID_PARAMS,
"Payloads exceed maximum onion packet size.");

packet = create_onionpacket(cmd, sp, ROUTING_INFO_SIZE, &shared_secrets);
packet = create_onionpacket(cmd, sp, *packet_size, &shared_secrets);
if (!packet)
return command_fail(cmd, LIGHTNINGD,
"Could not create onion packet");
Expand Down

0 comments on commit 2cf2a32

Please sign in to comment.