Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.12.0.x Use single random denom in new DS session #500

Merged
merged 1 commit into from
Aug 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/darksend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,9 +1587,9 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready)

std::vector<CAmount> vecAmounts;
pwalletMain->ConvertList(vCoins, vecAmounts);
// try to get random denoms out of vecAmounts
// try to get a single random denom out of vecAmounts
while(sessionDenom == 0)
sessionDenom = GetDenominationsByAmounts(vecAmounts, true);
sessionDenom = GetDenominationsByAmounts(vecAmounts);

pnode->PushMessage("dsa", sessionDenom, txCollateral);
LogPrintf("DoAutomaticDenominating --- connected, sending dsa for %d\n", sessionDenom);
Expand Down Expand Up @@ -1914,7 +1914,7 @@ int CDarksendPool::GetDenominations(const std::vector<CTxDSOut>& vout){
}

// return a bitshifted integer representing the denominations in this list
int CDarksendPool::GetDenominations(const std::vector<CTxOut>& vout, bool fRandDenom){
int CDarksendPool::GetDenominations(const std::vector<CTxOut>& vout, bool fSingleRandomDenom){
std::vector<pair<int64_t, int> > denomUsed;

// make a list of denominations, with zero uses
Expand All @@ -1937,8 +1937,11 @@ int CDarksendPool::GetDenominations(const std::vector<CTxOut>& vout, bool fRandD
int c = 0;
// if the denomination is used, shift the bit on.
// then move to the next
BOOST_FOREACH (PAIRTYPE(int64_t, int)& s, denomUsed)
denom |= ((fRandDenom ? rand()%2 : 1) * s.second) << c++;
BOOST_FOREACH (PAIRTYPE(int64_t, int)& s, denomUsed) {
int bit = (fSingleRandomDenom ? rand()%2 : 1) * s.second;
denom |= bit << c++;
if(fSingleRandomDenom && bit) break; // use just one random denomination
}

// Function returns as follows:
//
Expand All @@ -1951,20 +1954,17 @@ int CDarksendPool::GetDenominations(const std::vector<CTxOut>& vout, bool fRandD
}


int CDarksendPool::GetDenominationsByAmounts(std::vector<int64_t>& vecAmount, bool fRandDenom){
int CDarksendPool::GetDenominationsByAmounts(std::vector<int64_t>& vecAmount){
CScript e = CScript();
std::vector<CTxOut> vout1;

// Make outputs by looping through denominations, from small to large
BOOST_REVERSE_FOREACH(int64_t v, vecAmount){
int nOutputs = 0;

CTxOut o(v, e);
vout1.push_back(o);
nOutputs++;
}

return GetDenominations(vout1, fRandDenom);
return GetDenominations(vout1, true);
}

int CDarksendPool::GetDenominationsByAmount(int64_t nAmount, int nDenomTarget){
Expand Down
4 changes: 2 additions & 2 deletions src/darksend.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,14 @@ class CDarksendPool
bool CreateDenominated(int64_t nTotalValue);

/// Get the denominations for a list of outputs (returns a bitshifted integer)
int GetDenominations(const std::vector<CTxOut>& vout, bool fRandDenom = false);
int GetDenominations(const std::vector<CTxOut>& vout, bool fSingleRandomDenom = false);
int GetDenominations(const std::vector<CTxDSOut>& vout);

void GetDenominationsToString(int nDenom, std::string& strDenom);

/// Get the denominations for a specific amount of dash.
int GetDenominationsByAmount(int64_t nAmount, int nDenomTarget=0); // is not used anymore?
int GetDenominationsByAmounts(std::vector<int64_t>& vecAmount, bool fRandDenom = false);
int GetDenominationsByAmounts(std::vector<int64_t>& vecAmount);

std::string GetMessageByID(int messageID);

Expand Down