mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Fix locks in CMasternodeSync
This commit is contained in:
parent
cc601e80c5
commit
64d6e5720f
@ -23,20 +23,24 @@ CMasternodeSync::CMasternodeSync()
|
||||
void CMasternodeSync::Reset(bool fForce, bool fNotifyReset)
|
||||
{
|
||||
// Avoid resetting the sync process if we just "recently" received a new block
|
||||
if (fForce || (GetTime() - nTimeLastUpdateBlockTip > MASTERNODE_SYNC_RESET_SECONDS)) {
|
||||
{
|
||||
LOCK(cs);
|
||||
nCurrentAsset = MASTERNODE_SYNC_BLOCKCHAIN;
|
||||
nTriedPeerCount = 0;
|
||||
nTimeAssetSyncStarted = GetTime();
|
||||
nTimeLastBumped = GetTime();
|
||||
nTimeLastUpdateBlockTip = 0;
|
||||
fReachedBestHeader = false;
|
||||
}
|
||||
if (fNotifyReset) {
|
||||
uiInterface.NotifyAdditionalDataSyncProgressChanged(-1);
|
||||
if (!fForce) {
|
||||
LOCK(cs);
|
||||
if (GetTime() - nTimeLastUpdateBlockTip < MASTERNODE_SYNC_RESET_SECONDS) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
{
|
||||
LOCK(cs);
|
||||
nCurrentAsset = MASTERNODE_SYNC_BLOCKCHAIN;
|
||||
nTriedPeerCount = 0;
|
||||
nTimeAssetSyncStarted = GetTime();
|
||||
nTimeLastBumped = GetTime();
|
||||
nTimeLastUpdateBlockTip = 0;
|
||||
fReachedBestHeader = false;
|
||||
}
|
||||
if (fNotifyReset) {
|
||||
uiInterface.NotifyAdditionalDataSyncProgressChanged(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void CMasternodeSync::BumpAssetLastTime(const std::string& strFuncName)
|
||||
@ -88,6 +92,7 @@ void CMasternodeSync::SwitchToNextAsset(CConnman& connman)
|
||||
|
||||
std::string CMasternodeSync::GetSyncStatus() const
|
||||
{
|
||||
LOCK(cs);
|
||||
switch (nCurrentAsset) {
|
||||
case MASTERNODE_SYNC_BLOCKCHAIN: return _("Synchronizing blockchain...");
|
||||
case MASTERNODE_SYNC_GOVERNANCE: return _("Synchronizing governance objects...");
|
||||
@ -143,6 +148,7 @@ void CMasternodeSync::ProcessTick(CConnman& connman)
|
||||
return;
|
||||
}
|
||||
|
||||
LOCK(cs);
|
||||
// Calculate "progress" for LOG reporting / GUI notification
|
||||
double nSyncProgress = double(nTriedPeerCount + (nCurrentAsset - 1) * 8) / (8*4);
|
||||
LogPrint(BCLog::MNSYNC, "CMasternodeSync::ProcessTick -- nTick %d nCurrentAsset %d nTriedPeerCount %d nSyncProgress %f\n", nTick, nCurrentAsset, nTriedPeerCount, nSyncProgress);
|
||||
@ -371,6 +377,7 @@ void CMasternodeSync::UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitia
|
||||
// Note: since we sync headers first, it should be ok to use this
|
||||
bool fReachedBestHeaderNew = pindexNew->GetBlockHash() == pindexTip->GetBlockHash();
|
||||
|
||||
LOCK(cs);
|
||||
if (fReachedBestHeader && !fReachedBestHeaderNew) {
|
||||
// Switching from true to false means that we previously stuck syncing headers for some reason,
|
||||
// probably initial timeout was not enough,
|
||||
@ -378,10 +385,7 @@ void CMasternodeSync::UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitia
|
||||
Reset(true);
|
||||
}
|
||||
|
||||
{
|
||||
LOCK(cs);
|
||||
fReachedBestHeader = fReachedBestHeaderNew;
|
||||
}
|
||||
fReachedBestHeader = fReachedBestHeaderNew;
|
||||
LogPrint(BCLog::MNSYNC, "CMasternodeSync::UpdatedBlockTip -- pindexNew->nHeight: %d pindexTip->nHeight: %d fInitialDownload=%d fReachedBestHeader=%d\n",
|
||||
pindexNew->nHeight, pindexTip->nHeight, fInitialDownload, fReachedBestHeader);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user