MCPcopy Create free account
hub / github.com/LUX-Core/lux / AcceptBlockHeader

Function AcceptBlockHeader

src/main.cpp:4775–4822  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4773}
4774
4775bool 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
4824bool AcceptBlock(const CBlock& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, CDiskBlockPos* dbp)
4825{

Callers 2

AcceptBlockFunction · 0.85
ProcessMessageFunction · 0.85

Calls 12

LookupBlockIndexFunction · 0.85
errorFunction · 0.85
CheckBlockHeaderFunction · 0.85
FormatStateMessageFunction · 0.85
AddToBlockIndexFunction · 0.85
DoSMethod · 0.80
ParamsClass · 0.70
GetHashMethod · 0.45
GetHexMethod · 0.45
IsProofOfWorkMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected