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

Function ProcessNewBlock

src/main.cpp:4992–5102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4990}
4991
4992bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, CDiskBlockPos* dbp)
4993{
4994 // printf("function %s\n",__func__);
4995 int nHeight = chainActive.Height() + 1;
4996 bool alreadyAccepted = false;
4997
4998 // Do not accept the peers having older versions when the fork happens
4999 if (nHeight >= nLuxProtocolSwitchHeight)
5000 {
5001 SCVersion = WORKING_VERSION;
5002 }
5003
5004 // Reject the block from older version
5005 if (pfrom && pfrom->strSubVer.compare(SCVersion) < 0)
5006 return error("%s: Invalid block %d, wrong chain ver %s", __func__, nHeight, pfrom->strSubVer.c_str());
5007
5008 // Preliminary checks
5009 if (!CheckBlock(*pblock, state, chainparams.GetConsensus()))
5010 return error("%s: block not passing checks", __func__);
5011
5012 // printf("function 1 %s\n",__func__);
5013
5014 // Check proof-of-stake block signature
5015 if (!pblock->CheckBlockSignature())
5016 return state.DoS(100, false, REJECT_INVALID, "bad-blk-sign", false, "bad block signature");
5017
5018 // Limited duplicity on stake: prevents block flood attack
5019 // Duplicate stake allowed only when there is orphan child block
5020 if (pblock->IsProofOfStake() && stake->IsBlockStaked(pblock) && !mapBlockIndex.count(pblock->hashPrevBlock))
5021 return error("%s: duplicate proof-of-stake for block %s", __func__, pblock->GetHash().GetHex());
5022
5023 // Check if the prev block is our prev block, if not then request sync and return false
5024 else if (pblock->GetHash() != chainparams.GetConsensus().hashGenesisBlock && pfrom != NULL) {
5025 CBlockIndex* pindexPrev = LookupBlockIndex(pblock->hashPrevBlock);
5026 if (!pindexPrev) {
5027 pfrom->PushMessage("wtf getblocks", chainActive.GetLocator(), uint256(0));
5028 return false;
5029 } else {
5030 nHeight = pindexPrev->nHeight + 1;
5031 alreadyAccepted = (LookupBlockIndex(pblock->GetHash(nHeight)) != nullptr);
5032 }
5033 }
5034 // printf("function 2 %s\n",__func__);
5035 // Reject all blocks from old chain forks
5036 if (nHeight > SNAPSHOT_BLOCK && pblock->nTime < SNAPSHOT_VALID_TIME) {
5037 return error("%s: Invalid block %d, time too old (%x) for %s",
5038 __func__, nHeight, pblock->nTime, pblock->GetHash().GetHex());
5039 }
5040
5041 CBlockIndex* pindex = NULL;
5042 while (true) {
5043 TRY_LOCK(cs_main, lockMain);
5044 if (!lockMain) {
5045 MilliSleep(50);
5046 continue;
5047 }
5048 // printf("function 3 %s\n",__func__);
5049

Callers 8

generateBlocksFunction · 0.85
ProcessBlockFoundFunction · 0.85
getworkFunction · 0.85
submitblockFunction · 0.85
LoadBlockIndexDBFunction · 0.85
LoadExternalBlockFileFunction · 0.85
ProcessMessageFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 15

errorFunction · 0.85
LookupBlockIndexFunction · 0.85
MilliSleepFunction · 0.85
MarkBlockAsReceivedFunction · 0.85
AcceptBlockFunction · 0.85
CheckBlockIndexFunction · 0.85
ActivateBestChainFunction · 0.85
HeightMethod · 0.80
CheckBlockSignatureMethod · 0.80
DoSMethod · 0.80
IsBlockStakedMethod · 0.80
PushMessageMethod · 0.80

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68