Skip to content

Commit 9125c08

Browse files
committed
Merge pull request #6000
fd31199 consensus: don't use arith_uint256 in consensus.h (Cory Fields)
2 parents c2fa084 + fd31199 commit 9125c08

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

src/chainparams.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class CMainParams : public CChainParams {
105105
consensus.nMajorityEnforceBlockUpgrade = 750;
106106
consensus.nMajorityRejectBlockOutdated = 950;
107107
consensus.nMajorityWindow = 1000;
108-
consensus.powLimit = ~arith_uint256(0) >> 32;
108+
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
109109
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
110110
consensus.nPowTargetSpacing = 10 * 60;
111111
consensus.fPowAllowMinDifficultyBlocks = false;
@@ -245,7 +245,7 @@ class CRegTestParams : public CTestNetParams {
245245
consensus.nMajorityEnforceBlockUpgrade = 750;
246246
consensus.nMajorityRejectBlockOutdated = 950;
247247
consensus.nMajorityWindow = 1000;
248-
consensus.powLimit = ~arith_uint256(0) >> 1;
248+
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
249249
pchMessageStart[0] = 0xfa;
250250
pchMessageStart[1] = 0xbf;
251251
pchMessageStart[2] = 0xb5;

src/chainparams.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#ifndef BITCOIN_CHAINPARAMS_H
77
#define BITCOIN_CHAINPARAMS_H
88

9-
#include "arith_uint256.h"
109
#include "chainparamsbase.h"
1110
#include "checkpoints.h"
1211
#include "consensus/params.h"
@@ -45,7 +44,7 @@ class CChainParams
4544
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
4645
const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
4746
int GetDefaultPort() const { return nDefaultPort; }
48-
const arith_uint256& ProofOfWorkLimit() const { return consensus.powLimit; }
47+
const uint256& ProofOfWorkLimit() const { return consensus.powLimit; }
4948
int SubsidyHalvingInterval() const { return consensus.nSubsidyHalvingInterval; }
5049
int EnforceBlockUpgradeMajority() const { return consensus.nMajorityEnforceBlockUpgrade; }
5150
int RejectBlockOutdatedMajority() const { return consensus.nMajorityRejectBlockOutdated; }

src/consensus/params.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#ifndef BITCOIN_CONSENSUS_CONSENSUS_PARAMS_H
77
#define BITCOIN_CONSENSUS_CONSENSUS_PARAMS_H
88

9-
#include "arith_uint256.h"
109
#include "uint256.h"
1110

1211
namespace Consensus {
@@ -21,7 +20,7 @@ struct Params {
2120
int nMajorityRejectBlockOutdated;
2221
int nMajorityWindow;
2322
/** Proof of work parameters */
24-
arith_uint256 powLimit;
23+
uint256 powLimit;
2524
bool fPowAllowMinDifficultyBlocks;
2625
int64_t nPowTargetSpacing;
2726
int64_t nPowTargetTimespan;

src/pow.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
1515
{
16-
unsigned int nProofOfWorkLimit = params.powLimit.GetCompact();
16+
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
1717

1818
// Genesis block
1919
if (pindexLast == NULL)
@@ -61,15 +61,16 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
6161
nActualTimespan = params.nPowTargetTimespan*4;
6262

6363
// Retarget
64+
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
6465
arith_uint256 bnNew;
6566
arith_uint256 bnOld;
6667
bnNew.SetCompact(pindexLast->nBits);
6768
bnOld = bnNew;
6869
bnNew *= nActualTimespan;
6970
bnNew /= params.nPowTargetTimespan;
7071

71-
if (bnNew > params.powLimit)
72-
bnNew = params.powLimit;
72+
if (bnNew > bnPowLimit)
73+
bnNew = bnPowLimit;
7374

7475
/// debug print
7576
LogPrintf("GetNextWorkRequired RETARGET\n");
@@ -89,7 +90,7 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&
8990
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
9091

9192
// Check range
92-
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > params.powLimit)
93+
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
9394
return error("CheckProofOfWork(): nBits below minimum work");
9495

9596
// Check proof of work matches claimed amount

0 commit comments

Comments
 (0)