mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
daemon/sphinx: support modern v0 hop payload.
This just means we put the outgoing_cltv_value where we used to put zeroes. The old daemon simply ignores this, but the new one should check it as per BOLT 4. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
fed25cc540
commit
8a84e961ed
4 changed files with 27 additions and 9 deletions
|
@ -340,11 +340,12 @@ static void json_sendpay(struct command *cmd,
|
|||
/* What that hop will forward */
|
||||
tal_resize(&hoppayloads, n_hops);
|
||||
memset(&hoppayloads[n_hops-1], 0, sizeof(struct hoppayload));
|
||||
if (!json_tok_u64(buffer, amttok, &hoppayloads[n_hops-1].amount)) {
|
||||
if (!json_tok_u64(buffer, amttok, &hoppayloads[n_hops-1].amt_to_forward)) {
|
||||
command_fail(cmd, "route %zu invalid msatoshi", n_hops);
|
||||
return;
|
||||
}
|
||||
lastamount = hoppayloads[n_hops-1].amount;
|
||||
/* FIXME: Populate outgoing_cltv_value */
|
||||
lastamount = hoppayloads[n_hops-1].amt_to_forward;
|
||||
}
|
||||
|
||||
tal_resize(&ids, n_hops+1);
|
||||
|
|
|
@ -971,7 +971,7 @@ static void their_htlc_added(struct peer *peer, struct htlc *htlc,
|
|||
goto free_packet;
|
||||
|
||||
case ONION_FORWARD:
|
||||
route_htlc_onwards(peer, htlc, step->hoppayload->amount, step->next->nexthop,
|
||||
route_htlc_onwards(peer, htlc, step->hoppayload->amt_to_forward, step->next->nexthop,
|
||||
serialize_onionpacket(step, step->next), only_dest);
|
||||
goto free_packet;
|
||||
default:
|
||||
|
|
|
@ -110,8 +110,12 @@ static struct hoppayload *parse_hoppayload(const tal_t *ctx, u8 *src)
|
|||
struct hoppayload *result = talz(ctx, struct hoppayload);
|
||||
|
||||
read_buffer(&result->realm, src, sizeof(result->realm), &p);
|
||||
read_buffer(&result->amount, src, sizeof(result->amount), &p);
|
||||
read_buffer(&result->remainder, src, sizeof(result->remainder), &p);
|
||||
read_buffer(&result->amt_to_forward,
|
||||
src, sizeof(result->amt_to_forward), &p);
|
||||
read_buffer(&result->outgoing_cltv_value,
|
||||
src, sizeof(result->outgoing_cltv_value), &p);
|
||||
read_buffer(&result->unused_with_v0_version_on_header,
|
||||
src, sizeof(result->unused_with_v0_version_on_header), &p);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -120,8 +124,11 @@ static void serialize_hoppayload(u8 *dst, struct hoppayload *hp)
|
|||
int p = 0;
|
||||
|
||||
write_buffer(dst, &hp->realm, sizeof(hp->realm), &p);
|
||||
write_buffer(dst, &hp->amount, sizeof(hp->amount), &p);
|
||||
write_buffer(dst, &hp->remainder, sizeof(hp->remainder), &p);
|
||||
write_buffer(dst, &hp->amt_to_forward, sizeof(hp->amt_to_forward), &p);
|
||||
write_buffer(dst, &hp->outgoing_cltv_value,
|
||||
sizeof(hp->outgoing_cltv_value), &p);
|
||||
write_buffer(dst, &hp->unused_with_v0_version_on_header,
|
||||
sizeof(hp->unused_with_v0_version_on_header), &p);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,10 +35,20 @@ enum route_next_case {
|
|||
ONION_FORWARD = 1,
|
||||
};
|
||||
|
||||
/* BOLT #4:
|
||||
*
|
||||
* The format of the per-hop-payload for a version 0 packet is as follows:
|
||||
```
|
||||
+----------------+--------------------------+-------------------------------+--------------------------------------------+
|
||||
| realm (1 byte) | amt_to_forward (8 bytes) | outgoing_cltv_value (4 bytes) | unused_with_v0_version_on_header (7 bytes) |
|
||||
+----------------+--------------------------+-------------------------------+--------------------------------------------+
|
||||
```
|
||||
*/
|
||||
struct hoppayload {
|
||||
u8 realm;
|
||||
u64 amount;
|
||||
u8 remainder[11];
|
||||
u64 amt_to_forward;
|
||||
u32 outgoing_cltv_value;
|
||||
u8 unused_with_v0_version_on_header[7];
|
||||
};
|
||||
|
||||
struct route_step {
|
||||
|
|
Loading…
Add table
Reference in a new issue