Skip to content

Commit

Permalink
core: Defer extracting the script until we're sure we'll use it
Browse files Browse the repository at this point in the history
We were extracting the output script for all outputs, and discarding
them immediately again if they were not P2WSH outputs which are the
ones of interest to us. This patch move the extraction until after we
have determined it is useful, and so we should save a couple thousand
`tal()` and `tal_free()` calls.

Changelog-Changed: lightningd: Speed up blocksync by not parsing unused parts of the transactions
  • Loading branch information
cdecker committed Feb 21, 2024
1 parent c329756 commit d185b0f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lightningd/chaintopology.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,11 +965,12 @@ static void topo_add_utxos(struct chain_topology *topo, struct block *b)
if (!amount_asset_is_main(&amt))
continue; /* Ignore non-policy asset outputs */

const u8 *script = bitcoin_tx_output_get_script(tmpctx, tx, n);
if (!is_p2wsh(script, NULL))
if (!bitcoin_tx_output_script_is_p2wsh(tx, n))
continue; /* We only care about p2wsh utxos */

struct bitcoin_outpoint outpoint = { b->txids[i], n };
const u8 *script =
bitcoin_tx_output_get_script(tmpctx, tx, n);
wallet_utxoset_add(topo->ld->wallet, &outpoint,
b->height, i, script,
amount_asset_to_sat(&amt));
Expand Down

0 comments on commit d185b0f

Please sign in to comment.