mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Merge #8665: Assert all the things!
4d51e9b
Assert ConnectBlock block and pIndex are the same block (NicolasDorier)972714c
pow: GetNextWorkRequired never called with NULL pindexLast (Daniel Cousens)cc44c8f
ContextualCheckBlockHeader should never have pindexPrev to NULL (NicolasDorier) Tree-SHA512: 7cc568bf9417267c335f21ec3d1505b26e56e5b3d5f4d3dbb555279489800aaa65a3bcd7bc376e274dd102912aec16ddbb18de2e2060b2667b41eb979cd9321e
This commit is contained in:
commit
1b046603b3
2 changed files with 7 additions and 6 deletions
|
@ -12,12 +12,9 @@
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
assert(pindexLast != NULL);
|
||||||
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
|
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
|
||||||
|
|
||||||
// Genesis block
|
|
||||||
if (pindexLast == NULL)
|
|
||||||
return nProofOfWorkLimit;
|
|
||||||
|
|
||||||
// Only change once per difficulty adjustment interval
|
// Only change once per difficulty adjustment interval
|
||||||
if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
|
if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1714,7 +1714,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
||||||
CCoinsViewCache& view, const CChainParams& chainparams, bool fJustCheck)
|
CCoinsViewCache& view, const CChainParams& chainparams, bool fJustCheck)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
|
assert(pindex);
|
||||||
|
// pindex->phashBlock can be null if called by CreateNewBlock/TestBlockValidity
|
||||||
|
assert((pindex->phashBlock == NULL) ||
|
||||||
|
(*pindex->phashBlock == block.GetHash()));
|
||||||
int64_t nTimeStart = GetTimeMicros();
|
int64_t nTimeStart = GetTimeMicros();
|
||||||
|
|
||||||
// Check it again in case a previous version let a bad block in
|
// Check it again in case a previous version let a bad block in
|
||||||
|
@ -2948,7 +2951,8 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
|
||||||
|
|
||||||
bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev, int64_t nAdjustedTime)
|
bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev, int64_t nAdjustedTime)
|
||||||
{
|
{
|
||||||
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1;
|
assert(pindexPrev != NULL);
|
||||||
|
const int nHeight = pindexPrev->nHeight + 1;
|
||||||
// Check proof of work
|
// Check proof of work
|
||||||
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
|
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
|
||||||
return state.DoS(100, false, REJECT_INVALID, "bad-diffbits", false, "incorrect proof of work");
|
return state.DoS(100, false, REJECT_INVALID, "bad-diffbits", false, "incorrect proof of work");
|
||||||
|
|
Loading…
Add table
Reference in a new issue