diff --git a/src/chain.cpp b/src/chain.cpp index e90466a62..d2b7382d9 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -1,10 +1,8 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Copyright (c) 2016-2021 The Hush developers - // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * @@ -80,15 +78,13 @@ const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const { CChainPower::CChainPower(CBlockIndex *pblockIndex) { - nHeight = pblockIndex->GetHeight(); - chainStake = arith_uint256(0); + nHeight = pblockIndex->GetHeight(); chainWork = arith_uint256(0); } -CChainPower::CChainPower(CBlockIndex *pblockIndex, const arith_uint256 &stake, const arith_uint256 &work) +CChainPower::CChainPower(CBlockIndex *pblockIndex, const arith_uint256 &work) { - nHeight = pblockIndex->GetHeight(); - chainStake = stake; + nHeight = pblockIndex->GetHeight(); chainWork = work; } @@ -96,38 +92,29 @@ bool operator==(const CChainPower &p1, const CChainPower &p2) { arith_uint256 bigZero = arith_uint256(0); arith_uint256 workDivisor = p1.chainWork > p2.chainWork ? p1.chainWork : (p2.chainWork != bigZero ? p2.chainWork : 1); - arith_uint256 stakeDivisor = p1.chainStake > p2.chainStake ? p1.chainStake : (p2.chainStake != bigZero ? p2.chainStake : 1); // use up 16 bits for precision - return ((p1.chainWork << 16) / workDivisor + (p1.chainStake << 16) / stakeDivisor) == - ((p2.chainWork << 16) / workDivisor + (p2.chainStake << 16) / stakeDivisor); + return ((p1.chainWork << 16) / workDivisor == ((p2.chainWork << 16) / workDivisor)); } bool operator<(const CChainPower &p1, const CChainPower &p2) { arith_uint256 bigZero = arith_uint256(0); arith_uint256 workDivisor = p1.chainWork > p2.chainWork ? p1.chainWork : (p2.chainWork != bigZero ? p2.chainWork : 1); - arith_uint256 stakeDivisor = p1.chainStake > p2.chainStake ? p1.chainStake : (p2.chainStake != bigZero ? p2.chainStake : 1); // use up 16 bits for precision - return ((p1.chainWork << 16) / workDivisor + (p1.chainStake << 16) / stakeDivisor) < - ((p2.chainWork << 16) / workDivisor + (p2.chainStake << 16) / stakeDivisor); + return ((p1.chainWork << 16) / workDivisor < ((p2.chainWork << 16) / workDivisor)); } bool operator<=(const CChainPower &p1, const CChainPower &p2) { arith_uint256 bigZero = arith_uint256(0); arith_uint256 workDivisor = p1.chainWork > p2.chainWork ? p1.chainWork : (p2.chainWork != bigZero ? p2.chainWork : 1); - arith_uint256 stakeDivisor = p1.chainStake > p2.chainStake ? p1.chainStake : (p2.chainStake != bigZero ? p2.chainStake : 1); // use up 16 bits for precision - return ((p1.chainWork << 16) / workDivisor + (p1.chainStake << 16) / stakeDivisor) <= - ((p2.chainWork << 16) / workDivisor + (p2.chainStake << 16) / stakeDivisor); + return ((p1.chainWork << 16) / workDivisor <= ((p2.chainWork << 16) / workDivisor)); } - - - /** Turn the lowest '1' bit in the binary representation of a number into a '0'. */ int static inline InvertLowestOne(int n) { return n & (n - 1); } diff --git a/src/chain.h b/src/chain.h index bb0b2897f..3162f6634 100644 --- a/src/chain.h +++ b/src/chain.h @@ -127,31 +127,23 @@ static const BlockStatus BLOCK_VALID_CONSENSUS = BLOCK_VALID_SCRIPTS; class CBlockIndex; -// This class provides an accumulator for both the chainwork and the chainPOS value -// CChainPower's can be compared, and the comparison ensures that work and proof of stake power -// are both used equally to determine which chain has the most work. This makes an attack -// that involves mining in secret completely ineffective, even before dPOW, unless a large part -// of the staking supply is also controlled. It also enables a faster deterministic convergence, -// aided by both POS and POW. -// TODO: delete this junk +// This class provides an accumulator for chainwork class CChainPower { public: arith_uint256 chainWork; - arith_uint256 chainStake; int32_t nHeight; - CChainPower() : nHeight(0), chainStake(0), chainWork(0) {} + CChainPower() : nHeight(0), chainWork(0) {} CChainPower(CBlockIndex *pblockIndex); - CChainPower(CBlockIndex *pblockIndex, const arith_uint256 &stake, const arith_uint256 &work); - CChainPower(int32_t height) : nHeight(height), chainStake(0), chainWork(0) {} - CChainPower(int32_t height, const arith_uint256 &stake, const arith_uint256 &work) : - nHeight(height), chainStake(stake), chainWork(work) {} + CChainPower(CBlockIndex *pblockIndex, const arith_uint256 &work); + CChainPower(int32_t height) : nHeight(height), chainWork(0) {} + CChainPower(int32_t height, const arith_uint256 &work) : + nHeight(height), chainWork(work) {} CChainPower &operator=(const CChainPower &chainPower) { chainWork = chainPower.chainWork; - chainStake = chainPower.chainStake; nHeight = chainPower.nHeight; return *this; } @@ -159,7 +151,6 @@ class CChainPower CChainPower &operator+=(const CChainPower &chainPower) { this->chainWork += chainPower.chainWork; - this->chainStake += chainPower.chainStake; return *this; } @@ -167,7 +158,6 @@ class CChainPower { CChainPower result = CChainPower(chainPowerA); result.chainWork += chainPowerB.chainWork; - result.chainStake += chainPowerB.chainStake; return result; } @@ -175,7 +165,6 @@ class CChainPower { CChainPower result = CChainPower(chainPowerA); result.chainWork -= chainPowerB.chainWork; - result.chainStake -= chainPowerB.chainStake; return result; } @@ -183,16 +172,9 @@ class CChainPower { CChainPower result = CChainPower(chainPower); result.chainWork *= x; - result.chainStake *= x; return result; } - CChainPower &addStake(const arith_uint256 &nChainStake) - { - chainStake += nChainStake; - return *this; - } - CChainPower &addWork(const arith_uint256 &nChainWork) { chainWork += nChainWork; diff --git a/src/main.cpp b/src/main.cpp index 7e06fc512..eff2ebaaa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4207,19 +4207,17 @@ static bool ActivateBestChainStep(bool fSkipdpow, CValidationState &state, CBloc if ( reorgLength > MAX_REORG_LENGTH) { auto msg = strprintf(_( - "A block chain reorganization has been detected that would roll back %d blocks! " + "A block chain reorganization has been detected that would roll back %d blocks!!! " "This is larger than the maximum of %d blocks, and so the node is shutting down for your safety." ), reorgLength, MAX_REORG_LENGTH) + "\n\n" + _("Reorganization details") + ":\n" + - "- " + strprintf(_("Current tip: %s, height %d, work %s\nstake %s"), - pindexOldTip->phashBlock->GetHex(), pindexOldTip->GetHeight(), pindexOldTip->chainPower.chainWork.GetHex(), - pindexOldTip->chainPower.chainStake.GetHex()) + "\n" + - "- " + strprintf(_("New tip: %s, height %d, work %s\nstake %s"), - pindexMostWork->phashBlock->GetHex(), pindexMostWork->GetHeight(), pindexMostWork->chainPower.chainWork.GetHex(), - pindexMostWork->chainPower.chainStake.GetHex()) + "\n" + + "- " + strprintf(_("Current tip: %s, height %d, work %s\n"), + pindexOldTip->phashBlock->GetHex(), pindexOldTip->GetHeight(), pindexOldTip->chainPower.chainWork.GetHex()) + "\n" + + "- " + strprintf(_("New tip: %s, height %d, work %s\n"), + pindexMostWork->phashBlock->GetHex(), pindexMostWork->GetHeight(), pindexMostWork->chainPower.chainWork.GetHex()) + "\n" + "- " + strprintf(_("Fork point: %s %s, height %d"), SMART_CHAIN_SYMBOL,pindexFork->phashBlock->GetHex(), pindexFork->GetHeight()) + "\n\n" + - _("Please help, human!"); + _("Please help me, wise human!"); LogPrintf("*** %s\nif you launch with -maxreorg=%d it might be able to resolve this automatically", msg,reorgLength+10); fprintf(stderr,"*** %s\nif you launch with -maxreorg=%d it might be able to resolve this automatically", msg.c_str(),reorgLength+10); uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR); diff --git a/src/miner.cpp b/src/miner.cpp index 93f019d7f..fb3a574f0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -583,7 +583,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //pblock->nTime = blocktime + 1; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); - LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x stake.%i\n", nBlockSize,blocktime,pblock->nBits,isStake); + LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); // Create coinbase tx CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, nHeight); diff --git a/src/pow.cpp b/src/pow.cpp index 0838f6e2b..8b23c993f 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -749,7 +749,7 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t CChainPower GetBlockProof(const CBlockIndex& block) { - arith_uint256 bnWorkTarget, bnStakeTarget = arith_uint256(0); + arith_uint256 bnWorkTarget; bool fNegative; bool fOverflow; @@ -758,7 +758,7 @@ CChainPower GetBlockProof(const CBlockIndex& block) if (fNegative || fOverflow || bnWorkTarget == 0) return CChainPower(0); - return CChainPower(0, bnStakeTarget, (~bnWorkTarget / (bnWorkTarget + 1)) + 1); + return CChainPower(0, (~bnWorkTarget / (bnWorkTarget + 1)) + 1); } int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& from, const CBlockIndex& tip, const Consensus::Params& params) diff --git a/src/script/standard.h b/src/script/standard.h index 601b9e5cd..697150372 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -117,45 +117,6 @@ class COptCCParams std::vector AsVector(); }; -class CStakeParams -{ - public: - static const uint32_t STAKE_MINPARAMS = 4; - static const uint32_t STAKE_MAXPARAMS = 5; - - uint32_t srcHeight; - uint32_t blkHeight; - uint256 prevHash; - CPubKey pk; - - CStakeParams() : srcHeight(0), blkHeight(0), prevHash(), pk() {} - - CStakeParams(const std::vector> &vData); - - CStakeParams(uint32_t _srcHeight, uint32_t _blkHeight, const uint256 &_prevHash, const CPubKey &_pk) : - srcHeight(_srcHeight), blkHeight(_blkHeight), prevHash(_prevHash), pk(_pk) {} - - std::vector AsVector() - { - std::vector ret; - CScript scr = CScript(); - scr << OPRETTYPE_STAKEPARAMS; - scr << srcHeight; - scr << blkHeight; - scr << std::vector(prevHash.begin(), prevHash.end()); - - if (pk.IsValid()) - { - scr << std::vector(pk.begin(), pk.end()); - } - - ret = std::vector(scr.begin(), scr.end()); - return ret; - } - - bool IsValid() { return srcHeight != 0; } -}; - /** Check whether a CTxDestination is a CNoDestination. */ bool IsValidDestination(const CTxDestination& dest);