From 7801f4387d96c19de6dedc518e45d3037d9c53fa Mon Sep 17 00:00:00 2001 From: Eric Lombrozo Date: Mon, 19 Oct 2015 08:25:29 -0400 Subject: Added fPowNoRetargeting field to Consensus::Params that disables nBits recalculation. --- src/pow.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index bb53ad204..5ace3fbc9 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -52,6 +52,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params) { + if (params.fPowNoRetargeting) + return pindexLast->nBits; + // Limit adjustment step int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime; LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan); -- cgit v1.2.3 From fa24439ff3d8ab5b9efaf66ef4dae6713b88cb35 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sun, 13 Dec 2015 17:58:29 +0100 Subject: Bump copyright headers to 2015 --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index 5ace3fbc9..7392defe6 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2009-2015 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -- cgit v1.2.3 From e86756193ebdbf71504e2a1a8db43e38d57f9673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= Date: Mon, 30 Nov 2015 00:46:49 +0100 Subject: MOVEONLY: non-consensus: from pow to chain: - GetBlockProof - GetBlockProofEquivalentTime --- src/pow.cpp | 32 -------------------------------- 1 file changed, 32 deletions(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index 5ace3fbc9..dc58e21e1 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -102,35 +102,3 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& return true; } - -arith_uint256 GetBlockProof(const CBlockIndex& block) -{ - arith_uint256 bnTarget; - bool fNegative; - bool fOverflow; - bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); - if (fNegative || fOverflow || bnTarget == 0) - return 0; - // We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256 - // as it's too large for a arith_uint256. However, as 2**256 is at least as large - // as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / (bnTarget+1)) + 1, - // or ~bnTarget / (nTarget+1) + 1. - return (~bnTarget / (bnTarget + 1)) + 1; -} - -int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& from, const CBlockIndex& tip, const Consensus::Params& params) -{ - arith_uint256 r; - int sign = 1; - if (to.nChainWork > from.nChainWork) { - r = to.nChainWork - from.nChainWork; - } else { - r = from.nChainWork - to.nChainWork; - sign = -1; - } - r = r * arith_uint256(params.nPowTargetSpacing) / GetBlockProof(tip); - if (r.bits() > 63) { - return sign * std::numeric_limits::max(); - } - return sign * r.GetLow64(); -} -- cgit v1.2.3 From f3757a039196c804f252a4efba294e8f2b4d301d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= Date: Wed, 2 Dec 2015 03:15:42 +0100 Subject: Consensus: Decouple pow.cpp from util.h --- src/pow.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index 40c72f9d7..058404f35 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -9,7 +9,6 @@ #include "chain.h" #include "primitives/block.h" #include "uint256.h" -#include "util.h" unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { @@ -57,7 +56,6 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF // Limit adjustment step int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime; - LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan); if (nActualTimespan < params.nPowTargetTimespan/4) nActualTimespan = params.nPowTargetTimespan/4; if (nActualTimespan > params.nPowTargetTimespan*4) @@ -75,12 +73,6 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF if (bnNew > bnPowLimit) bnNew = bnPowLimit; - /// debug print - LogPrintf("GetNextWorkRequired RETARGET\n"); - LogPrintf("params.nPowTargetTimespan = %d nActualTimespan = %d\n", params.nPowTargetTimespan, nActualTimespan); - LogPrintf("Before: %08x %s\n", pindexLast->nBits, bnOld.ToString()); - LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString()); - return bnNew.GetCompact(); } @@ -94,11 +86,11 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& // Check range if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) - return error("CheckProofOfWork(): nBits below minimum work"); + return false; // Check proof of work matches claimed amount if (UintToArith256(hash) > bnTarget) - return error("CheckProofOfWork(): hash doesn't match nBits"); + return false; return true; } -- cgit v1.2.3 From c7aac2d557fe3d3aa5bcdd3301a9b87eb110d8ed Mon Sep 17 00:00:00 2001 From: 21E14 <21xe14@gmail.com> Date: Wed, 27 Apr 2016 22:36:45 -0400 Subject: Deprecating the remaining LogPrintf dependencies that were made obsolete in PR #7459. --- src/pow.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index 058404f35..1db3b6929 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -64,9 +64,7 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF // Retarget const arith_uint256 bnPowLimit = UintToArith256(params.powLimit); arith_uint256 bnNew; - arith_uint256 bnOld; bnNew.SetCompact(pindexLast->nBits); - bnOld = bnNew; bnNew *= nActualTimespan; bnNew /= params.nPowTargetTimespan; -- cgit v1.2.3 From 27765b6403cece54320374b37afb01a0cfe571c3 Mon Sep 17 00:00:00 2001 From: isle2983 Date: Sat, 31 Dec 2016 11:01:21 -0700 Subject: Increment MIT Licence copyright header year on files modified in 2016 Edited via: $ contrib/devtools/copyright_header.py update . --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index 1db3b6929..e57fd866f 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2015 The Bitcoin Core developers +// Copyright (c) 2009-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -- cgit v1.2.3 From 64af132fdba545f9caaa93597ad1f0c0a6b6ade1 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Tue, 18 Apr 2017 13:36:32 +0100 Subject: Replace consensus values with Dogecoin equivalents * Replace chain parameters with Dogecoin values * Update maximum coins to match Dogecoin * Disable version 2 block requirement * Update coinbase maturity to match Dogecoin --- src/pow.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index e57fd866f..52c826d72 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -9,6 +9,7 @@ #include "chain.h" #include "primitives/block.h" #include "uint256.h" +#include "util.h" unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { -- cgit v1.2.3 From 8279f81b44eaf1a4fc9f2c6a4871d853b5f3fc7e Mon Sep 17 00:00:00 2001 From: coblee Date: Sun, 9 Oct 2011 20:46:21 -1000 Subject: Litecoin: Fix zeitgeist2 attack thanks to Lolcust and ArtForz. This fixes an issue where a 51% attack can change difficulty at will. Go back the full period unless it's the first retarget after genesis. --- src/pow.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index 52c826d72..c629ee4a4 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -41,8 +41,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return pindexLast->nBits; } + // Litecoin: This fixes an issue where a 51% attack can change difficulty at will. + // Go back the full period unless it's the first retarget after genesis. Code courtesy of Art Forz + int blockstogoback = params.DifficultyAdjustmentInterval()-1; + if ((pindexLast->nHeight+1) != params.DifficultyAdjustmentInterval()) + blockstogoback = params.DifficultyAdjustmentInterval(); + // Go back by what we want to be 14 days worth of blocks - int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1); + int nHeightFirst = pindexLast->nHeight - blockstogoback; assert(nHeightFirst >= 0); const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst); assert(pindexFirst); -- cgit v1.2.3 From f0f9fd02926cc4b52ac1b73f494238d674a8c86c Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Tue, 18 Apr 2017 19:15:10 +0100 Subject: Add Dogecoin difficulty calculations --- src/pow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index c629ee4a4..64628b73f 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -7,6 +7,7 @@ #include "arith_uint256.h" #include "chain.h" +#include "dogecoin.h" #include "primitives/block.h" #include "uint256.h" #include "util.h" @@ -53,7 +54,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst); assert(pindexFirst); - return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params); + return CalculateDogecoinNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params); } unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params) -- cgit v1.2.3 From bc8cca48968dfa3f60b5eae6a2b92bdd2870eee3 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 13 Aug 2017 13:31:12 +0100 Subject: Merge AuxPoW support from Namecore Changes are as below: Wrap CBlockHeader::nVersion into a new class (CBlockVersion). This allows to take care of interpreting the field into a base version, auxpow flag and the chain ID. Update getauxblock.py for new 'generate' RPC call. Add 'auxpow' to block JSON. Accept auxpow as PoW verification. Add unit tests for auxpow verification. Add check for memory-layout of CBlockVersion. Weaken auxpow chain ID checks for the testnet. Allow Params() to overrule when to check the auxpow chain ID and for legacy blocks. Use this to disable the checks on testnet. Introduce CPureBlockHeader. Split the block header part that is used by auxpow and the "real" block header (that uses auxpow) to resolve the cyclic dependency between the two. Differentiate between uint256 and arith_uint256. This change was done upstream, modify the auxpow code. Add missing lock in auxpow_tests. Fix REST header check for auxpow headers. Those can be longer, thus take that into account. Also perform the check actually on an auxpow header. Correctly set the coinbase for getauxblock results. Call IncrementExtraNonce in getauxblock so that the coinbase is actually initialised with the stuff it should be. (BIP30 block height and COINBASE_FLAGS.) Implement getauxblock plus regression test. Turn auxpow test into FIXTURE test. This allows using of the Params() calls. Move CMerkleTx code to auxpow.cpp. Otherwise we get linker errors when building without wallet. Fix rebase with BIP66. Update the code to handle BIP66's nVersion=3. Enforce that auxpow parent blocks have no auxpow block version. This is for compatibility with namecoind. See also https://github.com/namecoin/namecoin/pull/199. Move auxpow-related parameters to Consensus::Params. --- src/pow.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index 64628b73f..a8d0efdab 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -5,6 +5,7 @@ #include "pow.h" +#include "auxpow.h" #include "arith_uint256.h" #include "chain.h" #include "dogecoin.h" -- cgit v1.2.3 From 1de15c70ce8065334fd827b137eba8fb899b527a Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 24 Sep 2017 15:56:19 +0100 Subject: Sync changes from Dogecoin 1.10 --- src/pow.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index a8d0efdab..8bbb66a70 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -21,8 +21,21 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexLast == NULL) return nProofOfWorkLimit; + // Dogecoin: Special rules for minimum difficulty blocks with Digishield + if (AllowDigishieldMinDifficultyForBlock(pindexLast, pblock, params)) + { + // Special difficulty rule for testnet: + // If the new block's timestamp is more than 2* nTargetSpacing minutes + // then allow mining of a min-difficulty block. + return nProofOfWorkLimit; + } + // Only change once per difficulty adjustment interval - if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0) + bool fNewDifficultyProtocol = (pindexLast->nHeight >= 145000); + const int64_t difficultyAdjustmentInterval = fNewDifficultyProtocol + ? 1 + : params.DifficultyAdjustmentInterval(); + if ((pindexLast->nHeight+1) % difficultyAdjustmentInterval != 0) { if (params.fPowAllowMinDifficultyBlocks) { -- cgit v1.2.3 From 0a403a2227dab68d861045ae1b2d5c8774db7101 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 19 Nov 2017 22:10:34 +0000 Subject: Correct PoW calculation logic to use locally calcualted difficulty --- src/pow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index 8bbb66a70..b569e709a 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -58,9 +58,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Litecoin: This fixes an issue where a 51% attack can change difficulty at will. // Go back the full period unless it's the first retarget after genesis. Code courtesy of Art Forz - int blockstogoback = params.DifficultyAdjustmentInterval()-1; - if ((pindexLast->nHeight+1) != params.DifficultyAdjustmentInterval()) - blockstogoback = params.DifficultyAdjustmentInterval(); + int blockstogoback = difficultyAdjustmentInterval-1; + if ((pindexLast->nHeight+1) != difficultyAdjustmentInterval) + blockstogoback = difficultyAdjustmentInterval; // Go back by what we want to be 14 days worth of blocks int nHeightFirst = pindexLast->nHeight - blockstogoback; -- cgit v1.2.3 From 1be681a1b97b686f838af90682a57f2030d26015 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Thu, 28 Dec 2017 15:04:08 +0000 Subject: Modify chain consensus parameters to be height aware (#1396) * Modify chain consensus parameters to be height aware * Correct implementation of simplified rewards in parameters * Correct max money * Use base block version in IsSuperMajority() instead of full version * Correct mining of blocks in AuxPoW tests * Add in missing pre-AuxPoW consensus checks --- src/pow.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index b569e709a..b0deab393 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -13,6 +13,22 @@ #include "uint256.h" #include "util.h" +// Determine if the for the given block, a min difficulty setting applies +bool AllowMinDifficultyForBlock(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) +{ + // check if the chain allows minimum difficulty blocks + if (!params.fPowAllowMinDifficultyBlocks) + return false; + + // Dogecoin: Magic number at which reset protocol switches + // check if we allow minimum difficulty at this block-height + if (pindexLast->nHeight < 157500) + return false; + + // Allow for a minimum block time if the elapsed time > 2*nTargetSpacing + return (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2); +} + unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); -- cgit v1.2.3