Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.cpp
Show All 12 Lines | |||||
#include <tuple> | #include <tuple> | ||||
/** | /** | ||||
* Run the avalanche event loop every 10ms. | * Run the avalanche event loop every 10ms. | ||||
*/ | */ | ||||
static const int64_t AVALANCHE_TIME_STEP_MILLISECONDS = 10; | static const int64_t AVALANCHE_TIME_STEP_MILLISECONDS = 10; | ||||
/** | |||||
* Maximum item count that can be polled at once. | |||||
*/ | |||||
static const size_t AVALANCHE_MAX_ELEMENT_POLL = 4096; | |||||
// 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 94 Lines • ▼ Show 20 Lines | static bool IsWorthPolling(const CBlockIndex *pindex) { | ||||
if (IsBlockFinalized(pindex)) { | 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) | |||||
: connman(connmanIn), | |||||
queryTimeoutDuration( | |||||
AVALANCHE_DEFAULT_QUERY_TIMEOUT_DURATION_MILLISECONDS), | |||||
round(0), stopRequest(false), running(false) {} | |||||
AvalancheProcessor::~AvalancheProcessor() { | |||||
stopEventLoop(); | |||||
} | |||||
bool AvalancheProcessor::addBlockToReconcile(const CBlockIndex *pindex) { | bool AvalancheProcessor::addBlockToReconcile(const CBlockIndex *pindex) { | ||||
bool isAccepted; | bool isAccepted; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (!IsWorthPolling(pindex)) { | if (!IsWorthPolling(pindex)) { | ||||
// There is no point polling this block. | // There is no point polling this block. | ||||
return false; | return false; | ||||
Show All 22 Lines | int AvalancheProcessor::getConfidence(const CBlockIndex *pindex) const { | ||||
auto it = r->find(pindex); | auto it = r->find(pindex); | ||||
if (it == r.end()) { | if (it == r.end()) { | ||||
return -1; | return -1; | ||||
} | } | ||||
return it->second.getConfidence(); | return it->second.getConfidence(); | ||||
} | } | ||||
void AvalancheProcessor::sendResponse(CNode *pfrom, | |||||
AvalancheResponse response) const { | |||||
connman->PushMessage( | |||||
pfrom, CNetMsgMaker(pfrom->GetSendVersion()) | |||||
.Make(NetMsgType::AVARESPONSE, std::move(response))); | |||||
} | |||||
bool AvalancheProcessor::registerVotes( | bool AvalancheProcessor::registerVotes( | ||||
NodeId nodeid, const AvalancheResponse &response, | NodeId nodeid, const AvalancheResponse &response, | ||||
std::vector<AvalancheBlockUpdate> &updates) { | std::vector<AvalancheBlockUpdate> &updates) { | ||||
{ | { | ||||
// Save the time at which we can query again. | // Save the time at which we can query again. | ||||
auto w = peerSet.getWriteView(); | auto w = peerSet.getWriteView(); | ||||
auto it = w->find(nodeid); | auto it = w->find(nodeid); | ||||
if (it != w->end()) { | if (it != w->end()) { | ||||
▲ Show 20 Lines • Show All 317 Lines • Show Last 20 Lines |