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 <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-04-09 17:49:03 +02:00
parent aa696370af
commit 86b6402e5c
3 changed files with 7 additions and 11 deletions

View File

@ -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 {

View File

@ -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);

View File

@ -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);
}