Changeset View
Changeset View
Standalone View
Standalone View
src/pow.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2017 The Bitcoin developers | // Copyright (c) 2017 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "pow.h" | #include "pow.h" | ||||
#include "arith_uint256.h" | #include "arith_uint256.h" | ||||
#include "chain.h" | #include "chain.h" | ||||
#include "chainparams.h" | #include "chainparams.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "consensus/params.h" | #include "consensus/params.h" | ||||
#include "primitives/block.h" | #include "primitives/block.h" | ||||
#include "uint256.h" | #include "uint256.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "validation.h" | |||||
/** | /** | ||||
* Compute the next required proof of work using the legacy Bitcoin difficulty | * Compute the next required proof of work using the legacy Bitcoin difficulty | ||||
* adjustment + Emergency Difficulty Adjustment (EDA). | * adjustment + Emergency Difficulty Adjustment (EDA). | ||||
*/ | */ | ||||
static uint32_t GetNextEDAWorkRequired(const CBlockIndex *pindexPrev, | static uint32_t GetNextEDAWorkRequired(const CBlockIndex *pindexPrev, | ||||
const CBlockHeader *pblock, | const CBlockHeader *pblock, | ||||
const Config &config) { | const Config &config) { | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | if (pindexPrev == nullptr) { | ||||
return UintToArith256(params.powLimit).GetCompact(); | return UintToArith256(params.powLimit).GetCompact(); | ||||
} | } | ||||
// Special rule for regtest: we never retarget. | // Special rule for regtest: we never retarget. | ||||
if (params.fPowNoRetargeting) { | if (params.fPowNoRetargeting) { | ||||
return pindexPrev->nBits; | return pindexPrev->nBits; | ||||
} | } | ||||
if (pindexPrev->GetMedianTimePast() >= params.cashHardForkActivationTime) { | if (IsCashHFEnabled(config, pindexPrev)) { | ||||
return GetNextCashWorkRequired(pindexPrev, pblock, config); | return GetNextCashWorkRequired(pindexPrev, pblock, config); | ||||
} | } | ||||
return GetNextEDAWorkRequired(pindexPrev, pblock, config); | return GetNextEDAWorkRequired(pindexPrev, pblock, config); | ||||
} | } | ||||
uint32_t CalculateNextWorkRequired(const CBlockIndex *pindexPrev, | uint32_t CalculateNextWorkRequired(const CBlockIndex *pindexPrev, | ||||
int64_t nFirstBlockTime, | int64_t nFirstBlockTime, | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |