Browse Source

watch: indicate which input of tx is spend the watch txo.

If we generate a tx which spends a heap of TXOs (eg. steal
transaction), we'll need this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
77a89bcf2b
  1. 2
      daemon/chaintopology.c
  2. 8
      daemon/peer.c
  3. 6
      daemon/watch.c
  4. 7
      daemon/watch.h

2
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. */

8
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 */

6
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)

7
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 */

Loading…
Cancel
Save