Refactor SelectCoinsMinConf() and add unit tests.#905
Refactor SelectCoinsMinConf() and add unit tests.#905dooglus wants to merge 4 commits intobitcoin:masterfrom
Conversation
AvailableCoins() makes a vector of available outputs which is then passed to SelectCoinsMinConf(). This allows unit tests to test the coin selection algorithm without having the whole blockchain available.
|
ACK; I really like having unit tests for the coin selection algorithm. |
There was a problem hiding this comment.
The random_shuffle was deleted here, but I don't see any calls to randomize the coins selected. A random_shuffle of the result of AvailableCoins should probably be done so coin selection is unpredictable.
A unit test to test randomness that calls SelectCoins two times to get (say) 5 out of 100 coins, all of the same value/age, and fails if exactly the same coins are selected would also be nifty.
|
@gavinandresen I noticed that the shuffle was missing some time ago. It has been added back in in #1017 which is my current branch for these changes, and includes the coincontrol and lesschange changes too. I'll also add a new unit test for randomness too. Do you need this pull request with just the refactoring updated too? I merged these related changes all together to make them easier to keep up to date. |
|
Notice that the coins are sorted into order before running the stochastic approximation: and so the shuffle's work will be undone in the case you propose. The only times the shuffle has any effect is if:
I added your suggested "4-from-100 identical" test to check that different random coins were being selected each time. It ran the test 100 times. And every time it failed on iterations 49 and 51. It turns out that this is because rand() is being used in the stochastic approximation code: and rand() isn't being seeded, so returns the same sequence each time bitcoin is run. See new bug #1057. If I use GetRandInt(2) instead of rand()%2 then the tests fail occasionally, but randomly. It turns out that selecting 4 coins from a sorted list of 100 often picks the same 4. So I'll pick 50 from 100 instead to minimise the chance of a random identical selection. |
…e. sub-cent change.
|
I've merged my latest changes to the unit tests from lesschange-v0.6.0 (#1017) back onto this branch. There are also tests for sub-cent change suggested by Luke here: #898 (comment) which didn't get into this branch before. |
…ndomized coin selection.
|
Is this superceded or not? |
|
Closing; I pulled 1416 which was an updated version. |
Change default datadir
Remove BITCOIN_CASH ifdef completely
AvailableCoins() makes a vector of available outputs which is then passed to SelectCoinsMinConf(). This allows unit tests to test the coin selection algorithm without having the whole blockchain available.
This change was suggested in the comments of pull #898.