From 8fc4cb6bef9ea0f0fdcedbe406cb157ead464f96 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 12 Mar 2025 21:53:47 +1300 Subject: [PATCH] hsmd: enable caching of sub-hashes when signing our PSBT inputs Enabling the cache makes signing significantly faster for segwit inputs, particularly taproot which was designed with caching in mind. Changelog-None Signed-off-by: Jon Griffiths --- hsmd/libhsmd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hsmd/libhsmd.c b/hsmd/libhsmd.c index d5ed6969a..d5abcc750 100644 --- a/hsmd/libhsmd.c +++ b/hsmd/libhsmd.c @@ -547,6 +547,7 @@ static void hsm_key_for_utxo(struct privkey *privkey, struct pubkey *pubkey, * add a partial sig for each */ static void sign_our_inputs(struct utxo **utxos, struct wally_psbt *psbt) { + bool is_cache_enabled = false; for (size_t i = 0; i < tal_count(utxos); i++) { struct utxo *utxo = utxos[i]; for (size_t j = 0; j < psbt->num_inputs; j++) { @@ -584,6 +585,11 @@ static void sign_our_inputs(struct utxo **utxos, struct wally_psbt *psbt) utxo->amount); } tal_wally_start(); + if (!is_cache_enabled) { + /* Enable caching signature sub-hashes */ + wally_psbt_signing_cache_enable(psbt, 0); + is_cache_enabled = true; + } if (wally_psbt_sign(psbt, privkey.secret.data, sizeof(privkey.secret.data), EC_FLAG_GRIND_R) != WALLY_OK) {