Skip to content

Commit

Permalink
Merge pull request #2 from FeatherCoin/0.9.6.2
Browse files Browse the repository at this point in the history
0.9.6.2   pull back update
  • Loading branch information
wrapperband committed Aug 17, 2017
2 parents ad3ca35 + 50027f8 commit 1c433f0
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 284 deletions.
98 changes: 68 additions & 30 deletions src/checkpointsync.cpp
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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))
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -348,22 +360,33 @@ bool SendSyncCheckpoint(uint256 hashCheckpoint)
checkpoint.vchMsg = std::vector<unsigned char>(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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -449,40 +480,47 @@ 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
CValidationState state;
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;
}
Expand Down
9 changes: 7 additions & 2 deletions src/db.cpp
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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))
Expand Down
76 changes: 49 additions & 27 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -149,7 +150,8 @@ void Shutdown()
if (pwalletMain)
delete pwalletMain;
#endif
LogPrintf("Shutdown : done\n");
if (fDebug)
LogPrintf("Shutdown : done\n");
}

//
Expand Down Expand Up @@ -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; i<nScriptCheckThreads-1; i++)
threadGroup.create_thread(&ThreadScriptCheck);
}
Expand All @@ -661,7 +671,8 @@ bool AppInit2(boost::thread_group& threadGroup)
// ********************************************************* Step 5: verify wallet database integrity
#ifdef ENABLE_WALLET
if (!fDisableWallet) {
LogPrintf("Using wallet %s\n", strWalletFile);
if (fDebug)
LogPrintf("Using wallet %s\n", strWalletFile);
uiInterface.InitMessage(_("Verifying wallet..."));

if (!bitdb.Open(GetDataDir()))
Expand Down Expand Up @@ -935,10 +946,12 @@ bool AppInit2(boost::thread_group& threadGroup)
// As the program has not fully started yet, Shutdown() is possibly overkill.
if (fRequestShutdown)
{
LogPrintf("Shutdown requested. Exiting.\n");
if (fDebug)
LogPrintf("Shutdown requested. Exiting.\n");
return false;
}
LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart);
if (fDebug)
LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart);

if (GetBoolArg("-printblockindex", false) || GetBoolArg("-printblocktree", false))
{
Expand All @@ -960,7 +973,8 @@ bool AppInit2(boost::thread_group& threadGroup)
ReadBlockFromDisk(block, pindex);
block.BuildMerkleTree();
block.print();
LogPrintf("\n");
if (fDebug)
LogPrintf("\n");
nFound++;
}
}
Expand Down Expand Up @@ -1047,10 +1061,11 @@ bool AppInit2(boost::thread_group& threadGroup)

pwalletMain->SetBestChain(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();
Expand All @@ -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++;
}
Expand Down Expand Up @@ -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

Expand All @@ -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);
Expand Down
Loading

0 comments on commit 1c433f0

Please sign in to comment.