diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp
index f8d0f9e86..c54c07e58 100644
--- a/src/masternode-sync.cpp
+++ b/src/masternode-sync.cpp
@@ -9,6 +9,7 @@
#include "masternode-budget.h"
#include "masternode.h"
#include "masternodeman.h"
+#include "spork.h"
#include "util.h"
#include "addrman.h"
@@ -76,6 +77,7 @@ void CMasternodeSync::Reset()
countBudgetItemFin = 0;
RequestedMasternodeAssets = MASTERNODE_SYNC_INITIAL;
RequestedMasternodeAttempt = 0;
+ nAssetSyncStarted = GetTime();
}
void CMasternodeSync::AddedMasternodeList(uint256 hash)
@@ -152,8 +154,22 @@ void CMasternodeSync::GetNextAsset()
break;
}
RequestedMasternodeAttempt = 0;
+ nAssetSyncStarted = GetTime();
}
+std::string CMasternodeSync::GetSyncStatus()
+{
+ switch (masternodeSync.RequestedMasternodeAssets) {
+ case MASTERNODE_SYNC_INITIAL: return _("Synchronization doesn't yet started");
+ case MASTERNODE_SYNC_SPORKS: return _("Synchronizing sporks...");
+ case MASTERNODE_SYNC_LIST: return _("Synchronizing masternodes...");
+ case MASTERNODE_SYNC_MNW: return _("Synchronizing masternode winners...");
+ case MASTERNODE_SYNC_BUDGET: return _("Synchronizing budgets...");
+ case MASTERNODE_SYNC_FAILED: return _("Synchronization failed");
+ case MASTERNODE_SYNC_FINISHED: return _("Synchronization finished");
+ }
+ return "";
+}
void CMasternodeSync::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
{
@@ -284,6 +300,21 @@ void CMasternodeSync::Process()
if(pnode->HasFulfilledRequest("mnsync")) continue;
pnode->FulfilledRequest("mnsync");
+ // timeout
+ if(lastMasternodeList == 0 &&
+ (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD*3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT*3)) {
+ if(IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) {
+ LogPrintf("CMasternodeSync::Process - ERROR - Sync has failed, will retry later\n");
+ RequestedMasternodeAssets = MASTERNODE_SYNC_FAILED;
+ RequestedMasternodeAttempt = 0;
+ lastFailure = GetTime();
+ nCountFailures++;
+ } else {
+ GetNextAsset();
+ }
+ return;
+ }
+
mnodeman.DsegUpdate(pnode);
RequestedMasternodeAttempt++;
return;
@@ -298,6 +329,21 @@ void CMasternodeSync::Process()
if(pnode->HasFulfilledRequest("mnwsync")) continue;
pnode->FulfilledRequest("mnwsync");
+ // timeout
+ if(lastMasternodeWinner == 0 &&
+ (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD*3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT*3)) {
+ if(IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) {
+ LogPrintf("CMasternodeSync::Process - ERROR - Sync has failed, will retry later\n");
+ RequestedMasternodeAssets = MASTERNODE_SYNC_FAILED;
+ RequestedMasternodeAttempt = 0;
+ lastFailure = GetTime();
+ nCountFailures++;
+ } else {
+ GetNextAsset();
+ }
+ return;
+ }
+
CBlockIndex* pindexPrev = chainActive.Tip();
if(pindexPrev == NULL) return;
@@ -332,7 +378,9 @@ void CMasternodeSync::Process()
}
// timeout
- if(lastBudgetItem == 0 && RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD*3) {
+ if(lastBudgetItem == 0 &&
+ (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD*3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT*3)) {
+ // maybe there is no budgets at all, so just finish syncing
GetNextAsset();
activeMasternode.ManageStatus();
return;
diff --git a/src/masternode-sync.h b/src/masternode-sync.h
index c559a4624..f44dd3247 100644
--- a/src/masternode-sync.h
+++ b/src/masternode-sync.h
@@ -15,7 +15,7 @@
#define MASTERNODE_SYNC_FAILED 998
#define MASTERNODE_SYNC_FINISHED 999
-#define MASTERNODE_SYNC_TIMEOUT 7
+#define MASTERNODE_SYNC_TIMEOUT 5
#define MASTERNODE_SYNC_THRESHOLD 4
class CMasternodeSync;
@@ -53,12 +53,16 @@ public:
int RequestedMasternodeAssets;
int RequestedMasternodeAttempt;
+ // Time when current masternode asset sync started
+ int64_t nAssetSyncStarted;
+
CMasternodeSync();
void AddedMasternodeList(uint256 hash);
void AddedMasternodeWinner(uint256 hash);
void AddedBudgetItem(uint256 hash);
void GetNextAsset();
+ std::string GetSyncStatus();
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
bool IsBudgetFinEmpty();
bool IsBudgetPropEmpty();
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index a57ef7716..6ac4621ef 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -758,46 +758,38 @@ void BitcoinGUI::setNumBlocks(int count)
// if(secs < 25*60) // 90*60 for bitcoin but we are 4x times faster
if(masternodeSync.IsBlockchainSynced())
{
+ QString strSyncStatus;
tooltip = tr("Up to date") + QString(".
") + tooltip;
- static int prevAttempt = -1;
- static int prevAssets = -1;
- static int progress = 0;
- if(masternodeSync.RequestedMasternodeAttempt != prevAttempt || masternodeSync.RequestedMasternodeAssets != prevAssets)
- {
+ if(masternodeSync.IsSynced()) {
+ progressBarLabel->setVisible(false);
+ progressBar->setVisible(false);
+ labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
+ } else {
+
+ int nAttempt;
+ int progress = 0;
+
labelBlocksIcon->setPixmap(QIcon(QString(
":/movies/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')))
.pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
spinnerFrame = (spinnerFrame + 1) % SPINNER_FRAMES;
- progressBar->setMaximum(4 * MASTERNODE_SYNC_THRESHOLD);
- prevAttempt = masternodeSync.RequestedMasternodeAttempt + 1;
- prevAssets = masternodeSync.RequestedMasternodeAssets;
- if(prevAttempt <= MASTERNODE_SYNC_THRESHOLD) progress = prevAttempt + (prevAssets - 1) * MASTERNODE_SYNC_THRESHOLD;
- progressBar->setValue(progress);
+
#ifdef ENABLE_WALLET
if(walletFrame)
walletFrame->showOutOfSyncWarning(false);
#endif // ENABLE_WALLET
+
+ nAttempt = masternodeSync.RequestedMasternodeAttempt < MASTERNODE_SYNC_THRESHOLD ?
+ masternodeSync.RequestedMasternodeAttempt + 1 : MASTERNODE_SYNC_THRESHOLD;
+ progress = nAttempt + (masternodeSync.RequestedMasternodeAssets - 1) * MASTERNODE_SYNC_THRESHOLD;
+ progressBar->setMaximum(4 * MASTERNODE_SYNC_THRESHOLD);
+ progressBar->setValue(progress);
}
- switch (masternodeSync.RequestedMasternodeAssets) {
- case MASTERNODE_SYNC_SPORKS:
- progressBarLabel->setText(tr("Synchronizing sporks..."));
- break;
- case MASTERNODE_SYNC_LIST:
- progressBarLabel->setText(tr("Synchronizing masternodes..."));
- break;
- case MASTERNODE_SYNC_MNW:
- progressBarLabel->setText(tr("Synchronizing masternode winners..."));
- break;
- case MASTERNODE_SYNC_BUDGET:
- progressBarLabel->setText(tr("Synchronizing budgets..."));
- break;
- case MASTERNODE_SYNC_FINISHED:
- progressBarLabel->setVisible(false);
- progressBar->setVisible(false);
- labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
- break;
- }
+
+ strSyncStatus = QString(masternodeSync.GetSyncStatus().c_str());
+ progressBarLabel->setText(strSyncStatus);
+ tooltip = strSyncStatus + QString("
") + tooltip;
}
else
{