From b24b7f90c434ee3532e54f74a5e7838bc7e37479 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 13 Oct 2021 14:15:36 +1030 Subject: [PATCH] lightningd: use bitcoin_outpoint in watch. This makes more sense than two args. Signed-off-by: Rusty Russell --- lightningd/chaintopology.c | 4 ++-- lightningd/watch.c | 22 +++++++++++----------- lightningd/watch.h | 12 +++--------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 17244bb02..09702f179 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -72,10 +72,10 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b) /* Tell them if it spends a txo we care about. */ for (j = 0; j < tx->wtx->num_inputs; j++) { - struct txwatch_output out; + struct bitcoin_outpoint out; struct txowatch *txo; bitcoin_tx_input_get_txid(tx, j, &out.txid); - out.index = tx->wtx->inputs[j].index; + out.n = tx->wtx->inputs[j].index; txo = txowatch_hash_get(&topo->txowatches, &out); if (txo) { diff --git a/lightningd/watch.c b/lightningd/watch.c index 34cc8ce4e..123d6e036 100644 --- a/lightningd/watch.c +++ b/lightningd/watch.c @@ -40,7 +40,7 @@ struct txowatch { struct channel *channel; /* Output to watch. */ - struct txwatch_output out; + struct bitcoin_outpoint out; /* A new tx. */ enum watch_result (*cb)(struct channel *channel, @@ -71,24 +71,24 @@ struct txwatch { unsigned int depth); }; -const struct txwatch_output *txowatch_keyof(const struct txowatch *w) +const struct bitcoin_outpoint *txowatch_keyof(const struct txowatch *w) { return &w->out; } -size_t txo_hash(const struct txwatch_output *out) +size_t txo_hash(const struct bitcoin_outpoint *out) { /* This hash-in-one-go trick only works if they're consecutive. */ - BUILD_ASSERT(offsetof(struct txwatch_output, index) - == sizeof(((struct txwatch_output *)NULL)->txid)); - return siphash24(siphash_seed(), &out->txid, - sizeof(out->txid) + sizeof(out->index)); + BUILD_ASSERT(offsetof(struct bitcoin_outpoint, n) + == sizeof(((struct bitcoin_outpoint *)NULL)->txid)); + return siphash24(siphash_seed(), out, + sizeof(out->txid) + sizeof(out->n)); } -bool txowatch_eq(const struct txowatch *w, const struct txwatch_output *out) +bool txowatch_eq(const struct txowatch *w, const struct bitcoin_outpoint *out) { return bitcoin_txid_eq(&w->out.txid, &out->txid) - && w->out.index == out->index; + && w->out.n == out->n; } static void destroy_txowatch(struct txowatch *w) @@ -198,7 +198,7 @@ struct txowatch *watch_txo(const tal_t *ctx, w->topo = topo; w->out.txid = *txid; - w->out.index = output; + w->out.n = output; w->channel = channel; w->cb = cb; @@ -266,7 +266,7 @@ void txowatch_fire(const struct txowatch *txow, log_debug(txow->channel->log, "Got UTXO spend for %s:%u: %s", type_to_string(tmpctx, struct bitcoin_txid, &txow->out.txid), - txow->out.index, + txow->out.n, type_to_string(tmpctx, struct bitcoin_txid, &txid)); r = txow->cb(txow->channel, tx, input_num, block); diff --git a/lightningd/watch.h b/lightningd/watch.h index fc67b43c1..348c50fbf 100644 --- a/lightningd/watch.h +++ b/lightningd/watch.h @@ -4,7 +4,6 @@ #include #include -struct bitcoin_tx; struct block; struct channel; struct chain_topology; @@ -17,14 +16,9 @@ enum watch_result { KEEP_WATCHING = -2 }; -struct txwatch_output { - struct bitcoin_txid txid; - unsigned int index; -}; - -const struct txwatch_output *txowatch_keyof(const struct txowatch *w); -size_t txo_hash(const struct txwatch_output *out); -bool txowatch_eq(const struct txowatch *w, const struct txwatch_output *out); +const struct bitcoin_outpoint *txowatch_keyof(const struct txowatch *w); +size_t txo_hash(const struct bitcoin_outpoint *out); +bool txowatch_eq(const struct txowatch *w, const struct bitcoin_outpoint *out); HTABLE_DEFINE_TYPE(struct txowatch, txowatch_keyof, txo_hash, txowatch_eq, txowatch_hash);