-
Notifications
You must be signed in to change notification settings - Fork 37.8k
refactor pre-selected coin code #13057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/wallet/wallet.cpp
Outdated
@@ -2537,6 +2523,11 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm | |||
return false; // TODO: Allow non-wallet inputs | |||
} | |||
|
|||
if (coin_control.HasSelected() && !coin_control.fAllowOtherInputs) | |||
{ | |||
return (nValueRet >= nTargetValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about setCoinsRet
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nValueRet
is never updated, so this will always return false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it will always fail when coin_control.fAllowOtherInputs
is not set? I don't think that's supposed to be the behavior.
NACK 4aaa5ba - this code isn't redundant, the out args are used by caller |
The fact that the test suite passes with this removal is a smell though - how about a test for |
I will write tests fix this, thanks. Just not at my computer today.
…On Mon, Apr 23, 2018, 4:38 PM Ben Woosley ***@***.***> wrote:
The fact that the test suite passes with this removal is a smell though -
how about a test for CreateTransaction or SelectCoins that fails with
this removal?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#13057 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFgC061sK4esuliPqtBCPdCuCC-mFlJ3ks5trjuzgaJpZM4Tf7aM>
.
|
This is what I was afraid of - I don't think we test the part of the wallet code that is used by the GUI coin selection very well. |
d45a954
to
ebc1934
Compare
ebc1934
to
358c298
Compare
did some additional refactoring to make flow easier to follow(early return if you captured enough value with presets), and added a basic unit test that should have failed with previous broken iteration |
coin_control2.ListSelected(coin_list); | ||
BOOST_CHECK(setCoinsRet.size() == coin_list.size()); | ||
// "over-selected" since these were mandatory | ||
BOOST_CHECK(nValueRet == (5+6+11) * CENT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BOOST_CHECK_EQUAL
here and above?
src/wallet/wallet.cpp
Outdated
for (std::vector<COutput>::iterator it = vCoins.begin(); it != vCoins.end() && coin_control.HasSelected();) | ||
{ | ||
if (setPresetCoins.count(CInputCoin(it->tx->tx, it->i))) | ||
for (std::vector<COutput>::iterator it = vCoins.begin(); it != vCoins.end() && coin_control.HasSelected();) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this could be a const_iterator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it's deleting entries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The vector is deleting entries, the COutputs themselves are unmodified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I assume const_iterator was const for everything, including the underlying vector. TIL
src/wallet/wallet.cpp
Outdated
(m_spend_zero_conf_change && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, CoinEligibilityFilter(0, 1, nMaxChainLength/2), vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used)) || | ||
(m_spend_zero_conf_change && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, CoinEligibilityFilter(0, 1, nMaxChainLength), vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used)) || | ||
(m_spend_zero_conf_change && !fRejectLongChains && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, CoinEligibilityFilter(0, 1, std::numeric_limits<uint64_t>::max()), vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used)); | ||
CAmount amount_to_select = nTargetValue - nValueFromPresetInputs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: const
1928a6f
to
228469b
Compare
228469b
to
04839bf
Compare
0a2fca8
to
c25c442
Compare
rebased, and did a tiny bit more refactoring for more readability. |
You have some whitespace inconsistencies, clang-format would be good. |
src/wallet/wallet.cpp
Outdated
(m_spend_zero_conf_change && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, CoinEligibilityFilter(0, 1, max_ancestors/2, max_descendants/2), vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used)) || | ||
(m_spend_zero_conf_change && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, CoinEligibilityFilter(0, 1, max_ancestors-1, max_descendants-1), vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used)) || | ||
(m_spend_zero_conf_change && !fRejectLongChains && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, CoinEligibilityFilter(0, 1, std::numeric_limits<uint64_t>::max()), vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used)); | ||
const CAmount amount_to_select = nTargetValue - nValueFromPresetInputs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loses the early return if nTargetValue <= nValueFromPresetInputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be covered here: https://github.com/bitcoin/bitcoin/pull/13057/files#diff-b2bb174788c7409b671c46ccc86034bdR2567
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks, in that case how about moving this assignment up to tie the two together?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/wallet/wallet.cpp
Outdated
SelectCoinsMinConf(amount_to_select, CoinEligibilityFilter(0, 1, max_ancestors/2, max_descendants/2), vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used) || | ||
SelectCoinsMinConf(amount_to_select, CoinEligibilityFilter(0, 1, max_ancestors-1, max_descendants-1), vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used) || | ||
(!fRejectLongChains && SelectCoinsMinConf(amount_to_select, CoinEligibilityFilter(0, 1, std::numeric_limits<uint64_t>::max()), vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I like not having repeated tests of m_spend_zero_conf_change
, but I would keep it as a single assignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
92572a0
to
31a0170
Compare
31a0170
to
4f0111e
Compare
rebased |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
The last travis run for this pull request was 277 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened. |
utACK 4f0111e but this would be easier to review if it focused around the fix e.g.: Empact@3bcd12d |
Any specific reason for closing this? |
No particular reason. Just something I didn't feel like pursuing review on. |
This section of code loops over the same coins twice, in two different ways depending on whether other inputs are allowed, even though the net effect is just an early return in one case. One used the available coins list(pruned to just preselected coins) and the other the preselected coins directly. Instead just do it once, and return early if no other inputs are allowed.
Note that by definition coin control is in use, so "fSpendable" will always be true, so filtering for this is a NOP.
Added basic unit test case as well.