Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show All 11 Lines | |||||
#include <validation.h> | #include <validation.h> | ||||
#include <chrono> | #include <chrono> | ||||
#include <tuple> | #include <tuple> | ||||
/** | /** | ||||
* Run the avalanche event loop every 10ms. | * Run the avalanche event loop every 10ms. | ||||
*/ | */ | ||||
static constexpr std::chrono::milliseconds AVALANCHE_TIME_STEP_MILLISECONDS{10}; | static constexpr std::chrono::milliseconds AVALANCHE_TIME_STEP{10}; | ||||
// Unfortunately, the bitcoind codebase is full of global and we are kinda | // Unfortunately, the bitcoind codebase is full of global and we are kinda | ||||
// forced into it here. | // forced into it here. | ||||
std::unique_ptr<AvalancheProcessor> g_avalanche; | std::unique_ptr<AvalancheProcessor> g_avalanche; | ||||
bool VoteRecord::registerVote(NodeId nodeid, uint32_t error) { | bool VoteRecord::registerVote(NodeId nodeid, uint32_t error) { | ||||
// We just got a new vote, so there is one less inflight request. | // We just got a new vote, so there is one less inflight request. | ||||
clearInflightRequest(); | clearInflightRequest(); | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | if (IsBlockFinalized(pindex)) { | ||||
// There is no point polling finalized block. | // There is no point polling finalized block. | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
AvalancheProcessor::AvalancheProcessor(CConnman *connmanIn) | AvalancheProcessor::AvalancheProcessor(CConnman *connmanIn) | ||||
: connman(connmanIn), | : connman(connmanIn), queryTimeoutDuration(AVALANCHE_DEFAULT_QUERY_TIMEOUT), | ||||
queryTimeoutDuration( | |||||
AVALANCHE_DEFAULT_QUERY_TIMEOUT_DURATION_MILLISECONDS), | |||||
round(0) { | round(0) { | ||||
// Pick a random key for the session. | // Pick a random key for the session. | ||||
sessionKey.MakeNewKey(true); | sessionKey.MakeNewKey(true); | ||||
} | } | ||||
AvalancheProcessor::~AvalancheProcessor() { | AvalancheProcessor::~AvalancheProcessor() { | ||||
stopEventLoop(); | stopEventLoop(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Lines | if (it == r->end()) { | ||||
return CPubKey(); | return CPubKey(); | ||||
} | } | ||||
return it->pubkey; | return it->pubkey; | ||||
} | } | ||||
bool AvalancheProcessor::startEventLoop(CScheduler &scheduler) { | bool AvalancheProcessor::startEventLoop(CScheduler &scheduler) { | ||||
return eventLoop.startEventLoop( | return eventLoop.startEventLoop( | ||||
scheduler, [this]() { this->runEventLoop(); }, | scheduler, [this]() { this->runEventLoop(); }, AVALANCHE_TIME_STEP); | ||||
AVALANCHE_TIME_STEP_MILLISECONDS); | |||||
} | } | ||||
bool AvalancheProcessor::stopEventLoop() { | bool AvalancheProcessor::stopEventLoop() { | ||||
return eventLoop.stopEventLoop(); | return eventLoop.stopEventLoop(); | ||||
} | } | ||||
std::vector<CInv> AvalancheProcessor::getInvsForNextPoll(bool forPoll) { | std::vector<CInv> AvalancheProcessor::getInvsForNextPoll(bool forPoll) { | ||||
std::vector<CInv> invs; | std::vector<CInv> invs; | ||||
▲ Show 20 Lines • Show All 162 Lines • Show Last 20 Lines |