Merge pull request #508 from UdjinM6/v0.12.0.x_sync_status

V0.12.0.x show masternode sync status in GUI
This commit is contained in:
evan82 2015-08-11 05:55:07 -07:00
commit 738f009a10
4 changed files with 55 additions and 16 deletions

View File

@ -81,7 +81,7 @@ void CMasternodeSync::Reset()
void CMasternodeSync::AddedMasternodeList(uint256 hash) void CMasternodeSync::AddedMasternodeList(uint256 hash)
{ {
if(mnodeman.mapSeenMasternodeBroadcast.count(hash)) { if(mnodeman.mapSeenMasternodeBroadcast.count(hash)) {
if(mapSeenSyncMNB[hash] < 2) { if(mapSeenSyncMNB[hash] < MASTERNODE_SYNC_TRESHOLD) {
lastMasternodeList = GetTime(); lastMasternodeList = GetTime();
mapSeenSyncMNB[hash]++; mapSeenSyncMNB[hash]++;
} }
@ -94,7 +94,7 @@ void CMasternodeSync::AddedMasternodeList(uint256 hash)
void CMasternodeSync::AddedMasternodeWinner(uint256 hash) void CMasternodeSync::AddedMasternodeWinner(uint256 hash)
{ {
if(masternodePayments.mapMasternodePayeeVotes.count(hash)) { if(masternodePayments.mapMasternodePayeeVotes.count(hash)) {
if(mapSeenSyncMNW[hash] < 2) { if(mapSeenSyncMNW[hash] < MASTERNODE_SYNC_TRESHOLD) {
lastMasternodeWinner = GetTime(); lastMasternodeWinner = GetTime();
mapSeenSyncMNW[hash]++; mapSeenSyncMNW[hash]++;
} }
@ -108,7 +108,7 @@ void CMasternodeSync::AddedBudgetItem(uint256 hash)
{ {
if(budget.mapSeenMasternodeBudgetProposals.count(hash) || budget.mapSeenMasternodeBudgetVotes.count(hash) || if(budget.mapSeenMasternodeBudgetProposals.count(hash) || budget.mapSeenMasternodeBudgetVotes.count(hash) ||
budget.mapSeenFinalizedBudgets.count(hash) || budget.mapSeenFinalizedBudgetVotes.count(hash)) { budget.mapSeenFinalizedBudgets.count(hash) || budget.mapSeenFinalizedBudgetVotes.count(hash)) {
if(mapSeenSyncBudget[hash] < 2) { if(mapSeenSyncBudget[hash] < MASTERNODE_SYNC_TRESHOLD) {
lastBudgetItem = GetTime(); lastBudgetItem = GetTime();
mapSeenSyncBudget[hash]++; mapSeenSyncBudget[hash]++;
} }
@ -276,7 +276,7 @@ void CMasternodeSync::Process()
if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST) { if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST) {
if(fDebug) LogPrintf("CMasternodeSync::Process() - lastMasternodeList %lld (GetTime() - MASTERNODE_SYNC_TIMEOUT) %lld\n", lastMasternodeList, GetTime() - MASTERNODE_SYNC_TIMEOUT); if(fDebug) LogPrintf("CMasternodeSync::Process() - lastMasternodeList %lld (GetTime() - MASTERNODE_SYNC_TIMEOUT) %lld\n", lastMasternodeList, GetTime() - MASTERNODE_SYNC_TIMEOUT);
if(lastMasternodeList > 0 && lastMasternodeList < GetTime() - MASTERNODE_SYNC_TIMEOUT && RequestedMasternodeAttempt >= 4){ //hasn't received a new item in the last five seconds, so we'll move to the if(lastMasternodeList > 0 && lastMasternodeList < GetTime() - MASTERNODE_SYNC_TIMEOUT && RequestedMasternodeAttempt >= MASTERNODE_SYNC_TRESHOLD){ //hasn't received a new item in the last five seconds, so we'll move to the
GetNextAsset(); GetNextAsset();
return; return;
} }
@ -290,7 +290,7 @@ void CMasternodeSync::Process()
} }
if(RequestedMasternodeAssets == MASTERNODE_SYNC_MNW) { if(RequestedMasternodeAssets == MASTERNODE_SYNC_MNW) {
if(lastMasternodeWinner > 0 && lastMasternodeWinner < GetTime() - MASTERNODE_SYNC_TIMEOUT && RequestedMasternodeAttempt >= 4){ //hasn't received a new item in the last five seconds, so we'll move to the if(lastMasternodeWinner > 0 && lastMasternodeWinner < GetTime() - MASTERNODE_SYNC_TIMEOUT && RequestedMasternodeAttempt >= MASTERNODE_SYNC_TRESHOLD){ //hasn't received a new item in the last five seconds, so we'll move to the
GetNextAsset(); GetNextAsset();
return; return;
} }
@ -314,7 +314,7 @@ void CMasternodeSync::Process()
if(RequestedMasternodeAssets == MASTERNODE_SYNC_BUDGET){ if(RequestedMasternodeAssets == MASTERNODE_SYNC_BUDGET){
//we'll start rejecting votes if we accidentally get set as synced too soon //we'll start rejecting votes if we accidentally get set as synced too soon
if(lastBudgetItem > 0 && lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT && RequestedMasternodeAttempt >= 4){ //hasn't received a new item in the last five seconds, so we'll move to the if(lastBudgetItem > 0 && lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT && RequestedMasternodeAttempt >= MASTERNODE_SYNC_TRESHOLD){ //hasn't received a new item in the last five seconds, so we'll move to the
//LogPrintf("CMasternodeSync::Process - HasNextFinalizedBudget %d nCountFailures %d IsBudgetPropEmpty %d\n", budget.HasNextFinalizedBudget(), nCountFailures, IsBudgetPropEmpty()); //LogPrintf("CMasternodeSync::Process - HasNextFinalizedBudget %d nCountFailures %d IsBudgetPropEmpty %d\n", budget.HasNextFinalizedBudget(), nCountFailures, IsBudgetPropEmpty());
//if(budget.HasNextFinalizedBudget() || nCountFailures >= 2 || IsBudgetPropEmpty()) { //if(budget.HasNextFinalizedBudget() || nCountFailures >= 2 || IsBudgetPropEmpty()) {
GetNextAsset(); GetNextAsset();

View File

@ -16,6 +16,7 @@
#define MASTERNODE_SYNC_FINISHED 999 #define MASTERNODE_SYNC_FINISHED 999
#define MASTERNODE_SYNC_TIMEOUT 7 #define MASTERNODE_SYNC_TIMEOUT 7
#define MASTERNODE_SYNC_TRESHOLD 4
class CMasternodeSync; class CMasternodeSync;
extern CMasternodeSync masternodeSync; extern CMasternodeSync masternodeSync;

View File

@ -197,10 +197,10 @@ BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) :
// Progress bar and label for blocks download // Progress bar and label for blocks download
progressBarLabel = new QLabel(); progressBarLabel = new QLabel();
progressBarLabel->setVisible(false); progressBarLabel->setVisible(true);
progressBar = new GUIUtil::ProgressBar(); progressBar = new GUIUtil::ProgressBar();
progressBar->setAlignment(Qt::AlignCenter); progressBar->setAlignment(Qt::AlignCenter);
progressBar->setVisible(false); progressBar->setVisible(true);
// Override style sheet for progress bar for styles that have a segmented progress bar, // Override style sheet for progress bar for styles that have a segmented progress bar,
// as they make the text unreadable (workaround for issue #1071) // as they make the text unreadable (workaround for issue #1071)
@ -755,18 +755,49 @@ void BitcoinGUI::setNumBlocks(int count)
tooltip = tr("Processed %n blocks of transaction history.", "", count); tooltip = tr("Processed %n blocks of transaction history.", "", count);
// Set icon state: spinning if catching up, tick otherwise // Set icon state: spinning if catching up, tick otherwise
if(secs < 25*60) // 90*60 for bitcoin but we are 4x times faster // if(secs < 25*60) // 90*60 for bitcoin but we are 4x times faster
if(masternodeSync.IsBlockchainSynced())
{ {
tooltip = tr("Up to date") + QString(".<br>") + tooltip; tooltip = tr("Up to date") + QString(".<br>") + tooltip;
labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
static int prevAttempt = -1;
static int prevAssets = -1;
static int progress = 0;
if(masternodeSync.RequestedMasternodeAttempt != prevAttempt || masternodeSync.RequestedMasternodeAssets != prevAssets)
{
labelBlocksIcon->setPixmap(QIcon(QString(
":/movies/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')))
.pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
spinnerFrame = (spinnerFrame + 1) % SPINNER_FRAMES;
prevAttempt = masternodeSync.RequestedMasternodeAttempt + 1;
prevAssets = masternodeSync.RequestedMasternodeAssets;
if(prevAttempt <= MASTERNODE_SYNC_TRESHOLD) progress = prevAttempt + (prevAssets - 1) * MASTERNODE_SYNC_TRESHOLD;
progressBar->setValue(progress);
}
switch (masternodeSync.RequestedMasternodeAssets) {
case MASTERNODE_SYNC_SPORKS:
progressBar->setMaximum(4 * MASTERNODE_SYNC_TRESHOLD);
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:
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
if(walletFrame) if(walletFrame)
walletFrame->showOutOfSyncWarning(false); walletFrame->showOutOfSyncWarning(false);
#endif // ENABLE_WALLET #endif // ENABLE_WALLET
progressBarLabel->setVisible(false);
progressBarLabel->setVisible(false); progressBar->setVisible(false);
progressBar->setVisible(false); labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
break;
}
} }
else else
{ {

View File

@ -16,6 +16,7 @@
#include "net.h" #include "net.h"
#include "ui_interface.h" #include "ui_interface.h"
#include "masternodeman.h" #include "masternodeman.h"
#include "masternode-sync.h"
#include "util.h" #include "util.h"
#include <stdint.h> #include <stdint.h>
@ -123,13 +124,19 @@ void ClientModel::updateTimer()
// Periodically check and update with a timer. // Periodically check and update with a timer.
int newNumBlocks = getNumBlocks(); int newNumBlocks = getNumBlocks();
static int prevAttempt = -1;
static int prevAssets = -1;
// check for changed number of blocks we have, number of blocks peers claim to have, reindexing state and importing state // check for changed number of blocks we have, number of blocks peers claim to have, reindexing state and importing state
if (cachedNumBlocks != newNumBlocks || if (cachedNumBlocks != newNumBlocks ||
cachedReindexing != fReindex || cachedImporting != fImporting) cachedReindexing != fReindex || cachedImporting != fImporting ||
masternodeSync.RequestedMasternodeAttempt != prevAttempt || masternodeSync.RequestedMasternodeAssets != prevAssets)
{ {
cachedNumBlocks = newNumBlocks; cachedNumBlocks = newNumBlocks;
cachedReindexing = fReindex; cachedReindexing = fReindex;
cachedImporting = fImporting; cachedImporting = fImporting;
prevAttempt = masternodeSync.RequestedMasternodeAttempt;
prevAssets = masternodeSync.RequestedMasternodeAssets;
emit numBlocksChanged(newNumBlocks); emit numBlocksChanged(newNumBlocks);
} }