Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.cpp
Show All 9 Lines | |||||
#include "validation.h" | #include "validation.h" | ||||
bool AvalancheProcessor::addBlockToReconcile(const CBlockIndex *pindex) { | bool AvalancheProcessor::addBlockToReconcile(const CBlockIndex *pindex) { | ||||
return vote_records.getWriteView() | return vote_records.getWriteView() | ||||
->insert(std::make_pair(pindex, VoteRecord())) | ->insert(std::make_pair(pindex, VoteRecord())) | ||||
.second; | .second; | ||||
} | } | ||||
static const VoteRecord *GetRecord( | static const VoteRecord * | ||||
const RWCollection<std::map<const CBlockIndex *, VoteRecord>> &vote_records, | GetRecord(const RWCollection<BlockVoteMap> &vote_records, | ||||
const CBlockIndex *pindex) { | const CBlockIndex *pindex) { | ||||
auto r = vote_records.getReadView(); | auto r = vote_records.getReadView(); | ||||
auto it = r->find(pindex); | auto it = r->find(pindex); | ||||
if (it == r.end()) { | if (it == r.end()) { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
return &it->second; | return &it->second; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | bool AvalancheProcessor::registerVotes(const AvalancheResponse &response) { | ||||
return true; | return true; | ||||
} | } | ||||
namespace { | namespace { | ||||
/** | /** | ||||
* Run the avalanche event loop every 10ms. | * Run the avalanche event loop every 10ms. | ||||
*/ | */ | ||||
static int64_t AVALANCHE_TIME_STEP_MILLISECONDS = 10; | static int64_t AVALANCHE_TIME_STEP_MILLISECONDS = 10; | ||||
/** | |||||
* Maximum item that can be polled at once. | |||||
*/ | |||||
static size_t AVALANCHE_MAX_ELEMENT_POLL = 4096; | |||||
} | } | ||||
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<const CBlockIndex *, 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->GetBlockHash())); | |||||
if (invs.size() >= AVALANCHE_MAX_ELEMENT_POLL) { | |||||
// Make sure we do not produce more invs than specified by the | |||||
// protocol. | |||||
return invs; | |||||
} | |||||
} | |||||
return invs; | |||||
} |