Fix PoS difficulty at 0.25 after blocks v3 supermajority threshold + misc fixes
[novacoin.git] / src / main.h
index 56ce0e4..e4c596f 100644 (file)
@@ -121,13 +121,11 @@ unsigned int ComputeMinWork(unsigned int nBase, int64 nTime);
 int GetNumBlocksOfPeers();
 bool IsInitialBlockDownload();
 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 BitcoinMiner(CWallet *pwallet, bool fProofOfStake);
-
-
-
-
+void ResendWalletTransactions();
 
 
 
@@ -860,7 +858,6 @@ public:
         return !(a == b);
     }
     int GetDepthInMainChain() const;
 };
 
 
@@ -931,7 +928,7 @@ public:
 
     void SetNull()
     {
-        nVersion = 2;
+        nVersion = 3;
         hashPrevBlock = 0;
         hashMerkleRoot = 0;
         nTime = 0;
@@ -969,8 +966,18 @@ public:
     void UpdateTime(const CBlockIndex* pindexPrev);
 
     // ppcoin: entropy bit for stake modifier if chosen by modifier
-    unsigned int GetStakeEntropyBit() const
+    unsigned int GetStakeEntropyBit(unsigned int nHeight) const
     {
+        // Protocol switch to support p2pool at novacoin block #9689
+        if (nHeight >= 9689)
+        {
+            // Take last bit of block hash as entropy bit
+            unsigned int nEntropyBit = ((GetHash().Get64()) & 1llu);
+            if (fDebug && GetBoolArg("-printstakemodifier"))
+                printf("GetStakeEntropyBit: nHeight=%u hashBlock=%s nEntropyBit=%u\n", nHeight, GetHash().ToString().c_str(), nEntropyBit);
+            return nEntropyBit;
+        }
+        // Before novacoin block #9689 - old protocol
         uint160 hashSig = Hash160(vchBlockSig);
         if (fDebug && GetBoolArg("-printstakemodifier"))
             printf("GetStakeEntropyBit: hashSig=%s", hashSig.ToString().c_str());
@@ -1358,6 +1365,18 @@ public:
         return (nFlags & BLOCK_PROOF_OF_STAKE);
     }
 
+    static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired, unsigned int nToCheck)
+    {
+        unsigned int nFound = 0;
+        for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++)
+        {
+            if (pstart->nVersion >= minVersion)
+                ++nFound;
+            pstart = pstart->pprev;
+        }
+        return (nFound >= nRequired);
+    }
+
     void SetProofOfStake()
     {
         nFlags |= BLOCK_PROOF_OF_STAKE;
@@ -1415,11 +1434,13 @@ class CDiskBlockIndex : public CBlockIndex
 public:
     uint256 hashPrev;
     uint256 hashNext;
+    int nProtocolVersion;
 
     CDiskBlockIndex()
     {
         hashPrev = 0;
         hashNext = 0;
+        nProtocolVersion = PROTOCOL_VERSION;
     }
 
     explicit CDiskBlockIndex(CBlockIndex* pindex) : CBlockIndex(*pindex)
@@ -1441,6 +1462,7 @@ public:
         READWRITE(nMoneySupply);
         READWRITE(nFlags);
         READWRITE(nStakeModifier);
+        READWRITE(nProtocolVersion);
         if (IsProofOfStake())
         {
             READWRITE(prevoutStake);