mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
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:
parent
aa696370af
commit
86b6402e5c
@ -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,
|
size_t get_tx_depth(const struct chain_topology *topo,
|
||||||
const struct bitcoin_txid *txid,
|
const struct bitcoin_txid *txid)
|
||||||
const struct bitcoin_tx **tx)
|
|
||||||
{
|
{
|
||||||
const struct block *b;
|
u32 blockheight = wallet_transaction_height(topo->wallet, txid);
|
||||||
|
|
||||||
b = block_for_tx(topo, txid, tx);
|
if (blockheight == 0)
|
||||||
if (!b)
|
|
||||||
return 0;
|
return 0;
|
||||||
return topo->tip->height - b->height + 1;
|
return topo->tip->height - blockheight + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct txs_to_broadcast {
|
struct txs_to_broadcast {
|
||||||
|
@ -129,10 +129,9 @@ struct txlocator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* This is the number of blocks which would have to be mined to invalidate
|
/* 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,
|
size_t get_tx_depth(const struct chain_topology *topo,
|
||||||
const struct bitcoin_txid *txid,
|
const struct bitcoin_txid *txid);
|
||||||
const struct bitcoin_tx **tx);
|
|
||||||
|
|
||||||
/* Get highest block number. */
|
/* Get highest block number. */
|
||||||
u32 get_block_height(const struct chain_topology *topo);
|
u32 get_block_height(const struct chain_topology *topo);
|
||||||
|
@ -281,9 +281,8 @@ again:
|
|||||||
w;
|
w;
|
||||||
w = txwatch_hash_next(&topo->txwatches, &i)) {
|
w = txwatch_hash_next(&topo->txwatches, &i)) {
|
||||||
u32 depth;
|
u32 depth;
|
||||||
const struct bitcoin_tx *tx;
|
|
||||||
|
|
||||||
depth = get_tx_depth(topo, &w->txid, &tx);
|
depth = get_tx_depth(topo, &w->txid);
|
||||||
if (depth)
|
if (depth)
|
||||||
needs_rerun |= txw_fire(w, &w->txid, depth);
|
needs_rerun |= txw_fire(w, &w->txid, depth);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user