From c94c49525739a3d479d036f1a63e478368ab93a6 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 3 May 2016 11:01:20 +0930 Subject: [PATCH] daemon: allow multiple watches on the same tx. This turns out to make life easier for watching HTLC timeouts (we just place a new watch for each HTLC). Signed-off-by: Rusty Russell --- daemon/chaintopology.c | 6 ++++-- daemon/watch.c | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/daemon/chaintopology.c b/daemon/chaintopology.c index d8a34217c..b3529ae77 100644 --- a/daemon/chaintopology.c +++ b/daemon/chaintopology.c @@ -137,6 +137,7 @@ static void connect_blocks(struct lightningd_state *dstate, struct block *b) struct bitcoin_tx *tx = b->full_txs[i]; struct txwatch *w; struct sha256_double txid; + struct txwatch_hash_iter iter; size_t j; /* Tell them if it spends a txo we care about. */ @@ -153,8 +154,9 @@ static void connect_blocks(struct lightningd_state *dstate, struct block *b) /* We do spends first, in case that tells us to watch tx. */ bitcoin_txid(tx, &txid); - w = txwatch_hash_get(&dstate->txwatches, &txid); - if (w) { + for (w = txwatch_hash_getfirst(&dstate->txwatches, &txid, &iter); + w; + w = txwatch_hash_getnext(&dstate->txwatches, &txid, &iter)){ add_tx_to_block(b, w); /* Fire if it's the first we've seen it: this might * set up txo watches, which could fire in this block */ diff --git a/daemon/watch.c b/daemon/watch.c index 71b265190..bcb696e12 100644 --- a/daemon/watch.c +++ b/daemon/watch.c @@ -90,8 +90,6 @@ struct txwatch *watch_txid_(const tal_t *ctx, { struct txwatch *w; - assert(!txwatch_hash_get(&peer->dstate->txwatches, txid)); - w = tal(ctx, struct txwatch); w->depth = -1; w->txid = *txid;