diff --git a/daemon/chaintopology.c b/daemon/chaintopology.c index f20926c87..d8a34217c 100644 --- a/daemon/chaintopology.c +++ b/daemon/chaintopology.c @@ -148,7 +148,7 @@ static void connect_blocks(struct lightningd_state *dstate, struct block *b) txo = txowatch_hash_get(&dstate->txowatches, &out); if (txo) - txowatch_fire(dstate, txo, tx); + txowatch_fire(dstate, txo, tx, j); } /* We do spends first, in case that tells us to watch tx. */ diff --git a/daemon/peer.c b/daemon/peer.c index 70f452cc7..48541fd98 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -754,11 +754,18 @@ static void close_depth_cb(struct peer *peer, int depth, * invalid transactions! */ static void anchor_spent(struct peer *peer, const struct bitcoin_tx *tx, + size_t input_num, void *unused) { struct anchor_watch *w = peer->anchor.watches; union input idata; + assert(input_num < tx->input_count); + + /* We only ever sign single-input txs. */ + if (input_num != 0) + fatal("Anchor spend by non-single input tx"); + /* FIXME: change type in idata? */ idata.btc = (struct bitcoin_event *)tx; if (is_unrevoked_commit(peer->them.commit, tx)) @@ -867,6 +874,7 @@ static void commit_tx_depth(struct peer *peer, int depth, /* We should map back from commit_tx permutation to figure out what happened. */ static void our_commit_spent(struct peer *peer, const struct bitcoin_tx *commit_tx, + size_t input_num, struct commit_info *info) { /* FIXME: do something useful here, if HTLCs spent */ diff --git a/daemon/watch.c b/daemon/watch.c index e9b59e847..71b265190 100644 --- a/daemon/watch.c +++ b/daemon/watch.c @@ -126,6 +126,7 @@ struct txowatch *watch_txo_(const tal_t *ctx, unsigned int output, void (*cb)(struct peer *peer, const struct bitcoin_tx *tx, + size_t input_num, void *), void *cbdata) { @@ -162,7 +163,8 @@ void txwatch_fire(struct lightningd_state *dstate, void txowatch_fire(struct lightningd_state *dstate, const struct txowatch *txow, - const struct bitcoin_tx *tx) + const struct bitcoin_tx *tx, + size_t input_num) { struct sha256_double txid; @@ -177,7 +179,7 @@ void txowatch_fire(struct lightningd_state *dstate, txid.sha.u.u8[1], txid.sha.u.u8[2], txid.sha.u.u8[3]); - txow->cb(txow->peer, tx, txow->cbdata); + txow->cb(txow->peer, tx, input_num, txow->cbdata); } void watch_topology_changed(struct lightningd_state *dstate) diff --git a/daemon/watch.h b/daemon/watch.h index 5ed76867d..41501ce65 100644 --- a/daemon/watch.h +++ b/daemon/watch.h @@ -27,6 +27,7 @@ struct txowatch { /* A new tx. */ void (*cb)(struct peer *peer, const struct bitcoin_tx *tx, + size_t input_num, void *cbdata); void *cbdata; @@ -103,6 +104,7 @@ struct txowatch *watch_txo_(const tal_t *ctx, unsigned int output, void (*cb)(struct peer *peer, const struct bitcoin_tx *tx, + size_t input_num, void *), void *cbdata); @@ -111,7 +113,8 @@ struct txowatch *watch_txo_(const tal_t *ctx, typesafe_cb_preargs(void, void *, \ (cb), (cbdata), \ struct peer *, \ - const struct bitcoin_tx *), \ + const struct bitcoin_tx *, \ + size_t), \ (cbdata)) void txwatch_fire(struct lightningd_state *dstate, @@ -120,7 +123,7 @@ void txwatch_fire(struct lightningd_state *dstate, void txowatch_fire(struct lightningd_state *dstate, const struct txowatch *txow, - const struct bitcoin_tx *tx); + const struct bitcoin_tx *tx, size_t input_num); void watch_topology_changed(struct lightningd_state *dstate); #endif /* LIGHTNING_DAEMON_WATCH_H */