Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.cpp
// Copyright (c) 2018 The Bitcoin developers | // Copyright (c) 2018 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "avalanche.h" | #include "avalanche.h" | ||||
#include "chain.h" | #include "chain.h" | ||||
#include "config/bitcoin-config.h" | #include "config/bitcoin-config.h" | ||||
#include "netmessagemaker.h" | #include "netmessagemaker.h" | ||||
#include "reverse_iterator.h" | #include "reverse_iterator.h" | ||||
#include "scheduler.h" | #include "scheduler.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
#include <tuple> | #include <tuple> | ||||
/** | |||||
* Run the avalanche event loop every 10ms. | |||||
*/ | |||||
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; | |||||
static uint32_t countBits(uint32_t v) { | static uint32_t countBits(uint32_t v) { | ||||
#if HAVE_DECL___BUILTIN_POPCOUNT | #if HAVE_DECL___BUILTIN_POPCOUNT | ||||
return __builtin_popcount(v); | return __builtin_popcount(v); | ||||
#else | #else | ||||
/** | /** | ||||
* Computes the number of bits set in each group of 8bits then uses a | * Computes the number of bits set in each group of 8bits then uses a | ||||
* multiplication to sum all of them in the 8 most significant bits and | * multiplication to sum all of them in the 8 most significant bits and | ||||
* return these. | * return these. | ||||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
bool AvalancheProcessor::addPeer(NodeId nodeid, int64_t score) { | bool AvalancheProcessor::addPeer(NodeId nodeid, int64_t score) { | ||||
return peerSet.getWriteView() | return peerSet.getWriteView() | ||||
->insert({nodeid, score, std::chrono::steady_clock::now()}) | ->insert({nodeid, score, std::chrono::steady_clock::now()}) | ||||
.second; | .second; | ||||
} | } | ||||
namespace { | |||||
/** | |||||
* Run the avalanche event loop every 10ms. | |||||
*/ | |||||
static int64_t AVALANCHE_TIME_STEP_MILLISECONDS = 10; | |||||
/** | |||||
* Maximum item count 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; | ||||
} | } | ||||
running = true; | running = true; | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |