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

Method GenBlockStake

src/stake.cpp:1354–1415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1352}
1353
1354bool Stake::GenBlockStake(CWallet* wallet, unsigned int& extra) {
1355 CBlockIndex* tip = nullptr;
1356 {
1357 LOCK(cs_main);
1358 tip = chainActive.Tip();
1359 }
1360
1361 std::unique_ptr <CBlockTemplate> blocktemplate(BlockAssembler(Params()).CreateNewStake(true, true));
1362 if (!blocktemplate) {
1363 return false; // No stake available.
1364 }
1365
1366 CBlock* const block = &blocktemplate->block;
1367 if (!block->IsProofOfStake()) {
1368 return error("%s: Created non-staked block:\n%s", __func__, block->ToString());
1369 }
1370
1371 IncrementExtraNonce(block, tip, extra);
1372
1373 if (!block->SignBlock(*wallet)) {
1374 return error("%s: Cant sign new block.", __func__);
1375 }
1376
1377 {
1378 LOCK(stakeMiner.lock);
1379 stakeMiner.nBlocksCreated++;
1380 }
1381
1382 SetThreadPriority(THREAD_PRIORITY_NORMAL);
1383
1384 int TheHeight;
1385 {
1386 LOCK(cs_main);
1387 CBlockIndex* pindexPrev = LookupBlockIndex(block->hashPrevBlock);
1388 TheHeight = pindexPrev ? pindexPrev->nHeight + 1 : 0;
1389 }
1390
1391 bool result = true;
1392 uint256 proof1, proof2;
1393 auto hash = block->GetHash(TheHeight);
1394 auto good = CheckProof(tip, *block, proof1);
1395
1396#if defined(DEBUG_DUMP_STAKE_CHECK) && defined(DEBUG_DUMP_STAKING_INFO)
1397 DEBUG_DUMP_STAKE_CHECK();
1398#endif
1399 if (good) {
1400#if defined(DEBUG_DUMP_STAKE_FOUND) && defined(DEBUG_DUMP_STAKING_INFO)
1401 DEBUG_DUMP_STAKE_FOUND();
1402#endif
1403 LogPrintf("%s: found stake %s, block %s\n%s\n", __func__,
1404 proof1.GetHex(), hash.GetHex(), block->ToString());
1405 ProcessBlockFound(block, *wallet);
1406 } else if (!GetProof(hash, proof2)) {
1407 SetProof(hash, proof1);
1408 } else if (proof1 != proof2) {
1409 result = error("%s: diverged stake %s, %s (block %s)", __func__,
1410 proof1.GetHex(), proof2.GetHex(), hash.GetHex());
1411 }

Callers

nothing calls this directly

Calls 15

BlockAssemblerClass · 0.85
errorFunction · 0.85
IncrementExtraNonceFunction · 0.85
SetThreadPriorityFunction · 0.85
LookupBlockIndexFunction · 0.85
CheckProofFunction · 0.85
ProcessBlockFoundFunction · 0.85
TipMethod · 0.80
CreateNewStakeMethod · 0.80
SignBlockMethod · 0.80
ParamsClass · 0.70
IsProofOfStakeMethod · 0.45

Tested by

no test coverage detected