Move stake mining function wrapper definition to miner.cpp. Also, init NTP thread...
authorCryptoManiac <balthazar@yandex.ru>
Wed, 23 Sep 2015 01:15:29 +0000 (04:15 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Wed, 23 Sep 2015 01:15:29 +0000 (04:15 +0300)
src/init.cpp
src/main.h
src/miner.cpp
src/miner.h
src/net.cpp

index 4a9e19d..1eb28a5 100644 (file)
@@ -8,7 +8,6 @@
 #include "net.h"
 #include "init.h"
 #include "util.h"
-#include "ntp.h"
 #include "ui_interface.h"
 #include "checkpoints.h"
 #include <boost/format.hpp>
@@ -996,14 +995,6 @@ bool AppInit2()
     if (fServer)
         NewThread(ThreadRPCServer, NULL);
 
-    // ********************************************************* Step 12: NTP synchronization
-
-    // Trusted NTP server, it's localhost by default.
-    strTrustedUpstream = GetArg("-ntp", "localhost");
-
-    // Start periodical NTP sampling thread
-    NewThread(ThreadNtpSamples, NULL);
-
     // ********************************************************* Step 12: finished
 
     uiInterface.InitMessage(_("Done loading"));
index d2df098..c659275 100644 (file)
@@ -137,7 +137,6 @@ std::string GetWarnings(std::string strFor);
 bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock);
 uint256 WantedByOrphan(const CBlock* pblockOrphan);
 const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake);
-void StakeMiner(CWallet *pwallet);
 void ResendWalletTransactions();
 
 bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType);
index f12376a..c03b37d 100644 (file)
@@ -649,7 +649,8 @@ bool ScanMap(const MidstateMap &inputsMap, uint32_t nBits, MidstateMap::key_type
     return false;
 }
 
-void StakeMiner(CWallet *pwallet)
+// TODO: Get rid of nested loops
+void StakeMiner(CWallet* pwallet)
 {
     SetThreadPriority(THREAD_PRIORITY_LOWEST);
 
@@ -769,3 +770,24 @@ void StakeMiner(CWallet *pwallet)
         continue;
     }
 }
+
+// Stake minter thread
+void ThreadStakeMinter(void* parg)
+{
+    printf("ThreadStakeMinter started\n");
+    CWallet* pwallet = (CWallet*)parg;
+    try
+    {
+        vnThreadsRunning[THREAD_MINTER]++;
+        StakeMiner(pwallet);
+        vnThreadsRunning[THREAD_MINTER]--;
+    }
+    catch (std::exception& e) {
+        vnThreadsRunning[THREAD_MINTER]--;
+        PrintException(&e, "ThreadStakeMinter()");
+    } catch (...) {
+        vnThreadsRunning[THREAD_MINTER]--;
+        PrintException(NULL, "ThreadStakeMinter()");
+    }
+    printf("ThreadStakeMinter exiting, %d threads remaining\n", vnThreadsRunning[THREAD_MINTER]);
+}
index abb81be..09bb460 100644 (file)
@@ -27,4 +27,7 @@ bool CheckStake(CBlock* pblock, CWallet& wallet);
 /** Base sha256 mining transform */
 void SHA256Transform(void* pstate, void* pinput, const void* pinit);
 
+/** Stake miner thread */
+void ThreadStakeMinter(void* parg);
+
 #endif // NOVACOIN_MINER_H
index 992d09e..632c9b9 100644 (file)
@@ -9,6 +9,8 @@
 #include "init.h"
 #include "addrman.h"
 #include "ui_interface.h"
+#include "miner.h"
+#include "ntp.h"
 
 #ifdef WIN32
 #include <string.h>
@@ -1295,27 +1297,6 @@ void static ProcessOneShot()
     }
 }
 
-// ppcoin: stake minter thread
-void static ThreadStakeMinter(void* parg)
-{
-    printf("ThreadStakeMinter started\n");
-    CWallet* pwallet = (CWallet*)parg;
-    try
-    {
-        vnThreadsRunning[THREAD_MINTER]++;
-        StakeMiner(pwallet);
-        vnThreadsRunning[THREAD_MINTER]--;
-    }
-    catch (std::exception& e) {
-        vnThreadsRunning[THREAD_MINTER]--;
-        PrintException(&e, "ThreadStakeMinter()");
-    } catch (...) {
-        vnThreadsRunning[THREAD_MINTER]--;
-        PrintException(NULL, "ThreadStakeMinter()");
-    }
-    printf("ThreadStakeMinter exiting, %d threads remaining\n", vnThreadsRunning[THREAD_MINTER]);
-}
-
 void ThreadOpenConnections2(void* parg)
 {
     printf("ThreadOpenConnections started\n");
@@ -1944,9 +1925,16 @@ void StartNode(void* parg)
     if (!NewThread(ThreadDumpAddress, NULL))
         printf("Error; NewThread(ThreadDumpAddress) failed\n");
 
-    // ppcoin: mint proof-of-stake blocks in the background
+    // Mint proof-of-stake blocks in the background
     if (!NewThread(ThreadStakeMinter, pwalletMain))
         printf("Error: NewThread(ThreadStakeMinter) failed\n");
+
+    // Trusted NTP server, it's localhost by default.
+    strTrustedUpstream = GetArg("-ntp", "localhost");
+
+    // Start periodical NTP sampling thread
+    NewThread(ThreadNtpSamples, NULL);
+
 }
 
 bool StopNode()