From 595a0e17c41254515014bdd183d14986e95f37a4 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Fri, 7 Aug 2020 04:11:58 +0200 Subject: [PATCH 01/45] wallet: Add m_dust_feerate to CCoinControl / Use it in CreateTransaction --- src/wallet/coincontrol.h | 2 ++ src/wallet/wallet.cpp | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h index 4dc3daafec81..2778eba014f1 100644 --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -39,6 +39,8 @@ class CCoinControl bool fOverrideFeeRate; //! Override the default payTxFee if set boost::optional m_feerate; + //! Override the dust feerate estimation with m_dust_feerate in CreateTransaction if set + boost::optional m_dust_feerate; //! Override the default confirmation target if set boost::optional m_confirm_target; //! Fee estimation mode to control arguments to estimateSmartFee diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 357c148186e7..7ffc0b468e34 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3734,6 +3734,7 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT assert(txNew.nLockTime <= (unsigned int)chainActive.Height()); assert(txNew.nLockTime < LOCKTIME_THRESHOLD); FeeCalculation feeCalc; + CFeeRate discard_rate = coin_control.m_dust_feerate ? *coin_control.m_dust_feerate : GetDiscardRate(::feeEstimator); CAmount nFeeNeeded; unsigned int nBytes; { @@ -3776,7 +3777,6 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT CTxOut change_prototype_txout(0, scriptChange); size_t change_prototype_size = GetSerializeSize(change_prototype_txout, SER_DISK, 0); - CFeeRate discard_rate = GetDiscardRate(::feeEstimator); nFeeRet = 0; bool pick_new_inputs = true; CAmount nValueIn = 0; @@ -3809,8 +3809,7 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT } } - if (IsDust(txout, ::dustRelayFee)) - { + if (IsDust(txout, discard_rate)) { if (recipient.fSubtractFeeFromAmount && nFeeRet > 0) { if (txout.nValue < 0) From 75196c6b6d7b45a80c5d13a77daf133aa22def86 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Thu, 6 Aug 2020 04:54:22 +0200 Subject: [PATCH 02/45] privatesend: Introduce CTransactionBuilder/CTransactionBuilderOutput Builder classes for transactions from type Inputs: Defined by CompactTallyItem Outputs: Simple outputs with lose reserve keys This takes fully takes care of fee calculations and makes sure calculations are the same like those happening when actually create the transaction with CreateTransaction. --- src/privatesend/privatesend-util.cpp | 226 +++++++++++++++++++++++++++ src/privatesend/privatesend-util.h | 96 ++++++++++++ 2 files changed, 322 insertions(+) diff --git a/src/privatesend/privatesend-util.cpp b/src/privatesend/privatesend-util.cpp index 161fd7b4a490..1acadbe6725d 100644 --- a/src/privatesend/privatesend-util.cpp +++ b/src/privatesend/privatesend-util.cpp @@ -2,7 +2,13 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include +#include +#include #include +#include