From 86b6402e5cf11e239a970ca1c1ef07200b363d18 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 9 Apr 2018 17:49:03 +0200 Subject: [PATCH] chaintopology: Refactor get_tx_depth to use the DB backed tx store We are slowly hollowing out the in-memory blockchain representation to make restarts easier. Signed-off-by: Christian Decker --- lightningd/chaintopology.c | 10 ++++------ lightningd/chaintopology.h | 5 ++--- lightningd/watch.c | 3 +-- 3 files changed, 7 insertions(+), 11 deletions(-) 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); }