mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-12 10:34:30 +01:00
block: Compute the txids only once
We're not going to mutate transactions in a block, so computing the txids every time we need them is a waste, let's compute them upfront and use them afterwards.
This commit is contained in:
@@ -208,9 +208,11 @@ bitcoin_block_from_hex(const tal_t *ctx, const struct chainparams *chainparams,
|
||||
|
||||
num = pull_varint(&p, &len);
|
||||
b->tx = tal_arr(b, struct bitcoin_tx *, num);
|
||||
b->txids = tal_arr(b, struct bitcoin_txid, num);
|
||||
for (i = 0; i < num; i++) {
|
||||
b->tx[i] = pull_bitcoin_tx(b->tx, &p, &len);
|
||||
b->tx[i]->chainparams = chainparams;
|
||||
bitcoin_txid(b->tx[i], &b->txids[i]);
|
||||
}
|
||||
|
||||
/* We should end up not overrunning, nor have extra */
|
||||
|
||||
@@ -36,6 +36,7 @@ struct bitcoin_block {
|
||||
struct bitcoin_block_hdr hdr;
|
||||
/* tal_count shows now many */
|
||||
struct bitcoin_tx **tx;
|
||||
struct bitcoin_txid *txids;
|
||||
};
|
||||
|
||||
struct bitcoin_block *
|
||||
|
||||
@@ -91,7 +91,7 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
|
||||
}
|
||||
|
||||
owned = AMOUNT_SAT(0);
|
||||
bitcoin_txid(tx, &txid);
|
||||
txid = b->txids[i];
|
||||
if (txfilter_match(topo->bitcoind->ld->owned_txfilter, tx)) {
|
||||
wallet_extract_owned_outputs(topo->bitcoind->ld->wallet,
|
||||
tx->wtx, &b->height, &owned);
|
||||
@@ -748,7 +748,7 @@ static void topo_update_spends(struct chain_topology *topo, struct block *b)
|
||||
struct bitcoin_txid txid;
|
||||
struct amount_sat inputs_total = AMOUNT_SAT(0);
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
txid = b->txids[i];
|
||||
|
||||
for (size_t j = 0; j < tx->wtx->num_inputs; j++) {
|
||||
const struct wally_tx_input *input = &tx->wtx->inputs[j];
|
||||
@@ -843,6 +843,7 @@ static struct block *new_block(struct chain_topology *topo,
|
||||
b->hdr = blk->hdr;
|
||||
|
||||
b->full_txs = tal_steal(b, blk->tx);
|
||||
b->txids = tal_steal(b, blk->txids);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ struct block {
|
||||
|
||||
/* Full copy of txs (freed in filter_block_txs) */
|
||||
struct bitcoin_tx **full_txs;
|
||||
struct bitcoin_txid *txids;
|
||||
};
|
||||
|
||||
/* Hash blocks by sha */
|
||||
|
||||
Reference in New Issue
Block a user