htlc: store which side created the HTLC.

This is generally redundant, since HTLC pointer is in that side's
commit_info, but makes HTLC completely self-contained.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-07-01 11:27:57 +09:30
parent fbe15bdce2
commit 7e6dc28f70
5 changed files with 18 additions and 5 deletions

View File

@ -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"

View File

@ -1,4 +1,5 @@
#include "channel.h"
#include "htlc.h"
#include <assert.h>
#include <ccan/array_size/array_size.h>
#include <ccan/mem/mem.h>

View File

@ -2,7 +2,6 @@
#define LIGHTNING_DAEMON_CHANNEL_H
#include "config.h"
#include "bitcoin/locktime.h"
#include "htlc.h"
#include <ccan/crypto/sha256/sha256.h>
#include <ccan/tal/tal.h>
#include <stdbool.h>

View File

@ -2,6 +2,7 @@
#define LIGHTNING_DAEMON_HTLC_H
#include "config.h"
#include "bitcoin/locktime.h"
#include "channel.h"
#include "pseudorand.h"
#include <ccan/crypto/sha256/sha256.h>
#include <ccan/crypto/siphash24/siphash24.h>
@ -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. */

View File

@ -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;