Attempt to fix testnet
This commit is contained in:
104
src/miner.cpp
104
src/miner.cpp
@@ -106,12 +106,11 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
|
||||
txNew.vin[0].prevout.SetNull();
|
||||
txNew.vout.resize(1);
|
||||
int nHeight = chainActive.Tip()->nHeight + 1;
|
||||
if (!fProofOfStake)
|
||||
{
|
||||
|
||||
if (!fProofOfStake) {
|
||||
txNew.vout[0].scriptPubKey = scriptPubKeyIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
txNew.vin[0].scriptSig = (CScript() << nHeight) + COINBASE_FLAGS;
|
||||
txNew.vout[0].SetEmpty();
|
||||
}
|
||||
@@ -352,67 +351,6 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
|
||||
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
// novacoin: attempt to generate suitable proof-of-stake
|
||||
bool SignBlock(CBlock& block, CWallet& wallet, int64_t& nFees)
|
||||
{
|
||||
// if we are trying to sign
|
||||
// something except proof-of-stake block template
|
||||
if (!block.vtx[0].vout[0].IsEmpty()){
|
||||
LogPrintf("something except proof-of-stake block\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// if we are trying to sign
|
||||
// a complete proof-of-stake block
|
||||
if (block.IsProofOfStake()){
|
||||
LogPrintf("trying to sign a complete proof-of-stake block\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
static int64_t nLastCoinStakeSearchTime = GetAdjustedTime(); // startup timestamp
|
||||
|
||||
CKey key;
|
||||
CMutableTransaction txCoinBase(block.vtx[0]);
|
||||
CMutableTransaction txCoinStake;
|
||||
txCoinStake.nTime = GetAdjustedTime();
|
||||
txCoinStake.nTime &= ~Params().GetConsensus().nStakeTimestampMask;
|
||||
|
||||
int64_t nSearchTime = txCoinStake.nTime; // search to current time
|
||||
|
||||
|
||||
if (nSearchTime > nLastCoinStakeSearchTime)
|
||||
{
|
||||
if (wallet.CreateCoinStake(wallet, block.nBits, 1, nFees, txCoinStake, key))
|
||||
{
|
||||
if (txCoinStake.nTime >= pindexBestHeader->GetPastTimeLimit()+1)
|
||||
{
|
||||
// make sure coinstake would meet timestamp protocol
|
||||
// as it would be the same as the block timestamp
|
||||
txCoinBase.nTime = block.nTime = txCoinStake.nTime;
|
||||
block.vtx[0] = txCoinBase;
|
||||
|
||||
// we have to make sure that we have no future timestamps in
|
||||
// our transactions set
|
||||
for (vector<CTransaction>::iterator it = block.vtx.begin(); it != block.vtx.end();)
|
||||
if (it->nTime > block.nTime) { it = block.vtx.erase(it); } else { ++it; }
|
||||
|
||||
block.vtx.insert(block.vtx.begin() + 1, txCoinStake);
|
||||
|
||||
block.hashMerkleRoot = BlockMerkleRoot(block);
|
||||
|
||||
// append a signature to our block
|
||||
return key.Sign(block.GetHash(), block.vchBlockSig);
|
||||
}
|
||||
}
|
||||
nLastCoinStakeSearchInterval = nSearchTime - nLastCoinStakeSearchTime;
|
||||
nLastCoinStakeSearchTime = nSearchTime;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void ThreadStakeMiner(CWallet *pwallet, const CChainParams& chainparams)
|
||||
{
|
||||
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
||||
@@ -481,39 +419,3 @@ void ThreadStakeMiner(CWallet *pwallet, const CChainParams& chainparams)
|
||||
MilliSleep(nMinerSleep);
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckStake(CBlock* pblock, CWallet& wallet, const CChainParams& chainparams)
|
||||
{
|
||||
uint256 hashBlock = pblock->GetHash();
|
||||
|
||||
if(!pblock->IsProofOfStake())
|
||||
return error("CheckStake() : %s is not a proof-of-stake block", hashBlock.GetHex());
|
||||
|
||||
CValidationState state;
|
||||
// verify hash target and signature of coinstake tx
|
||||
if (!CheckProofOfStake(mapBlockIndex[pblock->hashPrevBlock], pblock->vtx[1], pblock->nBits, state))
|
||||
return error("CheckStake() : proof-of-stake checking failed");
|
||||
|
||||
//// debug print
|
||||
LogPrintf("%s\n", pblock->ToString());
|
||||
LogPrintf("out %s\n", FormatMoney(pblock->vtx[1].GetValueOut()));
|
||||
|
||||
// Found a solution
|
||||
{
|
||||
LOCK(cs_main);
|
||||
if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash())
|
||||
return error("CheckStake() : generated block is stale");
|
||||
|
||||
// Track how many getdata requests this block gets
|
||||
{
|
||||
LOCK(wallet.cs_wallet);
|
||||
wallet.mapRequestCount[hashBlock] = 0;
|
||||
}
|
||||
|
||||
// Process this block the same as if we had received it from another node
|
||||
if (!ProcessBlockFound(pblock, chainparams))
|
||||
return error("CheckStake() : ProcessBlock, block not accepted");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user