Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.h
Show All 28 Lines | |||||
class CScheduler; | class CScheduler; | ||||
namespace { | namespace { | ||||
/** | /** | ||||
* Finalization score. | * Finalization score. | ||||
*/ | */ | ||||
static int AVALANCHE_FINALIZATION_SCORE = 128; | static int AVALANCHE_FINALIZATION_SCORE = 128; | ||||
/** | /** | ||||
* How long before we consider that a query timed out. | |||||
*/ | |||||
static int AVALANCHE_DEFAULT_QUERY_TIMEOUT_DURATION_MILLISECONDS = 10000; | |||||
/** | |||||
* Special NodeId that represent no node. | * Special NodeId that represent no node. | ||||
*/ | */ | ||||
static const NodeId NO_NODE = -1; | static const NodeId NO_NODE = -1; | ||||
} | } | ||||
/** | /** | ||||
* Vote history. | * Vote history. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | typedef std::map<const CBlockIndex *, VoteRecord, CBlockIndexWorkComparator> | ||||
BlockVoteMap; | BlockVoteMap; | ||||
struct next_request_time {}; | struct next_request_time {}; | ||||
struct query_timeout {}; | struct query_timeout {}; | ||||
class AvalancheProcessor { | class AvalancheProcessor { | ||||
private: | private: | ||||
CConnman *connman; | CConnman *connman; | ||||
std::chrono::milliseconds queryTimeoutDuration; | |||||
/** | /** | ||||
* Blocks to run avalanche on. | * Blocks to run avalanche on. | ||||
*/ | */ | ||||
RWCollection<BlockVoteMap> vote_records; | RWCollection<BlockVoteMap> vote_records; | ||||
/** | /** | ||||
* Keep track of peers and queries sent. | * Keep track of peers and queries sent. | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | private: | ||||
std::atomic<bool> stopRequest; | std::atomic<bool> stopRequest; | ||||
bool running GUARDED_BY(cs_running); | bool running GUARDED_BY(cs_running); | ||||
CWaitableCriticalSection cs_running; | CWaitableCriticalSection cs_running; | ||||
std::condition_variable cond_running; | std::condition_variable cond_running; | ||||
public: | public: | ||||
AvalancheProcessor(CConnman *connmanIn) | AvalancheProcessor(CConnman *connmanIn) | ||||
: connman(connmanIn), round(0), stopRequest(false), running(false) {} | : connman(connmanIn), | ||||
queryTimeoutDuration( | |||||
AVALANCHE_DEFAULT_QUERY_TIMEOUT_DURATION_MILLISECONDS), | |||||
round(0), stopRequest(false), running(false) {} | |||||
~AvalancheProcessor() { stopEventLoop(); } | ~AvalancheProcessor() { stopEventLoop(); } | ||||
void setQueryTimeoutDuration(std::chrono::milliseconds d) { | |||||
queryTimeoutDuration = d; | |||||
} | |||||
bool addBlockToReconcile(const CBlockIndex *pindex); | bool addBlockToReconcile(const CBlockIndex *pindex); | ||||
bool isAccepted(const CBlockIndex *pindex) const; | bool isAccepted(const CBlockIndex *pindex) const; | ||||
bool registerVotes(NodeId nodeid, const AvalancheResponse &response, | bool registerVotes(NodeId nodeid, const AvalancheResponse &response, | ||||
std::vector<AvalancheBlockUpdate> &updates); | std::vector<AvalancheBlockUpdate> &updates); | ||||
bool addPeer(NodeId nodeid, uint32_t score); | bool addPeer(NodeId nodeid, uint32_t score); | ||||
Show All 12 Lines |