Skip to content

Avoid transaction-wide work during PSBT input finalization - #1365

Merged
NicolasDorier merged 1 commit into
masterfrom
fix/psbt-finalization-performance
Oct 28, 2026
Merged

NicolasDorier merged 1 commit into
masterfrom
fix/psbt-finalization-performance

Conversation

@NicolasDorier

Copy link
Copy Markdown
Collaborator

Avoid repeated whole-transaction work when finalizing PSBT inputs, particularly large unsigned or partially signed PSBTs that cannot be finalized.

  • Remove the smart-finalization fallback that extracts a transaction and scans all its inputs after each failed input finalization. At that point the current input has neither a final scriptSig nor a final witness, so the extracted transaction contains no signatures to recover for that input. The other smart deductions remain enabled, and the public TransactionBuilder.ExtractSignatures API is unchanged.
  • Select the requested input directly when SignOnlyInputIndex is set, rather than enumerating every input and skipping the others. An out-of-range index continues to produce no input signing contexts. This also benefits single-input signing.

These changes remove two sources of quadratic work without adding a cache to mutable PSBT objects or disabling IsSmart globally.

This does not eliminate all transaction-wide work from repeated public TryFinalizeInput() calls: callers should still precompute signing data once through Settings.SigningOptions.PrecomputedTransactionData, or use bulk TryFinalize(), which already shares that data. A corresponding BTCPay Server caller adjustment is separate from this PR.

The library builds successfully for all four target frameworks, and the existing test project compiles for both targets. Tests were not run locally.

@NicolasDorier
NicolasDorier merged commit 85d077e into master Oct 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant