X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fmain.cpp;h=263a9e94902ef372855e806652032a0c60cef708;hb=b2516d2435f6916974ecd19241514b421a823a01;hp=4409dd2b02234e50d8467e824c5d6176094123f1;hpb=90f586177cfe64fcfaee902b72fd21ef06d5143f;p=novacoin.git diff --git a/src/main.cpp b/src/main.cpp index 4409dd2..263a9e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1847,6 +1847,24 @@ bool LoadBlockIndex(bool fAllowNew) return error("LoadBlockIndex() : failed to init sync checkpoint"); } + // ppcoin: if checkpoint master key changed must reset sync-checkpoint + { + CTxDB txdb; + string strPubKey = ""; + if (!txdb.ReadCheckpointPubKey(strPubKey) || strPubKey != CSyncCheckpoint::strMasterPubKey) + { + // write checkpoint master key to db + txdb.TxnBegin(); + if (!txdb.WriteCheckpointPubKey(CSyncCheckpoint::strMasterPubKey)) + return error("LoadBlockIndex() : failed to write new checkpoint master key to db"); + if (!txdb.TxnCommit()) + return error("LoadBlockIndex() : failed to commit new checkpoint master key to db"); + if (!Checkpoints::ResetSyncCheckpoint()) + return error("LoadBlockIndex() : failed to reset sync-checkpoint"); + } + txdb.Close(); + } + return true; } @@ -3034,7 +3052,7 @@ public: }; -CBlock* CreateNewBlock(CWallet* pwallet) +CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfWorkOnly) { CReserveKey reservekey(pwallet); @@ -3056,24 +3074,28 @@ CBlock* CreateNewBlock(CWallet* pwallet) // ppcoin: if coinstake available add coinstake tx static unsigned int nLastCoinStakeCheckTime = GetAdjustedTime() - nMaxClockDrift + 60; // only initialized at startup CBlockIndex* pindexPrev = pindexBest; - while (nLastCoinStakeCheckTime < GetAdjustedTime()) + + if (!fProofOfWorkOnly) { - pindexPrev = pindexBest; // get best block again to avoid getting stale - pblock->nBits = GetNextTargetRequired(pindexPrev, true); - static CCriticalSection cs; - CTransaction txCoinStake; - CRITICAL_BLOCK(cs) + while (nLastCoinStakeCheckTime < GetAdjustedTime()) { - // mining may have been suspended for a while so - // need to take max to satisfy the timestamp protocol - nLastCoinStakeCheckTime = max(++nLastCoinStakeCheckTime, (unsigned int) (GetAdjustedTime() - nMaxClockDrift + 60)); - txCoinStake.nTime = nLastCoinStakeCheckTime; - } - if (pwallet->CreateCoinStake(pblock->nBits, txCoinStake)) - { - pblock->vtx.push_back(txCoinStake); - pblock->vtx[0].vout[0].SetEmpty(); - break; + pindexPrev = pindexBest; // get best block again to avoid getting stale + pblock->nBits = GetNextTargetRequired(pindexPrev, true); + static CCriticalSection cs; + CTransaction txCoinStake; + CRITICAL_BLOCK(cs) + { + // mining may have been suspended for a while so + // need to take max to satisfy the timestamp protocol + nLastCoinStakeCheckTime = max(++nLastCoinStakeCheckTime, (unsigned int) (GetAdjustedTime() - nMaxClockDrift + 60)); + txCoinStake.nTime = nLastCoinStakeCheckTime; + } + if (pwallet->CreateCoinStake(pblock->nBits, txCoinStake)) + { + pblock->vtx.push_back(txCoinStake); + pblock->vtx[0].vout[0].SetEmpty(); + break; + } } } @@ -3352,8 +3374,11 @@ void static BitcoinMiner(CWallet *pwallet) // ppcoin: if proof-of-stake block found then process block if (pblock->IsProofOfStake()) { - // should be able to sign block - assert here for now - assert(pblock->SignBlock(*pwalletMain)); + if (!pblock->SignBlock(*pwalletMain)) + { + error("BitcoinMiner: Unable to sign new proof-of-stake block"); + return; + } printf("BitcoinMiner : proof-of-stake block found %s\n", pblock->GetHash().ToString().c_str()); SetThreadPriority(THREAD_PRIORITY_NORMAL); CheckWork(pblock.get(), *pwalletMain, reservekey); @@ -3404,8 +3429,11 @@ void static BitcoinMiner(CWallet *pwallet) // Found a solution pblock->nNonce = ByteReverse(nNonceFound); assert(hash == pblock->GetHash()); - // should be able to sign block - assert here for now - assert(pblock->SignBlock(*pwalletMain)); + if (!pblock->SignBlock(*pwalletMain)) + { + error("BitcoinMiner: Unable to sign new proof-of-work block"); + return; + } SetThreadPriority(THREAD_PRIORITY_NORMAL); CheckWork(pblock.get(), *pwalletMain, reservekey);