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

Method StakingThread

src/stake.cpp:1417–1484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1415}
1416
1417void Stake::StakingThread(CWallet* wallet) {
1418 LogPrintf("staking thread started!\n");
1419
1420 SetThreadPriority(THREAD_PRIORITY_LOWEST);
1421
1422 try {
1423 int nHeight = 0;
1424 (void) nHeight;
1425 unsigned int extra = 0;
1426 while (!nStakingInterrupped && !ShutdownRequested()) {
1427 std::size_t nNodes = 0;
1428 bool nCanStake = !IsInitialBlockDownload();
1429
1430 boost::this_thread::interruption_point();
1431
1432 if (nCanStake) {
1433 LOCK(cs_vNodes); // Lock nodes for security.
1434 if ((nNodes = vNodes.size()) == 0) {
1435 nCanStake = false;
1436 }
1437 }
1438
1439 const CBlockIndex* tip = nullptr;
1440 if (nCanStake) {
1441 while (wallet->IsLocked() || nReserveBalance >= wallet->GetBalance()) {
1442 if (!nStakingInterrupped && !ShutdownRequested()) {
1443 nStakeInterval = 0;
1444 MilliSleep(3000);
1445 continue;
1446 } else {
1447 nCanStake = false;
1448 break;
1449 }
1450 }
1451
1452 if (nCanStake) {
1453 LOCK(cs_main);
1454 tip = chainActive.Tip();
1455 nHeight = tip->nHeight;
1456 if (/*tip->nHeight < Params().LAST_POW_BLOCK() ||*/ IsBlockStaked(tip->nHeight)) {
1457 nCanStake = false;
1458 }
1459 }
1460 } else {
1461 // Give a break to avoid interrupting other jobs too much (e.g. syncing)
1462 MilliSleep(3000);
1463 continue;
1464 }
1465
1466#if defined(DEBUG_DUMP_STAKING_THREAD) && defined(DEBUG_DUMP_STAKING_INFO)
1467 DEBUG_DUMP_STAKING_THREAD();
1468#endif
1469 boost::this_thread::interruption_point();
1470
1471 if (nCanStake && GenBlockStake(wallet, extra)) {
1472 MilliSleep(1500);
1473 } else {
1474 MilliSleep(1000);

Callers

nothing calls this directly

Calls 8

SetThreadPriorityFunction · 0.85
IsInitialBlockDownloadFunction · 0.85
MilliSleepFunction · 0.85
IsLockedMethod · 0.80
TipMethod · 0.80
ShutdownRequestedFunction · 0.70
sizeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected