Skip to content

Commit f21e445

Browse files
committed
Merge bitcoin#497: [Wallet] Call AutocombineDust less often
6e39d70 [Performance] AutocombineDust is called less often (warrows) Tree-SHA512: d336609341222ac1c0ee6b9ab57ede0785ce941450e55408b1813bc44e15a8c6149eff47055516296fc15051ea7abe51375bb4911275e6093cc1cad67ca2c53b
2 parents 72d8c7d + 6e39d70 commit f21e445

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/wallet.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,11 +3985,11 @@ void CWallet::AutoZeromint()
39853985

39863986
void CWallet::AutoCombineDust()
39873987
{
3988-
if (IsInitialBlockDownload() || IsLocked()) {
3988+
if (chainActive.Tip()->nTime < (GetAdjustedTime() - 300) || IsLocked()) {
39893989
return;
39903990
}
39913991

3992-
map<CBitcoinAddress, vector<COutput> > mapCoinsByAddress = AvailableCoinsByAddress(true, 0);
3992+
map<CBitcoinAddress, vector<COutput> > mapCoinsByAddress = AvailableCoinsByAddress(true, nAutoCombineThreshold * COIN);
39933993

39943994
//coins are sectioned by address. This combination code only wants to combine inputs that belong to the same address
39953995
for (map<CBitcoinAddress, vector<COutput> >::iterator it = mapCoinsByAddress.begin(); it != mapCoinsByAddress.end(); it++) {
@@ -4008,13 +4008,15 @@ void CWallet::AutoCombineDust()
40084008
if (out.tx->IsCoinStake() && out.tx->GetDepthInMainChain() < COINBASE_MATURITY + 1)
40094009
continue;
40104010

4011-
if (out.Value() > nAutoCombineThreshold * COIN)
4012-
continue;
4013-
40144011
COutPoint outpt(out.tx->GetHash(), out.i);
40154012
coinControl->Select(outpt);
40164013
vRewardCoins.push_back(out);
40174014
nTotalRewardsValue += out.Value();
4015+
4016+
// Combine to the threshold and not way above
4017+
if (nTotalRewardsValue > nAutoCombineThreshold * COIN)
4018+
break;
4019+
40184020
// Around 180 bytes per input. We use 190 to be certain
40194021
txSizeEstimate += 190;
40204022
if (txSizeEstimate >= MAX_STANDARD_TX_SIZE - 200)
@@ -4049,6 +4051,10 @@ void CWallet::AutoCombineDust()
40494051
continue;
40504052
}
40514053

4054+
//we don't combine below the threshold unless the fees are 0 to avoid paying fees over fees over fees
4055+
if (vecSend[0].second < nAutoCombineThreshold * COIN && nFeeRet > 0)
4056+
continue;
4057+
40524058
if (!CommitTransaction(wtx, keyChange)) {
40534059
LogPrintf("AutoCombineDust transaction commit failed\n");
40544060
continue;

0 commit comments

Comments
 (0)