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)); }