Try to sync before start mining.
[novacoin.git] / src / miner.cpp
index 0f04521..aca0674 100644 (file)
@@ -520,6 +520,8 @@ void StakeMiner(CWallet *pwallet)
     // Make this thread recognisable as the mining thread
     RenameThread("novacoin-miner");
 
+    bool fTrySync = true;
+
     // Each thread has its own counter
     unsigned int nExtraNonce = 0;
 
@@ -537,11 +539,23 @@ void StakeMiner(CWallet *pwallet)
 
         while (vNodes.empty() || IsInitialBlockDownload())
         {
+            fTrySync = true;
+
             Sleep(1000);
             if (fShutdown)
                 return;
         }
 
+        if (fTrySync)
+        {
+            fTrySync = false;
+            if (vNodes.size() < 3 || nBestHeight < GetNumBlocksOfPeers())
+            {
+                Sleep(1000);
+                continue;
+            }
+        }
+
         //
         // Create new block
         //