| 4773 | } |
| 4774 | |
| 4775 | bool AcceptBlockHeader(const CBlock& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex) |
| 4776 | { |
| 4777 | AssertLockHeld(cs_main); |
| 4778 | |
| 4779 | // Get prev block index (or not and check for duplicate) |
| 4780 | CBlockIndex* pindexPrev = LookupBlockIndex(block.hashPrevBlock); |
| 4781 | uint256 hash; |
| 4782 | if (!pindexPrev) { |
| 4783 | if (block.GetHash() != Params().GenesisBlock().GetHash()) |
| 4784 | return state.DoS(0, error("%s : prev block %s not found", __func__, block.hashPrevBlock.GetHex()), 0, "bad-prevblk"); |
| 4785 | // Check for duplicate |
| 4786 | hash = block.GetHash(); |
| 4787 | } else |
| 4788 | { |
| 4789 | // Check for duplicate |
| 4790 | hash = block.GetHash(pindexPrev->nHeight + 1); |
| 4791 | } |
| 4792 | |
| 4793 | |
| 4794 | |
| 4795 | CBlockIndex* pindex = LookupBlockIndex(hash); |
| 4796 | |
| 4797 | // TODO : ENABLE BLOCK CACHE IN SPECIFIC CASES |
| 4798 | if (pindex) { |
| 4799 | // Block header is already known. |
| 4800 | if (ppindex) |
| 4801 | *ppindex = pindex; |
| 4802 | // if (pindex->nStatus & BLOCK_FAILED_MASK) |
| 4803 | // return state.Invalid(error("%s : block is marked invalid", __func__), 0, "duplicate"); |
| 4804 | return true; |
| 4805 | } |
| 4806 | |
| 4807 | if (!CheckBlockHeader(block, state, chainparams.GetConsensus(), block.IsProofOfWork())) { |
| 4808 | LogPrintf("%s: CheckBlockHeader failed \n", __func__); |
| 4809 | return error("%s: Consensus::CheckBlockHeader: %s, %s", __func__, hash.ToString(), FormatStateMessage(state)); |
| 4810 | } |
| 4811 | |
| 4812 | if (!ContextualCheckBlockHeader(block, state, chainparams.GetConsensus(), pindexPrev)) |
| 4813 | return error("%s: Consensus::ContextualCheckBlockHeader: %s, %s", __func__, hash.ToString(), FormatStateMessage(state)); |
| 4814 | |
| 4815 | if (pindex == NULL) |
| 4816 | pindex = AddToBlockIndex(block); |
| 4817 | |
| 4818 | if (ppindex) |
| 4819 | *ppindex = pindex; |
| 4820 | |
| 4821 | return true; |
| 4822 | } |
| 4823 | |
| 4824 | bool AcceptBlock(const CBlock& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, CDiskBlockPos* dbp) |
| 4825 | { |
no test coverage detected