Skip to content

Commit

Permalink
Changed for loop copies to references, and added stake logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew LaChasse committed Jun 16, 2020
1 parent 95ab6e4 commit 113aeea
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/accumulators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ bool CalculateAccumulatorCheckpoint(int nHeight, uint256& nCheckpoint, Accumulat
LogPrint("zero", "%s found %d mints\n", __func__, listPubcoins.size());

//add the pubcoins to accumulator
for (const PublicCoin pubcoin : listPubcoins) {
for (const PublicCoin& pubcoin : listPubcoins) {
if(!mapAccumulators.Accumulate(pubcoin, true))
return error("%s: failed to add pubcoin to accumulator at height %d", __func__, pindex->nHeight);
}
Expand Down
8 changes: 4 additions & 4 deletions src/denomination_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bool getIdealSpends(
// Start with the Highest Denomination coin and grab coins as long as the remaining amount is greater than the
// current denomination value
for (auto& coin : reverse_iterate(zerocoinDenomList)) {
for (const CMintMeta mint : listMints) {
for (const CMintMeta& mint : listMints) {
if (mint.isUsed) continue;
if (nRemainingValue >= ZerocoinDenominationToAmount(coin) && coin == mint.denom) {
mapOfDenomsUsed.at(coin)++;
Expand All @@ -134,7 +134,7 @@ std::vector<CMintMeta> getSpends(
nCoinsSpentValue = 0;
for (auto& coin : reverse_iterate(zerocoinDenomList)) {
do {
for (const CMintMeta mint : listMints) {
for (const CMintMeta& mint : listMints) {
if (mint.isUsed) continue;
if (coin == mint.denom && mapOfDenomsUsed.at(coin)) {
vSelectedMints.push_back(mint);
Expand All @@ -155,7 +155,7 @@ void listSpends(const std::vector<CZerocoinMint>& vSelectedMints)
for (auto& denom : libzerocoin::zerocoinDenomList)
mapZerocoinSupply.insert(std::make_pair(denom, 0));

for (const CZerocoinMint mint : vSelectedMints) {
for (const CZerocoinMint& mint : vSelectedMints) {
libzerocoin::CoinDenomination denom = mint.GetDenomination();
mapZerocoinSupply.at(denom)++;
}
Expand Down Expand Up @@ -409,7 +409,7 @@ int calculateChange(
// 'spends' are required
// -------------------------------------------------------------------------------------------------------
std::vector<CMintMeta> SelectMintsFromList(const CAmount nValueTarget, CAmount& nSelectedValue, int nMaxNumberOfSpends, bool fMinimizeChange,
int& nCoinsReturned, const std::list<CMintMeta>& listMints,
int& nCoinsReturned, const std::list<CMintMeta>& listMints,
const std::map<CoinDenomination, CAmount> mapOfDenomsHeld, int& nNeededSpends)
{
std::vector<CMintMeta> vSelectedMints;
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-stopafterblockimport", strprintf(_("Stop running after importing blocks from disk (default: %u)"), 0));
strUsage += HelpMessageOpt("-sporkkey=<privkey>", _("Enable spork administration functionality with the appropriate private key."));
}
string debugCategories = "addrman, alert, bench, coindb, db, lock, rand, rpc, selectcoins, tor, mempool, net, proxy, http, libevent, ohmcoin, (obfuscation, swiftx, karmanode, mnpayments, knbudget, zero)"; // Don't translate these and qt below
string debugCategories = "addrman, alert, bench, coindb, db, lock, rand, rpc, selectcoins, tor, mempool, net, proxy, http, libevent, ohmcoin, (obfuscation, swiftx, masternode, mnpayments, mnbudget, zero, precompute, staking)"; // Don't translate these and qt below
if (mode == HMM_BITCOIN_QT)
debugCategories += ", qt";
strUsage += HelpMessageOpt("-debug=<category>", strprintf(_("Output debugging information (default: %u, supplying <category> is optional)"), 0) + ". " +
Expand Down
18 changes: 9 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ bool TxOutToPublicCoin(const CTxOut txout, PublicCoin& pubCoin, CValidationState

bool BlockToPubcoinList(const CBlock& block, list<PublicCoin>& listPubcoins)
{
for (const CTransaction tx : block.vtx) {
for (const CTransaction& tx : block.vtx) {
if(!tx.IsZerocoinMint())
continue;

Expand All @@ -1154,7 +1154,7 @@ bool BlockToPubcoinList(const CBlock& block, list<PublicCoin>& listPubcoins)
//return a list of zerocoin mints contained in a specific block
bool BlockToZerocoinMintList(const CBlock& block, std::list<CZerocoinMint>& vMints)
{
for (const CTransaction tx : block.vtx) {
for (const CTransaction& tx : block.vtx) {
if(!tx.IsZerocoinMint())
continue;

Expand All @@ -1179,11 +1179,11 @@ bool BlockToZerocoinMintList(const CBlock& block, std::list<CZerocoinMint>& vMin

bool BlockToMintValueVector(const CBlock& block, const CoinDenomination denom, vector<CBigNum>& vValues)
{
for (const CTransaction tx : block.vtx) {
for (const CTransaction& tx : block.vtx) {
if(!tx.IsZerocoinMint())
continue;

for (const CTxOut txOut : tx.vout) {
for (const CTxOut& txOut : tx.vout) {
if(!txOut.scriptPubKey.IsZerocoinMint())
continue;

Expand All @@ -1206,7 +1206,7 @@ bool BlockToMintValueVector(const CBlock& block, const CoinDenomination denom, v
std::list<libzerocoin::CoinDenomination> ZerocoinSpendListFromBlock(const CBlock& block)
{
std::list<libzerocoin::CoinDenomination> vSpends;
for (const CTransaction tx : block.vtx) {
for (const CTransaction& tx : block.vtx) {
if (!tx.IsZerocoinSpend())
continue;

Expand Down Expand Up @@ -2768,7 +2768,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
}
if (tx.IsZerocoinMint()) {
//erase all zerocoinmints in this transaction
for (const CTxOut txout : tx.vout) {
for (const CTxOut& txout : tx.vout) {
if (txout.scriptPubKey.empty() || !txout.scriptPubKey.IsZerocoinMint())
continue;

Expand Down Expand Up @@ -2975,7 +2975,7 @@ bool RecalculateOHMCSupply(int nHeightStart)

CAmount nValueIn = 0;
CAmount nValueOut = 0;
for (const CTransaction tx : block.vtx) {
for (const CTransaction& tx : block.vtx) {
for (unsigned int i = 0; i < tx.vin.size(); i++) {
if (tx.IsCoinBase())
break;
Expand Down Expand Up @@ -5210,7 +5210,7 @@ bool static LoadBlockIndexDB(string& strError)
// Calculate nChainWork
vector<pair<int, CBlockIndex*> > vSortedByHeight;
vSortedByHeight.reserve(mapBlockIndex.size());
for (const PAIRTYPE(uint256, CBlockIndex*) & item : mapBlockIndex) {
for (const std::pair<const uint256, CBlockIndex*>& item : mapBlockIndex) {
CBlockIndex* pindex = item.second;
vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex));
}
Expand Down Expand Up @@ -5260,7 +5260,7 @@ bool static LoadBlockIndexDB(string& strError)
// Check presence of blk files
LogPrintf("Checking all blk files are present...\n");
set<int> setBlkDataFiles;
for (const PAIRTYPE(uint256, CBlockIndex*) & item : mapBlockIndex) {
for (const std::pair<const uint256, CBlockIndex*>& item : mapBlockIndex) {
CBlockIndex* pindex = item.second;
if (pindex->nStatus & BLOCK_HAVE_DATA) {
setBlkDataFiles.insert(pindex->nFile);
Expand Down
5 changes: 3 additions & 2 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
}

if (!fStakeFound)
LogPrint("staking", "CreateNewBlock(): stake not found\n");
return NULL;
}

Expand Down Expand Up @@ -385,7 +386,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
continue;

bool fDoubleSerial = false;
for (const CTxIn txIn : tx.vin) {
for (const CTxIn& txIn : tx.vin) {
if (txIn.scriptSig.IsZerocoinSpend()) {
libzerocoin::CoinSpend spend = TxInToZerocoinSpend(txIn);
int effectiveHeight = libzerocoin::ExtractVersionFromSerial(spend.getCoinSerialNumber()) < libzerocoin::PrivateCoin::PUBKEY_VERSION ? Params().Zerocoin_LastOldParams() : Params().Zerocoin_LastOldParams() + 1;
Expand Down Expand Up @@ -425,7 +426,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
++nBlockTx;
nFees += nTxFees;

for (const CBigNum bnSerial : vTxSerials)
for (const CBigNum& bnSerial : vTxSerials)
vBlockSerials.emplace_back(bnSerial);

if (fPrintPriority) {
Expand Down
8 changes: 4 additions & 4 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ CAmount CTransaction::GetValueOut() const

CAmount CTransaction::GetZerocoinMinted() const
{
for (const CTxOut txOut : vout) {
for (const CTxOut& txOut : vout) {
if(!txOut.scriptPubKey.IsZerocoinMint())
continue;

Expand All @@ -170,7 +170,7 @@ CAmount CTransaction::GetZerocoinMinted() const

bool CTransaction::UsesUTXO(const COutPoint out)
{
for (const CTxIn in : vin) {
for (const CTxIn& in : vin) {
if (in.prevout == out)
return true;
}
Expand All @@ -193,7 +193,7 @@ CAmount CTransaction::GetZerocoinSpent() const
return 0;

CAmount nValueOut = 0;
for (const CTxIn txin : vin) {
for (const CTxIn& txin : vin) {
if(!txin.scriptSig.IsZerocoinSpend())
continue;

Expand All @@ -206,7 +206,7 @@ CAmount CTransaction::GetZerocoinSpent() const
int CTransaction::GetZerocoinMintCount() const
{
int nCount = 0;
for (const CTxOut out : vout) {
for (const CTxOut& out : vout) {
if (out.scriptPubKey.IsZerocoinMint())
nCount++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*

//zerocoin spend outputs
bool fFeeAssigned = false;
for (const CTxOut txout : wtx.vout) {
for (const CTxOut& txout : wtx.vout) {
// change that was reminted as zerocoins
if (txout.IsZerocoinMint()) {
// do not display record if this isn't from our wallet
Expand Down
10 changes: 5 additions & 5 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2756,7 +2756,7 @@ UniValue mintzerocoin(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_WALLET_ERROR, strError);

UniValue arrMints(UniValue::VARR);
for (CDeterministicMint dMint : vDMints) {
for (CDeterministicMint& dMint : vDMints) {
UniValue m(UniValue::VOBJ);
m.push_back(Pair("txid", wtx.GetHash().ToString()));
m.push_back(Pair("value", ValueFromAmount(libzerocoin::ZerocoinDenominationToAmount(dMint.GetDenomination()))));
Expand Down Expand Up @@ -3051,7 +3051,7 @@ UniValue getarchivedzerocoin(const UniValue& params, bool fHelp)
list<CDeterministicMint> listDMints = walletdb.ListArchivedDeterministicMints();

UniValue arrRet(UniValue::VARR);
for (const CZerocoinMint mint : listMints) {
for (const CZerocoinMint& mint : listMints) {
UniValue objMint(UniValue::VOBJ);
objMint.push_back(Pair("txid", mint.GetTxHash().GetHex()));
objMint.push_back(Pair("denomination", ValueFromAmount(mint.GetDenominationAsAmount())));
Expand All @@ -3061,7 +3061,7 @@ UniValue getarchivedzerocoin(const UniValue& params, bool fHelp)
arrRet.push_back(objMint);
}

for (const CDeterministicMint dMint : listDMints) {
for (const CDeterministicMint& dMint : listDMints) {
UniValue objDMint(UniValue::VOBJ);
objDMint.push_back(Pair("txid", dMint.GetTxHash().GetHex()));
objDMint.push_back(Pair("denomination", ValueFromAmount(libzerocoin::ZerocoinDenominationToAmount(dMint.GetDenomination()))));
Expand Down Expand Up @@ -3270,7 +3270,7 @@ UniValue reconsiderzerocoins(const UniValue& params, bool fHelp)
pwalletMain->ReconsiderZerocoins(listMints, listDMints);

UniValue arrRet(UniValue::VARR);
for (const CZerocoinMint mint : listMints) {
for (const CZerocoinMint& mint : listMints) {
UniValue objMint(UniValue::VOBJ);
objMint.push_back(Pair("txid", mint.GetTxHash().GetHex()));
objMint.push_back(Pair("denomination", ValueFromAmount(mint.GetDenominationAsAmount())));
Expand All @@ -3279,7 +3279,7 @@ UniValue reconsiderzerocoins(const UniValue& params, bool fHelp)
arrRet.push_back(objMint);
}

for (const CDeterministicMint dMint : listDMints) {
for (const CDeterministicMint& dMint : listDMints) {
UniValue objMint(UniValue::VOBJ);
objMint.push_back(Pair("txid", dMint.GetTxHash().GetHex()));
objMint.push_back(Pair("denomination", FormatMoney(libzerocoin::ZerocoinDenominationToAmount(dMint.GetDenomination()))));
Expand Down
6 changes: 3 additions & 3 deletions src/test/zerocoin_implementation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool CheckZerocoinSpendNoDB(const CTransaction tx, string& strError)
//max needed non-mint outputs should be 2 - one for redemption address and a possible 2nd for change
if (tx.vout.size() > 2){
int outs = 0;
for (const CTxOut out : tx.vout) {
for (const CTxOut& out : tx.vout) {
if (out.IsZerocoinMint())
continue;
outs++;
Expand All @@ -123,7 +123,7 @@ bool CheckZerocoinSpendNoDB(const CTransaction tx, string& strError)

//compute the txout hash that is used for the zerocoinspend signatures
CMutableTransaction txTemp;
for (const CTxOut out : tx.vout) {
for (const CTxOut& out : tx.vout) {
txTemp.vout.push_back(out);
}
// uint256 hashTxOut = txTemp.GetHash();
Expand Down Expand Up @@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(checkzerocoinspend_test)
CTransaction tx;
BOOST_CHECK_MESSAGE(DecodeHexTx(tx, raw.first, true), "Failed to deserialize hex transaction");

for(const CTxOut out : tx.vout){
for(const CTxOut& out : tx.vout){
if(!out.scriptPubKey.empty() && out.scriptPubKey.IsZerocoinMint()) {
PublicCoin publicCoin(Params().OldZerocoin_Params());
BOOST_CHECK_MESSAGE(TxOutToPublicCoin(out, publicCoin, state), "Failed to convert CTxOut " << out.ToString() << " to PublicCoin");
Expand Down
2 changes: 2 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ bool LogAcceptCategory(const char* category)
ptrCategory->insert(string("mnpayments"));
ptrCategory->insert(string("zero"));
ptrCategory->insert(string("knbudget"));
ptrCategory->insert(string("precompute"));
ptrCategory->insert(string("staking"));
}
}
const set<string>& setCategories = *ptrCategory.get();
Expand Down
11 changes: 7 additions & 4 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3002,14 +3002,17 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int

if (GetTime() - nLastStakeSetUpdate > nStakeSetUpdateTime) {
setStakeCoins.clear();
if (!SelectStakeCoins(setStakeCoins, nBalance - nReserveBalance))
if (!SelectStakeCoins(setStakeCoins, nBalance - nReserveBalance)) {
LogPrint("staking", "CreateCoinStake(): selectStakeCoins failed\n");
return false;

}
nLastStakeSetUpdate = GetTime();
}

if (setStakeCoins.empty())
if (setStakeCoins.empty()) {
LogPrint("staking", "CreateCoinStake(): listInputs empty\n");
return false;
}

vector<const CWalletTx*> vwtxPrev;

Expand Down Expand Up @@ -4924,7 +4927,7 @@ bool CWallet::CreateZerocoinSpendTransaction(CAmount nValue, int nSecurityLevel,
vSelectedMints.emplace_back(mint);
}
} else {
for (const CZerocoinMint mint : vSelectedMints)
for (const CZerocoinMint& mint : vSelectedMints)
nValueSelected += ZerocoinDenominationToAmount(mint.GetDenomination());
}

Expand Down

1 comment on commit 113aeea

@2a5A1Ghu1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops sorry about that wrong ref link this is the correct one phoreproject/Phore@2a109e5

Please sign in to comment.