Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | bool AvalancheProcessor::registerVotes(const AvalancheResponse &response) { | ||||
// Register votes. | // Register votes. | ||||
auto w = vote_records.getWriteView(); | auto w = vote_records.getWriteView(); | ||||
for (auto &v : votes) { | for (auto &v : votes) { | ||||
w[v.GetHash()].registerVote(v.IsValid()); | w[v.GetHash()].registerVote(v.IsValid()); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
namespace { | |||||
/** | |||||
* Run the avalanche event loop every 20ms. | |||||
*/ | |||||
static int64_t AVALANCHE_TIME_STEP_MILISECONDS = 10; | |||||
jasonbcox: MILISECONDS -> MILLISECONDS
Comment says every 20ms, so this should be `20` not `10` (or just… | |||||
} | |||||
bool AvalancheProcessor::startEventLoop(CScheduler &scheduler) { | |||||
LOCK(cs_running); | |||||
if (running) { | |||||
// Do not start the event loop twice. | |||||
return false; | |||||
} | |||||
running = true; | |||||
// Start the event loop. | |||||
scheduler.scheduleEvery( | |||||
[this]() -> bool { | |||||
if (!stopRequest) { | |||||
jasonbcoxUnsubmitted Not Done Inline ActionsThis statement can be more concise: if (stopRequest) { // A stop request was made. LOCK(cs_running); running = false; cond_running.notify_all(); } return running; jasonbcox: This statement can be more concise:
```
if (stopRequest) {
// A stop request was made. | |||||
deadalnixAuthorUnsubmitted Done Inline ActionsMore concise and also incorrect. deadalnix: More concise and also incorrect. | |||||
return true; | |||||
} | |||||
LOCK(cs_running); | |||||
running = false; | |||||
cond_running.notify_all(); | |||||
// A stop request was made. | |||||
return false; | |||||
}, | |||||
AVALANCHE_TIME_STEP_MILISECONDS); | |||||
return true; | |||||
} | |||||
bool AvalancheProcessor::stopEventLoop() { | |||||
WAIT_LOCK(cs_running, lock); | |||||
if (!running) { | |||||
return false; | |||||
} | |||||
// Request avalanche to stop. | |||||
stopRequest = true; | |||||
// Wait for avalanche to stop. | |||||
cond_running.wait(lock, [this] { return !running; }); | |||||
stopRequest = false; | |||||
return true; | |||||
} |
MILISECONDS -> MILLISECONDS
Comment says every 20ms, so this should be 20 not 10 (or just fix the comment).