Skip to content

Commit d185b0f

Browse files
committed
core: Defer extracting the script until we're sure we'll use it
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
1 parent c329756 commit d185b0f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lightningd/chaintopology.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,11 +965,12 @@ static void topo_add_utxos(struct chain_topology *topo, struct block *b)
965965
if (!amount_asset_is_main(&amt))
966966
continue; /* Ignore non-policy asset outputs */
967967

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

972971
struct bitcoin_outpoint outpoint = { b->txids[i], n };
972+
const u8 *script =
973+
bitcoin_tx_output_get_script(tmpctx, tx, n);
973974
wallet_utxoset_add(topo->ld->wallet, &outpoint,
974975
b->height, i, script,
975976
amount_asset_to_sat(&amt));

0 commit comments

Comments
 (0)