From e7d5f4087bd6aeb348ca6b9593cdda23eb720f8d Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 4 Jul 2021 04:35:53 +0300 Subject: [PATCH] wallet|cj|tests: Adjust Dash-specific code to create signatures with Low R too --- src/coinjoin/coinjoin-util.cpp | 14 ++------------ src/wallet/test/coinjoin_tests.cpp | 10 +++++----- src/wallet/wallet.cpp | 19 ++++--------------- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/coinjoin/coinjoin-util.cpp b/src/coinjoin/coinjoin-util.cpp index 12101b00ff..4a8092225a 100644 --- a/src/coinjoin/coinjoin-util.cpp +++ b/src/coinjoin/coinjoin-util.cpp @@ -135,19 +135,9 @@ CTransactionBuilder::CTransactionBuilder(std::shared_ptr pwalletIn, con CPubKey dummyPubkey = pwallet->GenerateNewKey(dummyBatch, 0, false); dummyBatch.TxnAbort(); dummyScript = ::GetScriptForDestination(dummyPubkey.GetID()); - // Create dummy signatures for all inputs - int nIn = 0; - for (const auto& coin : tallyItem.vecInputCoins) { - const CScript& scriptPubKey = coin.txout.scriptPubKey; - SignatureData sigdata; - bool res = ProduceSignature(*pwallet, DUMMY_SIGNATURE_CREATOR, scriptPubKey, sigdata); - assert(res); - UpdateInput(dummyTx.vin[nIn], sigdata); - nIn++; - } + // Calculate required bytes for the dummy signed tx with tallyItem's inputs only + nBytesBase = CalculateMaximumSignedTxSize(dummyTx, pwallet.get(), false); } - // Calculate required bytes for the dummy tx with tallyItem's inputs only - nBytesBase = ::GetSerializeSize(dummyTx, SER_NETWORK, PROTOCOL_VERSION); // Calculate the output size nBytesOutput = ::GetSerializeSize(CTxOut(0, dummyScript), SER_NETWORK, PROTOCOL_VERSION); // Just to make sure.. diff --git a/src/wallet/test/coinjoin_tests.cpp b/src/wallet/test/coinjoin_tests.cpp index 5a597cb4ff..f92f13bc48 100644 --- a/src/wallet/test/coinjoin_tests.cpp +++ b/src/wallet/test/coinjoin_tests.cpp @@ -107,20 +107,20 @@ public: BOOST_FIXTURE_TEST_CASE(CTransactionBuilderTest, CTransactionBuilderTestSetup) { // NOTE: Mock wallet version is FEATURE_BASE which means that it uses uncompressed pubkeys - // (65 bytes instead of 33 bytes), so CTxIn size is 180 bytes, not 148 bytes as one might expect. + // (65 bytes instead of 33 bytes), so CTxIn size is 179 bytes, not 147 bytes as one might expect. // Each output is 34 bytes, vin and vout compact sizes are 1 byte each. // Therefore base size (i.e. for a tx with 1 input, 0 outputs) is expected to be - // 4(n32bitVersion) + 1(vin size) + 180(vin[0]) + 1(vout size) + 4(nLockTime) = 190 bytes. + // 4(n32bitVersion) + 1(vin size) + 179(vin[0]) + 1(vout size) + 4(nLockTime) = 189 bytes. minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); // Tests with single outpoint tallyItem { - CompactTallyItem tallyItem = GetTallyItem({5000}); + CompactTallyItem tallyItem = GetTallyItem({4999}); CTransactionBuilder txBuilder(wallet, tallyItem); BOOST_CHECK_EQUAL(txBuilder.CountOutputs(), 0); BOOST_CHECK_EQUAL(txBuilder.GetAmountInitial(), tallyItem.nAmount); - BOOST_CHECK_EQUAL(txBuilder.GetAmountLeft(), 4810); // 5000 - 190 + BOOST_CHECK_EQUAL(txBuilder.GetAmountLeft(), 4810); // 4999 - 189 BOOST_CHECK(txBuilder.CouldAddOutput(4776)); // 4810 - 34 BOOST_CHECK(!txBuilder.CouldAddOutput(4777)); @@ -131,7 +131,7 @@ BOOST_FIXTURE_TEST_CASE(CTransactionBuilderTest, CTransactionBuilderTestSetup) BOOST_CHECK(txBuilder.CouldAddOutputs({1000, 1000, 2708})); // (4810 - 34 * 3) split in 3 outputs BOOST_CHECK(!txBuilder.CouldAddOutputs({1000, 1000, 2709})); - BOOST_CHECK_EQUAL(txBuilder.AddOutput(5000), nullptr); + BOOST_CHECK_EQUAL(txBuilder.AddOutput(4999), nullptr); BOOST_CHECK_EQUAL(txBuilder.AddOutput(-1), nullptr); CTransactionBuilderOutput* output = txBuilder.AddOutput(); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c338c3e599..7f88fd43cc 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3719,23 +3719,12 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CTransac } auto calculateFee = [&](CAmount& nFee) -> bool { - // Fill in dummy signatures for fee calculation. - int nIn = 0; - for (const auto& coin : vecCoins) { - const CScript& scriptPubKey = coin.txout.scriptPubKey; - SignatureData sigdata; - if (!ProduceSignature(*this, DUMMY_SIGNATURE_CREATOR, scriptPubKey, sigdata)) { - strFailReason = _("Signing transaction failed"); - return false; - } else { - UpdateInput(txNew.vin[nIn], sigdata); - } - - nIn++; + nBytes = CalculateMaximumSignedTxSize(txNew, this, coin_control.fAllowWatchOnly); + if (nBytes < 0) { + strFailReason = _("Signing transaction failed"); + return false; } - nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION); - if (nExtraPayloadSize != 0) { // account for extra payload in fee calculation nBytes += GetSizeOfCompactSize(nExtraPayloadSize) + nExtraPayloadSize;