Skip to content

Commit 4600479

Browse files
committed
psbt: always put a non_witness_utxo and don't remove it
Offline signers will always need a non_witness_utxo so make sure it is there.
1 parent 5279d8b commit 4600479

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

src/psbt.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ void PSBTInput::Merge(const PSBTInput& input)
136136
{
137137
if (!non_witness_utxo && input.non_witness_utxo) non_witness_utxo = input.non_witness_utxo;
138138
if (witness_utxo.IsNull() && !input.witness_utxo.IsNull()) {
139+
// TODO: For segwit v1, we will want to clear out the non-witness utxo when setting a witness one. For v0 and non-segwit, this is not safe
139140
witness_utxo = input.witness_utxo;
140-
non_witness_utxo = nullptr; // Clear out any non-witness utxo when we set a witness one.
141141
}
142142

143143
partial_sigs.insert(input.partial_sigs.begin(), input.partial_sigs.end());
@@ -274,10 +274,11 @@ bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction&
274274
if (require_witness_sig && !sigdata.witness) return false;
275275
input.FromSignatureData(sigdata);
276276

277-
// If we have a witness signature, use the smaller witness UTXO.
277+
// If we have a witness signature, put a witness UTXO.
278+
// TODO: For segwit v1, we should remove the non_witness_utxo
278279
if (sigdata.witness) {
279280
input.witness_utxo = utxo;
280-
input.non_witness_utxo = nullptr;
281+
// input.non_witness_utxo = nullptr;
281282
}
282283

283284
// Fill in the missing info

src/psbt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ struct PSBTInput
6767
template <typename Stream>
6868
inline void Serialize(Stream& s) const {
6969
// Write the utxo
70-
// If there is a non-witness utxo, then don't add the witness one.
7170
if (non_witness_utxo) {
7271
SerializeToVector(s, PSBT_IN_NON_WITNESS_UTXO);
7372
OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
7473
SerializeToVector(os, non_witness_utxo);
75-
} else if (!witness_utxo.IsNull()) {
74+
}
75+
if (!witness_utxo.IsNull()) {
7676
SerializeToVector(s, PSBT_IN_WITNESS_UTXO);
7777
SerializeToVector(s, witness_utxo);
7878
}

src/wallet/test/psbt_wallet_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(psbt_updater_test)
6464
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
6565
ssTx << psbtx;
6666
std::string final_hex = HexStr(ssTx);
67-
BOOST_CHECK_EQUAL(final_hex, "70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88701042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000");
67+
BOOST_CHECK_EQUAL(final_hex, "70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001008a020000000158e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7501000000171600145f275f436b09a8cc9a2eb2a2f528485c68a56323feffffff02d8231f1b0100000017a914aed962d6654f9a2b36608eb9d64d2b260db4f1118700c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8876500000001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88701042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000");
6868

6969
// Mutate the transaction so that one of the inputs is invalid
7070
psbtx.tx->vin[0].prevout.n = 2;

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,7 @@ TransactionError CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bool& comp
24922492
}
24932493

24942494
// If we have no utxo, grab it from the wallet.
2495-
if (!input.non_witness_utxo && input.witness_utxo.IsNull()) {
2495+
if (!input.non_witness_utxo) {
24962496
const uint256& txhash = txin.prevout.hash;
24972497
const auto it = mapWallet.find(txhash);
24982498
if (it != mapWallet.end()) {

test/functional/rpc_psbt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def set_test_params(self):
3838
def skip_test_if_missing_module(self):
3939
self.skip_if_no_wallet()
4040

41+
# TODO: Re-enable this test with segwit v1
4142
def test_utxo_conversion(self):
4243
mining_node = self.nodes[2]
4344
offline_node = self.nodes[0]
@@ -352,7 +353,8 @@ def run_test(self):
352353
for i, signer in enumerate(signers):
353354
self.nodes[2].unloadwallet("wallet{}".format(i))
354355

355-
self.test_utxo_conversion()
356+
# TODO: Re-enable this for segwit v1
357+
# self.test_utxo_conversion()
356358

357359
# Test that psbts with p2pkh outputs are created properly
358360
p2pkh = self.nodes[0].getnewaddress(address_type='legacy')

0 commit comments

Comments
 (0)