From 70ec8940d30e3ef32728c3a044092170fe6c40b9 Mon Sep 17 00:00:00 2001 From: Hou5e <20870053+Hou5e@users.noreply.github.com> Date: Sat, 12 Jan 2019 12:20:46 -0800 Subject: [PATCH] The initial POS validation was failing for POS Min Age being checked to 30 days now that it's 4 days, after the hardfork. Details: The error "CheckStakeKernelHash() : min age violation" was being thrown in CheckProofOfStake because the nStakeMinAge variable wasn't being updated for the changes after the hardfork. The fix was to update this number, about where the Testnet would update this number: if ( nBestHeight > (int)HF_BLOCK ) nStakeMinAge = 60 * 60 * 24 * 4; // 4 day min stake age hardfork The testnet would have missed this because it was setting the value in a good location. The Peershares fix (https://github.com/Peershares/Peershares/commit/ad71a3b1890208c9ef8ea005c76ee18fbf0b6065) looks good so far with that addition. --- src/main.cpp | 18 +++++++++++++++--- src/net.h | 9 ++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index fe867ed..270537f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2013-2018 The Curecoin developers +// Copyright (c) 2013-2019 The Curecoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -2333,6 +2333,11 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock) if (!CheckProofOfStake(pblock->vtx[1], pblock->nBits, hashProofOfStake)) { printf("WARNING: ProcessBlock(): check proof-of-stake failed for block %s\n", hash.ToString().c_str()); + + // peershares: ask for missing blocks + if (pfrom) + pfrom->PushGetBlocks(pindexBest, pblock->GetHash()); + return false; // do not error here as we expect this during initial block download } if (!mapProofOfStake.count(hash)) // add to mapProofOfStake @@ -2724,6 +2729,12 @@ bool LoadBlockIndex(bool fAllowNew) txdb.Close(); } + if (!fTestNet){ + //Update nStakeMinAge before CheckProofOfStake fails for 30 days min stake age reduced to 4 days after the hardfork + if ( nBestHeight > (int)HF_BLOCK ) nStakeMinAge = 60 * 60 * 24 * 4; // 4 day min stake age hardfork + } + //printf("nBestHeight: %u, nStakeMinAge: %u \n", nBestHeight, nStakeMinAge); + return true; } @@ -3243,7 +3254,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) printf(" got inventory: %s %s\n", inv.ToString().c_str(), fAlreadyHave ? "have" : "new"); if (!fAlreadyHave) - pfrom->AskFor(inv); + pfrom->AskFor(inv, IsInitialBlockDownload()); // peershares: immediate retry during initial download else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash)) { pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash])); } else if (nInv == nLastBlock) { @@ -3297,8 +3308,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) // ppcoin: send latest proof-of-work block to allow the // download node to accept as orphan (proof-of-stake // block might be rejected by stake connection check) + // peershares: send latest block vector vInv; - vInv.push_back(CInv(MSG_BLOCK, GetLastBlockIndex(pindexBest, false)->GetBlockHash())); + vInv.push_back(CInv(MSG_BLOCK, hashBestChain)); pfrom->PushMessage("inv", vInv); pfrom->hashContinue = 0; } diff --git a/src/net.h b/src/net.h index fbad7a0..ee804a6 100644 --- a/src/net.h +++ b/src/net.h @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2013 The curecoin developer +// Copyright (c) 2013-2019 The Curecoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef curecoin_NET_H @@ -314,7 +314,7 @@ public: } } - void AskFor(const CInv& inv) + void AskFor(const CInv& inv, bool fImmediateRetry = false) { // We're using mapAskFor as a priority queue, // the key is the earliest time the request can be sent @@ -330,7 +330,10 @@ public: nLastTime = nNow; // Each retry is 2 minutes after the last - nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow); + if (fImmediateRetry) + nRequestTime = nNow; + else + nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow); mapAskFor.insert(std::make_pair(nRequestTime, inv)); }