diff --git a/commit_tx.c b/commit_tx.c index c66e4f3a0..7a27a5281 100644 --- a/commit_tx.c +++ b/commit_tx.c @@ -5,6 +5,7 @@ #include "bitcoin/tx.h" #include "commit_tx.h" #include "daemon/channel.h" +#include "daemon/htlc.h" #include "overflows.h" #include "permute_tx.h" #include "remove_dust.h" diff --git a/daemon/channel.c b/daemon/channel.c index 6ecfa4940..1ab0d0cf0 100644 --- a/daemon/channel.c +++ b/daemon/channel.c @@ -1,4 +1,5 @@ #include "channel.h" +#include "htlc.h" #include #include #include diff --git a/daemon/channel.h b/daemon/channel.h index f146172a8..74a96262a 100644 --- a/daemon/channel.h +++ b/daemon/channel.h @@ -2,7 +2,6 @@ #define LIGHTNING_DAEMON_CHANNEL_H #include "config.h" #include "bitcoin/locktime.h" -#include "htlc.h" #include #include #include diff --git a/daemon/htlc.h b/daemon/htlc.h index 6b9bbc692..1ceccf283 100644 --- a/daemon/htlc.h +++ b/daemon/htlc.h @@ -2,6 +2,7 @@ #define LIGHTNING_DAEMON_HTLC_H #include "config.h" #include "bitcoin/locktime.h" +#include "channel.h" #include "pseudorand.h" #include #include @@ -11,6 +12,10 @@ struct htlc { /* Useful for debugging, and decoding via ->src. */ struct peer *peer; + /* Block number where we abort if it's still live (OURS only) */ + u32 deadline; + /* Did we create it, or did they? */ + enum channel_side side; /* The unique ID for this peer and this direction (ours or theirs) */ u64 id; /* The amount in millisatoshi. */ @@ -27,8 +32,6 @@ struct htlc { const u8 *routing; /* Previous HTLC (if any) which made us offer this (OURS only) */ struct htlc *src; - /* Block number where we abort if it's still live (OURS only) */ - u32 deadline; }; /* htlc_map: ID -> htlc mapping. */ diff --git a/daemon/peer.c b/daemon/peer.c index 3899e7faf..d5a2bdff8 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -1004,8 +1004,16 @@ static struct peer *new_peer(struct lightningd_state *dstate, static void htlc_destroy(struct htlc *htlc) { - if (!htlc_map_del(&htlc->peer->local.htlcs, htlc) - && !htlc_map_del(&htlc->peer->remote.htlcs, htlc)) + struct htlc_map *map; + + if (htlc->side == OURS) + map = &htlc->peer->local.htlcs; + else { + assert(htlc->side == THEIRS); + map = &htlc->peer->remote.htlcs; + } + + if (!htlc_map_del(map, htlc)) fatal("Could not find htlc to destroy"); } @@ -1021,6 +1029,7 @@ struct htlc *peer_new_htlc(struct peer *peer, { struct htlc *h = tal(peer, struct htlc); h->peer = peer; + h->side = side; h->id = id; h->msatoshis = msatoshis; h->rhash = *rhash;