From: Sunny King Date: Mon, 27 Aug 2012 00:15:11 +0000 (+0100) Subject: PPCoin: Enable public testnet X-Git-Tag: v0.4.0-unstable~80 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=c92c001769447619f77841511fd022000af71988 PPCoin: Enable public testnet --- diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 0f6e441..94e5c23 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -195,7 +195,7 @@ namespace Checkpoints // Select the last proof-of-work block const CBlockIndex *pindex = GetLastBlockIndex(pindexBest, false); // Search forward for a block within max span and maturity window - while (pindex->pnext && (pindex->GetBlockTime() + CHECKPOINT_MAX_SPAN <= pindexBest->GetBlockTime() || pindex->nHeight + COINBASE_MATURITY - 20 <= pindexBest->nHeight)) + while (pindex->pnext && (pindex->GetBlockTime() + CHECKPOINT_MAX_SPAN <= pindexBest->GetBlockTime() || pindex->nHeight + nCoinbaseMaturity - 20 <= pindexBest->nHeight)) pindex = pindex->pnext; return pindex->GetBlockHash(); } @@ -348,8 +348,8 @@ namespace Checkpoints // sync-checkpoint should always be accepted block assert(mapBlockIndex.count(hashSyncCheckpoint)); const CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint]; - return (nBestHeight >= pindexSync->nHeight + COINBASE_MATURITY || - pindexSync->GetBlockTime() + STAKE_MIN_AGE < GetAdjustedTime()); + return (nBestHeight >= pindexSync->nHeight + nCoinbaseMaturity || + pindexSync->GetBlockTime() + nStakeMinAge < GetAdjustedTime()); } } diff --git a/src/main.cpp b/src/main.cpp index 0390b9c..bc0bdd9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,8 @@ set > setStakeSeen; uint256 hashGenesisBlock = hashGenesisBlockOfficial; static CBigNum bnProofOfWorkLimit(~uint256(0) >> 32); static CBigNum bnInitialHashTarget(~uint256(0) >> 40); +unsigned int nStakeMinAge = STAKE_MIN_AGE; +int nCoinbaseMaturity = COINBASE_MATURITY; CBlockIndex* pindexGenesisBlock = NULL; int nBestHeight = -1; CBigNum bnBestChainTrust = 0; @@ -709,7 +711,7 @@ int CMerkleTx::GetBlocksToMaturity() const { if (!(IsCoinBase() || IsCoinStake())) return 0; - return max(0, (COINBASE_MATURITY+20) - GetDepthInMainChain()); + return max(0, (nCoinbaseMaturity+20) - GetDepthInMainChain()); } @@ -1168,7 +1170,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, // If prev is coinbase/coinstake, check that it's matured if (txPrev.IsCoinBase() || txPrev.IsCoinStake()) - for (const CBlockIndex* pindex = pindexBlock; pindex && pindexBlock->nHeight - pindex->nHeight < COINBASE_MATURITY; pindex = pindex->pprev) + for (const CBlockIndex* pindex = pindexBlock; pindex && pindexBlock->nHeight - pindex->nHeight < nCoinbaseMaturity; pindex = pindex->pprev) if (pindex->nBlockPos == txindex.pos.nBlockPos && pindex->nFile == txindex.pos.nFile) return error("ConnectInputs() : tried to spend coinbase/coinstake at depth %d", pindexBlock->nHeight - pindex->nHeight); @@ -1721,7 +1723,7 @@ bool CTransaction::CheckProofOfStake(unsigned int nBits) const CBlock block; if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false)) return false; // unable to read block of previous transaction - if (block.GetBlockTime() + STAKE_MIN_AGE > nTime) + if (block.GetBlockTime() + nStakeMinAge > nTime) return false; // only count coins meeting min age requirement int64 nValueIn = txPrev.vout[txin.prevout.n].nValue; @@ -1764,7 +1766,7 @@ bool CTransaction::GetCoinAge(CTxDB& txdb, uint64& nCoinAge) const CBlock block; if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false)) return false; // unable to read block of previous transaction - if (block.GetBlockTime() + STAKE_MIN_AGE > nTime) + if (block.GetBlockTime() + nStakeMinAge > nTime) continue; // only count coins meeting min age requirement int64 nValueIn = txPrev.vout[txin.prevout.n].nValue; @@ -2242,12 +2244,18 @@ bool LoadBlockIndex(bool fAllowNew) { hashGenesisBlock = hashGenesisBlockTestNet; bnProofOfWorkLimit = CBigNum(~uint256(0) >> 28); - pchMessageStart[0] = 0xfa; - pchMessageStart[1] = 0xbf; - pchMessageStart[2] = 0xb5; - pchMessageStart[3] = 0xda; + pchMessageStart[0] = 0x9b; + pchMessageStart[1] = 0xa1; + pchMessageStart[2] = 0xb2; + pchMessageStart[3] = 0xb6; + nStakeMinAge = 60 * 60 * 24; // test net min age is 1 day + nCoinbaseMaturity = 60; + bnInitialHashTarget = CBigNum(~uint256(0) >> 29); } + printf("%s Network: genesis=0x%s nBitsLimit=0x%08x nBitsInitial=0x%08x nStakeMinAge=%d nCoinbaseMaturity=%d\n", + fTestNet? "Test" : "PPCoin", hashGenesisBlock.ToString().substr(0, 20).c_str(), bnProofOfWorkLimit.GetCompact(), bnInitialHashTarget.GetCompact(), nStakeMinAge, nCoinbaseMaturity); + // // Load block index // @@ -2328,7 +2336,7 @@ bool LoadBlockIndex(bool fAllowNew) 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()) + if ((!fTestNet) && !Checkpoints::ResetSyncCheckpoint()) return error("LoadBlockIndex() : failed to reset sync-checkpoint"); } txdb.Close(); @@ -2457,7 +2465,7 @@ string GetWarnings(string strFor) // ppcoin: should not enter safe mode for longer invalid chain // ppcoin: if sync-checkpoint too old enter safe mode - if (Checkpoints::IsMatureSyncCheckpoint()) + if (Checkpoints::IsMatureSyncCheckpoint() && !fTestNet) { nPriority = 2000; strStatusBar = strRPC = "WARNING: Checkpoint is too old. Wait for block chain to download, or notify developers of the issue."; @@ -2933,7 +2941,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) printf(" getblocks stopping at %d %s (%u bytes)\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str(), nBytes); // ppcoin: tell downloading node about the latest block if it's // without risk being rejected due to stake connection check - if (hashStop != hashBestChain && pindex->GetBlockTime() + STAKE_MIN_AGE > pindexBest->GetBlockTime()) + if (hashStop != hashBestChain && pindex->GetBlockTime() + nStakeMinAge > pindexBest->GetBlockTime()) pfrom->PushInventory(CInv(MSG_BLOCK, hashBestChain)); break; } diff --git a/src/main.h b/src/main.h index 92ed8dd..0bd9ab4 100644 --- a/src/main.h +++ b/src/main.h @@ -61,6 +61,8 @@ extern CCriticalSection cs_main; extern std::map mapBlockIndex; extern std::set > setStakeSeen; extern uint256 hashGenesisBlock; +extern unsigned int nStakeMinAge; +extern int nCoinbaseMaturity; extern CBlockIndex* pindexGenesisBlock; extern int nBestHeight; extern CBigNum bnBestChainTrust; diff --git a/src/wallet.cpp b/src/wallet.cpp index 4dbc6af..b24d251 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1242,7 +1242,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, CTr CBlock block; if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false)) continue; - if (block.GetBlockTime() + STAKE_MIN_AGE > txNew.nTime) + if (block.GetBlockTime() + nStakeMinAge > txNew.nTime) continue; // only count coins meeting min age requirement int64 nValueIn = pcoin.first->vout[pcoin.second].nValue;