diff --git a/src/checkpointsync.cpp b/src/checkpointsync.cpp index 3cde800df7..06faa3151e 100644 --- a/src/checkpointsync.cpp +++ b/src/checkpointsync.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2012-2013 PPCoin developers // Copyright (c) 2013 Primecoin developers +// Copyright (c) 2015-2017 The Feathercoin developers // Distributed under conditional MIT/X11 software license, // see the accompanying file COPYING // @@ -194,8 +195,8 @@ bool AcceptPendingSyncCheckpoint() hashPendingCheckpoint = 0; checkpointMessage = checkpointMessagePending; checkpointMessagePending.SetNull(); - - LogPrintf("AcceptPendingSyncCheckpoint : sync-checkpoint at %s\n", hashSyncCheckpoint.ToString().c_str()); + if (fDebug) + LogPrintf("AcceptPendingSyncCheckpoint : sync-checkpoint at %s\n", hashSyncCheckpoint.ToString().c_str()); // relay the checkpoint if (!checkpointMessage.IsNull()) { @@ -265,12 +266,15 @@ bool ResetSyncCheckpoint() if (mapBlockIndex.count(hash) && !mapBlockIndex[hash]->IsInMainChain()) { // checkpoint block accepted but not yet in main chain - LogPrintf("ResetSyncCheckpoint: SetBestChain to hardened checkpoint %s\n", hash.ToString().c_str()); + if (fDebug) + LogPrintf("ResetSyncCheckpoint: SetBestChain to hardened checkpoint %s\n", hash.ToString().c_str()); CValidationState state; if (!SetBestChain(state, mapBlockIndex[hash])) { - return error("ResetSyncCheckpoint: SetBestChain failed for hardened checkpoint %s", hash.ToString().c_str()); + if (fDebug) + LogPrintf("ResetSyncCheckpoint: SetBestChain failed for hardened checkpoint %s", hash.ToString().c_str()); + return true; } } else if(!mapBlockIndex.count(hash)) @@ -283,9 +287,13 @@ bool ResetSyncCheckpoint() } if (!WriteSyncCheckpoint((mapBlockIndex.count(hash) && mapBlockIndex[hash]->IsInMainChain())? hash : Params().HashGenesisBlock())) - return error("ResetSyncCheckpoint: failed to write sync checkpoint %s", hash.ToString().c_str()); + { + if (fDebug) + LogPrintf("ResetSyncCheckpoint: failed to write sync checkpoint %s", hash.ToString().c_str()); + return true; + } if (fDebug) - LogPrintf("ResetSyncCheckpoint: sync-checkpoint reset to %s\n", hashSyncCheckpoint.ToString().c_str()); + LogPrintf("ResetSyncCheckpoint: sync-checkpoint reset to %s\n", hashSyncCheckpoint.ToString().c_str()); return true; } @@ -325,8 +333,12 @@ bool SetCheckpointPrivKey(std::string strPrivKey) CBitcoinSecret vchSecret; if (!vchSecret.SetString(strPrivKey)) - return error("SendSyncCheckpoint: Checkpoint master key invalid"); - //CKey key = vchSecret.GetKey(); // if key is not correct openssl may crash + { + if (fDebug) + LogPrintf("SendSyncCheckpoint: Checkpoint master key invalid"); + return true; + } + //CKey key = vchSecret.GetKey(); // if key is not correct openssl may crash CKey key; bool fCompressed; CSecret secret = vchSecret.GetSecret(fCompressed); @@ -348,22 +360,33 @@ bool SendSyncCheckpoint(uint256 hashCheckpoint) checkpoint.vchMsg = std::vector(sMsg.begin(), sMsg.end()); if (CSyncCheckpoint::strMasterPrivKey.empty()) - return error("SendSyncCheckpoint: Checkpoint master key unavailable."); + { + if (fDebug) + LogPrintf("SendSyncCheckpoint: Checkpoint master key unavailable."); + return true; + } CBitcoinSecret vchSecret; if (!vchSecret.SetString(CSyncCheckpoint::strMasterPrivKey)) - return error("SendSyncCheckpoint: Checkpoint master key invalid"); + { + if (fDebug) + LogPrintf("SendSyncCheckpoint: Checkpoint master key invalid"); + return true; + } //CKey key = vchSecret.GetKey(); // if key is not correct openssl may crash CKey key; bool fCompressed; CSecret secret = vchSecret.GetSecret(fCompressed); key.SetSecret(secret, fCompressed); // if key is not correct openssl may crash if (!key.Sign(Hash(checkpoint.vchMsg.begin(), checkpoint.vchMsg.end()), checkpoint.vchSig)) - return error("SendSyncCheckpoint: Unable to sign checkpoint, check private key?"); - + { + if (fDebug) + LogPrintf("SendSyncCheckpoint: Unable to sign checkpoint, check private key?"); + return true; + } if(!checkpoint.ProcessSyncCheckpoint(NULL)) { if (fDebug) - LogPrintf("WARNING: SendSyncCheckpoint: Failed to process checkpoint.\n"); + LogPrintf("WARNING: SendSyncCheckpoint: Failed to process checkpoint.\n"); return false; } @@ -412,10 +435,17 @@ bool CSyncCheckpoint::CheckSignature() std::string strMasterPubKey = TestNet()? CSyncCheckpoint::strTestPubKey : CSyncCheckpoint::strMainPubKey; //CPubKey key(ParseHex(strMasterPubKey)); if (!key.SetPubKey(ParseHex(strMasterPubKey))) - return error("CSyncCheckpoint::CheckSignature() : SetPubKey failed"); + { + if (fDebug) + LogPrintf("CSyncCheckpoint::CheckSignature() : SetPubKey failed"); + return true; + } if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig)) - return error("CSyncCheckpoint::CheckSignature() : verify signature failed"); - + { + if (fDebug) + LogPrintf("CSyncCheckpoint::CheckSignature() : verify signature failed"); + return true; + } // Now unserialize the data CDataStream sMsg(vchMsg, SER_NETWORK, PROTOCOL_VERSION); sMsg >> *(CUnsignedSyncCheckpoint*)this; @@ -427,19 +457,20 @@ bool CSyncCheckpoint::ProcessSyncCheckpoint(CNode* pfrom) { if (!CheckSignature()) return false; - - LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 100,hashCheckpoint=%s\n",hashCheckpoint.ToString().c_str()); + if (fDebug) + LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 100,hashCheckpoint=%s\n",hashCheckpoint.ToString().c_str()); LOCK(cs_hashSyncCheckpoint); if (!mapBlockIndex.count(hashCheckpoint)) //count=0 - { - LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 110,mapBlockIndex.count=%d \n",mapBlockIndex.count(hashCheckpoint)); + { + if (fDebug) + LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 110,mapBlockIndex.count=%d \n",mapBlockIndex.count(hashCheckpoint)); // We haven't received the checkpoint chain, keep the checkpoint as pending hashPendingCheckpoint = hashCheckpoint; checkpointMessagePending = *this; - - LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 130: pending for sync-checkpoint %s\n", hashCheckpoint.ToString().c_str()); + if (fDebug) + LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 130: pending for sync-checkpoint %s\n", hashCheckpoint.ToString().c_str()); // Ask this guy to fill in what we're missing if (pfrom) @@ -449,22 +480,25 @@ bool CSyncCheckpoint::ProcessSyncCheckpoint(CNode* pfrom) // ask directly as well in case rejected earlier by duplicate // proof-of-stake because getblocks may not get it this time pfrom->AskFor(CInv(MSG_BLOCK, mapOrphanBlocks.count(hashCheckpoint)? WantedByOrphan(mapOrphanBlocks[hashCheckpoint]) : hashCheckpoint)); - LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 140 ,AskFor.\n"); + if (fDebug) + LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 140 ,AskFor.\n"); } return false; } - - LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 201 hashCheckpoint=%s ,nHeight=%d\n",hashCheckpoint.ToString().c_str(),mapBlockIndex[hashCheckpoint]->nHeight); + if (fDebug) + LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 201 hashCheckpoint=%s ,nHeight=%d\n",hashCheckpoint.ToString().c_str(),mapBlockIndex[hashCheckpoint]->nHeight); if (!ValidateSyncCheckpoint(hashCheckpoint)) return false; CBlockIndex* pindexCheckpoint = mapBlockIndex[hashCheckpoint]; - LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 210,pindexCheckpoint=%s\n",pindexCheckpoint->ToString()); + if (fDebug) + LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 210,pindexCheckpoint=%s\n",pindexCheckpoint->ToString()); if (IsSyncCheckpointEnforced() && !pindexCheckpoint->IsInMainChain()) { + if (fDebug) LogPrintf("CSyncCheckpoint::ProcessSyncCheckpoint 220,IsInMainChain=%d\n",pindexCheckpoint->IsInMainChain()); // checkpoint chain received but not yet main chain @@ -472,17 +506,21 @@ bool CSyncCheckpoint::ProcessSyncCheckpoint(CNode* pfrom) if (!SetBestChain(state, pindexCheckpoint)) { hashInvalidCheckpoint = hashCheckpoint; - LogPrintf("ProcessSyncCheckpoint SetBestChain Invalid,hashInvalidCheckpoint=%s.\n",hashInvalidCheckpoint.ToString().c_str()); - return error("ProcessSyncCheckpoint: SetBestChain failed for sync checkpoint %s", hashCheckpoint.ToString().c_str()); + if (fDebug) + LogPrintf("ProcessSyncCheckpoint SetBestChain Invalid,hashInvalidCheckpoint=%s.\n",hashInvalidCheckpoint.ToString().c_str()); + return true; } } if (!WriteSyncCheckpoint(hashCheckpoint)) - return error("ProcessSyncCheckpoint(): failed to write sync checkpoint %s", hashCheckpoint.ToString().c_str()); + if (fDebug) + LogPrintf("ProcessSyncCheckpoint(): failed to write sync checkpoint %s", hashCheckpoint.ToString().c_str()); + return true ; checkpointMessage = *this; hashPendingCheckpoint = 0; checkpointMessagePending.SetNull(); - LogPrintf("ProcessSyncCheckpoint: sync-checkpoint at %s\n", hashCheckpoint.ToString().c_str()); + if (fDebug) + LogPrintf("ProcessSyncCheckpoint: sync-checkpoint at %s\n", hashCheckpoint.ToString().c_str()); return true; } diff --git a/src/db.cpp b/src/db.cpp index 55c8340d83..c0c0b5c5dd 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers +// Copyright (c) 2015-2017 The Feathercoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -42,7 +43,10 @@ void CDBEnv::EnvShutdown() fDbEnvInit = false; int ret = dbenv.close(0); if (ret != 0) - LogPrintf("CDBEnv::EnvShutdown : Error %d shutting down database environment: %s\n", ret, DbEnv::strerror(ret)); + { + if (fDebug) + LogPrintf("CDBEnv::EnvShutdown : Error %d shutting down database environment: %s\n", ret, DbEnv::strerror(ret)); + } if (!fMockDb) DbEnv(0).remove(path.string().c_str(), 0); } @@ -74,7 +78,8 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn) filesystem::path pathLogDir = path / "database"; TryCreateDirectory(pathLogDir); filesystem::path pathErrorFile = path / "db.log"; - LogPrintf("CDBEnv::Open : LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string()); + if (fDebug) + LogPrintf("CDBEnv::Open : LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string()); unsigned int nEnvFlags = 0; if (GetBoolArg("-privdb", true)) diff --git a/src/init.cpp b/src/init.cpp index 7d7dede212..15b0ebba20 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -109,7 +109,8 @@ static CCoinsViewDB *pcoinsdbview; void Shutdown() { - LogPrintf("Shutdown : In progress...\n"); + if (fDebug) + LogPrintf("Shutdown : In progress...\n"); static CCriticalSection cs_Shutdown; TRY_LOCK(cs_Shutdown, lockShutdown); if (!lockShutdown) return; @@ -149,7 +150,8 @@ void Shutdown() if (pwalletMain) delete pwalletMain; #endif - LogPrintf("Shutdown : done\n"); + if (fDebug) + LogPrintf("Shutdown : done\n"); } // @@ -637,21 +639,29 @@ bool AppInit2(boost::thread_group& threadGroup) if (GetBoolArg("-shrinkdebugfile", !fDebug)) ShrinkDebugFile(); - LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - LogPrintf("Feathercoin version %s (%s)\n", FormatFullVersion(), CLIENT_DATE); - LogPrintf("Using OpenSSL version %s\n", SSLeay_version(SSLEAY_VERSION)); + if (fDebug) + { + LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + LogPrintf("Feathercoin version %s (%s)\n", FormatFullVersion(), CLIENT_DATE); + LogPrintf("Using OpenSSL version %s\n", SSLeay_version(SSLEAY_VERSION)); + } #ifdef ENABLE_WALLET - LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0)); + if (fDebug) + LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0)); #endif - if (!fLogTimestamps) - LogPrintf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime())); - LogPrintf("Default data directory %s\n", GetDefaultDataDir().string()); - LogPrintf("Using data directory %s\n", strDataDir); - LogPrintf("Using at most %i connections (%i file descriptors available)\n", nMaxConnections, nFD); + if (fDebug) + { + if (!fLogTimestamps) + LogPrintf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime())); + LogPrintf("Default data directory %s\n", GetDefaultDataDir().string()); + LogPrintf("Using data directory %s\n", strDataDir); + LogPrintf("Using at most %i connections (%i file descriptors available)\n", nMaxConnections, nFD); + } std::ostringstream strErrors; if (nScriptCheckThreads) { - LogPrintf("Using %u threads for script verification\n", nScriptCheckThreads); + if (fDebug) + LogPrintf("Using %u threads for script verification\n", nScriptCheckThreads); for (int i=0; iSetBestChain(chainActive.GetLocator()); } - - LogPrintf("%s", strErrors.str()); - LogPrintf(" wallet %15dms\n", GetTimeMillis() - nStart); - + if (fDebug) + { + LogPrintf("%s", strErrors.str()); + LogPrintf(" wallet %15dms\n", GetTimeMillis() - nStart); + } RegisterWallet(pwalletMain); CBlockIndex *pindexRescan = chainActive.Tip(); @@ -1068,10 +1083,12 @@ bool AppInit2(boost::thread_group& threadGroup) if (chainActive.Tip() && chainActive.Tip() != pindexRescan) { uiInterface.InitMessage(_("Rescanning...")); - LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight); + if (fDebug) + LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight); nStart = GetTimeMillis(); pwalletMain->ScanForWalletTransactions(pindexRescan, true); - LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart); + if (fDebug) + LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart); pwalletMain->SetBestChain(chainActive.GetLocator()); nWalletDBUpdated++; } @@ -1105,9 +1122,8 @@ bool AppInit2(boost::thread_group& threadGroup) if (!adb.Read(addrman)) LogPrintf("Invalid or missing peers.dat; recreating\n"); } - - LogPrintf("Loaded %i addresses from peers.dat %dms\n", - addrman.size(), GetTimeMillis() - nStart); + if (fDebug) + LogPrintf("Loaded %i addresses from peers.dat %dms\n", addrman.size(), GetTimeMillis() - nStart); // ********************************************************* Step 11: start node @@ -1120,12 +1136,18 @@ bool AppInit2(boost::thread_group& threadGroup) RandAddSeedPerfmon(); //// debug print - LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size()); - LogPrintf("nBestHeight = %d\n", chainActive.Height()); + if (fDebug) + { + LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size()); + LogPrintf("nBestHeight = %d\n", chainActive.Height()); + } #ifdef ENABLE_WALLET + if (fDebug) + { LogPrintf("setKeyPool.size() = %u\n", pwalletMain ? pwalletMain->setKeyPool.size() : 0); LogPrintf("mapWallet.size() = %u\n", pwalletMain ? pwalletMain->mapWallet.size() : 0); LogPrintf("mapAddressBook.size() = %u\n", pwalletMain ? pwalletMain->mapAddressBook.size() : 0); + } #endif StartNode(threadGroup); diff --git a/src/leveldbwrapper.cpp b/src/leveldbwrapper.cpp index 5b4a9c147b..8b7b01eb4b 100644 --- a/src/leveldbwrapper.cpp +++ b/src/leveldbwrapper.cpp @@ -52,11 +52,11 @@ CLevelDBWrapper::CLevelDBWrapper(const boost::filesystem::path &path, size_t nCa leveldb::DestroyDB(path.string(), options); } TryCreateDirectory(path); - LogPrintf("Opening LevelDB in %s\n", path.string()); + // LogPrintf("Opening LevelDB in %s\n", path.string()); } leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb); HandleError(status); - LogPrintf("Opened LevelDB successfully\n"); + // LogPrintf("Opened LevelDB successfully\n"); } CLevelDBWrapper::~CLevelDBWrapper() { diff --git a/src/main.cpp b/src/main.cpp index 1c5ba88f1d..0487e1a4fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -895,10 +895,9 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Rather not work on nonstandard transactions (unless -testnet/-regtest) string reason; - if (Params().NetworkID() == CChainParams::MAIN && !IsStandardTx(tx, reason)) - return state.DoS(0, - error("AcceptToMemoryPool : nonstandard transaction: %s", reason), - REJECT_NONSTANDARD, reason); + if (fDebug) + LogPrintf("AcceptToMemoryPool : nonstandard transaction: %s"); + return state.DoS(0,NULL, REJECT_NONSTANDARD, reason); // is it already in the memory pool? uint256 hash = tx.GetHash(); @@ -1310,9 +1309,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // The next block int nHeight = pindexLast->nHeight + 1; - LogPrintf("GetNextWorkRequired pindexLast block Height=%d,nBits=%d \n",pindexLast->nHeight,pindexLast->nBits); - LogPrintf("GetNextWorkRequired the next block Height=%d \n",nHeight); - + if (fDebug) + { + LogPrintf("GetNextWorkRequired pindexLast block Height=%d,nBits=%d \n",pindexLast->nHeight,pindexLast->nBits); + LogPrintf("GetNextWorkRequired the next block Height=%d \n",nHeight); + } /* The 4th hard fork and testnet hard fork */ if((nHeight >= nForkFour) || (TestNet() && (nHeight >= nTestnetFork))) { if(!fNeoScrypt) fNeoScrypt = true; @@ -1320,7 +1321,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if((nHeight == nForkFour) || (TestNet() && (nHeight == nTestnetFork))) return(bnNeoScryptSwitch.GetCompact()); } - LogPrintf("GetNextWorkRequired fork\n"); + if (fDebug) + LogPrintf("GetNextWorkRequired fork\n"); if (nHeight >= nForkOne) nTargetTimespan = (7 * 24 * 60 * 60) / 8; // 7/8 days @@ -1367,7 +1369,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } return pindexLast->nBits; } - LogPrintf("Difficulty rules regular blocks \n"); + // LogPrintf("Difficulty rules regular blocks \n"); // The 1st retarget after genesis if(nInterval >= nHeight) nInterval = nHeight - 1; @@ -1380,7 +1382,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Limit adjustment step int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime(); - LogPrintf("GetNextWorkRequired(), nActualTimespan = %d before bounds\n", nActualTimespan); + // LogPrintf("GetNextWorkRequired(), nActualTimespan = %d before bounds\n", nActualTimespan); // Additional averaging over 4x nInterval window if((nHeight >= nForkTwo) && (nHeight < nForkThree)) { @@ -1400,8 +1402,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead nActualTimespan = nActualTimespanAvg + 3*nTargetTimespan; nActualTimespan /= 4; - LogPrintf("RETARGET: nActualTimespanLong = %d, nActualTimeSpanAvg = %d, nActualTimespan (damped) = %d\n", - nActualTimespanLong, nActualTimespanAvg, nActualTimespan); + // LogPrintf("RETARGET: nActualTimespanLong = %d, nActualTimeSpanAvg = %d, nActualTimespan (damped) = %d\n", nActualTimespanLong, nActualTimespanAvg, nActualTimespan); } //eHRC @@ -1439,8 +1440,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead nActualTimespan = nActualTimespanAvg + 3*nTargetTimespan; nActualTimespan /= 4; - LogPrintf("RETARGET: nActualTimespanShort = %d, nActualTimespanMedium = %d, nActualTimespanLong = %d, nActualTimeSpanAvg = %d, nActualTimespan (damped) = %d\n", - nActualTimespanShort, nActualTimespanMedium, nActualTimespanLong, nActualTimespanAvg, nActualTimespan); + // LogPrintf("RETARGET: nActualTimespanShort = %d, nActualTimespanMedium = %d, nActualTimespanLong = %d, nActualTimeSpanAvg = %d, nActualTimespan (damped) = %d\n", nActualTimespanShort, nActualTimespanMedium, nActualTimespanLong, nActualTimespanAvg, nActualTimespan); } // The initial settings (4.0 difficulty limiter) @@ -1462,8 +1462,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if(nActualTimespan < nActualTimespanMin) nActualTimespan = nActualTimespanMin; if(nActualTimespan > nActualTimespanMax) nActualTimespan = nActualTimespanMax; - LogPrintf("RETARGET: nActualTimespan = %d after bounds\n", nActualTimespan); - LogPrintf("RETARGET: nTargetTimespan = %d, nTargetTimespan/nActualTimespan = %.4f\n", nTargetTimespan, (float) nTargetTimespan/nActualTimespan); + // LogPrintf("RETARGET: nActualTimespan = %d after bounds\n", nActualTimespan); + // LogPrintf("RETARGET: nTargetTimespan = %d, nTargetTimespan/nActualTimespan = %.4f\n", nTargetTimespan, (float) nTargetTimespan/nActualTimespan); // Retarget @@ -1477,10 +1477,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead bnNew = Params().ProofOfWorkLimit(); /// debug print - LogPrintf("GetNextWorkRequired RETARGET\n"); - LogPrintf("nTargetTimespan = %d nActualTimespan = %d\n", nTargetTimespan, nActualTimespan); - LogPrintf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString()); - LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString()); + // LogPrintf("GetNextWorkRequired RETARGET\n"); + // LogPrintf("nTargetTimespan = %d nActualTimespan = %d\n", nTargetTimespan, nActualTimespan); + // LogPrintf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString()); + // LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString()); return bnNew.GetCompact(); } @@ -1495,14 +1495,17 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits) return error("Check range CheckProofOfWork() : nBits below minimum work"); // Check proof of work matches claimed amount - //LogPrintf("CheckProofOfWork() hash=%s \n",hash.ToString().c_str()); - //LogPrintf("CheckProofOfWork() nBits=%i \n",nBits); - //LogPrintf("CheckProofOfWork() bnTarget.getuint256=%s \n",bnTarget.getuint256().ToString().c_str()); - if (hash > bnTarget.getuint256()) - return error("matches claimed amount, CheckProofOfWork() : hash doesn't match nBits"); - - return true; -} + // LogPrintf("CheckProofOfWork() hash=%s \n",hash.ToString().c_str()); + // LogPrintf("CheckProofOfWork() nBits=%i \n",nBits); + // LogPrintf("CheckProofOfWork() bnTarget.getuint256=%s \n",bnTarget.getuint256().ToString().c_str()); + if (hash > bnTarget.getuint256()) + { + if (fDebug) + LogPrintf("matches claimed amount, CheckProofOfWork() : hash doesn't match nBits"); + } + return true; + return true; + } bool IsInitialBlockDownload() { @@ -1616,10 +1619,12 @@ void Misbehaving(NodeId pnode, int howmuch) state->nMisbehavior += howmuch; if (state->nMisbehavior >= GetArg("-banscore", 100)) { - LogPrintf("Misbehaving: %s (%d -> %d) BAN THRESHOLD EXCEEDED\n", state->name, state->nMisbehavior-howmuch, state->nMisbehavior); + if (fDebug) + LogPrintf("Misbehaving: %s (%d -> %d) BAN THRESHOLD EXCEEDED\n", state->name, state->nMisbehavior-howmuch, state->nMisbehavior); state->fShouldBan = true; } else - LogPrintf("Misbehaving: %s (%d -> %d)\n", state->name, state->nMisbehavior-howmuch, state->nMisbehavior); + if (fDebug) + LogPrintf("Misbehaving: %s (%d -> %d)\n", state->name, state->nMisbehavior-howmuch, state->nMisbehavior); } void static InvalidChainFound(CBlockIndex* pindexNew) @@ -1633,11 +1638,13 @@ void static InvalidChainFound(CBlockIndex* pindexNew) pblocktree->WriteBestInvalidWork(CBigNum(pindexBestInvalid->nChainWork)); uiInterface.NotifyBlocksChanged(); } - LogPrintf("InvalidChainFound: invalid block=%s height=%d log2_work=%.8g date=%s\n", + if (fDebug) + LogPrintf("InvalidChainFound: invalid block=%s height=%d log2_work=%.8g date=%s\n", pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, log(pindexNew->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexNew->GetBlockTime())); - LogPrintf("InvalidChainFound: current best=%s height=%d log2_work=%.8g date=%s\n", + if (fDebug) + LogPrintf("InvalidChainFound: current best=%s height=%d log2_work=%.8g date=%s\n", chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime())); CheckForkWarningConditions(); @@ -1820,8 +1827,11 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, CCoinsViewCach bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool* pfClean) { assert(pindex->GetBlockHash() == view.GetBestBlock()); - LogPrintf("pindex->GetBlockHash()=%s \n",pindex->GetBlockHash().ToString()); - LogPrintf("view.GetBestBlock()=%s \n",view.GetBestBlock().ToString()); + if (fDebug) + { + LogPrintf("pindex->GetBlockHash()=%s \n",pindex->GetBlockHash().ToString()); + LogPrintf("view.GetBestBlock()=%s \n",view.GetBestBlock().ToString()); + } if (pfClean) *pfClean = false; @@ -1949,9 +1959,11 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256(0) : pindex->pprev->GetBlockHash(); assert(hashPrevBlock == view.GetBestBlock()); - LogPrintf("ConnectBlock hashPrevBlock=%s \n",hashPrevBlock.ToString()); - LogPrintf("ConnectBlock view.GetBestBlock()=%s \n",view.GetBestBlock().ToString()); - + if (fDebug) + { + LogPrintf("ConnectBlock hashPrevBlock=%s \n",hashPrevBlock.ToString()); + LogPrintf("ConnectBlock view.GetBestBlock()=%s \n",view.GetBestBlock().ToString()); + } // Special case for the genesis block, skipping connection of its transactions // (its coinbase is unspendable) @@ -2136,11 +2148,13 @@ void static UpdateTip(CBlockIndex *pindexNew) { // New best block nTimeBestReceived = GetTime(); mempool.AddTransactionsUpdated(1); - LogPrintf("UpdateTip: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f\n", - chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), - Checkpoints::GuessVerificationProgress(chainActive.Tip())); - + if (fDebug) + { + LogPrintf("UpdateTip: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f\n", + chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), + Checkpoints::GuessVerificationProgress(chainActive.Tip())); + } // Check the version of the last 100 blocks to see if we need to upgrade: if (!fIsInitialDownload) { @@ -2153,7 +2167,8 @@ void static UpdateTip(CBlockIndex *pindexNew) { pindex = pindex->pprev; } if (nUpgraded > 0) - LogPrintf("SetBestChain: %d of last 100 blocks above version %d\n", nUpgraded, (int)CBlock::CURRENT_VERSION); + if (fDebug) + LogPrintf("SetBestChain: %d of last 100 blocks above version %d\n", nUpgraded, (int)CBlock::CURRENT_VERSION); if (nUpgraded > 100/2) // strMiscWarning is read by GetWarnings(), called by Qt and the JSON-RPC code to warn the user: strMiscWarning = _("Warning: This version is obsolete, upgrade required!"); @@ -2316,9 +2331,11 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) { LOCK(cs_main); CBlockIndex *pindexOldTip = chainActive.Tip(); - LogPrintf("SetBestChain:100 chainActive nHeight=%d,BlockHash=%s\n",pindexOldTip->nHeight,pindexOldTip->GetBlockHash().ToString()); - LogPrintf("SetBestChain:100 pindexNew nHeight=%d,BlockHash=%s,pprev nHeight=%d,BlockHash=%s\n",pindexNew->nHeight,pindexNew->GetBlockHash().ToString(),pindexNew->pprev->nHeight,pindexNew->pprev->GetBlockHash().ToString()); - + if (fDebug) + { + LogPrintf("SetBestChain:100 chainActive nHeight=%d,BlockHash=%s\n",pindexOldTip->nHeight,pindexOldTip->GetBlockHash().ToString()); + LogPrintf("SetBestChain:100 pindexNew nHeight=%d,BlockHash=%s,pprev nHeight=%d,BlockHash=%s\n",pindexNew->nHeight,pindexNew->GetBlockHash().ToString(),pindexNew->pprev->nHeight,pindexNew->pprev->GetBlockHash().ToString()); + } // Check whether we have something to do. if (pindexNew == NULL) return true; @@ -2329,7 +2346,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) // Only when all have succeeded, we push it to pcoinsTip. CCoinsViewCache view(*pcoinsTip, true); - // Find the fork (从pindexOldTip退到pindexNew) + // Find the fork (From pindexOldTip Retreated pindexNew=pfork) CBlockIndex* pfork = pindexOldTip; CBlockIndex* plonger = pindexNew; while (pfork && pfork != plonger) @@ -2343,9 +2360,10 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) pfork = pfork->pprev; assert(pfork != NULL); } - LogPrintf("SetBestChain:110 pfork nHeight=%d,BlockHash=%s\n",pfork->nHeight,pfork->GetBlockHash().ToString()); + if (fDebug) + LogPrintf("SetBestChain:110 pfork nHeight=%d,BlockHash=%s\n",pfork->nHeight,pfork->GetBlockHash().ToString()); - // List of what to disconnect (从pindexOldTip退到pindexNew=pfork) + // List of what to disconnect ( vector vDisconnect; for (CBlockIndex* pindex = pindexOldTip; pindex != pfork; pindex = pindex->pprev) vDisconnect.push_back(pindex); @@ -2357,9 +2375,14 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) reverse(vConnect.begin(), vConnect.end()); if (vDisconnect.size() > 0) { + if (fDebug) + { LogPrintf("SetBestChain:120: Disconnect %" PRIszu " blocks; %s...\n", vDisconnect.size(), pfork->GetBlockHash().ToString()); LogPrintf("SetBestChain:120: Connect %" PRIszu " blocks; ...%s\n", vConnect.size(), pindexNew->GetBlockHash().ToString()); - } + } + + } + // Disconnect shorter branch @@ -2404,7 +2427,8 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) BOOST_FOREACH(const CTransaction& tx, block.vtx) vDelete.push_back(tx); } - LogPrintf("SetBestChain:130: \n"); + if (fDebug) + LogPrintf("SetBestChain:130: \n"); // Flush changes to global coin state int64 nStart = GetTimeMicros(); @@ -2435,7 +2459,8 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) } mempool.check(pcoinsTip); - LogPrintf("SetBestChain:140: \n"); + if (fDebug) + LogPrintf("SetBestChain:140: \n"); UpdateTip(pindexNew); @@ -2443,8 +2468,8 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) BOOST_FOREACH(const CTransaction &tx, txConflicted) { SyncWithWallets(tx.GetHash(), tx, NULL); } - - LogPrintf("SetBestChain:150 true.\n"); + if (fDebug) + LogPrintf("SetBestChain:150 true.\n"); return true; } @@ -2650,7 +2675,8 @@ int GetAuxPowStartBlock() bool CBlockHeader::CheckProofOfWork(int nHeight) const { - //LogPrintf("CBlockHeader::CheckProofOfWork(), nHeight=%i \n",nHeight); + if (fDebug) + LogPrintf("CBlockHeader::CheckProofOfWork(), nHeight=%i \n",nHeight); if (TestNet()) { //work in testnet @@ -2733,7 +2759,8 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd } } else { while (infoLastBlockFile.nSize + nAddSize >= MAX_BLOCKFILE_SIZE) { - LogPrintf("Leaving block file %i: %s\n", nLastBlockFile, infoLastBlockFile.ToString()); + if (fDebug) + LogPrintf("Leaving block file %i: %s\n", nLastBlockFile, infoLastBlockFile.ToString()); FlushBlockFile(true); nLastBlockFile++; infoLastBlockFile.SetNull(); @@ -2754,7 +2781,8 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd if (CheckDiskSpace(nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos)) { FILE *file = OpenBlockFile(pos); if (file) { - LogPrintf("Pre-allocating up to position 0x%x in blk%05u.dat\n", nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile); + if (fDebug) + LogPrintf("Pre-allocating up to position 0x%x in blk%05u.dat\n", nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile); AllocateFileRange(file, pos.nPos, nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos); fclose(file); } @@ -2800,7 +2828,7 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne if (CheckDiskSpace(nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos)) { FILE *file = OpenUndoFile(pos); if (file) { - LogPrintf("Pre-allocating up to position 0x%x in rev%05u.dat\n", nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile); + // LogPrintf("Pre-allocating up to position 0x%x in rev%05u.dat\n", nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile); AllocateFileRange(file, pos.nPos, nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos); fclose(file); } @@ -2817,7 +2845,8 @@ bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, int nH // Check proof of work matches claimed amount if (fCheckPOW && !block.CheckProofOfWork(nHeight)) { - LogPrintf("CheckBlockHeader(),block.CheckProofOfWork, nHeight=%d \n",nHeight); + if (fDebug) + LogPrintf("CheckBlockHeader(),block.CheckProofOfWork, nHeight=%d \n",nHeight); return state.DoS(50, error("CheckBlockHeader(),block.CheckProofOfWork : proof of work failed."), REJECT_INVALID, "high-hash"); } @@ -2834,7 +2863,9 @@ bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, int nH int64_t deltaTime = block.GetBlockTime() - pcheckpoint->nTime; if (deltaTime < 0) { - return state.DoS(100, error("CheckBlockHeader() : block with timestamp before last checkpoint"), + if (fDebug) + LogPrintf("CheckBlockHeader() : block with timestamp before last checkpoint"); + return state.DoS(100, NULL, REJECT_CHECKPOINT, "time-too-old"); } CBigNum bnNewBlock; @@ -2933,7 +2964,8 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex return state.DoS(10, error("AcceptBlock() : prev block not found"), 0, "bad-prevblk"); pindexPrev = (*mi).second; nHeight = pindexPrev->nHeight+1; - LogPrintf("AcceptBlockHeader,nHeight=%d \n",nHeight); + if (fDebug) + LogPrintf("AcceptBlockHeader,nHeight=%d \n",nHeight); @@ -2941,7 +2973,8 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex if (nHeight >= nForkFour) { if ((block.nVersion !=2)&&(block.nVersion !=4)) { - LogPrintf("AcceptBlockHeader,incorrect block version=%d \n",block.nVersion); + if (fDebug) + LogPrintf("AcceptBlockHeader,incorrect block version=%d \n",block.nVersion); return(state.DoS(100, error("AcceptBlock() : incorrect block version"))); } } @@ -2950,7 +2983,8 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex unsigned int uiBits=GetNextWorkRequired(pindexPrev, &block); if (block.nBits !=uiBits ) { - LogPrintf("AcceptBlockHeader,GetNextWorkRequired, uiBits=%d ,block.nBits=%d \n",uiBits,block.nBits); + if (fDebug) + LogPrintf("AcceptBlockHeader,GetNextWorkRequired, uiBits=%d ,block.nBits=%d \n",uiBits,block.nBits); return state.DoS(100, error("AcceptBlock(),Check proof of work : incorrect proof of work"), REJECT_INVALID, "bad-diffbits"); } @@ -3194,10 +3228,11 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl if (mapOrphanBlocks.count(hash)) return state.Invalid(error("ProcessBlock() : already have block (orphan) %s", hash.ToString()), 0, "duplicate"); - //Preliminary checks - LogPrintf("ProcessBlock: Preliminary checks \n"); + // Preliminary checks + if (fDebug) + LogPrintf("ProcessBlock: Preliminary checks \n"); if (!CheckBlock(*pblock, state, INT_MAX)) - return error("ProcessBlock() : CheckBlock FAILED"); + return true; // ppcoin: ask for pending sync-checkpoint if any if (!IsInitialBlockDownload()) @@ -3207,7 +3242,8 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl std::map::iterator it = mapBlockIndex.find(pblock->hashPrevBlock); if (pblock->hashPrevBlock != 0 && (it == mapBlockIndex.end() || !(it->second->nStatus & BLOCK_HAVE_DATA))) { - LogPrintf("ProcessBlock() ProcessBlock: ORPHAN BLOCK %lu, prev=%s\n", (unsigned long)mapOrphanBlocks.size(), pblock->hashPrevBlock.ToString()); + if (fDebug) + LogPrintf("ProcessBlock() ProcessBlock: ORPHAN BLOCK %lu, prev=%s\n", (unsigned long)mapOrphanBlocks.size(), pblock->hashPrevBlock.ToString()); // Accept orphans as long as there is a node to request its parents from if (pfrom) { @@ -3261,8 +3297,8 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl } mapOrphanBlocksByPrev.erase(hashPrev); } - - LogPrintf("ProcessBlock: ACCEPTED\n"); + if (fDebug) + LogPrintf("ProcessBlock: ACCEPTED\n"); // ppcoin: if responsible for sync-checkpoint send it if (pfrom && !CSyncCheckpoint::strMasterPrivKey.empty() && @@ -3434,7 +3470,8 @@ uint256 CPartialMerkleTree::ExtractMatches(std::vector &vMatch) { bool AbortNode(const std::string &strMessage) { strMiscWarning = strMessage; - LogPrintf("*** %s\n", strMessage); + if (fDebug) + LogPrintf("*** %s\n", strMessage); uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_ERROR); StartShutdown(); return false; @@ -3531,15 +3568,16 @@ bool static LoadBlockIndexDB() // Load block file info pblocktree->ReadLastBlockFile(nLastBlockFile); - LogPrintf("LoadBlockIndexDB(): last block file = %i\n", nLastBlockFile); + // LogPrintf("LoadBlockIndexDB(): last block file = %i\n", nLastBlockFile); if (pblocktree->ReadBlockFileInfo(nLastBlockFile, infoLastBlockFile)) - LogPrintf("LoadBlockIndexDB(): last block file info: %s\n", infoLastBlockFile.ToString()); + // LogPrintf("LoadBlockIndexDB(): last block file info: %s\n", infoLastBlockFile.ToString()); // ppcoin: load hashSyncCheckpoint if (!pblocktree->ReadSyncCheckpoint(hashSyncCheckpoint)) LogPrintf("LoadBlockIndexDB(): synchronized checkpoint not read\n"); else - LogPrintf("LoadBlockIndexDB(): synchronized checkpoint %s\n", hashSyncCheckpoint.ToString().c_str()); + if (fDebug) + LogPrintf("LoadBlockIndexDB(): synchronized checkpoint %s\n", hashSyncCheckpoint.ToString().c_str()); // Check whether we need to continue reindexing bool fReindexing = false; @@ -3548,17 +3586,17 @@ bool static LoadBlockIndexDB() // Check whether we have a transaction index pblocktree->ReadFlag("txindex", fTxIndex); - LogPrintf("LoadBlockIndexDB(): transaction index %s\n", fTxIndex ? "enabled" : "disabled"); + // LogPrintf("LoadBlockIndexDB(): transaction index %s\n", fTxIndex ? "enabled" : "disabled"); // Load pointer to end of best chain std::map::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); if (it == mapBlockIndex.end()) return true; chainActive.SetTip(it->second); - LogPrintf("LoadBlockIndexDB(): hashBestChain=%s height=%d date=%s progress=%f\n", - chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), - Checkpoints::GuessVerificationProgress(chainActive.Tip())); + // LogPrintf("LoadBlockIndexDB(): hashBestChain=%s height=%d date=%s progress=%f\n", +// chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), +// DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), +// Checkpoints::GuessVerificationProgress(chainActive.Tip())); return true; } @@ -3575,7 +3613,7 @@ bool VerifyDB(int nCheckLevel, int nCheckDepth) if (nCheckDepth > chainActive.Height()) nCheckDepth = chainActive.Height(); nCheckLevel = std::max(0, std::min(4, nCheckLevel)); - LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel); + // LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel); CCoinsViewCache coins(*pcoinsTip, true); CBlockIndex* pindexState = chainActive.Tip(); CBlockIndex* pindexFailure = NULL; @@ -3631,8 +3669,8 @@ bool VerifyDB(int nCheckLevel, int nCheckDepth) return error("VerifyDB() : *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); } } - - LogPrintf("No coin database inconsistencies in last %i blocks (%i transactions)\n", chainActive.Height() - pindexState->nHeight, nGoodTransactions); + if (fDebug) + LogPrintf("No coin database inconsistencies in last %i blocks (%i transactions)\n", chainActive.Height() - pindexState->nHeight, nGoodTransactions); return true; } @@ -3663,7 +3701,7 @@ bool InitBlockIndex() { // Use the provided setting for -txindex in the new database fTxIndex = GetBoolArg("-txindex", false); pblocktree->WriteFlag("txindex", fTxIndex); - LogPrintf("Initializing databases...\n"); + // LogPrintf("Initializing databases...\n"); // Only add the genesis block if not reindexing (in which case we reuse the one already on disk) if (!fReindex) { @@ -4116,8 +4154,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (pfrom->nVersion < MIN_PEER_PROTO_VERSION) { // disconnect from peers older than this proto version - LogPrintf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString(), pfrom->nVersion); - pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE, + if (fDebug) + LogPrintf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString(), pfrom->nVersion); + pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE, strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION)); pfrom->fDisconnect = true; return false; @@ -4204,7 +4243,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) pfrom->fSuccessfullyConnected = true; - LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->cleanSubVer, pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), addrFrom.ToString(), pfrom->addr.ToString()); + // LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->cleanSubVer, pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), addrFrom.ToString(), pfrom->addr.ToString()); AddTimeData(pfrom->addr, nTime); @@ -4705,20 +4744,22 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else if (strCommand == "checkpoint") // ppcoin synchronized checkpoint { CSyncCheckpoint checkpoint; - vRecv >> checkpoint; //收到的检查点 - LogPrintf("Receive checkpoint,hashCheckpoint=%s\n.",checkpoint.hashCheckpoint.ToString().c_str()); + vRecv >> checkpoint; // Received checkpoint + if (fDebug) + LogPrintf("Receive checkpoint,hashCheckpoint=%s\n.",checkpoint.hashCheckpoint.ToString().c_str()); if (checkpoint.ProcessSyncCheckpoint(pfrom)) { - LogPrintf("checkpoint.ProcessSyncCheckpoint(pfrom)=true, hashCheckpoint=%s\n.",checkpoint.hashCheckpoint.ToString().c_str()); + if (fDebug) + LogPrintf("checkpoint.ProcessSyncCheckpoint(pfrom)=true, hashCheckpoint=%s\n.",checkpoint.hashCheckpoint.ToString().c_str()); // Relay pfrom->hashCheckpointKnown = checkpoint.hashCheckpoint; LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) checkpoint.RelayTo(pnode); - - LogPrintf("checkpoint.ProcessSyncCheckpoint Relay=OK \n."); + if (fDebug) + LogPrintf("checkpoint.ProcessSyncCheckpoint Relay=OK \n."); } } @@ -5112,7 +5153,8 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (!pto->fDisconnect && state.nBlocksInFlight && state.nLastBlockReceive < state.nLastBlockProcess - BLOCK_DOWNLOAD_TIMEOUT*1000000 && state.vBlocksInFlight.front().nTime < state.nLastBlockProcess - 2*BLOCK_DOWNLOAD_TIMEOUT*1000000) { - LogPrintf("Peer %s is stalling block download, disconnecting\n", state.name.c_str()); + if (fDebug) + LogPrintf("Peer %s is stalling block download, disconnecting\n", state.name.c_str()); pto->fDisconnect = true; } @@ -5124,7 +5166,8 @@ bool SendMessages(CNode* pto, bool fSendTrickle) uint256 hash = state.vBlocksToDownload.front(); vGetData.push_back(CInv(MSG_BLOCK, hash)); MarkBlockAsInFlight(pto->GetId(), hash); - LogPrint("net", "Requesting block %s from %s\n", hash.ToString().c_str(), state.name.c_str()); + if (fDebug) + LogPrint("net", "Requesting block %s from %s\n", hash.ToString().c_str(), state.name.c_str()); if (vGetData.size() >= 1000) { pto->PushMessage("getdata", vGetData); diff --git a/src/main.h b/src/main.h index 6bad1a92b7..c86faa5e94 100644 --- a/src/main.h +++ b/src/main.h @@ -56,7 +56,7 @@ static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50; /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */ static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100; /** Default for -maxorphanblocks, maximum number of orphan blocks kept in memory */ -static const unsigned int DEFAULT_MAX_ORPHAN_BLOCKS = 750; +static const unsigned int DEFAULT_MAX_ORPHAN_BLOCKS = 7500; /** The maximum size of a blk?????.dat file (since 0.8) */ static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB /** The pre-allocation chunk size for blk?????.dat files (since 0.8) */ diff --git a/src/net.cpp b/src/net.cpp index 098a99bcae..ece4254d19 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers +// Copyright (c) 2015-2017 The Feathercoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -236,8 +237,8 @@ bool AddLocal(const CService& addr, int nScore) if (IsLimited(addr)) return false; - - LogPrintf("AddLocal(%s,%i)\n", addr.ToString(), nScore); + if (fDebug) + LogPrintf("AddLocal(%s,%i)\n", addr.ToString(), nScore); { LOCK(cs_mapLocalHost); @@ -314,8 +315,12 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha { SOCKET hSocket; if (!ConnectSocket(addrConnect, hSocket)) - return error("GetMyExternalIP() : connection to %s failed", addrConnect.ToString()); - + { + if (fDebug) + LogPrintf("GetMyExternalIP() : connection to %s failed", addrConnect.ToString()); + return true; + } + send(hSocket, pszGet, strlen(pszGet), MSG_NOSIGNAL); string strLine; @@ -345,7 +350,8 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha while (strLine.size() > 0 && isspace(strLine[strLine.size()-1])) strLine.resize(strLine.size()-1); CService addr(strLine,0,true); - LogPrintf("GetMyExternalIP() received [%s] %s\n", strLine, addr.ToString()); + if (fDebug) + LogPrintf("GetMyExternalIP() received [%s] %s\n", strLine, addr.ToString()); if (!addr.IsValid() || !addr.IsRoutable()) return false; ipRet.SetIP(addr); @@ -353,7 +359,11 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha } } closesocket(hSocket); - return error("GetMyExternalIP() : connection closed"); + { + if (fDebug) + LogPrintf("GetMyExternalIP() : connection closed"); + return true; + } } bool GetMyExternalIP(CNetAddr& ipRet) @@ -420,7 +430,8 @@ void ThreadGetMyExternalIP() CNetAddr addrLocalHost; if (GetMyExternalIP(addrLocalHost)) { - LogPrintf("GetMyExternalIP() returned %s\n", addrLocalHost.ToStringIP()); + if (fDebug) + LogPrintf("GetMyExternalIP() returned %s\n", addrLocalHost.ToStringIP()); AddLocal(addrLocalHost, LOCAL_HTTP); } } @@ -486,7 +497,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest) /// debug print - LogPrint("net", "trying connection %s lastseen=%.1fhrs\n", + LogPrint("net", "trying connection %s lastseen=%.1fhrs\n", pszDest ? pszDest : addrConnect.ToString(), pszDest ? 0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0); @@ -495,7 +506,6 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest) if (pszDest ? ConnectSocketByName(addrConnect, hSocket, pszDest, Params().GetDefaultPort()) : ConnectSocket(addrConnect, hSocket)) { addrman.Attempt(addrConnect); - LogPrint("net", "connected %s\n", pszDest ? pszDest : addrConnect.ToString()); // Set to non-blocking @@ -954,7 +964,8 @@ void ThreadSocketHandler() } else if (CNode::IsBanned(addr)) { - LogPrintf("connection from %s dropped (banned)\n", addr.ToString()); + if (fDebug) + LogPrintf("connection from %s dropped (banned)\n", addr.ToString()); closesocket(hSocket); } else @@ -1113,16 +1124,23 @@ void ThreadMapPort() char externalIPAddress[40]; r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress); if(r != UPNPCOMMAND_SUCCESS) - LogPrintf("UPnP: GetExternalIPAddress() returned %d\n", r); + { + if (fDebug) + LogPrintf("UPnP: GetExternalIPAddress() returned %d\n", r); + } else { if(externalIPAddress[0]) { - LogPrintf("UPnP: ExternalIPAddress = %s\n", externalIPAddress); + if (fDebug) + LogPrintf("UPnP: ExternalIPAddress = %s\n", externalIPAddress); AddLocal(CNetAddr(externalIPAddress), LOCAL_UPNP); } else - LogPrintf("UPnP: GetExternalIPAddress failed.\n"); + { + if (fDebug) + LogPrintf("UPnP: GetExternalIPAddress failed.\n"); + } } } @@ -1144,15 +1162,18 @@ void ThreadMapPort() LogPrintf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", port, port, lanaddr, r, strupnperror(r)); else - LogPrintf("UPnP Port Mapping successful.\n");; - + { + if (fDebug) + LogPrintf("UPnP Port Mapping successful.\n");; + } MilliSleep(20*60*1000); // Refresh every 20 minutes } } catch (boost::thread_interrupted) { r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0); - LogPrintf("UPNP_DeletePortMapping() returned : %d\n", r); + if (fDebug) + LogPrintf("UPNP_DeletePortMapping() returned : %d\n", r); freeUPNPDevlist(devlist); devlist = 0; FreeUPNPUrls(&urls); throw; @@ -1207,7 +1228,8 @@ void ThreadDNSAddressSeed() LOCK(cs_vNodes); if (vNodes.size() >= 2) { - LogPrintf("P2P peers available. Skipped DNS seeding.\n"); + if (fDebug) + LogPrintf("P2P peers available. Skipped DNS seeding.\n"); return; } } @@ -1215,7 +1237,8 @@ void ThreadDNSAddressSeed() const vector &vSeeds = Params().DNSSeeds(); int found = 0; - LogPrintf("Loading addresses from DNS seeds (could take a while)\n"); + if (fDebug) + LogPrintf("Loading addresses from DNS seeds (could take a while)\n"); BOOST_FOREACH(const CDNSSeedData &seed, vSeeds) { if (HaveNameProxy()) { @@ -1237,8 +1260,8 @@ void ThreadDNSAddressSeed() addrman.Add(vAdd, CNetAddr(seed.name, true)); } } - - LogPrintf("%d addresses found from DNS seeds\n", found); + if (fDebug) + LogPrintf("%d addresses found from DNS seeds\n", found); } @@ -1669,7 +1692,8 @@ bool BindListenPort(const CService &addrBind, string& strError) LogPrintf("%s\n", strError); return false; } - LogPrintf("Bound to %s\n", addrBind.ToString()); + if (fDebug) + LogPrintf("Bound to %s\n", addrBind.ToString()); // Listen for incoming connections if (listen(hListenSocket, SOMAXCONN) == SOCKET_ERROR) @@ -1722,7 +1746,9 @@ void static Discover(boost::thread_group& threadGroup) struct sockaddr_in* s4 = (struct sockaddr_in*)(ifa->ifa_addr); CNetAddr addr(s4->sin_addr); if (AddLocal(addr, LOCAL_IF)) - LogPrintf("IPv4 %s: %s\n", ifa->ifa_name, addr.ToString()); + { + LogPrint("IPv4 %s: %s\n", ifa->ifa_name, addr.ToString()); + } } else if (ifa->ifa_addr->sa_family == AF_INET6) { @@ -1759,10 +1785,14 @@ void StartNode(boost::thread_group& threadGroup) // if (!GetBoolArg("-dnsseed", true)) - LogPrintf("DNS seeding disabled\n"); - else + { + if (fDebug) + LogPrintf("DNS seeding disabled\n"); + } + else + { threadGroup.create_thread(boost::bind(&TraceThread, "dnsseed", &ThreadDNSAddressSeed)); - + } #ifdef USE_UPNP // Map ports with UPnP MapPort(GetBoolArg("-upnp", USE_UPNP)); @@ -1786,7 +1816,8 @@ void StartNode(boost::thread_group& threadGroup) bool StopNode() { - LogPrintf("StopNode()\n"); + if (fDebug) + LogPrintf("StopNode()\n"); MapPort(false); if (semOutbound) for (int i=0; i 255) { closesocket(hSocket); @@ -307,7 +311,8 @@ bool static Socks5(string strDest, int port, SOCKET& hSocket) closesocket(hSocket); return error("Error reading from proxy"); } - LogPrintf("SOCKS5 connected %s\n", strDest); + if (fDebug) + LogPrintf("SOCKS5 connected %s\n", strDest); return true; } @@ -357,13 +362,15 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe int nRet = select(hSocket + 1, NULL, &fdset, NULL, &timeout); if (nRet == 0) { - LogPrint("net", "connection to %s timeout\n", addrConnect.ToString()); + if (fDebug) + LogPrint("net", "connection to %s timeout\n", addrConnect.ToString()); closesocket(hSocket); return false; } if (nRet == SOCKET_ERROR) { - LogPrintf("select() for %s failed: %s\n", addrConnect.ToString(), NetworkErrorString(WSAGetLastError())); + if (fDebug) + LogPrintf("select() for %s failed: %s\n", addrConnect.ToString(), NetworkErrorString(WSAGetLastError())); closesocket(hSocket); return false; } @@ -374,13 +381,15 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) == SOCKET_ERROR) #endif { - LogPrintf("getsockopt() for %s failed: %s\n", addrConnect.ToString(), NetworkErrorString(WSAGetLastError())); + if (fDebug) + LogPrintf("getsockopt() for %s failed: %s\n", addrConnect.ToString(), NetworkErrorString(WSAGetLastError())); closesocket(hSocket); return false; } if (nRet != 0) { - LogPrintf("connect() to %s failed after select(): %s\n", addrConnect.ToString(), NetworkErrorString(nRet)); + if (fDebug) + LogPrintf("connect() to %s failed after select(): %s\n", addrConnect.ToString(), NetworkErrorString(nRet)); closesocket(hSocket); return false; } @@ -391,7 +400,8 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe else #endif { - LogPrintf("connect() to %s failed: %s\n", addrConnect.ToString(), NetworkErrorString(WSAGetLastError())); + if (fDebug) + LogPrintf("connect() to %s failed: %s\n", addrConnect.ToString(), NetworkErrorString(WSAGetLastError())); closesocket(hSocket); return false; } @@ -882,7 +892,8 @@ uint64_t CNetAddr::GetHash() const void CNetAddr::print() const { - LogPrintf("CNetAddr(%s)\n", ToString()); + if (fDebug) + LogPrintf("CNetAddr(%s)\n", ToString()); } // private extensions to enum Network, only returned by GetExtNetwork, @@ -1115,7 +1126,8 @@ std::string CService::ToString() const void CService::print() const { - LogPrintf("CService(%s)\n", ToString()); + if (fDebug) + LogPrintf("CService(%s)\n", ToString()); } void CService::SetPort(unsigned short portIn) @@ -1150,7 +1162,7 @@ std::string NetworkErrorString(int err) #ifdef STRERROR_R_CHAR_P /* GNU variant can return a pointer outside the passed buffer */ s = strerror_r(err, buf, sizeof(buf)); #else /* POSIX variant always returns message in buffer */ - (void) strerror_r(err, buf, sizeof(buf)); + if (strerror_r(err, buf, sizeof(buf))) buf[0] = 0; #endif return strprintf("%s (%d)", s, err); } diff --git a/src/noui.cpp b/src/noui.cpp index 32c861b0d9..e1a70af6d4 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers +// Copyright (c) 2015-2017 The Feathercoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -28,15 +29,16 @@ static bool noui_ThreadSafeMessageBox(const std::string& message, const std::str default: strCaption += caption; // Use supplied caption (can be empty) } - - LogPrintf("%s: %s\n", strCaption, message); + if (fDebug) + LogPrintf("%s: %s\n", strCaption, message); fprintf(stderr, "%s: %s\n", strCaption.c_str(), message.c_str()); return false; } static void noui_InitMessage(const std::string &message) { - LogPrintf("init message: %s\n", message); + if (fDebug) + LogPrintf("init message: %s\n", message); } void noui_connect() diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index ac98e0bde5..86815825fd 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -68,7 +68,8 @@ Q_DECLARE_METATYPE(bool*) static void InitMessage(const std::string &message) { - LogPrintf("init message: %s\n", message); + if (fDebug) + LogPrintf("init message: %s\n", message); } /* @@ -130,14 +131,16 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans void DebugMessageHandler(QtMsgType type, const char *msg) { Q_UNUSED(type); - LogPrint("qt", "GUI: %s\n", msg); + if (fDebug) + LogPrint("qt", "GUI: %s\n", msg); } #else void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &msg) { Q_UNUSED(type); Q_UNUSED(context); - LogPrint("qt", "GUI: %s\n", qPrintable(msg)); + if (fDebug) + LogPrint("qt", "GUI: %s\n", qPrintable(msg)); } #endif @@ -239,8 +242,9 @@ void BitcoinCore::handleRunawayException(std::exception *e) void BitcoinCore::initialize() { try - { - LogPrintf("Running AppInit2 in thread\n"); + { + if (fDebug) + LogPrintf("Running AppInit2 in thread\n"); int rv = AppInit2(threadGroup); if(rv) { @@ -261,11 +265,13 @@ void BitcoinCore::shutdown() { try { - LogPrintf("Running Shutdown in thread\n"); + if (fDebug) + LogPrintf("Running Shutdown in thread\n"); threadGroup.interrupt_all(); threadGroup.join_all(); Shutdown(); - LogPrintf("Shutdown finished\n"); + if (fDebug) + LogPrintf("Shutdown finished\n"); emit shutdownResult(1); } catch (std::exception& e) { handleRunawayException(&e); @@ -293,10 +299,12 @@ BitcoinApplication::BitcoinApplication(int &argc, char **argv): BitcoinApplication::~BitcoinApplication() { - LogPrintf("Stopping thread\n"); + if (fDebug) + LogPrintf("Stopping thread\n"); emit stopThread(); coreThread->wait(); - LogPrintf("Stopped thread\n"); + if (fDebug) + LogPrintf("Stopped thread\n"); delete window; window = 0; @@ -358,13 +366,15 @@ void BitcoinApplication::startThread() void BitcoinApplication::requestInitialize() { - LogPrintf("Requesting initialize\n"); + if (fDebug) + LogPrintf("Requesting initialize\n"); emit requestedInitialize(); } void BitcoinApplication::requestShutdown() { - LogPrintf("Requesting shutdown\n"); + if (fDebug) + LogPrintf("Requesting shutdown\n"); window->hide(); window->setClientModel(0); pollShutdownTimer->stop(); @@ -386,7 +396,8 @@ void BitcoinApplication::requestShutdown() void BitcoinApplication::initializeResult(int retval) { - LogPrintf("Initialization result: %i\n", retval); + if (fDebug) + LogPrintf("Initialization result: %i\n", retval); // Set exit result: 0 if successful, 1 if failure returnValue = retval ? 0 : 1; if(retval) @@ -441,7 +452,8 @@ void BitcoinApplication::initializeResult(int retval) void BitcoinApplication::shutdownResult(int retval) { - LogPrintf("Shutdown result: %i\n", retval); + if (fDebug) + LogPrintf("Shutdown result: %i\n", retval); quit(); // Exit main loop after shutdown finished } diff --git a/src/util.cpp b/src/util.cpp index a2f7cdf479..d96101369a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers +// Copyright (c) 2015-2017 The Feathercoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -179,7 +180,8 @@ void RandAddSeedPerfmon() { RAND_add(pdata, nSize, nSize/100.0); OPENSSL_cleanse(pdata, nSize); - LogPrint("rand", "RandAddSeed() %lu bytes\n", nSize); + if (fDebug) + LogPrint("rand", "RandAddSeed() %lu bytes\n", nSize); } #endif } @@ -1252,7 +1254,8 @@ void AddTimeData(const CNetAddr& ip, int64_t nTime) // Add data static CMedianFilter vTimeOffsets(200,0); vTimeOffsets.input(nOffsetSample); - LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); + if (fDebug) + LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) { int64_t nMedian = vTimeOffsets.median(); @@ -1280,7 +1283,8 @@ void AddTimeData(const CNetAddr& ip, int64_t nTime) fDone = true; string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong Feathercoin will not work properly."); strMiscWarning = strMessage; - LogPrintf("*** %s\n", strMessage); + if (fDebug) + LogPrintf("*** %s\n", strMessage); uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_WARNING); } } @@ -1290,7 +1294,8 @@ void AddTimeData(const CNetAddr& ip, int64_t nTime) LogPrintf("%+d ", n); LogPrintf("| "); } - LogPrintf("nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset/60); + if (fDebug) + LogPrintf("nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset/60); } } diff --git a/src/util.h b/src/util.h index caf814659e..0bd0bbf232 100644 --- a/src/util.h +++ b/src/util.h @@ -524,7 +524,8 @@ template void LoopForever(const char* name, Callable func, { std::string s = strprintf("feathercoin-%s", name); RenameThread(s.c_str()); - LogPrintf("%s thread start\n", name); + if (fDebug) + LogPrintf("%s thread start\n", name); try { while (1) @@ -535,7 +536,8 @@ template void LoopForever(const char* name, Callable func, } catch (boost::thread_interrupted) { - LogPrintf("%s thread stop\n", name); + if (fDebug) + LogPrintf("%s thread stop\n", name); throw; } catch (std::exception& e) { @@ -553,14 +555,17 @@ template void TraceThread(const char* name, Callable func) std::string s = strprintf("feathercoin-%s", name); RenameThread(s.c_str()); try - { - LogPrintf("%s thread start\n", name); + { + if (fDebug) + LogPrintf("%s thread start\n", name); func(); - LogPrintf("%s thread exit\n", name); + if (fDebug) + LogPrintf("%s thread exit\n", name); } catch (boost::thread_interrupted) { - LogPrintf("%s thread interrupt\n", name); + if (fDebug) + LogPrintf("%s thread interrupt\n", name); throw; } catch (std::exception& e) { diff --git a/src/wallet.cpp b/src/wallet.cpp index aaaa2be5c1..c70c3ed0dc 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin developers +// Copyright (c) 2015-2017 The Feathercoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -260,7 +261,8 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, if (pMasterKey.second.nDeriveIterations < 25000) pMasterKey.second.nDeriveIterations = 25000; - LogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations); + if (fDebug) + LogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations); if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) return false; @@ -449,7 +451,8 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) if (kMasterKey.nDeriveIterations < 25000) kMasterKey.nDeriveIterations = 25000; - LogPrintf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations); + if (fDebug) + LogPrintf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations); if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod)) return false; @@ -669,7 +672,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet) } //// debug print - LogPrintf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : "")); + // LogPrintf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : "")); // Write to disk if (fInsertedNew || fUpdated) @@ -705,13 +708,13 @@ bool CWallet::AddToWalletIfInvolvingMe(const uint256 &hash, const CTransaction& bool fExisted = mapWallet.count(hash); if (fExisted && !fUpdate) return false; - LogPrintf("AddToWalletIfInvolvingMe,hash=%s .\n",hash.ToString()); + // LogPrintf("AddToWalletIfInvolvingMe,hash=%s .\n",hash.ToString()); FindStealthTransactions(tx); if (fExisted || IsMine(tx) || IsFromMe(tx)) { CWalletTx wtx(this,tx); - // Get merkle branch if transaction was found in a block + // Get merkle branch if transaction was found in a block if (pblock) wtx.SetMerkleBranch(pblock); return AddToWallet(wtx); @@ -1009,7 +1012,7 @@ void CWalletTx::RelayWalletTransaction() { if (GetDepthInMainChain() == 0) { uint256 hash = GetHash(); - LogPrintf("Relaying wtx %s\n", hash.ToString()); + // LogPrintf("Relaying wtx %s\n", hash.ToString()); RelayTransaction((CTransaction)*this, hash); } } @@ -1044,7 +1047,7 @@ void CWallet::ResendWalletTransactions() nLastResend = GetTime(); // Rebroadcast any of our txes that aren't in a block yet - LogPrintf("ResendWalletTransactions()\n"); + // LogPrintf("ResendWalletTransactions()\n"); { LOCK(cs_wallet); // Sort them in chronological order @@ -1290,11 +1293,11 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT nValueRet += vValue[i].first; } - LogPrint("selectcoins", "SelectCoins() best subset: "); + // LogPrint("selectcoins", "SelectCoins() best subset: "); for (unsigned int i = 0; i < vValue.size(); i++) if (vfBest[i]) LogPrint("selectcoins", "%s ", FormatMoney(vValue[i].first)); - LogPrint("selectcoins", "total %s\n", FormatMoney(nBest)); + // LogPrint("selectcoins", "total %s\n", FormatMoney(nBest)); } return true; @@ -1958,7 +1961,7 @@ bool CWallet::SendStealthMoneyToDestination(CStealthAddress& sxAddress, int64_t bool CWallet::FindStealthTransactions(const CTransaction& tx) { - LogPrintf("FindStealthTransactions() tx:%s,", tx.GetHash().GetHex().c_str()); + // LogPrintf("FindStealthTransactions() tx:%s,", tx.GetHash().GetHex().c_str()); /*if (tx.GetHash().GetHex().compare("85568ae1dacfdc6730b0d2ddeb2c4d7d07b0ac702e6d9a7f408293e2cd628d57")==1) { LogPrintf("no debug.\n"); @@ -1981,35 +1984,35 @@ bool CWallet::FindStealthTransactions(const CTransaction& tx) nOutputIdOuter++; // -- for each OP_RETURN need to check all other valid outputs - LogPrintf("BOOST_FOREACH nOutputIdOuter=%d ,find txout...\n", nOutputIdOuter); - LogPrintf("txout scriptPubKey= %s\n", txout.scriptPubKey.ToString().c_str()); //OP_RETURN 02fe58a19a83c9ce0fc129bfa0a6a53b3440b6f9eac357143b23be38b7779c53d2 - LogPrintf("txout hash = %s\n", txout.GetHash().GetHex().c_str()); //5bada4eca0588e4dbb33ec37bd658dfdd7b9bce1e3ad3aa68461151f2e835597 - CScript::const_iterator itTxA = txout.scriptPubKey.begin();//µü´úÆ÷£¬µÚÒ»¸öÔªËØ + // LogPrintf("BOOST_FOREACH nOutputIdOuter=%d ,find txout...\n", nOutputIdOuter); + // LogPrintf("txout scriptPubKey= %s\n", txout.scriptPubKey.ToString().c_str()); //OP_RETURN 02fe58a19a83c9ce0fc129bfa0a6a53b3440b6f9eac357143b23be38b7779c53d2 + // LogPrintf("txout hash = %s\n", txout.GetHash().GetHex().c_str()); //5bada4eca0588e4dbb33ec37bd658dfdd7b9bce1e3ad3aa68461151f2e835597 + CScript::const_iterator itTxA = txout.scriptPubKey.begin(); // An iterator, the first element if (!txout.scriptPubKey.GetOp(itTxA, opCode, vchEphemPK) || opCode != OP_RETURN) continue; - LogPrintf("Note: txout.scriptPubKey,check vchEphemPK=%s\n", HexStr(vchEphemPK).c_str()); //Õâ¸öÊä³ö²»ÄÜÊÇ¿Õ£¬Ó¦¸ÃÊÇephem_pubkey - LogPrintf("Note: opCode=%i\n", (int)opCode);//=106 - LogPrintf("Note: itTxA=%s\n", HexStr(itTxA,itTxA).c_str());//ʹÓõü´úÆ÷ - *itTxA++;//¿ç¹ý²Ù×÷·û + // LogPrintf("Note: txout.scriptPubKey,check vchEphemPK=%s\n", HexStr(vchEphemPK).c_str()); // This output can not be empty, should be ephem_pubkey + // LogPrintf("Note: opCode=%i\n", (int)opCode);// =106 + // LogPrintf("Note: itTxA=%s\n", HexStr(itTxA,itTxA).c_str());// Use iterator + *itTxA++; // Cross the operator vchEphemPKtt.assign(itTxA, itTxA + 33); - vchEphemPK.assign(itTxA, itTxA + 33); //ÎÒ²¹³äµÄ´úÂ룬¹Ø¼ü£¬Õâ¸öÊä³ö²»ÄÜÊÇ¿Õ£¬Ó¦¸ÃÊÇephem_pubkey - LogPrintf("Note: txout.scriptPubKey,again vchEphemPKtt=%s\n", HexStr(vchEphemPKtt).c_str()); - LogPrintf("Note: txout.scriptPubKey,again vchEphemPK=%s\n", HexStr(vchEphemPK).c_str()); + vchEphemPK.assign(itTxA, itTxA + 33); // I added the code to the key that this output can not be empty and should be ephem_pubkey + // LogPrintf("Note: txout.scriptPubKey,again vchEphemPKtt=%s\n", HexStr(vchEphemPKtt).c_str()); + // LogPrintf("Note: txout.scriptPubKey,again vchEphemPK=%s\n", HexStr(vchEphemPK).c_str()); int32_t nOutputId = -1; nStealth++; BOOST_FOREACH(const CTxOut& txoutB, tx.vout) //tx.vout again { nOutputId++; - LogPrintf("BOOST_FOREACH nOutputId=%d ,print param.....\n", nOutputId); + // LogPrintf("BOOST_FOREACH nOutputId=%d ,print param.....\n", nOutputId); - if (&txoutB == &txout) //°ÑOP_RETURN½»Ò×·Ö±ðÓëÁí2¸öÖ´ÐÐ + if (&txoutB == &txout) //To put OP_RETURN The transaction is executed separately from the other two continue; bool txnMatch = false; // only 1 txn will match an ephem pk - LogPrintf("CTxOut: %s\n", txoutB.ToString().c_str()); - LogPrintf("only 1 txn will match an ephem pk,tx.vout scriptPubKey %s\n", txoutB.scriptPubKey.ToString().c_str()); + // LogPrintf("CTxOut: %s\n", txoutB.ToString().c_str()); + // LogPrintf("only 1 txn will match an ephem pk,tx.vout scriptPubKey %s\n", txoutB.scriptPubKey.ToString().c_str()); //OP_DUP OP_HASH160 d0ae59f757fc9ce14559413e2d00ac8fede6f9a2 OP_EQUALVERIFY OP_CHECKSIG CTxDestination address; @@ -2022,7 +2025,7 @@ bool CWallet::FindStealthTransactions(const CTransaction& tx) CKeyID ckidMatch = boost::get(address); if (HaveKey(ckidMatch)) // no point checking if already have key continue; - LogPrintf("CTxDestination=CKeyID,ckidMatch=%s \n", ckidMatch.ToString().c_str()); + // LogPrintf("CTxDestination=CKeyID,ckidMatch=%s \n", ckidMatch.ToString().c_str()); //a2f9e6ed8fac002d3e415945e19cfc57f759aed0 int i=0; @@ -2030,38 +2033,39 @@ bool CWallet::FindStealthTransactions(const CTransaction& tx) for (it = stealthAddresses.begin(); it != stealthAddresses.end(); ++it) { i++; - LogPrintf("StealthAddress iterator=%d \n", i); // + // LogPrintf("StealthAddress iterator=%d \n", i); // if (it->scan_secret.size() != ec_secret_size) continue; // stealth address is not owned - LogPrintf("it->scan_secret.size() %d\n", it->scan_secret.size()); - LogPrintf("it->Encodeded() %s\n", it->Encoded().c_str()); //ÕÒµ½ÊÕ¿îÈËÒþÉí¹«³×µØÖ· + // LogPrintf("it->scan_secret.size() %d\n", it->scan_secret.size()); + // LogPrintf("it->Encodeded() %s\n", it->Encoded().c_str()); // Find the recipient's stealth key address memcpy(&sScan.e[0], &it->scan_secret[0], ec_secret_size); //??? 33u - LogPrintf("StealthAddress Label=%s\n",it->label); - LogPrintf("StealthAddress Address=%s\n",it->Encoded()); - LogPrintf("StealthAddress Scan Secret=%s\n",HexStr(it->scan_secret.begin(), it->scan_secret.end()));//f1e76e169c05b00ad755ef6128a1fe2ccc1f2351383f5a5969f4040994d3f25e - LogPrintf("StealthAddress Scan Pubkey=%s\n",HexStr(it->scan_pubkey.begin(), it->scan_pubkey.end()));//038cf92caa6f1fe56b19e09cca0bdc52a81e46007bc12622688c0feda804f9d073 - LogPrintf("StealthAddress Spend Secret=%s\n",HexStr(it->spend_secret.begin(), it->spend_secret.end()));//117a9e4a428e7549eeeaa1dc3deb5cab2696518e2af0849fc6b7d675fe0a10ee - LogPrintf("StealthAddress Spend Pubkey=%s\n",HexStr(it->spend_pubkey.begin(), it->spend_pubkey.end())); - //02ffae1e8fda48c5ff6824ac0d497ea3c3b1ef3a438832bd5e5edc0bf4f93172d6,ÓëOP_RETURN²»Æ¥Åä + // LogPrintf("StealthAddress Label=%s\n",it->label); + // LogPrintf("StealthAddress Address=%s\n",it->Encoded()); + // LogPrintf("StealthAddress Scan Secret=%s\n",HexStr(it->scan_secret.begin(), it->scan_secret.end()));//f1e76e169c05b00ad755ef6128a1fe2ccc1f2351383f5a5969f4040994d3f25e + // LogPrintf("StealthAddress Scan Pubkey=%s\n",HexStr(it->scan_pubkey.begin(), it->scan_pubkey.end()));//038cf92caa6f1fe56b19e09cca0bdc52a81e46007bc12622688c0feda804f9d073 + // LogPrintf("StealthAddress Spend Secret=%s\n",HexStr(it->spend_secret.begin(), it->spend_secret.end()));//117a9e4a428e7549eeeaa1dc3deb5cab2696518e2af0849fc6b7d675fe0a10ee + // LogPrintf("StealthAddress Spend Pubkey=%s\n",HexStr(it->spend_pubkey.begin(), it->spend_pubkey.end())); + //02ffae1e8fda48c5ff6824ac0d497ea3c3b1ef3a438832bd5e5edc0bf4f93172d6, versus OP_RETURN Mismatch - LogPrintf("StealthSecret....."); - LogPrintf("sScan.e=%s\n",HexStr(&sScan.e[0],&sScan.e[32]).c_str()); //ÊÕ¿îÈËÒþÉí¹«³×µØÖ·,Scan Secret:scan_secret - LogPrintf("vchEphemPK=%s\n", HexStr(vchEphemPK).c_str()); //??? Ϊ¿Õ£¬pubkeyÊǸöÎÊÌâ - LogPrintf("it->spend_pubkey=%s\n", HexStr(it->spend_pubkey)); // - LogPrintf("sShared.e=%s\n",HexStr(&sShared.e[0],&sShared.e[32]).c_str()); //Ϊ¿Õ - LogPrintf("pkExtracted=%" PRIszu ":%s\n", pkExtracted.size(), HexStr(pkExtracted).c_str());//Ϊ¿Õ + // LogPrintf("StealthSecret....."); + // LogPrintf("sScan.e=%s\n",HexStr(&sScan.e[0],&sScan.e[32]).c_str()); //,Payee stealth public key address Scan Secret:scan_secret + // LogPrintf("vchEphemPK=%s\n", HexStr(vchEphemPK).c_str()); //??? Is empty pubkey Is a problem + // LogPrintf("it->spend_pubkey=%s\n", HexStr(it->spend_pubkey)); // + // LogPrintf("sShared.e=%s\n",HexStr(&sShared.e[0],&sShared.e[32]).c_str()); // Is empty + // LogPrintf("pkExtracted=%" PRIszu ":%s\n", pkExtracted.size(), HexStr(pkExtracted).c_str()); // Is empty int rv=StealthSecret(sScan, vchEphemPK, it->spend_pubkey, sShared, pkExtracted); //StealthSecret(ephem_secret, sxAddr.scan_pubkey, sxAddr.spend_pubkey, secretShared, pkSendTo) != 0) //receive:secret = scan_secret, pubkey = ephem_pubkey(vchEphemPK) if (rv!= 0) { - LogPrintf("StealthSecret failed.rv=%d \n",rv); + if (fDebug) + LogPrintf("StealthSecret failed.rv=%d \n",rv); continue; }; - LogPrintf("StealthSecret ok.rv=%d \n",rv); - LogPrintf("pkExtracted= %" PRIszu ": %s\n", pkExtracted.size(), HexStr(pkExtracted).c_str());//pkOut + // LogPrintf("StealthSecret ok.rv=%d \n",rv); + // LogPrintf("pkExtracted= %" PRIszu ": %s\n", pkExtracted.size(), HexStr(pkExtracted).c_str());//pkOut CPubKey cpkE(pkExtracted); if (!cpkE.IsValid()) @@ -2071,7 +2075,7 @@ bool CWallet::FindStealthTransactions(const CTransaction& tx) if (ckidMatch != ckidE) continue; - //if (fDebug) + if (fDebug) LogPrintf("Found stealth txn to address %s\n", it->Encoded().c_str()); if (IsLocked()) @@ -2182,8 +2186,8 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) { LOCK2(cs_main, cs_wallet); - LogPrintf("CommitTransaction start................\n"); - LogPrintf("CommitTransaction:\n%s", wtxNew.ToString()); + // LogPrintf("CommitTransaction start................\n"); + // LogPrintf("CommitTransaction:\n%s", wtxNew.ToString()); { // This is only to keep the database open to defeat the auto-flush for the // duration of this scope. This is the only place where this optimization @@ -2214,7 +2218,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) mapRequestCount[wtxNew.GetHash()] = 0; // Broadcast - LogPrintf("CommitTransaction Broadcast start.............\n"); + // LogPrintf("CommitTransaction Broadcast start.............\n"); if (!wtxNew.AcceptToMemoryPool(false)) { // This must not fail. The transaction has already been signed and recorded. @@ -2222,7 +2226,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) return false; } wtxNew.RelayWalletTransaction(); - LogPrintf("CommitTransaction RelayWalletTransaction............\n"); + // LogPrintf("CommitTransaction RelayWalletTransaction............\n"); } return true; } @@ -2239,7 +2243,7 @@ string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNe if (IsLocked()) { string strError = _("Error: Wallet locked, unable to create transaction!"); - LogPrintf("SendMoney() : %s", strError); + // LogPrintf("SendMoney() : %s", strError); return strError; } string strError; @@ -2247,7 +2251,7 @@ string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNe { if (nValue + nFeeRequired > GetBalance()) strError = strprintf(_("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!"), FormatMoney(nFeeRequired)); - LogPrintf("SendMoney() : %s\n", strError); + // LogPrintf("SendMoney() : %s\n", strError); return strError; } @@ -2255,7 +2259,7 @@ string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNe if (fAskFee && !uiInterface.ThreadSafeAskFee(nFeeRequired, _("Sending..."))) return "ABORTED"; - LogPrintf("SendMoney, scriptPubKey=%s \n",scriptPubKey.ToString()); + // LogPrintf("SendMoney, scriptPubKey=%s \n",scriptPubKey.ToString()); if (!CommitTransaction(wtxNew, reservekey)) return _("Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."); @@ -2278,7 +2282,7 @@ string CWallet::SendMoneyToDestination(const CTxDestination& address, int64_t nV CScript scriptPubKey; scriptPubKey.SetDestination(address); - LogPrintf("SendMoneyToDestination.....................\n"); + // LogPrintf("SendMoneyToDestination.....................\n"); return SendMoney(scriptPubKey, nValue, wtxNew, fAskFee); } @@ -2420,7 +2424,7 @@ bool CWallet::NewKeyPool() walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey())); setKeyPool.insert(nIndex); } - LogPrintf("CWallet::NewKeyPool wrote %d new keys\n", nKeys); + // LogPrintf("CWallet::NewKeyPool wrote %d new keys\n", nKeys); } return true; } @@ -2450,7 +2454,7 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize) if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey()))) throw runtime_error("TopUpKeyPool() : writing generated key failed"); setKeyPool.insert(nEnd); - LogPrintf("keypool added key %d, size=%u\n", nEnd, setKeyPool.size()); + // LogPrintf("keypool added key %d, size=%u\n", nEnd, setKeyPool.size()); } } return true; @@ -2479,7 +2483,7 @@ void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool) if (!HaveKey(keypool.vchPubKey.GetID())) throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool"); assert(keypool.vchPubKey.IsValid()); - LogPrintf("keypool reserve %d\n", nIndex); + // LogPrintf("keypool reserve %d\n", nIndex); } } @@ -2506,7 +2510,7 @@ void CWallet::KeepKey(int64_t nIndex) CWalletDB walletdb(strWalletFile); walletdb.ErasePool(nIndex); } - LogPrintf("keypool keep %d\n", nIndex); + // LogPrintf("keypool keep %d\n", nIndex); } void CWallet::ReturnKey(int64_t nIndex) @@ -2516,7 +2520,7 @@ void CWallet::ReturnKey(int64_t nIndex) LOCK(cs_wallet); setKeyPool.insert(nIndex); } - LogPrintf("keypool return %d\n", nIndex); + // LogPrintf("keypool return %d\n", nIndex); } bool CWallet::GetKeyFromPool(CPubKey& result) diff --git a/src/walletdb.cpp b/src/walletdb.cpp index 8b6c44e21c..c96f14ebb4 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin developers +// Copyright (c) 2015-2017 The Feathercoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -692,12 +693,12 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) // upgrading, we don't want to make it worse. if (result != DB_LOAD_OK) return result; - - LogPrintf("nFileVersion = %d\n", wss.nFileVersion); - - LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n", - wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys); - + if (fDebug) + { + LogPrintf("nFileVersion = %d\n", wss.nFileVersion); + LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n", + wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys); + } // nTimeFirstKey is only reliable if all keys have metadata if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta) pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value'