changeset 29733:f0e1ee44d172

Begins to sync, fails block 3753 ConnectBlock: CheckQueue failed
author Troy Benjegerdes <troy@7el.us>
date Sat, 13 Feb 2021 18:53:44 -0600
parents 15256d32d3b1
children 73dbba662001
files src/Makefile src/bitcoin/trust.cpp src/grantcoin/grantcoin.h src/grantcoin/params.cpp src/litecoin/trust.cpp src/net_processing.cpp src/pow.cpp src/pow.h src/txdb.h src/validation.cpp src/version.h
diffstat 11 files changed, 208 insertions(+), 204 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile	Fri Feb 12 22:48:17 2021 -0600
+++ b/src/Makefile	Sat Feb 13 18:53:44 2021 -0600
@@ -217,6 +217,7 @@
     $(OBJDIR)/base58.o \
     $(OBJDIR)/bech32.o \
     $(OBJDIR)/$(COIN_BRAND)/params.o \
+    $(OBJDIR)/$(COIN_BRAND)/trust.o \
     $(OBJDIR)/coins.o \
     $(OBJDIR)/compressor.o \
     $(OBJDIR)/consensus/merkle.o \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/bitcoin/trust.cpp	Sat Feb 13 18:53:44 2021 -0600
@@ -0,0 +1,126 @@
+// Copyright (c) 2009-2010 Satoshi Nakamoto
+// Copyright (c) 2009-2015 The Bitcoin Core developers
+// Copyright (c) 2009-2012 The *coin developers
+// where * = (Bit, Lite, PP, Peerunity, Blu, Cat, Solar, URO, ...)
+// Previously distributed under the MIT/X11 software license, see the
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2014-2015 Troy Benjegerdes, under AGPLv3
+// Distributed under the Affero GNU General public license version 3
+// file COPYING or http://www.gnu.org/licenses/agpl-3.0.html
+
+#include <pow.h>
+
+#include <arith_uint256.h>
+#include <chain.h>
+#include <primitives/block.h>
+#include <uintBIG.h>
+
+CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
+{
+    int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
+    // Force block reward to zero when right shift is undefined.
+    if (halvings >= 64)
+        return 0;
+
+    CAmount nSubsidy = 50 * COIN;
+    // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
+    nSubsidy >>= halvings;
+    return nSubsidy;
+}
+
+unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
+{
+    assert(pindexLast != nullptr);
+    unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
+
+    // Genesis block
+    if (pindexLast == NULL)
+        return nProofOfWorkLimit;
+
+    // Only change once per difficulty adjustment interval
+    if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
+    {
+        if (params.fPowAllowMinDifficultyBlocks)
+        {
+            // Special difficulty rule for testnet:
+            // If the new block's timestamp is more than 2* 10 minutes
+            // then allow mining of a min-difficulty block.
+            if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2)
+                return nProofOfWorkLimit;
+            else
+            {
+                // Return the last non-special-min-difficulty-rules-block
+                const CBlockIndex* pindex = pindexLast;
+                while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval() != 0 && pindex->nBits == nProofOfWorkLimit)
+                    pindex = pindex->pprev;
+                return pindex->nBits;
+            }
+        }
+        return pindexLast->nBits;
+    }
+
+/* Catoshi TODO: move to per-coin directory */
+#if defined(BRAND_bitcoin)
+    // Go back by what we want to be 14 days worth of blocks
+    int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);
+    assert(nHeightFirst >= 0);
+    const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst);
+#elif defined(BRAND_litecoin) 
+    // Litecoin: This fixes an issue where a 51% attack can change difficulty at will.
+    // Go back the full period unless it's the first retarget after genesis. Code courtesy of Art Forz
+    int blockstogoback = params.DifficultyAdjustmentInterval()-1;
+    if ((pindexLast->nHeight+1) != params.DifficultyAdjustmentInterval())
+        blockstogoback = params.DifficultyAdjustmentInterval();
+
+    // Go back by what we want to be 14 days worth of blocks
+    const CBlockIndex* pindexFirst = pindexLast;
+    for (int i = 0; pindexFirst && i < blockstogoback; i++)
+        pindexFirst = pindexFirst->pprev;
+#else
+#error "Catoshi: move GetNextWorkRequired out to coin specific dir"
+#endif
+    assert(pindexFirst);
+
+    return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params);
+}
+
+unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params)
+{
+    if (params.fPowNoRetargeting)
+        return pindexLast->nBits;
+
+    // Limit adjustment step
+    int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime;
+    if (nActualTimespan < params.nPowTargetTimespan/4)
+        nActualTimespan = params.nPowTargetTimespan/4;
+    if (nActualTimespan > params.nPowTargetTimespan*4)
+        nActualTimespan = params.nPowTargetTimespan*4;
+
+    // Retarget
+    const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
+    arith_uint256 bnNew;
+#if defined (BRAND_bitcoin)
+    bnNew.SetCompact(pindexLast->nBits);
+    bnNew *= nActualTimespan;
+    bnNew /= params.nPowTargetTimespan;
+
+#elif defined(BRAND_litecoin) || defined(BRAND_grantcoin)
+    arith_uint256 bnOld;
+    bnNew.SetCompact(pindexLast->nBits);
+    bnOld = bnNew;
+    // Litecoin: intermediate uint256 can overflow by 1 bit
+    bool fShift = bnNew.bits() > 235;
+    if (fShift)
+        bnNew >>= 1;
+    bnNew *= nActualTimespan;
+    bnNew /= params.nPowTargetTimespan;
+    if (fShift)
+        bnNew <<= 1;
+#else
+#error: "Catoshi: move CalculateNextWorkRequired out to coin specific dir"
+#endif
+    if (bnNew > bnPowLimit)
+        bnNew = bnPowLimit;
+
+    return bnNew.GetCompact();
+}
--- a/src/grantcoin/grantcoin.h	Fri Feb 12 22:48:17 2021 -0600
+++ b/src/grantcoin/grantcoin.h	Sat Feb 13 18:53:44 2021 -0600
@@ -27,6 +27,11 @@
 /** Maximum length of incoming protocol messages (no message over 4 MB is currently accep    table). */
 static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
 
+//! Follow bitcoin-core unles there is a really good reason
+// see version.h // static const int PROTOCOL_VERSION = 70012
+//! minimum version we will talk to
+static const int MIN_PEER_PROTO_VERSION = 60004;
+
 static const int64_t COIN = 1000000;
 static const int64_t CENT = 10000;
 static const int64_t PERKB_TX_FEE = CENT;
--- a/src/grantcoin/params.cpp	Fri Feb 12 22:48:17 2021 -0600
+++ b/src/grantcoin/params.cpp	Sat Feb 13 18:53:44 2021 -0600
@@ -37,7 +37,7 @@
         //consensus.nMajorityEnforceBlockUpgrade = 750;
         //consensus.nMajorityRejectBlockOutdated = 950;
         //consensus.nMajorityWindow = 1000;
-        consensus.nPowTargetTimespan = 3.5 * 24 * 60 * 60; // 3.5 days FIXME not used for GRT?
+        consensus.nPowTargetTimespan = 24 * 60 * 60; // 3.5 days FIXME not used for GRT?
         consensus.nPowTargetSpacing = 1.5 * 60; // 1.5 minutes
         consensus.nMinerConfirmationWindow = 3360;
         consensus.nRuleChangeActivationThreshold = 3024; /* 90% of miners */
@@ -66,7 +66,6 @@
         txNew.vout[0].nValue = 0; /* SetEmpty() used to do this */
         txNew.vout[0].scriptPubKey.clear(); /* maybe put it back?? */
 
-        CBlock genesis;
         genesis.nVersion = 1;
         genesis.nTime    = 1427086539;
         genesis.nBits    = 0x1d0fffff;
@@ -74,14 +73,16 @@
         genesis.vtx.push_back(MakeTransactionRef(std::move(txNew)));
         genesis.hashPrevBlock.SetNull();  // = 0;  // old way is simpler to read
         genesis.hashMerkleRoot = BlockMerkleRoot(genesis); //genesis.BuildMerkleTree();
+        consensus.hashGenesisBlock = genesis.GetHash();
 
         //std::cout << genesis.ToString();
         assert(genesis.hashMerkleRoot == uint256S("0xca7e1b14fe8d66d18650db8fa0c1b2787fa48b4a342fff3b00aa1cc9b0ae85f3"));
-        assert(genesis.GetHash() == uint256S("0000000f0483c7cc4433d89e321373d82d86ef5ba8157d8f7b9ef3449283421a"));
+        assert(consensus.hashGenesisBlock == uint256S("0000000f0483c7cc4433d89e321373d82d86ef5ba8157d8f7b9ef3449283421a"));
 
-        vSeeds.emplace_back("grt.7el.us", true);
-//        vSeeds.emplace_back("seed1.grantcoin.net", true);
-//        vSeeds.emplace_back("seed2.grantcoin.net", true);
+        //vSeeds.emplace_back("grt.7el.us", true);
+        vSeeds.emplace_back("seed1-mannacurrency.net", true);
+        vSeeds.emplace_back("seed2-mannacurrency.net", true);
+        vSeeds.emplace_back("seed3-mannacurrency.net", true);
 
         base58Prefixes[PUBKEY_ADDRESS] = {  38 }; // grantcoin: addresses begin with 'G'
         base58Prefixes[SCRIPT_ADDRESS] = {  97 }; // grantcoin: addresses begin with 'g'
@@ -431,90 +432,3 @@
 static const int64_t nTargetTimespan = 24 * 60 * 60;  // 24 hours
 static const int64_t nTargetSpacingWorkMax = 12 * STAKE_TARGET_SPACING; // 18 minutes
 
-// ppcoin: find last block index up to pindex
-// TODO: move up to generic code
-const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake)
-{
-#if !defined(PPCOINSTAKE)
-        /* better to assert than look for things that don't exist? */
-        assert(fProofOfStake == false);
-        // TODO: this could probably be optimized better to just return pindex-pprev,
-        // but genesis block case has to be dealt with.
-#endif
-        while (pindex && pindex->pprev && (pindex->IsProofOfStake() != fProofOfStake))
-                pindex = pindex->pprev;
-        return pindex;
-}
-
-
-unsigned int static GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake)
-{
-    arith_uint256 powLimit = UintToArith256(Params().GetConsensus().powLimit);
-    if (pindexLast == NULL)
-        return powLimit.GetCompact(); // genesis block
-
-    const CBlockIndex* pindexPrev = GetLastBlockIndex(pindexLast, fProofOfStake);
-    if (pindexPrev->pprev == NULL)
-        return powLimit.GetCompact(); // first block
-    const CBlockIndex* pindexPrevPrev = GetLastBlockIndex(pindexPrev->pprev, fProofOfStake);
-    if (pindexPrevPrev->pprev == NULL)
-        return powLimit.GetCompact(); // second block
-
-    int64_t nActualSpacing = pindexPrev->GetBlockTime() - pindexPrevPrev->GetBlockTime();
-
-    // peercoin: target change every block
-    // peercoin: retarget with exponential moving toward target spacing
-    arith_uint256 newLimit;
-    newLimit.SetCompact(pindexPrev->nBits);
-    int64_t nTargetSpacing = fProofOfStake? STAKE_TARGET_SPACING : min(nTargetSpacingWorkMax, (int64_t) STAKE_TARGET_SPACING * (1 + pindexLast->nHeight - pindexPrev->nHeight));
-    int64_t nInterval = nTargetTimespan / nTargetSpacing;
-    newLimit *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing);
-    newLimit /= ((nInterval + 1) * nTargetSpacing);
-
-    if (newLimit > powLimit)
-	return powLimit.GetCompact();
-
-    return newLimit.GetCompact();
-}
-
-#if defined(PPCOINSTAKE)
-unsigned int GetNextTrustRequired(const CBlockIndex* pindexLast, const CBlock *pblock)
-{
-	return GetNextTargetRequired(pindexLast, pblock->IsProofOfStake());	
-}
-#else
-unsigned int GetNextTrustRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock)
-{
-	return GetNextTargetRequired(pindexLast, false);	
-}
-#endif
-
-static int minimum_time_fork = 250000;	// minimum time fork
-static int minimum_time_fork_2 = 250000;	// minimum time fork
-
-//Checks for 'hardcoded' block timestamps
-bool AcceptBlockTimestamp(CValidationState &state, CBlockIndex* pindexPrev, const CBlockHeader *pblock)
-{
-	int64_t time_allow = -30;
-	int64_t time_warn = MINIMUM_BLOCK_SPACING;
-	int64_t delta = pblock->GetBlockTime() - pindexPrev->GetBlockTime();
-	int nHeight = pindexPrev->nHeight + 1;
-
-	if (nHeight > minimum_time_fork_2){
-		time_allow = 30;
-	}
-	
-	if (delta < time_warn){
-		printf("WARNING blocktime nHeight %d time_allow %" PRId64" time_warn %" PRId64" time delta %" PRId64"\n", nHeight, time_allow, time_warn, delta);
-	}
-
-	if (nHeight >= minimum_time_fork_2) {
-		if (delta <= time_allow) // see above, from first hard limit
-			return state.Invalid(error("AcceptBlock(height=%d) : block time delta %" PRId64" too short", nHeight, delta));
-	}
-	if (nHeight >= minimum_time_fork) { /* don't forward these */
-		if (delta <= MINIMUM_BLOCK_SPACING)
-			return state.DoS(10, (error("AcceptBlock(height=%d) : block time delta %" PRId64" too short", nHeight, delta)));
-	}
-	return true;	
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/litecoin/trust.cpp	Sat Feb 13 18:53:44 2021 -0600
@@ -0,0 +1,1 @@
+../bitcoin/trust.cpp
\ No newline at end of file
--- a/src/net_processing.cpp	Fri Feb 12 22:48:17 2021 -0600
+++ b/src/net_processing.cpp	Sat Feb 13 18:53:44 2021 -0600
@@ -1676,11 +1676,13 @@
         pfrom->nTimeOffset = nTimeOffset;
         AddTimeData(pfrom->addr, nTimeOffset);
 
+#if !defined(FEATURE_ALERT)
         // If the peer is old enough to have the old alert system, send it the final alert.
         if (pfrom->nVersion <= 70012) {
             CDataStream finalAlert(ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50"), SER_NETWORK, PROTOCOL_VERSION);
             connman->PushMessage(pfrom, CNetMsgMaker(nSendVersion).Make("alert", finalAlert));
         }
+#endif
 
         // Feeler connections exist only to verify if address is online.
         if (pfrom->fFeeler) {
@@ -2580,9 +2582,35 @@
             return error("headers message size = %u", nCount);
         }
         headers.resize(nCount);
+#if defined(PPCOINSTAKE)
+	{
+        LOCK(cs_main);
+#endif
         for (unsigned int n = 0; n < nCount; n++) {
             vRecv >> headers[n];
             ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
+#if defined(PPCOINSTAKE) || defined(BRAND_grantcoin)  // TODO refactor this disaster
+            ReadCompactSize(vRecv); // needed for vchBlockSig.
+#endif
+#if defined(PPCOINSTAKE)
+            // peercoin: quick check to see if we should ban peers for PoS spam
+            // note: at this point we don't know if PoW headers are valid - we just assume they are
+            // so we need to update pfrom->nPoSTemperature once we actualy check them
+            bool fPoS = headers[n].nFlags & CBlockIndex::BLOCK_PROOF_OF_STAKE;
+            nTmpPoSTemperature += fPoS ? 1 : -POW_HEADER_COOLING;
+            // peer cannot cool himself by PoW headers from other branches
+            if (n == 0 && !fPoS && headers[n].hashPrevBlock != pfrom->lastAcceptedHeader)
+                nTmpPoSTemperature += POW_HEADER_COOLING;
+            nTmpPoSTemperature = std::max(nTmpPoSTemperature, 0);
+            if (nTmpPoSTemperature >= MAX_CONSECUTIVE_POS_HEADERS) {
+                nPoSTemperature = (MAX_CONSECUTIVE_POS_HEADERS*3)/4;
+                if (Params().NetworkIDString() != "test") {
+                    g_connman->Ban(pfrom->addr, BanReasonNodeMisbehaving, gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME) * 7);
+                    return error("too many consecutive pos headers");
+                }
+            }
+        }
+#endif
         }
 
         // Headers received via a HEADERS message should be valid, and reflect
--- a/src/pow.cpp	Fri Feb 12 22:48:17 2021 -0600
+++ b/src/pow.cpp	Sat Feb 13 18:53:44 2021 -0600
@@ -15,103 +15,6 @@
 #include <primitives/block.h>
 #include <uintBIG.h>
 
-unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
-{
-    assert(pindexLast != nullptr);
-    unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
-
-    // Genesis block
-    if (pindexLast == NULL)
-        return nProofOfWorkLimit;
-
-    // Only change once per difficulty adjustment interval
-    if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
-    {
-        if (params.fPowAllowMinDifficultyBlocks)
-        {
-            // Special difficulty rule for testnet:
-            // If the new block's timestamp is more than 2* 10 minutes
-            // then allow mining of a min-difficulty block.
-            if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2)
-                return nProofOfWorkLimit;
-            else
-            {
-                // Return the last non-special-min-difficulty-rules-block
-                const CBlockIndex* pindex = pindexLast;
-                while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval() != 0 && pindex->nBits == nProofOfWorkLimit)
-                    pindex = pindex->pprev;
-                return pindex->nBits;
-            }
-        }
-        return pindexLast->nBits;
-    }
-
-/* Catoshi TODO: move to per-coin directory */
-#if defined(BRAND_bitcoin)
-    // Go back by what we want to be 14 days worth of blocks
-    int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);
-    assert(nHeightFirst >= 0);
-    const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst);
-#elif defined(BRAND_litecoin) || defined(BRAND_grantcoin)
-    // Litecoin: This fixes an issue where a 51% attack can change difficulty at will.
-    // Go back the full period unless it's the first retarget after genesis. Code courtesy of Art Forz
-    int blockstogoback = params.DifficultyAdjustmentInterval()-1;
-    if ((pindexLast->nHeight+1) != params.DifficultyAdjustmentInterval())
-        blockstogoback = params.DifficultyAdjustmentInterval();
-
-    // Go back by what we want to be 14 days worth of blocks
-    const CBlockIndex* pindexFirst = pindexLast;
-    for (int i = 0; pindexFirst && i < blockstogoback; i++)
-        pindexFirst = pindexFirst->pprev;
-#else
-#error "Catoshi: move GetNextWorkRequired out to coin specific dir"
-#endif
-    assert(pindexFirst);
-
-    return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params);
-}
-
-unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params)
-{
-    if (params.fPowNoRetargeting)
-        return pindexLast->nBits;
-
-    // Limit adjustment step
-    int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime;
-    if (nActualTimespan < params.nPowTargetTimespan/4)
-        nActualTimespan = params.nPowTargetTimespan/4;
-    if (nActualTimespan > params.nPowTargetTimespan*4)
-        nActualTimespan = params.nPowTargetTimespan*4;
-
-    // Retarget
-    const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
-    arith_uint256 bnNew;
-#if defined (BRAND_bitcoin)
-    bnNew.SetCompact(pindexLast->nBits);
-    bnNew *= nActualTimespan;
-    bnNew /= params.nPowTargetTimespan;
-
-#elif defined(BRAND_litecoin) || defined(BRAND_grantcoin)
-    arith_uint256 bnOld;
-    bnNew.SetCompact(pindexLast->nBits);
-    bnOld = bnNew;
-    // Litecoin: intermediate uint256 can overflow by 1 bit
-    bool fShift = bnNew.bits() > 235;
-    if (fShift)
-        bnNew >>= 1;
-    bnNew *= nActualTimespan;
-    bnNew /= params.nPowTargetTimespan;
-    if (fShift)
-        bnNew <<= 1;
-#else
-#error: "Catoshi: move CalculateNextWorkRequired out to coin specific dir"
-#endif
-    if (bnNew > bnPowLimit)
-        bnNew = bnPowLimit;
-
-    return bnNew.GetCompact();
-}
-
 bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
 {
     bool fNegative;
--- a/src/pow.h	Fri Feb 12 22:48:17 2021 -0600
+++ b/src/pow.h	Sat Feb 13 18:53:44 2021 -0600
@@ -11,9 +11,13 @@
 #include <stdint.h>
 
 class CBlockHeader;
+class CValidationState;
 class CBlockIndex;
 class uint256;
 
+/* defined in $COIN/trust.cpp */
+bool AcceptBlockTimestamp(const CBlockHeader* pblock, CValidationState &state, const CBlockIndex* pindexPrev);
+
 unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params&);
 unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params&);
 
--- a/src/txdb.h	Fri Feb 12 22:48:17 2021 -0600
+++ b/src/txdb.h	Sat Feb 13 18:53:44 2021 -0600
@@ -4,7 +4,7 @@
 // where * = (Bit, Lite, PP, Peerunity, Blu, Cat, Solar, URO, ...)
 // Previously distributed under the MIT/X11 software license, see the
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
-// Copyright (c) 2014-2018 Troy Benjegerdes, under AGPLv3
+// Copyright (c) 2014-2021 Troy Benjegerdes, under AGPLv3
 // Distributed under the Affero GNU General public license version 3
 // file COPYING or http://www.gnu.org/licenses/agpl-3.0.html
 
--- a/src/validation.cpp	Fri Feb 12 22:48:17 2021 -0600
+++ b/src/validation.cpp	Sat Feb 13 18:53:44 2021 -0600
@@ -1119,6 +1119,8 @@
 {
     block.SetNull();
 
+    LogPrintf("ReadBlockFromDisk ( %s )\n", pos.ToString());
+
     // Open history file to read
     CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
     if (filein.IsNull())
@@ -1149,18 +1151,7 @@
     return true;
 }
 
-CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
-{
-    int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
-    // Force block reward to zero when right shift is undefined.
-    if (halvings >= 64)
-        return 0;
-
-    CAmount nSubsidy = 50 * COIN;
-    // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
-    nSubsidy >>= halvings;
-    return nSubsidy;
-}
+// GetBlockSubsidy to $COIN/trust.cpp
 
 bool IsInitialBlockDownload()
 {
@@ -1840,6 +1831,12 @@
            (*pindex->phashBlock == block.GetHash()));
     int64_t nTimeStart = GetTimeMicros();
 
+// TODO: audit peercoin code again and refactor to a separate class
+#if defined(PPCOINSTAKE)
+    if (pindex->nStakeModifier == 0 && pindex->nStakeModifierChecksum == 0 && !PeercoinContextualBlockChecks(block, state, pindex, fJustCheck))
+        return error("%s: failed PoS check %s", __func__, FormatStateMessage(state));
+#endif
+
     // Check it again in case a previous version let a bad block in
     // NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
     // ContextualCheckBlockHeader() here. This means that if we add a new
@@ -2121,6 +2118,17 @@
     if (fJustCheck)
         return true;
 
+#if defined(PPCOINSTAKE)
+    // peercoin: track money supply and mint amount info
+    pindex->nMint = nValueOut - nValueIn + nFees;
+    pindex->nMoneySupply = (pindex->pprev? pindex->pprev->nMoneySupply : 0) + nValueOut - nValueIn;
+
+    // peercoin: fees are not collected by miners as in bitcoin
+    // peercoin: fees are destroyed to compensate the entire network
+    if (gArgs.GetBoolArg("-printcreation", false))
+        LogPrintf("%s: destroy=%s nFees=%lld\n", __func__, FormatMoney(nFees), nFees);
+#endif
+
     if (!WriteUndoDataForBlock(blockundo, state, pindex, chainparams))
         return false;
 
@@ -3296,6 +3304,14 @@
     if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME)
         return state.Invalid(false, REJECT_INVALID, "time-too-new", "block timestamp too far in the future");
 
+#if defined(BRAND_grantcoin)
+#warning "implement BIP34/65/66 upgrades"
+
+    // Some coins have more demanding time tolerances
+    if (!AcceptBlockTimestamp(&block, state, pindexPrev))
+        return false;
+
+#else
     // Reject outdated version blocks when 95% (75% on testnet) of the network has upgraded:
     // check for version 2, 3 and 4 upgrades
     if((block.nVersion < 2 && nHeight >= consensusParams.BIP34Height) ||
@@ -3307,7 +3323,7 @@
     if (block.nVersion < VERSIONBITS_TOP_BITS && IsWitnessEnabled(pindexPrev, consensusParams))
         return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", block.nVersion),
                                  strprintf("rejected nVersion=0x%08x block", block.nVersion));
-
+#endif
     return true;
 }
 
@@ -3338,6 +3354,9 @@
         }
     }
 
+#if defined(BRAND_grantcoin)
+#warning "TODO: fix this and upgraded to v2"
+#else
     // Enforce rule that the coinbase starts with serialized block height
     if (nHeight >= consensusParams.BIP34Height)
     {
@@ -3347,6 +3366,7 @@
             return state.DoS(100, false, REJECT_INVALID, "bad-cb-height", false, "block height mismatch in coinbase");
         }
     }
+#endif
 
     // Validation for witness commitments.
     // * We compute the witness hash (which is the hash including witnesses) of all the block's transactions, except the
--- a/src/version.h	Fri Feb 12 22:48:17 2021 -0600
+++ b/src/version.h	Sat Feb 13 18:53:44 2021 -0600
@@ -42,8 +42,10 @@
 //! In this version, 'getheaders' was introduced.
 static const int GETHEADERS_VERSION = 70002;
 
+#if !defined(BRAND_grantcoin) /* talk to really old GRT versions */
 //! disconnect from peers older than this proto version
 static const int MIN_PEER_PROTO_VERSION = GETHEADERS_VERSION;
+#endif
 
 //! nTime field added to CAddress, starting with this version;
 //! if possible, avoid requesting addresses nodes older than this