diff options
| author | Wladimir J. van der Laan <[email protected]> | 2017-02-16 10:22:17 +0100 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2017-02-16 10:23:41 +0100 |
| commit | 1e92e041ddc8232bcf64f09fd70891b80ac05c66 (patch) | |
| tree | be67cb270126a6fa21ff7f542ebc5afb6b1f194a /src/validation.cpp | |
| parent | Merge #9756: Return error when importmulti called with invalid address. (diff) | |
| parent | Harden against mistakes handling invalid blocks (diff) | |
| download | discoin-1e92e041ddc8232bcf64f09fd70891b80ac05c66.tar.xz discoin-1e92e041ddc8232bcf64f09fd70891b80ac05c66.zip | |
Merge #9765: Harden against mistakes handling invalid blocks
ba803ef Harden against mistakes handling invalid blocks (Suhas Daftuar)
Diffstat (limited to 'src/validation.cpp')
| -rw-r--r-- | src/validation.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index fe8f8365b..4ce0723b2 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3187,7 +3187,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation } if (fNewBlock) *fNewBlock = true; - if (!CheckBlock(block, state, chainparams.GetConsensus(), GetAdjustedTime()) || + if (!CheckBlock(block, state, chainparams.GetConsensus()) || !ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindex->pprev)) { if (state.IsInvalid() && !state.CorruptionPossible()) { pindex->nStatus |= BLOCK_FAILED_VALID; @@ -3229,13 +3229,19 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool *fNewBlock) { { - LOCK(cs_main); - - // Store to disk CBlockIndex *pindex = NULL; if (fNewBlock) *fNewBlock = false; CValidationState state; - bool ret = AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, NULL, fNewBlock); + // Ensure that CheckBlock() passes before calling AcceptBlock, as + // belt-and-suspenders. + bool ret = CheckBlock(*pblock, state, chainparams.GetConsensus()); + + LOCK(cs_main); + + if (ret) { + // Store to disk + ret = AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, NULL, fNewBlock); + } CheckBlockIndex(chainparams.GetConsensus()); if (!ret) { GetMainSignals().BlockChecked(*pblock, state); |