CGovernanceManager initialization fix (#1138)

* Fix CGovernanceManager initialization problem

* Added logging messages for cases where CGovernanceManager receives a message while not synced

* Prevent potential NULL pointer dereference
This commit is contained in:
Tim Flynn 2016-11-12 06:14:50 -05:00 committed by UdjinM6
parent d2f1fd253c
commit 82ca5fdbb8
2 changed files with 13 additions and 2 deletions

View File

@ -129,7 +129,10 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
LOCK(cs);
// MAKE SURE WE HAVE A VALID REFERENCE TO THE TIP BEFORE CONTINUING
if(!pCurrentBlockIndex) return;
if(!pCurrentBlockIndex) {
LogPrintf("CGovernanceManager::ProcessMessage MNGOVERNANCEOBJECT -- pCurrentBlockIndex is NULL\n");
return;
}
CGovernanceObject govobj;
vRecv >> govobj;
@ -172,7 +175,10 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
else if (strCommand == NetMsgType::MNGOVERNANCEOBJECTVOTE)
{
// Ignore such messages until masternode list is synced
if(!masternodeSync.IsMasternodeListSynced()) return;
if(!masternodeSync.IsMasternodeListSynced()) {
LogPrint("gobject", "CGovernanceManager::ProcessMessage MNGOVERNANCEOBJECTVOTE -- masternode list not synced\n");
return;
}
CGovernanceVote vote;
vRecv >> vote;
@ -1125,6 +1131,10 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex *pindex)
// On the other hand it should be safe for us to access pindex without holding a lock
// on cs_main because the CBlockIndex objects are dynamically allocated and
// presumably never deleted.
if(!pindex) {
return;
}
LOCK(cs);
pCurrentBlockIndex = pindex;
nCachedBlockHeight = pCurrentBlockIndex->nHeight;

View File

@ -1883,6 +1883,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
darkSendPool.UpdatedBlockTip(chainActive.Tip());
mnpayments.UpdatedBlockTip(chainActive.Tip());
masternodeSync.UpdatedBlockTip(chainActive.Tip());
governance.UpdatedBlockTip(chainActive.Tip());
// ********************************************************* Step 11d: start dash-privatesend thread