Merge #13812: wallet: sum ancestors rather than taking max in output groups

23fbbb100f wallet: sum ancestors rather than taking max in output groups (Karl-Johan Alm)

Pull request description:

  This is pointed out in https://github.com/bitcoin/bitcoin/pull/12257#discussion_r204549758.

  Basically, the ancestors gives an indication as to how many ancestors the resulting transaction will have, which is more precise when summing up the values, rather than taking the maximum, since all the coins in the group will become ancestors if selected.

Tree-SHA512: 0588c4b6059669650614817e041526a2ab89dda8c07fca8e077c7669dca1fed51cd164f7df56340840ab60285d48f3b140dcee64f64bf696b2dd4ab16d556a13
This commit is contained in:
Wladimir J. van der Laan 2018-08-07 17:18:33 +02:00
commit 9d86aad287
No known key found for this signature in database
GPG key ID: 1E4AED62986CD25D

View file

@ -299,12 +299,12 @@ void OutputGroup::Insert(const CInputCoin& output, int depth, bool from_me, size
m_from_me &= from_me; m_from_me &= from_me;
m_value += output.effective_value; m_value += output.effective_value;
m_depth = std::min(m_depth, depth); m_depth = std::min(m_depth, depth);
// m_ancestors is currently the max ancestor count for all coins in the group; however, this is // ancestors here express the number of ancestors the new coin will end up having, which is
// not ideal, as a wallet will consider e.g. thirty 2-ancestor coins as having two ancestors, // the sum, rather than the max; this will overestimate in the cases where multiple inputs
// when in reality it has 60 ancestors. // have common ancestors
m_ancestors = std::max(m_ancestors, ancestors); m_ancestors += ancestors;
// m_descendants is the count as seen from the top ancestor, not the descendants as seen from the // descendants is the count as seen from the top ancestor, not the descendants as seen from the
// coin itself; thus, this value is accurate // coin itself; thus, this value is counted as the max, not the sum
m_descendants = std::max(m_descendants, descendants); m_descendants = std::max(m_descendants, descendants);
effective_value = m_value; effective_value = m_value;
} }