Skip to content

Commit beffd02

Browse files
committed
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 <[email protected]>
1 parent 9247ec9 commit beffd02

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

hsmd/libhsmd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ static void hsm_key_for_utxo(struct privkey *privkey, struct pubkey *pubkey,
547547
* add a partial sig for each */
548548
static void sign_our_inputs(struct utxo **utxos, struct wally_psbt *psbt)
549549
{
550+
bool is_cache_enabled = false;
550551
for (size_t i = 0; i < tal_count(utxos); i++) {
551552
struct utxo *utxo = utxos[i];
552553
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)
584585
utxo->amount);
585586
}
586587
tal_wally_start();
588+
if (!is_cache_enabled) {
589+
/* Enable caching signature sub-hashes */
590+
wally_psbt_signing_cache_enable(psbt, 0);
591+
is_cache_enabled = true;
592+
}
587593
if (wally_psbt_sign(psbt, privkey.secret.data,
588594
sizeof(privkey.secret.data),
589595
EC_FLAG_GRIND_R) != WALLY_OK) {

0 commit comments

Comments
 (0)