@@ -3991,11 +3991,11 @@ void CWallet::AutoZeromint()
39913991
39923992void CWallet::AutoCombineDust ()
39933993{
3994- if (IsInitialBlockDownload ( ) || IsLocked ()) {
3994+ if (chainActive. Tip ()-> nTime < ( GetAdjustedTime () - 300 ) || IsLocked ()) {
39953995 return ;
39963996 }
39973997
3998- map<CBitcoinAddress, vector<COutput> > mapCoinsByAddress = AvailableCoinsByAddress (true , 0 );
3998+ map<CBitcoinAddress, vector<COutput> > mapCoinsByAddress = AvailableCoinsByAddress (true , nAutoCombineThreshold * COIN );
39993999
40004000 // coins are sectioned by address. This combination code only wants to combine inputs that belong to the same address
40014001 for (map<CBitcoinAddress, vector<COutput> >::iterator it = mapCoinsByAddress.begin (); it != mapCoinsByAddress.end (); it++) {
@@ -4014,13 +4014,15 @@ void CWallet::AutoCombineDust()
40144014 if (out.tx ->IsCoinStake () && out.tx ->GetDepthInMainChain () < COINBASE_MATURITY + 1 )
40154015 continue ;
40164016
4017- if (out.Value () > nAutoCombineThreshold * COIN)
4018- continue ;
4019-
40204017 COutPoint outpt (out.tx ->GetHash (), out.i );
40214018 coinControl->Select (outpt);
40224019 vRewardCoins.push_back (out);
40234020 nTotalRewardsValue += out.Value ();
4021+
4022+ // Combine to the threshold and not way above
4023+ if (nTotalRewardsValue > nAutoCombineThreshold * COIN)
4024+ break ;
4025+
40244026 // Around 180 bytes per input. We use 190 to be certain
40254027 txSizeEstimate += 190 ;
40264028 if (txSizeEstimate >= MAX_STANDARD_TX_SIZE - 200 )
@@ -4055,6 +4057,10 @@ void CWallet::AutoCombineDust()
40554057 continue ;
40564058 }
40574059
4060+ // we don't combine below the threshold unless the fees are 0 to avoid paying fees over fees over fees
4061+ if (vecSend[0 ].second < nAutoCombineThreshold * COIN && nFeeRet > 0 )
4062+ continue ;
4063+
40584064 if (!CommitTransaction (wtx, keyChange)) {
40594065 LogPrintf (" AutoCombineDust transaction commit failed\n " );
40604066 continue ;
0 commit comments