From 37b269f53e1389bfe714024f5319db7bb1a75355 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 30 Jun 2016 09:08:11 +0930 Subject: [PATCH] daemon: link HTLCs together. Most HTLCs we offer are triggered by an incoming HTLC from a different peer. Save this "source" htlc, so we can fail/fulfill it when we fail/fulfill this one. Signed-off-by: Rusty Russell --- daemon/packets.c | 2 +- daemon/peer.c | 7 +++++-- daemon/peer.h | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/daemon/packets.c b/daemon/packets.c index 6d623b2a4..45f2c6935 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -643,7 +643,7 @@ Pkt *accept_pkt_htlc_add(struct peer *peer, const Pkt *pkt) htlc = peer_new_htlc(peer, u->id, u->amount_msat, &rhash, abs_locktime_to_blocks(&expiry), u->route->info.data, u->route->info.len, - THEIRS); + NULL, THEIRS); /* BOLT #2: * diff --git a/daemon/peer.c b/daemon/peer.c index 69b769e1e..d5694ac3b 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -558,6 +558,7 @@ static bool command_htlc_fulfill(struct peer *peer, static bool command_htlc_add(struct peer *peer, u64 msatoshis, unsigned int expiry, const struct sha256 *rhash, + struct htlc *src, const u8 *route) { struct channel_state *cstate; @@ -601,7 +602,7 @@ static bool command_htlc_add(struct peer *peer, u64 msatoshis, htlc = peer_new_htlc(peer, peer->htlc_id_counter, msatoshis, rhash, expiry, route, tal_count(route), - OURS); + src, OURS); /* FIXME: BOLT is not correct here: we should say IFF we cannot * afford it in remote at its own current proposed fee-rate. */ @@ -880,6 +881,7 @@ struct htlc *peer_new_htlc(struct peer *peer, u32 expiry, const u8 *route, size_t routelen, + struct htlc *src, enum channel_side side) { struct htlc *h = tal(peer, struct htlc); @@ -890,6 +892,7 @@ struct htlc *peer_new_htlc(struct peer *peer, if (!blocks_to_abs_locktime(expiry, &h->expiry)) fatal("Invalid HTLC expiry %u", expiry); h->routing = tal_dup_arr(h, u8, route, routelen, 0); + h->src = src; if (side == OURS) htlc_map_add(&peer->local.htlcs, h); else { @@ -2667,7 +2670,7 @@ static void json_newhtlc(struct command *cmd, return; } - if (!command_htlc_add(peer, msatoshis, expiry, &rhash, + if (!command_htlc_add(peer, msatoshis, expiry, &rhash, NULL, dummy_single_route(cmd, peer, msatoshis))) { command_fail(cmd, "could not add htlc"); return; diff --git a/daemon/peer.h b/daemon/peer.h index e8abc0814..11a9bd6df 100644 --- a/daemon/peer.h +++ b/daemon/peer.h @@ -252,6 +252,7 @@ struct htlc *peer_new_htlc(struct peer *peer, u32 expiry, const u8 *route, size_t route_len, + struct htlc *src, enum channel_side side); /* Peer has recieved revocation. */