diff --git a/daemon/pay.c b/daemon/pay.c index dd6924be6..9792be65c 100644 --- a/daemon/pay.c +++ b/daemon/pay.c @@ -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); diff --git a/daemon/peer.c b/daemon/peer.c index c72073f57..13eac4bf4 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -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: diff --git a/daemon/sphinx.c b/daemon/sphinx.c index 3d1485659..0bd99c7ab 100644 --- a/daemon/sphinx.c +++ b/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); 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); } diff --git a/daemon/sphinx.h b/daemon/sphinx.h index ab373c079..28e255045 100644 --- a/daemon/sphinx.h +++ b/daemon/sphinx.h @@ -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 {