Skip to content

Commit

Permalink
Added Python test for transaction too large issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wqking committed Nov 12, 2019
1 parent 5928d0b commit 5b08df9
Show file tree
Hide file tree
Showing 2 changed files with 446 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2155,23 +2155,31 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
coinLowestLarger.second.first = NULL;
vector<pair<CAmount, pair<const CWalletTx*, unsigned int> > > vValue;
CAmount nTotalLower = 0;

switch(coinSelectStrategy) {
case CoinSelectStrategy::random:
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt);
break;

default:
break;
}

// move denoms down on the list
sort(vCoins.begin(), vCoins.end(), less_then_denom);

switch(coinSelectStrategy) {
case CoinSelectStrategy::descentByAmount:
// sort after sorted by denoms
std::sort(vCoins.begin(), vCoins.end(), [](const COutput & a, const COutput & b) -> bool {
return a.Value() > b.Value();
});
break;

case CoinSelectStrategy::random:
default:
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt);
break;
}

// move denoms down on the list
sort(vCoins.begin(), vCoins.end(), less_then_denom);

// try to find nondenom first to prevent unneeded spending of mixed coins
for (unsigned int tryDenom = 0; tryDenom < 2; tryDenom++) {
if (fDebug) LogPrint("selectcoins", "tryDenom: %d\n", tryDenom);
Expand All @@ -2192,8 +2200,14 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
if (tryDenom == 0 && IsDenominatedAmount(n)) continue; // we don't want denom values on first run

pair<CAmount, pair<const CWalletTx*, unsigned int> > coin = make_pair(n, make_pair(pcoin, i));

bool equalOrGreater = (n == nTargetValue);

if(coinSelectStrategy == CoinSelectStrategy::descentByAmount) {
equalOrGreater = (n >= nTargetValue);
}

if (n == nTargetValue) {
if (equalOrGreater) {
setCoinsRet.insert(coin.second);
nValueRet += coin.first;
return true;
Expand Down
Loading

0 comments on commit 5b08df9

Please sign in to comment.