mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
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>
This commit is contained in:
parent
9eabab78ab
commit
77a89bcf2b
4 changed files with 18 additions and 5 deletions
|
@ -148,7 +148,7 @@ static void connect_blocks(struct lightningd_state *dstate, struct block *b)
|
||||||
|
|
||||||
txo = txowatch_hash_get(&dstate->txowatches, &out);
|
txo = txowatch_hash_get(&dstate->txowatches, &out);
|
||||||
if (txo)
|
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. */
|
/* We do spends first, in case that tells us to watch tx. */
|
||||||
|
|
|
@ -754,11 +754,18 @@ static void close_depth_cb(struct peer *peer, int depth,
|
||||||
* invalid transactions! */
|
* invalid transactions! */
|
||||||
static void anchor_spent(struct peer *peer,
|
static void anchor_spent(struct peer *peer,
|
||||||
const struct bitcoin_tx *tx,
|
const struct bitcoin_tx *tx,
|
||||||
|
size_t input_num,
|
||||||
void *unused)
|
void *unused)
|
||||||
{
|
{
|
||||||
struct anchor_watch *w = peer->anchor.watches;
|
struct anchor_watch *w = peer->anchor.watches;
|
||||||
union input idata;
|
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? */
|
/* FIXME: change type in idata? */
|
||||||
idata.btc = (struct bitcoin_event *)tx;
|
idata.btc = (struct bitcoin_event *)tx;
|
||||||
if (is_unrevoked_commit(peer->them.commit, 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. */
|
/* We should map back from commit_tx permutation to figure out what happened. */
|
||||||
static void our_commit_spent(struct peer *peer,
|
static void our_commit_spent(struct peer *peer,
|
||||||
const struct bitcoin_tx *commit_tx,
|
const struct bitcoin_tx *commit_tx,
|
||||||
|
size_t input_num,
|
||||||
struct commit_info *info)
|
struct commit_info *info)
|
||||||
{
|
{
|
||||||
/* FIXME: do something useful here, if HTLCs spent */
|
/* FIXME: do something useful here, if HTLCs spent */
|
||||||
|
|
|
@ -126,6 +126,7 @@ struct txowatch *watch_txo_(const tal_t *ctx,
|
||||||
unsigned int output,
|
unsigned int output,
|
||||||
void (*cb)(struct peer *peer,
|
void (*cb)(struct peer *peer,
|
||||||
const struct bitcoin_tx *tx,
|
const struct bitcoin_tx *tx,
|
||||||
|
size_t input_num,
|
||||||
void *),
|
void *),
|
||||||
void *cbdata)
|
void *cbdata)
|
||||||
{
|
{
|
||||||
|
@ -162,7 +163,8 @@ void txwatch_fire(struct lightningd_state *dstate,
|
||||||
|
|
||||||
void txowatch_fire(struct lightningd_state *dstate,
|
void txowatch_fire(struct lightningd_state *dstate,
|
||||||
const struct txowatch *txow,
|
const struct txowatch *txow,
|
||||||
const struct bitcoin_tx *tx)
|
const struct bitcoin_tx *tx,
|
||||||
|
size_t input_num)
|
||||||
{
|
{
|
||||||
struct sha256_double txid;
|
struct sha256_double txid;
|
||||||
|
|
||||||
|
@ -177,7 +179,7 @@ void txowatch_fire(struct lightningd_state *dstate,
|
||||||
txid.sha.u.u8[1],
|
txid.sha.u.u8[1],
|
||||||
txid.sha.u.u8[2],
|
txid.sha.u.u8[2],
|
||||||
txid.sha.u.u8[3]);
|
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)
|
void watch_topology_changed(struct lightningd_state *dstate)
|
||||||
|
|
|
@ -27,6 +27,7 @@ struct txowatch {
|
||||||
/* A new tx. */
|
/* A new tx. */
|
||||||
void (*cb)(struct peer *peer,
|
void (*cb)(struct peer *peer,
|
||||||
const struct bitcoin_tx *tx,
|
const struct bitcoin_tx *tx,
|
||||||
|
size_t input_num,
|
||||||
void *cbdata);
|
void *cbdata);
|
||||||
|
|
||||||
void *cbdata;
|
void *cbdata;
|
||||||
|
@ -103,6 +104,7 @@ struct txowatch *watch_txo_(const tal_t *ctx,
|
||||||
unsigned int output,
|
unsigned int output,
|
||||||
void (*cb)(struct peer *peer,
|
void (*cb)(struct peer *peer,
|
||||||
const struct bitcoin_tx *tx,
|
const struct bitcoin_tx *tx,
|
||||||
|
size_t input_num,
|
||||||
void *),
|
void *),
|
||||||
void *cbdata);
|
void *cbdata);
|
||||||
|
|
||||||
|
@ -111,7 +113,8 @@ struct txowatch *watch_txo_(const tal_t *ctx,
|
||||||
typesafe_cb_preargs(void, void *, \
|
typesafe_cb_preargs(void, void *, \
|
||||||
(cb), (cbdata), \
|
(cb), (cbdata), \
|
||||||
struct peer *, \
|
struct peer *, \
|
||||||
const struct bitcoin_tx *), \
|
const struct bitcoin_tx *, \
|
||||||
|
size_t), \
|
||||||
(cbdata))
|
(cbdata))
|
||||||
|
|
||||||
void txwatch_fire(struct lightningd_state *dstate,
|
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,
|
void txowatch_fire(struct lightningd_state *dstate,
|
||||||
const struct txowatch *txow,
|
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);
|
void watch_topology_changed(struct lightningd_state *dstate);
|
||||||
#endif /* LIGHTNING_DAEMON_WATCH_H */
|
#endif /* LIGHTNING_DAEMON_WATCH_H */
|
||||||
|
|
Loading…
Add table
Reference in a new issue