From 10db7eddb688a980032d781b190b94955eb1314c Mon Sep 17 00:00:00 2001 From: alexhz Date: Sat, 6 Apr 2013 06:07:31 +0000 Subject: [PATCH] Add checkpoint at block 14189, v3 lock-in since supermajority and bnProofOfStakeLimit switch since block #15000 --- src/checkpoints.cpp | 1 + src/main.cpp | 92 ++++++++---- src/main.h | 18 +-- src/qt/forms/overviewpage.ui | 355 +++++++++++++++++++++--------------------- src/qt/locale/bitcoin_en.ts | 2 +- src/qt/locale/bitcoin_ru.ts | 4 +- src/version.h | 4 +- 7 files changed, 248 insertions(+), 228 deletions(-) diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index f6682ba..ac884ec 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -30,6 +30,7 @@ namespace Checkpoints ( 6000, uint256("0x000000000945e3c9d8e15df834e802521eb79f9ceb4191a27bdfadad4b777f4a")) ( 8700, uint256("0x00000000014270724837789c9a69859290f6bdee38556bc4561c21f17935a178")) ( 13560, uint256("0xa1591a0fcbf11f282d671581edb9f0aadcd06fee69761081e0a3245914c13729")) + ( 14189, uint256("0x00000000020f76474d2522b19c7bfafc43ba6ecbabae54293bcd9546159c8c1d")) ; bool CheckHardened(int nHeight, const uint256& hash) diff --git a/src/main.cpp b/src/main.cpp index a101105..1befcb8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,7 +34,8 @@ map mapBlockIndex; set > setStakeSeen; uint256 hashGenesisBlock = hashGenesisBlockOfficial; static CBigNum bnProofOfWorkLimit(~uint256(0) >> 20); -static CBigNum bnProofOfStakeLimit(~uint256(0) >> 30); +static CBigNum bnProofOfStakeLimit(~uint256(0) >> 24); +static CBigNum bnProofOfStakeHardLimit(~uint256(0) >> 30); static CBigNum bnInitialHashTarget(~uint256(0) >> 20); unsigned int nStakeMinAge = STAKE_MIN_AGE; int nCoinbaseMaturity = COINBASE_MATURITY_PPC; @@ -891,19 +892,30 @@ static const int64 nTargetSpacingWorkMax = 12 * STAKE_TARGET_SPACING; // 2-hour // minimum amount of work that could possibly be required nTime after // minimum work required was nBase // -unsigned int ComputeMinWork(unsigned int nBase, int64 nTime) +unsigned int ComputeMinWork(unsigned int nBase, int64 nTime, bool fProofOfStake, int nHeight) { + CBigNum bnTargetLimit = bnProofOfWorkLimit; + + if(fProofOfStake) + { + // Proof-of-Stake blocks has own target limit since nVersion=3 supermajority on mainNet and always on testNet + if(fTestNet || nHeight > 15000) + bnTargetLimit = bnProofOfStakeLimit; + else if(nHeight > 14060) + bnTargetLimit = bnProofOfStakeHardLimit; + } + CBigNum bnResult; bnResult.SetCompact(nBase); bnResult *= 2; - while (nTime > 0 && bnResult < bnProofOfWorkLimit) + while (nTime > 0 && bnResult < bnTargetLimit) { // Maximum 200% adjustment per day... bnResult *= 2; nTime -= 24 * 60 * 60; } - if (bnResult > bnProofOfWorkLimit) - bnResult = bnProofOfWorkLimit; + if (bnResult > bnTargetLimit) + bnResult = bnTargetLimit; return bnResult.GetCompact(); } @@ -917,7 +929,16 @@ const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfSta unsigned int static GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake) { - CBigNum bnTargetLimit = (fProofOfStake && CBlockIndex::IsSuperMajority(3, pindexLast, 950, 1000)) ? bnProofOfStakeLimit : bnProofOfWorkLimit; + CBigNum bnTargetLimit = bnProofOfWorkLimit; + + if(fProofOfStake) + { + // Proof-of-Stake blocks has own target limit since nVersion=3 supermajority on mainNet and always on testNet + if(fTestNet || (pindexLast->nHeight + 1 > 15000)) + bnTargetLimit = bnProofOfStakeLimit; + else if(pindexLast->nHeight + 1 > 14060) + bnTargetLimit = bnProofOfStakeHardLimit; + } if (pindexLast == NULL) return bnTargetLimit.GetCompact(); // genesis block @@ -1924,6 +1945,25 @@ bool CBlock::CheckBlock() const return true; } +int CBlock::GetBlockHeight() const +{ + if(nVersion == 1) + return 0; + + if(vtx[0].vin[0].scriptSig[0] > 4) + return vtx[0].vin[0].scriptSig[0] - 80; + + int nBlockHeight = 0; + + memcpy((void *)&nBlockHeight, (const void *)&vtx[0].vin[0].scriptSig[1], vtx[0].vin[0].scriptSig[0]); + +#ifdef BIGENDIAN + return htonl(nBlockHeight); +#else + return nBlockHeight; +#endif +} + bool CBlock::AcceptBlock() { // Check for duplicate @@ -1959,22 +1999,21 @@ bool CBlock::AcceptBlock() if (!Checkpoints::CheckSync(hash, pindexPrev)) return error("AcceptBlock() : rejected by synchronized checkpoint"); - // Reject block.nVersion < 3 blocks when 95% (75% on testnet) of the network has upgraded: - if (nVersion < 3) - { - if ((!fTestNet && CBlockIndex::IsSuperMajority(3, pindexPrev, 950, 1000)) || (fTestNet && CBlockIndex::IsSuperMajority(3, pindexPrev, 75, 100))) - { - return error("CheckBlock() : rejected nVersion < 3 block"); - } - } + // Reject block.nVersion < 3 blocks since 95% threshold on mainNet and always on testNet: + if (nVersion < 3 && ((!fTestNet && nHeight > 14060) || (fTestNet && nHeight > 0))) + return error("CheckBlock() : rejected nVersion < 3 block"); - if(nHeight > 0) - { - CScript expect = CScript() << nHeight; + CScript expect = CScript() << nHeight; + if (!std::equal(expect.begin(), expect.end(), vtx[0].vin[0].scriptSig.begin())) + return DoS(100, error("AcceptBlock() : block height mismatch in coinbase")); + + /** + * TODO: replace previous check with this. + */ + + // if(nHeight != GetBlockHeight()) + // return DoS(100, error("AcceptBlock() : block height mismatch in coinbase")); - if (!std::equal(expect.begin(), expect.end(), vtx[0].vin[0].scriptSig.begin())) - return DoS(100, error("AcceptBlock() : block height mismatch in coinbase")); - } // Write block to history file if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK, CLIENT_VERSION))) @@ -2042,7 +2081,7 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock) CBigNum bnNewBlock; bnNewBlock.SetCompact(pblock->nBits); CBigNum bnRequired; - bnRequired.SetCompact(ComputeMinWork(GetLastBlockIndex(pcheckpoint, pblock->IsProofOfStake())->nBits, deltaTime)); + bnRequired.SetCompact(ComputeMinWork(GetLastBlockIndex(pcheckpoint, pblock->IsProofOfStake())->nBits, deltaTime, pblock->IsProofOfStake(), pblock->GetBlockHeight())); if (bnNewBlock > bnRequired) { @@ -2124,11 +2163,10 @@ bool CBlock::SignBlock(const CKeyStore& keystore) { vector vSolutions; txnouttype whichType; - int nVouts = nTime < 1361664000 ? 1 : vtx[0].vout.size(); if(!IsProofOfStake()) { - for(int i = 0; i < nVouts; i++) + for(int i = 0; i < vtx[0].vout.size(); i++) { const CTxOut& txout = vtx[0].vout[i]; @@ -2186,7 +2224,6 @@ bool CBlock::CheckBlockSignature() const vector vSolutions; txnouttype whichType; - int nVouts = nTime < 1361664000 ? 1 : vtx[0].vout.size(); if(IsProofOfStake()) { @@ -2207,7 +2244,7 @@ bool CBlock::CheckBlockSignature() const } else { - for(int i = 0; i < nVouts; i++) + for(int i = 0; i < vtx[0].vout.size(); i++) { const CTxOut& txout = vtx[0].vout[i]; @@ -2233,11 +2270,6 @@ bool CBlock::CheckBlockSignature() const return false; } - - - - - bool CheckDiskSpace(uint64 nAdditionalBytes) { uint64 nFreeBytesAvailable = filesystem::space(GetDataDir()).available; diff --git a/src/main.h b/src/main.h index e4c596f..4064a1d 100644 --- a/src/main.h +++ b/src/main.h @@ -117,7 +117,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey); bool CheckProofOfWork(uint256 hash, unsigned int nBits); int64 GetProofOfWorkReward(unsigned int nBits); int64 GetProofOfStakeReward(int64 nCoinAge); -unsigned int ComputeMinWork(unsigned int nBase, int64 nTime); +unsigned int ComputeMinWork(unsigned int nBase, int64 nTime, bool fProofOfStake, int nHeight); int GetNumBlocksOfPeers(); bool IsInitialBlockDownload(); std::string GetWarnings(std::string strFor); @@ -957,6 +957,7 @@ public: return thash; } + int GetBlockHeight() const; int64 GetBlockTime() const { @@ -1365,18 +1366,6 @@ public: return (nFlags & BLOCK_PROOF_OF_STAKE); } - static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired, unsigned int nToCheck) - { - unsigned int nFound = 0; - for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++) - { - if (pstart->nVersion >= minVersion) - ++nFound; - pstart = pstart->pprev; - } - return (nFound >= nRequired); - } - void SetProofOfStake() { nFlags |= BLOCK_PROOF_OF_STAKE; @@ -1434,13 +1423,11 @@ class CDiskBlockIndex : public CBlockIndex public: uint256 hashPrev; uint256 hashNext; - int nProtocolVersion; CDiskBlockIndex() { hashPrev = 0; hashNext = 0; - nProtocolVersion = PROTOCOL_VERSION; } explicit CDiskBlockIndex(CBlockIndex* pindex) : CBlockIndex(*pindex) @@ -1462,7 +1449,6 @@ public: READWRITE(nMoneySupply); READWRITE(nFlags); READWRITE(nStakeModifier); - READWRITE(nProtocolVersion); if (IsProofOfStake()) { READWRITE(prevoutStake); diff --git a/src/qt/forms/overviewpage.ui b/src/qt/forms/overviewpage.ui index c58c176..dd543c4 100644 --- a/src/qt/forms/overviewpage.ui +++ b/src/qt/forms/overviewpage.ui @@ -1,177 +1,178 @@ - - - OverviewPage - - - - 0 - 0 - 552 - 342 - - - - Form - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - QFormLayout::AllNonFixedFieldsGrow - - - 12 - - - 12 - - - - - Balance: - - - - - - - 0 BTC - - - - - - - Number of transactions: - - - - - - - 0 - - - - - - - Unconfirmed: - - - - - - - 0 BTC - - - - - - - Stake: - - - - - - - 0 BTC - - - - - - - - 11 - true - - - - Wallet - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - <b>Recent transactions</b> - - - - - - - QFrame::NoFrame - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - + + + OverviewPage + + + + 0 + 0 + 552 + 342 + + + + Form + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + QFormLayout::AllNonFixedFieldsGrow + + + 12 + + + 12 + + + + + Balance: + + + + + + + 0 NVC + + + + + + + Number of transactions: + + + + + + + 0 + + + + + + + Unconfirmed: + + + + + + + 0 NVC + + + + + + + Stake: + + + + + + + 0 NVC + + + + + + + + 11 + 75 + true + + + + Wallet + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + <b>Recent transactions</b> + + + + + + + QFrame::NoFrame + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/src/qt/locale/bitcoin_en.ts b/src/qt/locale/bitcoin_en.ts index 31174de..a8e0ce7 100644 --- a/src/qt/locale/bitcoin_en.ts +++ b/src/qt/locale/bitcoin_en.ts @@ -222,7 +222,7 @@ This product includes software developed by the OpenSSL Project for use in the O - WARNING: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR NovaCoinS</b>! + WARNING: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR COINS</b>! Are you sure you wish to encrypt your wallet? diff --git a/src/qt/locale/bitcoin_ru.ts b/src/qt/locale/bitcoin_ru.ts index 28b024d..17c70f1 100644 --- a/src/qt/locale/bitcoin_ru.ts +++ b/src/qt/locale/bitcoin_ru.ts @@ -226,9 +226,9 @@ This product includes software developed by the OpenSSL Project for use in the O - WARNING: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR NovaCoinS</b>! + WARNING: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR COINS</b>! Are you sure you wish to encrypt your wallet? - ВНИМАНИЕ: Если вы зашифруете бумажник и потеряете свой ​​пароль, вы <b>ПОТЕРЯЕТЕ ВСЕ ВАШИ БИТКОИНЫ!</b> + ВНИМАНИЕ: Если вы зашифруете бумажник и потеряете свой ​​пароль, вы <b>ПОТЕРЯЕТЕ ВСЕ ВАШИ МОНЕТЫ!</b> Вы действительно хотите зашифровать ваш бумажник? diff --git a/src/version.h b/src/version.h index d61c542..56297a3 100644 --- a/src/version.h +++ b/src/version.h @@ -30,14 +30,14 @@ extern const std::string CLIENT_DATE; // ppcoin version - intended for display purpose ONLY #define PPCOIN_VERSION_MAJOR 0 #define PPCOIN_VERSION_MINOR 3 -#define PPCOIN_VERSION_REVISION 4 +#define PPCOIN_VERSION_REVISION 5 #define PPCOIN_VERSION_BUILD 0 // // network protocol versioning // -static const int PROTOCOL_VERSION = 60004; +static const int PROTOCOL_VERSION = 60005; // earlier versions not supported as of Feb 2012, and are disconnected // NOTE: as of bitcoin v0.6 message serialization (vSend, vRecv) still -- 1.7.1