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 (ad71a3b189) looks good so far with that addition.
This commit is contained in:
Hou5e 2019-01-12 12:20:46 -08:00
parent b307e32c17
commit 70ec8940d3
2 changed files with 21 additions and 6 deletions

View File

@ -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<CInv> 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;
}

View File

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