Browse Source

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>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
8a84e961ed
  1. 5
      daemon/pay.c
  2. 2
      daemon/peer.c
  3. 15
      daemon/sphinx.c
  4. 14
      daemon/sphinx.h

5
daemon/pay.c

@ -340,11 +340,12 @@ static void json_sendpay(struct command *cmd,
/* What that hop will forward */ /* What that hop will forward */
tal_resize(&hoppayloads, n_hops); tal_resize(&hoppayloads, n_hops);
memset(&hoppayloads[n_hops-1], 0, sizeof(struct hoppayload)); 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); command_fail(cmd, "route %zu invalid msatoshi", n_hops);
return; 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); tal_resize(&ids, n_hops+1);

2
daemon/peer.c

@ -971,7 +971,7 @@ static void their_htlc_added(struct peer *peer, struct htlc *htlc,
goto free_packet; goto free_packet;
case ONION_FORWARD: 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); serialize_onionpacket(step, step->next), only_dest);
goto free_packet; goto free_packet;
default: default:

15
daemon/sphinx.c

@ -110,8 +110,12 @@ static struct hoppayload *parse_hoppayload(const tal_t *ctx, u8 *src)
struct hoppayload *result = talz(ctx, struct hoppayload); struct hoppayload *result = talz(ctx, struct hoppayload);
read_buffer(&result->realm, src, sizeof(result->realm), &p); read_buffer(&result->realm, src, sizeof(result->realm), &p);
read_buffer(&result->amount, src, sizeof(result->amount), &p); read_buffer(&result->amt_to_forward,
read_buffer(&result->remainder, src, sizeof(result->remainder), &p); 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; return result;
} }
@ -120,8 +124,11 @@ static void serialize_hoppayload(u8 *dst, struct hoppayload *hp)
int p = 0; int p = 0;
write_buffer(dst, &hp->realm, sizeof(hp->realm), &p); write_buffer(dst, &hp->realm, sizeof(hp->realm), &p);
write_buffer(dst, &hp->amount, sizeof(hp->amount), &p); write_buffer(dst, &hp->amt_to_forward, sizeof(hp->amt_to_forward), &p);
write_buffer(dst, &hp->remainder, sizeof(hp->remainder), &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);
} }

14
daemon/sphinx.h

@ -35,10 +35,20 @@ enum route_next_case {
ONION_FORWARD = 1, 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 { struct hoppayload {
u8 realm; u8 realm;
u64 amount; u64 amt_to_forward;
u8 remainder[11]; u32 outgoing_cltv_value;
u8 unused_with_v0_version_on_header[7];
}; };
struct route_step { struct route_step {

Loading…
Cancel
Save