diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 3b253f9cf..6ff3d941b 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -127,15 +127,13 @@ static struct block *block_for_tx(const struct chain_topology *topo, } size_t get_tx_depth(const struct chain_topology *topo, - const struct bitcoin_txid *txid, - const struct bitcoin_tx **tx) + const struct bitcoin_txid *txid) { - const struct block *b; + u32 blockheight = wallet_transaction_height(topo->wallet, txid); - b = block_for_tx(topo, txid, tx); - if (!b) + if (blockheight == 0) return 0; - return topo->tip->height - b->height + 1; + return topo->tip->height - blockheight + 1; } struct txs_to_broadcast { diff --git a/lightningd/chaintopology.h b/lightningd/chaintopology.h index d1934bb3f..f0ac98fc5 100644 --- a/lightningd/chaintopology.h +++ b/lightningd/chaintopology.h @@ -129,10 +129,9 @@ struct txlocator { }; /* This is the number of blocks which would have to be mined to invalidate - * the tx (optional tx is filled in if return is non-zero). */ + * the tx */ size_t get_tx_depth(const struct chain_topology *topo, - const struct bitcoin_txid *txid, - const struct bitcoin_tx **tx); + const struct bitcoin_txid *txid); /* Get highest block number. */ u32 get_block_height(const struct chain_topology *topo); diff --git a/lightningd/watch.c b/lightningd/watch.c index f0fe8c124..32f0bfbf2 100644 --- a/lightningd/watch.c +++ b/lightningd/watch.c @@ -281,9 +281,8 @@ again: w; w = txwatch_hash_next(&topo->txwatches, &i)) { u32 depth; - const struct bitcoin_tx *tx; - depth = get_tx_depth(topo, &w->txid, &tx); + depth = get_tx_depth(topo, &w->txid); if (depth) needs_rerun |= txw_fire(w, &w->txid, depth); }