optimize PS (#1180)

* move HasCollateralInputs out of the loop

* optimize HasCollateralInputs
This commit is contained in:
UdjinM6 2016-12-05 00:33:11 +04:00 committed by GitHub
parent 786f17e1f2
commit 80444ea8e4
4 changed files with 12 additions and 10 deletions

View File

@ -1855,8 +1855,10 @@ bool CDarksendPool::CreateDenominated()
return false; return false;
} }
bool fCreateMixingCollaterals = !pwalletMain->HasCollateralInputs();
BOOST_FOREACH(CompactTallyItem& item, vecTally) { BOOST_FOREACH(CompactTallyItem& item, vecTally) {
if(!CreateDenominated(item)) continue; if(!CreateDenominated(item, fCreateMixingCollaterals)) continue;
return true; return true;
} }
@ -1865,7 +1867,7 @@ bool CDarksendPool::CreateDenominated()
} }
// Create denominations // Create denominations
bool CDarksendPool::CreateDenominated(const CompactTallyItem& tallyItem) bool CDarksendPool::CreateDenominated(const CompactTallyItem& tallyItem, bool fCreateMixingCollaterals)
{ {
std::vector<CRecipient> vecSend; std::vector<CRecipient> vecSend;
CAmount nValueLeft = tallyItem.nAmount; CAmount nValueLeft = tallyItem.nAmount;
@ -1882,7 +1884,7 @@ bool CDarksendPool::CreateDenominated(const CompactTallyItem& tallyItem)
// ****** Add collateral outputs ************ / // ****** Add collateral outputs ************ /
if(!pwalletMain->HasCollateralInputs()) { if(fCreateMixingCollaterals) {
vecSend.push_back((CRecipient){scriptCollateral, PRIVATESEND_COLLATERAL*4, false}); vecSend.push_back((CRecipient){scriptCollateral, PRIVATESEND_COLLATERAL*4, false});
nValueLeft -= PRIVATESEND_COLLATERAL*4; nValueLeft -= PRIVATESEND_COLLATERAL*4;
} }

View File

@ -382,7 +382,7 @@ private:
/// Create denominations /// Create denominations
bool CreateDenominated(); bool CreateDenominated();
bool CreateDenominated(const CompactTallyItem& tallyItem); bool CreateDenominated(const CompactTallyItem& tallyItem, bool fCreateMixingCollaterals);
/// Split up large inputs or make fee sized inputs /// Split up large inputs or make fee sized inputs
bool MakeCollateralAmounts(); bool MakeCollateralAmounts();

View File

@ -2118,6 +2118,8 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
if(found && fMasterNode) found = pcoin->vout[i].nValue != 1000*COIN; // do not use Hot MN funds if(found && fMasterNode) found = pcoin->vout[i].nValue != 1000*COIN; // do not use Hot MN funds
} else if(nCoinType == ONLY_1000) { } else if(nCoinType == ONLY_1000) {
found = pcoin->vout[i].nValue == 1000*COIN; found = pcoin->vout[i].nValue == 1000*COIN;
} else if(nCoinType == ONLY_PRIVATESEND_COLLATERAL) {
found = IsCollateralAmount(pcoin->vout[i].nValue);
} else { } else {
found = true; found = true;
} }
@ -2781,12 +2783,9 @@ int CWallet::CountInputsWithAmount(CAmount nInputAmount)
bool CWallet::HasCollateralInputs(bool fOnlyConfirmed) const bool CWallet::HasCollateralInputs(bool fOnlyConfirmed) const
{ {
vector<COutput> vCoins; vector<COutput> vCoins;
AvailableCoins(vCoins, fOnlyConfirmed); AvailableCoins(vCoins, fOnlyConfirmed, NULL, false, ONLY_PRIVATESEND_COLLATERAL);
BOOST_FOREACH(const COutput& out, vCoins) return !vCoins.empty();
if(IsCollateralAmount(out.tx->vout[out.i].nValue)) return true;
return false;
} }
bool CWallet::IsCollateralAmount(CAmount nInputAmount) const bool CWallet::IsCollateralAmount(CAmount nInputAmount) const

View File

@ -97,7 +97,8 @@ enum AvailableCoinsType
ONLY_DENOMINATED = 2, ONLY_DENOMINATED = 2,
ONLY_NOT1000IFMN = 3, ONLY_NOT1000IFMN = 3,
ONLY_NONDENOMINATED_NOT1000IFMN = 4, ONLY_NONDENOMINATED_NOT1000IFMN = 4,
ONLY_1000 = 5 // find masternode outputs including locked ones (use with caution) ONLY_1000 = 5, // find masternode outputs including locked ones (use with caution)
ONLY_PRIVATESEND_COLLATERAL = 6
}; };
struct CompactTallyItem struct CompactTallyItem