Browse Source

consensus: don't use arith_uint256 in consensus.h

Requiring arith_uint256 at such a base level is not good for modularity.
0.13
Cory Fields 10 years ago
parent
commit
fd311996e8
  1. 4
      src/chainparams.cpp
  2. 3
      src/chainparams.h
  3. 3
      src/consensus/params.h
  4. 9
      src/pow.cpp

4
src/chainparams.cpp

@ -105,7 +105,7 @@ public:
consensus.nMajorityEnforceBlockUpgrade = 750; consensus.nMajorityEnforceBlockUpgrade = 750;
consensus.nMajorityRejectBlockOutdated = 950; consensus.nMajorityRejectBlockOutdated = 950;
consensus.nMajorityWindow = 1000; consensus.nMajorityWindow = 1000;
consensus.powLimit = ~arith_uint256(0) >> 32; consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60; consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = false; consensus.fPowAllowMinDifficultyBlocks = false;
@ -245,7 +245,7 @@ public:
consensus.nMajorityEnforceBlockUpgrade = 750; consensus.nMajorityEnforceBlockUpgrade = 750;
consensus.nMajorityRejectBlockOutdated = 950; consensus.nMajorityRejectBlockOutdated = 950;
consensus.nMajorityWindow = 1000; consensus.nMajorityWindow = 1000;
consensus.powLimit = ~arith_uint256(0) >> 1; consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
pchMessageStart[0] = 0xfa; pchMessageStart[0] = 0xfa;
pchMessageStart[1] = 0xbf; pchMessageStart[1] = 0xbf;
pchMessageStart[2] = 0xb5; pchMessageStart[2] = 0xb5;

3
src/chainparams.h

@ -6,7 +6,6 @@
#ifndef BITCOIN_CHAINPARAMS_H #ifndef BITCOIN_CHAINPARAMS_H
#define BITCOIN_CHAINPARAMS_H #define BITCOIN_CHAINPARAMS_H
#include "arith_uint256.h"
#include "chainparamsbase.h" #include "chainparamsbase.h"
#include "checkpoints.h" #include "checkpoints.h"
#include "consensus/params.h" #include "consensus/params.h"
@ -45,7 +44,7 @@ public:
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; } const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; } const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
int GetDefaultPort() const { return nDefaultPort; } int GetDefaultPort() const { return nDefaultPort; }
const arith_uint256& ProofOfWorkLimit() const { return consensus.powLimit; } const uint256& ProofOfWorkLimit() const { return consensus.powLimit; }
int SubsidyHalvingInterval() const { return consensus.nSubsidyHalvingInterval; } int SubsidyHalvingInterval() const { return consensus.nSubsidyHalvingInterval; }
int EnforceBlockUpgradeMajority() const { return consensus.nMajorityEnforceBlockUpgrade; } int EnforceBlockUpgradeMajority() const { return consensus.nMajorityEnforceBlockUpgrade; }
int RejectBlockOutdatedMajority() const { return consensus.nMajorityRejectBlockOutdated; } int RejectBlockOutdatedMajority() const { return consensus.nMajorityRejectBlockOutdated; }

3
src/consensus/params.h

@ -6,7 +6,6 @@
#ifndef BITCOIN_CONSENSUS_CONSENSUS_PARAMS_H #ifndef BITCOIN_CONSENSUS_CONSENSUS_PARAMS_H
#define BITCOIN_CONSENSUS_CONSENSUS_PARAMS_H #define BITCOIN_CONSENSUS_CONSENSUS_PARAMS_H
#include "arith_uint256.h"
#include "uint256.h" #include "uint256.h"
namespace Consensus { namespace Consensus {
@ -21,7 +20,7 @@ struct Params {
int nMajorityRejectBlockOutdated; int nMajorityRejectBlockOutdated;
int nMajorityWindow; int nMajorityWindow;
/** Proof of work parameters */ /** Proof of work parameters */
arith_uint256 powLimit; uint256 powLimit;
bool fPowAllowMinDifficultyBlocks; bool fPowAllowMinDifficultyBlocks;
int64_t nPowTargetSpacing; int64_t nPowTargetSpacing;
int64_t nPowTargetTimespan; int64_t nPowTargetTimespan;

9
src/pow.cpp

@ -13,7 +13,7 @@
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
{ {
unsigned int nProofOfWorkLimit = params.powLimit.GetCompact(); unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
// Genesis block // Genesis block
if (pindexLast == NULL) if (pindexLast == NULL)
@ -61,6 +61,7 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
nActualTimespan = params.nPowTargetTimespan*4; nActualTimespan = params.nPowTargetTimespan*4;
// Retarget // Retarget
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
arith_uint256 bnNew; arith_uint256 bnNew;
arith_uint256 bnOld; arith_uint256 bnOld;
bnNew.SetCompact(pindexLast->nBits); bnNew.SetCompact(pindexLast->nBits);
@ -68,8 +69,8 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
bnNew *= nActualTimespan; bnNew *= nActualTimespan;
bnNew /= params.nPowTargetTimespan; bnNew /= params.nPowTargetTimespan;
if (bnNew > params.powLimit) if (bnNew > bnPowLimit)
bnNew = params.powLimit; bnNew = bnPowLimit;
/// debug print /// debug print
LogPrintf("GetNextWorkRequired RETARGET\n"); LogPrintf("GetNextWorkRequired RETARGET\n");
@ -89,7 +90,7 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&
bnTarget.SetCompact(nBits, &fNegative, &fOverflow); bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
// Check range // Check range
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > params.powLimit) if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
return error("CheckProofOfWork(): nBits below minimum work"); return error("CheckProofOfWork(): nBits below minimum work");
// Check proof of work matches claimed amount // Check proof of work matches claimed amount

Loading…
Cancel
Save