mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
chaintopology: do less work when iterating blocks
- Avoid overhead from tal checks when iterating block txs - Skip pegin txs as well as coinbase txs while iterating - Early-exit if the txout cannot possibly be p2wsh - Don't re-calculate the txid when we already have it - Don't allocate a script for non-policy asset outputs - Don't copy txids for non-interesting UTXOs Note the below -Changed line covers the previous wally and PSBT commits which also provide general block processing speedups. Changelog-Changed: core: Processing blocks should now be faster Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
This commit is contained in:
parent
40dd780ea7
commit
d5808d921a
1 changed files with 19 additions and 16 deletions
|
@ -942,26 +942,29 @@ static void topo_update_spends(struct chain_topology *topo, struct block *b)
|
|||
|
||||
static void topo_add_utxos(struct chain_topology *topo, struct block *b)
|
||||
{
|
||||
for (size_t i = 0; i < tal_count(b->full_txs); i++) {
|
||||
/* Coinbase and pegin UTXOs can be ignored */
|
||||
const uint32_t skip_features = WALLY_TX_IS_COINBASE | WALLY_TX_IS_PEGIN;
|
||||
const size_t num_txs = tal_count(b->full_txs);
|
||||
for (size_t i = 0; i < num_txs; i++) {
|
||||
const struct bitcoin_tx *tx = b->full_txs[i];
|
||||
struct bitcoin_outpoint outpoint;
|
||||
|
||||
bitcoin_txid(tx, &outpoint.txid);
|
||||
for (outpoint.n = 0;
|
||||
outpoint.n < tx->wtx->num_outputs;
|
||||
outpoint.n++) {
|
||||
if (tx->wtx->outputs[outpoint.n].features
|
||||
& WALLY_TX_IS_COINBASE)
|
||||
for (size_t n = 0; n < tx->wtx->num_outputs; n++) {
|
||||
if (tx->wtx->outputs[n].features & skip_features)
|
||||
continue;
|
||||
if (tx->wtx->outputs[n].script_len != BITCOIN_SCRIPTPUBKEY_P2WSH_LEN)
|
||||
continue; /* Cannot possibly be a p2wsh utxo */
|
||||
|
||||
const u8 *script = bitcoin_tx_output_get_script(tmpctx, tx, outpoint.n);
|
||||
struct amount_asset amt = bitcoin_tx_output_get_amount(tx, outpoint.n);
|
||||
struct amount_asset amt = bitcoin_tx_output_get_amount(tx, n);
|
||||
if (!amount_asset_is_main(&amt))
|
||||
continue; /* Ignore non-policy asset outputs */
|
||||
|
||||
if (amount_asset_is_main(&amt) && is_p2wsh(script, NULL)) {
|
||||
wallet_utxoset_add(topo->ld->wallet, &outpoint,
|
||||
b->height, i, script,
|
||||
amount_asset_to_sat(&amt));
|
||||
}
|
||||
const u8 *script = bitcoin_tx_output_get_script(tmpctx, tx, n);
|
||||
if (!is_p2wsh(script, NULL))
|
||||
continue; /* We only care about p2wsh utxos */
|
||||
|
||||
struct bitcoin_outpoint outpoint = { b->txids[i], n };
|
||||
wallet_utxoset_add(topo->ld->wallet, &outpoint,
|
||||
b->height, i, script,
|
||||
amount_asset_to_sat(&amt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue