Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.cpp
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | bool AvalancheProcessor::registerVotes(const AvalancheResponse &response) { | ||||
return true; | return true; | ||||
} | } | ||||
namespace { | namespace { | ||||
/** | /** | ||||
* Run the avalanche event loop every 20ms. | * Run the avalanche event loop every 20ms. | ||||
*/ | */ | ||||
static int64_t AVALANCHE_TIME_STEP_MILISECONDS = 10; | static int64_t AVALANCHE_TIME_STEP_MILISECONDS = 10; | ||||
/** | |||||
* Maximum item that can be polled at once. | |||||
*/ | |||||
static size_t AVALANCHE_MAX_ELEMENT_POLL = 4096; | |||||
jasonbcox: Does this need a static_assert() to ensure it's strictly less than MAX_INV_SZ? | |||||
jasonbcoxUnsubmitted Not Done Inline ActionsThe more I look at the other changes, the more important I think this is. Either strictly less than MAX_INV_SZ or dependent on MAX_PROTOCOL_MESSAGE_LENGTH in some way. jasonbcox: The more I look at the other changes, the more important I think this is. Either strictly less… | |||||
deadalnixAuthorUnsubmitted Done Inline ActionsNo. This is fast protocol, we want a low limit. deadalnix: No. This is fast protocol, we want a low limit. | |||||
jasonbcoxUnsubmitted Not Done Inline ActionsOk, as long as we expect it to always be way lower. jasonbcox: Ok, as long as we expect it to always be way lower. | |||||
} | } | ||||
bool AvalancheProcessor::startEventLoop(CScheduler &scheduler) { | bool AvalancheProcessor::startEventLoop(CScheduler &scheduler) { | ||||
LOCK(cs_running); | LOCK(cs_running); | ||||
if (running) { | if (running) { | ||||
// Do not start the event loop twice. | // Do not start the event loop twice. | ||||
return false; | return false; | ||||
} | } | ||||
Show All 30 Lines | bool AvalancheProcessor::stopEventLoop() { | ||||
stopRequest = true; | stopRequest = true; | ||||
// Wait for avalanche to stop. | // Wait for avalanche to stop. | ||||
cond_running.wait(lock, [this] { return !running; }); | cond_running.wait(lock, [this] { return !running; }); | ||||
stopRequest = false; | stopRequest = false; | ||||
return true; | return true; | ||||
} | } | ||||
std::vector<CInv> AvalancheProcessor::getInvsForNextPoll() const { | |||||
std::vector<CInv> invs; | |||||
auto r = vote_records.getReadView(); | |||||
for (const std::pair<uint256, VoteRecord> &p : r) { | |||||
const VoteRecord &v = p.second; | |||||
if (v.hasFinalized()) { | |||||
// If this has finalized, we can just skip. | |||||
continue; | |||||
} | |||||
// We don't have a decision, we need more votes. | |||||
invs.push_back(CInv(MSG_BLOCK, p.first)); | |||||
if (invs.size() >= AVALANCHE_MAX_ELEMENT_POLL) { | |||||
// Make sure we do not produce more invs than specified by the | |||||
// protocol. | |||||
return invs; | |||||
} | |||||
} | |||||
return invs; | |||||
} | |||||
void AvalancheProcessor::runEventLoop() { | |||||
std::vector<CInv> invs = getInvsForNextPoll(); | |||||
} |
Does this need a static_assert() to ensure it's strictly less than MAX_INV_SZ?