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