See https://github.com/bitcoin/bitcoin/pull/1767
[novacoin.git] / src / kernel.cpp
index 0585842..d31bfe9 100644 (file)
@@ -9,11 +9,13 @@
 #include "kernel_worker.h"
 #include "txdb.h"
 
-extern uint32_t nStakeMaxAge;
 extern uint32_t nStakeTargetSpacing;
 
 using namespace std;
 
+uint32_t nStakeMinAge = 30 * nOneDay; // 30 days as zero time weight
+uint32_t nStakeMaxAge = 90 * nOneDay; // 90 days as full weight
+
 // Protocol switch time for fixed kernel modifier interval
 uint32_t nModifierSwitchTime  = 1413763200;    // Mon, 20 Oct 2014 00:00:00 GMT
 uint32_t nModifierTestSwitchTime = 1397520000; // Tue, 15 Apr 2014 00:00:00 GMT
@@ -301,7 +303,7 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexCurrent, uint64_t& nStake
 
 // The stake modifier used to hash for a stake kernel is chosen as the stake
 // modifier about a selection interval later than the coin generating the kernel
-static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifier, int& nStakeModifierHeight, int64_t& nStakeModifierTime, bool fPrintProofOfStake)
+static bool GetKernelStakeModifier(const uint256 &hashBlockFrom, uint64_t& nStakeModifier, int& nStakeModifierHeight, int64_t& nStakeModifierTime, bool fPrintProofOfStake)
 {
     nStakeModifier = 0;
     if (!mapBlockIndex.count(hashBlockFrom))
@@ -333,7 +335,7 @@ static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifi
     return true;
 }
 
-bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifier)
+bool GetKernelStakeModifier(const uint256 &hashBlockFrom, uint64_t& nStakeModifier)
 {
     int nStakeModifierHeight;
     int64_t nStakeModifierTime;
@@ -429,7 +431,11 @@ bool ScanKernelForward(unsigned char *kernel, uint32_t nBits, uint32_t nInputTxT
     {
         using namespace boost;
 
-        auto nThreads = std::thread::hardware_concurrency();
+        auto nThreads = boost::thread::hardware_concurrency();
+        if (nThreads == 0) {
+           nThreads = 1;
+           printf("Warning: hardware_concurrency() failed in %s:%d\n", __FILE__, __LINE__);
+        }
         auto vWorkers = vector<KernelWorker>(nThreads);
         auto nPart = (SearchInterval.second - SearchInterval.first) / nThreads;
         thread_group group;
@@ -504,7 +510,7 @@ uint32_t GetStakeModifierChecksum(const CBlockIndex* pindex)
     ss << pindex->nFlags << pindex->hashProofOfStake << pindex->nStakeModifier;
     auto hashChecksum = Hash(ss.begin(), ss.end());
     hashChecksum >>= (256 - 32);
-    return static_cast<uint32_t>(hashChecksum.Get64());
+    return hashChecksum.Get32();
 }
 
 // Check stake modifier hard checkpoints