dash/src/wallet/fees.cpp

99 lines
4.3 KiB
C++
Raw Normal View History

// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2017 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
Backport 11651 (#3358) * scripted-diff: Replace #include "" with #include <> (ryanofsky) -BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT- Signed-off-by: Pasta <pasta@dashboost.org> * scripted-diff: Replace #include "" with #include <> (Dash Specific) -BEGIN VERIFY SCRIPT- for f in \ src/bls/*.cpp \ src/bls/*.h \ src/evo/*.cpp \ src/evo/*.h \ src/governance/*.cpp \ src/governance/*.h \ src/llmq/*.cpp \ src/llmq/*.h \ src/masternode/*.cpp \ src/masternode/*.h \ src/privatesend/*.cpp \ src/privatesend/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT- Signed-off-by: Pasta <pasta@dashboost.org> * build: Remove -I for everything but project root Remove -I from build system for everything but the project root, and built-in dependencies. Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/Makefile.test.include * qt: refactor: Use absolute include paths in .ui files * qt: refactor: Changes to make include paths absolute This makes all include paths in the GUI absolute. Many changes are involved as every single source file in src/qt/ assumes to be able to use relative includes. Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/qt/dash.cpp # src/qt/optionsmodel.cpp # src/qt/test/rpcnestedtests.cpp * test: refactor: Use absolute include paths for test data files * Recommend #include<> syntax in developer notes * refactor: Include obj/build.h instead of build.h * END BACKPORT #11651 Remove trailing whitespace causing travis failure * fix backport 11651 Signed-off-by: Pasta <pasta@dashboost.org> * More of 11651 * fix blockchain.cpp Signed-off-by: pasta <pasta@dashboost.org> * Add missing "qt/" in includes * Add missing "test/" in includes * Fix trailing whitespaces Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com> Co-authored-by: Russell Yanofsky <russ@yanofsky.org> Co-authored-by: MeshCollider <dobsonsa68@gmail.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2020-03-19 23:46:56 +01:00
#include <wallet/fees.h>
Backport 11651 (#3358) * scripted-diff: Replace #include "" with #include <> (ryanofsky) -BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT- Signed-off-by: Pasta <pasta@dashboost.org> * scripted-diff: Replace #include "" with #include <> (Dash Specific) -BEGIN VERIFY SCRIPT- for f in \ src/bls/*.cpp \ src/bls/*.h \ src/evo/*.cpp \ src/evo/*.h \ src/governance/*.cpp \ src/governance/*.h \ src/llmq/*.cpp \ src/llmq/*.h \ src/masternode/*.cpp \ src/masternode/*.h \ src/privatesend/*.cpp \ src/privatesend/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT- Signed-off-by: Pasta <pasta@dashboost.org> * build: Remove -I for everything but project root Remove -I from build system for everything but the project root, and built-in dependencies. Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/Makefile.test.include * qt: refactor: Use absolute include paths in .ui files * qt: refactor: Changes to make include paths absolute This makes all include paths in the GUI absolute. Many changes are involved as every single source file in src/qt/ assumes to be able to use relative includes. Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/qt/dash.cpp # src/qt/optionsmodel.cpp # src/qt/test/rpcnestedtests.cpp * test: refactor: Use absolute include paths for test data files * Recommend #include<> syntax in developer notes * refactor: Include obj/build.h instead of build.h * END BACKPORT #11651 Remove trailing whitespace causing travis failure * fix backport 11651 Signed-off-by: Pasta <pasta@dashboost.org> * More of 11651 * fix blockchain.cpp Signed-off-by: pasta <pasta@dashboost.org> * Add missing "qt/" in includes * Add missing "test/" in includes * Fix trailing whitespaces Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com> Co-authored-by: Russell Yanofsky <russ@yanofsky.org> Co-authored-by: MeshCollider <dobsonsa68@gmail.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2020-03-19 23:46:56 +01:00
#include <policy/policy.h>
#include <txmempool.h>
#include <util.h>
#include <validation.h>
#include <wallet/coincontrol.h>
#include <wallet/wallet.h>
CAmount GetRequiredFee(unsigned int nTxBytes)
{
return std::max(CWallet::minTxFee.GetFee(nTxBytes), ::minRelayTxFee.GetFee(nTxBytes));
}
CAmount GetMinimumFee(unsigned int nTxBytes, const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation *feeCalc)
Backport bitcoin#10637 (partial) (#3878) * Calculate and store the number of bytes required to spend an input * Store effective value, fee, and long term fee in CInputCoin Have CInputCOin store effective value information. This includes the effective value itself, the fee, and the long term fee for the input * Implement Branch and Bound coin selection in a new file Create a new file for coin selection logic and implement the BnB algorithm in it. * Move output eligibility to a separate function * Use a struct for output eligibility Instead of specifying 3 parameters, use a struct for those parameters in order to reduce the number of arguments to SelectCoinsMinConf. * Remove coinselection.h -> wallet.h circular dependency Changes CInputCoin to coinselection and to use CTransactionRef in order to avoid a circular dependency. Also moves other coin selection specific variables out of wallet.h to coinselectoin.h * Add tests for the Branch and Bound algorithm * Move current coin selection algorithm to coinselection.{cpp,h} Moves the current coin selection algorithm out of SelectCoinsMinConf and puts it in coinselection.{cpp,h}. The new function, KnapsackSolver, instead of taking a vector of COutputs, will take a vector of CInputCoins that is prepared by SelectCoinsMinConf. * Move original knapsack solver tests to coinselector_tests.cpp * Add a GetMinimumFeeRate function which is wrapped by GetMinimumFee * Have SelectCoinsMinConf and SelectCoins use BnB or Knapsack and use it (partial) Allows SelectCoinsMinConf and SelectCoins be able to switch between using BnB or Knapsack for choosing coins. Has SelectCoinsMinConf do the preprocessing necessary to support either BnB or Knapsack. This includes calculating the filtering the effective values for each input. Uses BnB in CreateTransaction to find an exact match for the output. If BnB fails, it will fallback to the Knapsack solver. Dash specific note: just always use Knapsack in CreateTransaction. * Benchmark BnB in the worst case where it exhausts * Add a test to make sure that negative effective values are filtered * More of 12747: Fix typos Co-authored-by: Andrew Chow <achow101-github@achow101.com>
2020-12-18 18:43:48 +01:00
{
CAmount fee_needed = GetMinimumFeeRate(coin_control, pool, estimator, feeCalc).GetFee(nTxBytes);
// Always obey the maximum
if (fee_needed > maxTxFee) {
fee_needed = maxTxFee;
if (feeCalc) feeCalc->reason = FeeReason::MAXTXFEE;
}
return fee_needed;
}
CFeeRate GetRequiredFeeRate()
{
return std::max(CWallet::minTxFee, ::minRelayTxFee);
}
CFeeRate GetMinimumFeeRate(const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation *feeCalc)
{
/* User control of how to calculate fee uses the following parameter precedence:
1. coin_control.m_feerate
2. coin_control.m_confirm_target
3. payTxFee (user-set global variable)
4. nTxConfirmTarget (user-set global variable)
The first parameter that is set is used.
*/
Backport bitcoin#10637 (partial) (#3878) * Calculate and store the number of bytes required to spend an input * Store effective value, fee, and long term fee in CInputCoin Have CInputCOin store effective value information. This includes the effective value itself, the fee, and the long term fee for the input * Implement Branch and Bound coin selection in a new file Create a new file for coin selection logic and implement the BnB algorithm in it. * Move output eligibility to a separate function * Use a struct for output eligibility Instead of specifying 3 parameters, use a struct for those parameters in order to reduce the number of arguments to SelectCoinsMinConf. * Remove coinselection.h -> wallet.h circular dependency Changes CInputCoin to coinselection and to use CTransactionRef in order to avoid a circular dependency. Also moves other coin selection specific variables out of wallet.h to coinselectoin.h * Add tests for the Branch and Bound algorithm * Move current coin selection algorithm to coinselection.{cpp,h} Moves the current coin selection algorithm out of SelectCoinsMinConf and puts it in coinselection.{cpp,h}. The new function, KnapsackSolver, instead of taking a vector of COutputs, will take a vector of CInputCoins that is prepared by SelectCoinsMinConf. * Move original knapsack solver tests to coinselector_tests.cpp * Add a GetMinimumFeeRate function which is wrapped by GetMinimumFee * Have SelectCoinsMinConf and SelectCoins use BnB or Knapsack and use it (partial) Allows SelectCoinsMinConf and SelectCoins be able to switch between using BnB or Knapsack for choosing coins. Has SelectCoinsMinConf do the preprocessing necessary to support either BnB or Knapsack. This includes calculating the filtering the effective values for each input. Uses BnB in CreateTransaction to find an exact match for the output. If BnB fails, it will fallback to the Knapsack solver. Dash specific note: just always use Knapsack in CreateTransaction. * Benchmark BnB in the worst case where it exhausts * Add a test to make sure that negative effective values are filtered * More of 12747: Fix typos Co-authored-by: Andrew Chow <achow101-github@achow101.com>
2020-12-18 18:43:48 +01:00
CFeeRate feerate_needed ;
if (coin_control.m_feerate) { // 1.
Backport bitcoin#10637 (partial) (#3878) * Calculate and store the number of bytes required to spend an input * Store effective value, fee, and long term fee in CInputCoin Have CInputCOin store effective value information. This includes the effective value itself, the fee, and the long term fee for the input * Implement Branch and Bound coin selection in a new file Create a new file for coin selection logic and implement the BnB algorithm in it. * Move output eligibility to a separate function * Use a struct for output eligibility Instead of specifying 3 parameters, use a struct for those parameters in order to reduce the number of arguments to SelectCoinsMinConf. * Remove coinselection.h -> wallet.h circular dependency Changes CInputCoin to coinselection and to use CTransactionRef in order to avoid a circular dependency. Also moves other coin selection specific variables out of wallet.h to coinselectoin.h * Add tests for the Branch and Bound algorithm * Move current coin selection algorithm to coinselection.{cpp,h} Moves the current coin selection algorithm out of SelectCoinsMinConf and puts it in coinselection.{cpp,h}. The new function, KnapsackSolver, instead of taking a vector of COutputs, will take a vector of CInputCoins that is prepared by SelectCoinsMinConf. * Move original knapsack solver tests to coinselector_tests.cpp * Add a GetMinimumFeeRate function which is wrapped by GetMinimumFee * Have SelectCoinsMinConf and SelectCoins use BnB or Knapsack and use it (partial) Allows SelectCoinsMinConf and SelectCoins be able to switch between using BnB or Knapsack for choosing coins. Has SelectCoinsMinConf do the preprocessing necessary to support either BnB or Knapsack. This includes calculating the filtering the effective values for each input. Uses BnB in CreateTransaction to find an exact match for the output. If BnB fails, it will fallback to the Knapsack solver. Dash specific note: just always use Knapsack in CreateTransaction. * Benchmark BnB in the worst case where it exhausts * Add a test to make sure that negative effective values are filtered * More of 12747: Fix typos Co-authored-by: Andrew Chow <achow101-github@achow101.com>
2020-12-18 18:43:48 +01:00
feerate_needed = *(coin_control.m_feerate);
if (feeCalc) feeCalc->reason = FeeReason::PAYTXFEE;
// Allow to override automatic min/max check over coin control instance
Backport bitcoin#10637 (partial) (#3878) * Calculate and store the number of bytes required to spend an input * Store effective value, fee, and long term fee in CInputCoin Have CInputCOin store effective value information. This includes the effective value itself, the fee, and the long term fee for the input * Implement Branch and Bound coin selection in a new file Create a new file for coin selection logic and implement the BnB algorithm in it. * Move output eligibility to a separate function * Use a struct for output eligibility Instead of specifying 3 parameters, use a struct for those parameters in order to reduce the number of arguments to SelectCoinsMinConf. * Remove coinselection.h -> wallet.h circular dependency Changes CInputCoin to coinselection and to use CTransactionRef in order to avoid a circular dependency. Also moves other coin selection specific variables out of wallet.h to coinselectoin.h * Add tests for the Branch and Bound algorithm * Move current coin selection algorithm to coinselection.{cpp,h} Moves the current coin selection algorithm out of SelectCoinsMinConf and puts it in coinselection.{cpp,h}. The new function, KnapsackSolver, instead of taking a vector of COutputs, will take a vector of CInputCoins that is prepared by SelectCoinsMinConf. * Move original knapsack solver tests to coinselector_tests.cpp * Add a GetMinimumFeeRate function which is wrapped by GetMinimumFee * Have SelectCoinsMinConf and SelectCoins use BnB or Knapsack and use it (partial) Allows SelectCoinsMinConf and SelectCoins be able to switch between using BnB or Knapsack for choosing coins. Has SelectCoinsMinConf do the preprocessing necessary to support either BnB or Knapsack. This includes calculating the filtering the effective values for each input. Uses BnB in CreateTransaction to find an exact match for the output. If BnB fails, it will fallback to the Knapsack solver. Dash specific note: just always use Knapsack in CreateTransaction. * Benchmark BnB in the worst case where it exhausts * Add a test to make sure that negative effective values are filtered * More of 12747: Fix typos Co-authored-by: Andrew Chow <achow101-github@achow101.com>
2020-12-18 18:43:48 +01:00
if (coin_control.fOverrideFeeRate) return feerate_needed;
}
else if (!coin_control.m_confirm_target && ::payTxFee != CFeeRate(0)) { // 3. TODO: remove magic value of 0 for global payTxFee
Backport bitcoin#10637 (partial) (#3878) * Calculate and store the number of bytes required to spend an input * Store effective value, fee, and long term fee in CInputCoin Have CInputCOin store effective value information. This includes the effective value itself, the fee, and the long term fee for the input * Implement Branch and Bound coin selection in a new file Create a new file for coin selection logic and implement the BnB algorithm in it. * Move output eligibility to a separate function * Use a struct for output eligibility Instead of specifying 3 parameters, use a struct for those parameters in order to reduce the number of arguments to SelectCoinsMinConf. * Remove coinselection.h -> wallet.h circular dependency Changes CInputCoin to coinselection and to use CTransactionRef in order to avoid a circular dependency. Also moves other coin selection specific variables out of wallet.h to coinselectoin.h * Add tests for the Branch and Bound algorithm * Move current coin selection algorithm to coinselection.{cpp,h} Moves the current coin selection algorithm out of SelectCoinsMinConf and puts it in coinselection.{cpp,h}. The new function, KnapsackSolver, instead of taking a vector of COutputs, will take a vector of CInputCoins that is prepared by SelectCoinsMinConf. * Move original knapsack solver tests to coinselector_tests.cpp * Add a GetMinimumFeeRate function which is wrapped by GetMinimumFee * Have SelectCoinsMinConf and SelectCoins use BnB or Knapsack and use it (partial) Allows SelectCoinsMinConf and SelectCoins be able to switch between using BnB or Knapsack for choosing coins. Has SelectCoinsMinConf do the preprocessing necessary to support either BnB or Knapsack. This includes calculating the filtering the effective values for each input. Uses BnB in CreateTransaction to find an exact match for the output. If BnB fails, it will fallback to the Knapsack solver. Dash specific note: just always use Knapsack in CreateTransaction. * Benchmark BnB in the worst case where it exhausts * Add a test to make sure that negative effective values are filtered * More of 12747: Fix typos Co-authored-by: Andrew Chow <achow101-github@achow101.com>
2020-12-18 18:43:48 +01:00
feerate_needed = ::payTxFee;
if (feeCalc) feeCalc->reason = FeeReason::PAYTXFEE;
}
else { // 2. or 4.
// We will use smart fee estimation
unsigned int target = coin_control.m_confirm_target ? *coin_control.m_confirm_target : ::nTxConfirmTarget;
// By default estimates are economical
bool conservative_estimate = true;
// Allow to override the default fee estimate mode over the CoinControl instance
if (coin_control.m_fee_mode == FeeEstimateMode::CONSERVATIVE) conservative_estimate = true;
else if (coin_control.m_fee_mode == FeeEstimateMode::ECONOMICAL) conservative_estimate = false;
Backport bitcoin#10637 (partial) (#3878) * Calculate and store the number of bytes required to spend an input * Store effective value, fee, and long term fee in CInputCoin Have CInputCOin store effective value information. This includes the effective value itself, the fee, and the long term fee for the input * Implement Branch and Bound coin selection in a new file Create a new file for coin selection logic and implement the BnB algorithm in it. * Move output eligibility to a separate function * Use a struct for output eligibility Instead of specifying 3 parameters, use a struct for those parameters in order to reduce the number of arguments to SelectCoinsMinConf. * Remove coinselection.h -> wallet.h circular dependency Changes CInputCoin to coinselection and to use CTransactionRef in order to avoid a circular dependency. Also moves other coin selection specific variables out of wallet.h to coinselectoin.h * Add tests for the Branch and Bound algorithm * Move current coin selection algorithm to coinselection.{cpp,h} Moves the current coin selection algorithm out of SelectCoinsMinConf and puts it in coinselection.{cpp,h}. The new function, KnapsackSolver, instead of taking a vector of COutputs, will take a vector of CInputCoins that is prepared by SelectCoinsMinConf. * Move original knapsack solver tests to coinselector_tests.cpp * Add a GetMinimumFeeRate function which is wrapped by GetMinimumFee * Have SelectCoinsMinConf and SelectCoins use BnB or Knapsack and use it (partial) Allows SelectCoinsMinConf and SelectCoins be able to switch between using BnB or Knapsack for choosing coins. Has SelectCoinsMinConf do the preprocessing necessary to support either BnB or Knapsack. This includes calculating the filtering the effective values for each input. Uses BnB in CreateTransaction to find an exact match for the output. If BnB fails, it will fallback to the Knapsack solver. Dash specific note: just always use Knapsack in CreateTransaction. * Benchmark BnB in the worst case where it exhausts * Add a test to make sure that negative effective values are filtered * More of 12747: Fix typos Co-authored-by: Andrew Chow <achow101-github@achow101.com>
2020-12-18 18:43:48 +01:00
feerate_needed = estimator.estimateSmartFee(target, feeCalc, conservative_estimate);
if (feerate_needed == CFeeRate(0)) {
// if we don't have enough data for estimateSmartFee, then use fallbackFee
Backport bitcoin#10637 (partial) (#3878) * Calculate and store the number of bytes required to spend an input * Store effective value, fee, and long term fee in CInputCoin Have CInputCOin store effective value information. This includes the effective value itself, the fee, and the long term fee for the input * Implement Branch and Bound coin selection in a new file Create a new file for coin selection logic and implement the BnB algorithm in it. * Move output eligibility to a separate function * Use a struct for output eligibility Instead of specifying 3 parameters, use a struct for those parameters in order to reduce the number of arguments to SelectCoinsMinConf. * Remove coinselection.h -> wallet.h circular dependency Changes CInputCoin to coinselection and to use CTransactionRef in order to avoid a circular dependency. Also moves other coin selection specific variables out of wallet.h to coinselectoin.h * Add tests for the Branch and Bound algorithm * Move current coin selection algorithm to coinselection.{cpp,h} Moves the current coin selection algorithm out of SelectCoinsMinConf and puts it in coinselection.{cpp,h}. The new function, KnapsackSolver, instead of taking a vector of COutputs, will take a vector of CInputCoins that is prepared by SelectCoinsMinConf. * Move original knapsack solver tests to coinselector_tests.cpp * Add a GetMinimumFeeRate function which is wrapped by GetMinimumFee * Have SelectCoinsMinConf and SelectCoins use BnB or Knapsack and use it (partial) Allows SelectCoinsMinConf and SelectCoins be able to switch between using BnB or Knapsack for choosing coins. Has SelectCoinsMinConf do the preprocessing necessary to support either BnB or Knapsack. This includes calculating the filtering the effective values for each input. Uses BnB in CreateTransaction to find an exact match for the output. If BnB fails, it will fallback to the Knapsack solver. Dash specific note: just always use Knapsack in CreateTransaction. * Benchmark BnB in the worst case where it exhausts * Add a test to make sure that negative effective values are filtered * More of 12747: Fix typos Co-authored-by: Andrew Chow <achow101-github@achow101.com>
2020-12-18 18:43:48 +01:00
feerate_needed = CWallet::fallbackFee;
if (feeCalc) feeCalc->reason = FeeReason::FALLBACK;
}
// Obey mempool min fee when using smart fee estimation
Backport bitcoin#10637 (partial) (#3878) * Calculate and store the number of bytes required to spend an input * Store effective value, fee, and long term fee in CInputCoin Have CInputCOin store effective value information. This includes the effective value itself, the fee, and the long term fee for the input * Implement Branch and Bound coin selection in a new file Create a new file for coin selection logic and implement the BnB algorithm in it. * Move output eligibility to a separate function * Use a struct for output eligibility Instead of specifying 3 parameters, use a struct for those parameters in order to reduce the number of arguments to SelectCoinsMinConf. * Remove coinselection.h -> wallet.h circular dependency Changes CInputCoin to coinselection and to use CTransactionRef in order to avoid a circular dependency. Also moves other coin selection specific variables out of wallet.h to coinselectoin.h * Add tests for the Branch and Bound algorithm * Move current coin selection algorithm to coinselection.{cpp,h} Moves the current coin selection algorithm out of SelectCoinsMinConf and puts it in coinselection.{cpp,h}. The new function, KnapsackSolver, instead of taking a vector of COutputs, will take a vector of CInputCoins that is prepared by SelectCoinsMinConf. * Move original knapsack solver tests to coinselector_tests.cpp * Add a GetMinimumFeeRate function which is wrapped by GetMinimumFee * Have SelectCoinsMinConf and SelectCoins use BnB or Knapsack and use it (partial) Allows SelectCoinsMinConf and SelectCoins be able to switch between using BnB or Knapsack for choosing coins. Has SelectCoinsMinConf do the preprocessing necessary to support either BnB or Knapsack. This includes calculating the filtering the effective values for each input. Uses BnB in CreateTransaction to find an exact match for the output. If BnB fails, it will fallback to the Knapsack solver. Dash specific note: just always use Knapsack in CreateTransaction. * Benchmark BnB in the worst case where it exhausts * Add a test to make sure that negative effective values are filtered * More of 12747: Fix typos Co-authored-by: Andrew Chow <achow101-github@achow101.com>
2020-12-18 18:43:48 +01:00
CFeeRate min_mempool_feerate = pool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
if (feerate_needed < min_mempool_feerate) {
feerate_needed = min_mempool_feerate;
if (feeCalc) feeCalc->reason = FeeReason::MEMPOOL_MIN;
}
}
// prevent user from paying a fee below minRelayTxFee or minTxFee
Backport bitcoin#10637 (partial) (#3878) * Calculate and store the number of bytes required to spend an input * Store effective value, fee, and long term fee in CInputCoin Have CInputCOin store effective value information. This includes the effective value itself, the fee, and the long term fee for the input * Implement Branch and Bound coin selection in a new file Create a new file for coin selection logic and implement the BnB algorithm in it. * Move output eligibility to a separate function * Use a struct for output eligibility Instead of specifying 3 parameters, use a struct for those parameters in order to reduce the number of arguments to SelectCoinsMinConf. * Remove coinselection.h -> wallet.h circular dependency Changes CInputCoin to coinselection and to use CTransactionRef in order to avoid a circular dependency. Also moves other coin selection specific variables out of wallet.h to coinselectoin.h * Add tests for the Branch and Bound algorithm * Move current coin selection algorithm to coinselection.{cpp,h} Moves the current coin selection algorithm out of SelectCoinsMinConf and puts it in coinselection.{cpp,h}. The new function, KnapsackSolver, instead of taking a vector of COutputs, will take a vector of CInputCoins that is prepared by SelectCoinsMinConf. * Move original knapsack solver tests to coinselector_tests.cpp * Add a GetMinimumFeeRate function which is wrapped by GetMinimumFee * Have SelectCoinsMinConf and SelectCoins use BnB or Knapsack and use it (partial) Allows SelectCoinsMinConf and SelectCoins be able to switch between using BnB or Knapsack for choosing coins. Has SelectCoinsMinConf do the preprocessing necessary to support either BnB or Knapsack. This includes calculating the filtering the effective values for each input. Uses BnB in CreateTransaction to find an exact match for the output. If BnB fails, it will fallback to the Knapsack solver. Dash specific note: just always use Knapsack in CreateTransaction. * Benchmark BnB in the worst case where it exhausts * Add a test to make sure that negative effective values are filtered * More of 12747: Fix typos Co-authored-by: Andrew Chow <achow101-github@achow101.com>
2020-12-18 18:43:48 +01:00
CFeeRate required_feerate = GetRequiredFeeRate();
if (required_feerate > feerate_needed) {
feerate_needed = required_feerate;
if (feeCalc) feeCalc->reason = FeeReason::REQUIRED;
}
Backport bitcoin#10637 (partial) (#3878) * Calculate and store the number of bytes required to spend an input * Store effective value, fee, and long term fee in CInputCoin Have CInputCOin store effective value information. This includes the effective value itself, the fee, and the long term fee for the input * Implement Branch and Bound coin selection in a new file Create a new file for coin selection logic and implement the BnB algorithm in it. * Move output eligibility to a separate function * Use a struct for output eligibility Instead of specifying 3 parameters, use a struct for those parameters in order to reduce the number of arguments to SelectCoinsMinConf. * Remove coinselection.h -> wallet.h circular dependency Changes CInputCoin to coinselection and to use CTransactionRef in order to avoid a circular dependency. Also moves other coin selection specific variables out of wallet.h to coinselectoin.h * Add tests for the Branch and Bound algorithm * Move current coin selection algorithm to coinselection.{cpp,h} Moves the current coin selection algorithm out of SelectCoinsMinConf and puts it in coinselection.{cpp,h}. The new function, KnapsackSolver, instead of taking a vector of COutputs, will take a vector of CInputCoins that is prepared by SelectCoinsMinConf. * Move original knapsack solver tests to coinselector_tests.cpp * Add a GetMinimumFeeRate function which is wrapped by GetMinimumFee * Have SelectCoinsMinConf and SelectCoins use BnB or Knapsack and use it (partial) Allows SelectCoinsMinConf and SelectCoins be able to switch between using BnB or Knapsack for choosing coins. Has SelectCoinsMinConf do the preprocessing necessary to support either BnB or Knapsack. This includes calculating the filtering the effective values for each input. Uses BnB in CreateTransaction to find an exact match for the output. If BnB fails, it will fallback to the Knapsack solver. Dash specific note: just always use Knapsack in CreateTransaction. * Benchmark BnB in the worst case where it exhausts * Add a test to make sure that negative effective values are filtered * More of 12747: Fix typos Co-authored-by: Andrew Chow <achow101-github@achow101.com>
2020-12-18 18:43:48 +01:00
return feerate_needed;
}
CFeeRate GetDiscardRate(const CBlockPolicyEstimator& estimator)
{
unsigned int highest_target = estimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
CFeeRate discard_rate = estimator.estimateSmartFee(highest_target, nullptr /* FeeCalculation */, false /* conservative */);
// Don't let discard_rate be greater than longest possible fee estimate if we get a valid fee estimate
discard_rate = (discard_rate == CFeeRate(0)) ? CWallet::m_discard_rate : std::min(discard_rate, CWallet::m_discard_rate);
// Discard rate must be at least dustRelayFee
discard_rate = std::max(discard_rate, ::dustRelayFee);
return discard_rate;
}