Merge pull request #2563 from starius/psbt-oom

psbt: compact witness utxo scripts after parsing
This commit is contained in:
Olaoluwa Osuntokun 2026-07-20 16:34:19 -05:00 committed by GitHub
commit aa108a28ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View file

@ -240,7 +240,9 @@ func TestParsesWitnessUtxoTxOutStrictly(t *testing.T) {
strictnessPSBTWithWitnessUtxo(t, txOutBytes),
), false)
require.NoError(t, err)
require.Equal(t, pkScript, packet.Inputs[0].WitnessUtxo.PkScript)
script := packet.Inputs[0].WitnessUtxo.PkScript
require.Equal(t, pkScript, script)
require.Equal(t, len(script), cap(script))
malformedTxOut := append(append([]byte{}, txOutBytes...), 0x00)
_, err = NewFromRawBytes(bytes.NewReader(

View file

@ -315,6 +315,13 @@ func readTxOut(txout []byte) (*wire.TxOut, error) {
return nil, err
}
// wire.ReadTxOut stores PkScript in an internal 4 MiB script slab.
// Compact it before storing the TxOut in the PSBT so tiny witness
// scripts do not retain the full slab.
script := make([]byte, len(txOut.PkScript))
copy(script, txOut.PkScript)
txOut.PkScript = script
return txOut, nil
}