diff options
Diffstat (limited to 'src/wallet/coinselection.cpp')
-rw-r--r-- | src/wallet/coinselection.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index 1a810e763f..8a37f374a1 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -1,10 +1,13 @@ -// Copyright (c) 2017 The Bitcoin Core developers +// Copyright (c) 2017-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <wallet/coinselection.h> -#include <util.h> -#include <utilmoneystr.h> + +#include <util/system.h> +#include <util/moneystr.h> + +#include <boost/optional.hpp> // Descending order comparator struct { @@ -220,7 +223,7 @@ bool KnapsackSolver(const CAmount& nTargetValue, std::vector<OutputGroup>& group std::vector<OutputGroup> applicable_groups; CAmount nTotalLower = 0; - random_shuffle(groups.begin(), groups.end(), GetRandInt); + Shuffle(groups.begin(), groups.end(), FastRandomContext()); for (const OutputGroup& group : groups) { if (group.m_value == nTargetValue) { @@ -299,12 +302,12 @@ void OutputGroup::Insert(const CInputCoin& output, int depth, bool from_me, size m_from_me &= from_me; m_value += output.effective_value; m_depth = std::min(m_depth, depth); - // m_ancestors is currently the max ancestor count for all coins in the group; however, this is - // not ideal, as a wallet will consider e.g. thirty 2-ancestor coins as having two ancestors, - // when in reality it has 60 ancestors. - m_ancestors = std::max(m_ancestors, ancestors); - // m_descendants is the count as seen from the top ancestor, not the descendants as seen from the - // coin itself; thus, this value is accurate + // ancestors here express the number of ancestors the new coin will end up having, which is + // the sum, rather than the max; this will overestimate in the cases where multiple inputs + // have common ancestors + m_ancestors += ancestors; + // descendants is the count as seen from the top ancestor, not the descendants as seen from the + // coin itself; thus, this value is counted as the max, not the sum m_descendants = std::max(m_descendants, descendants); effective_value = m_value; } |