Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.h
// 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. | ||||
#ifndef BITCOIN_AVALANCHE_H | #ifndef BITCOIN_AVALANCHE_H | ||||
#define BITCOIN_AVALANCHE_H | #define BITCOIN_AVALANCHE_H | ||||
#include "net.h" // for NodeId | #include "net.h" // for NodeId | ||||
#include "protocol.h" // for CInv | #include "protocol.h" // for CInv | ||||
#include "rwcollection.h" | #include "rwcollection.h" | ||||
#include "serialize.h" | #include "serialize.h" | ||||
#include "uint256.h" | #include "uint256.h" | ||||
#include <atomic> | |||||
#include <condition_variable> | |||||
#include <cstdint> | #include <cstdint> | ||||
#include <vector> | #include <vector> | ||||
class Config; | class Config; | ||||
class CBlockIndex; | class CBlockIndex; | ||||
class CScheduler; | class CScheduler; | ||||
namespace { | namespace { | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | |||||
class AvalancheProcessor { | class AvalancheProcessor { | ||||
private: | private: | ||||
/** | /** | ||||
* Blocks to run avalanche on. | * Blocks to run avalanche on. | ||||
*/ | */ | ||||
RWCollection<std::map<const CBlockIndex *, VoteRecord>> vote_records; | RWCollection<std::map<const CBlockIndex *, VoteRecord>> vote_records; | ||||
/** | |||||
* Start stop machinery. | |||||
*/ | |||||
std::atomic<bool> stopRequest; | |||||
bool running GUARDED_BY(cs_running); | |||||
CWaitableCriticalSection cs_running; | |||||
std::condition_variable cond_running; | |||||
public: | public: | ||||
AvalancheProcessor() {} | AvalancheProcessor() : stopRequest(false), running(false) {} | ||||
~AvalancheProcessor() { stopEventLoop(); } | |||||
bool addBlockToReconcile(const CBlockIndex *pindex); | bool addBlockToReconcile(const CBlockIndex *pindex); | ||||
bool isAccepted(const CBlockIndex *pindex) const; | bool isAccepted(const CBlockIndex *pindex) const; | ||||
bool hasFinalized(const CBlockIndex *pindex) const; | bool hasFinalized(const CBlockIndex *pindex) const; | ||||
bool registerVotes(const AvalancheResponse &response); | bool registerVotes(const AvalancheResponse &response); | ||||
bool startEventLoop(CScheduler &scheduler); | |||||
bool stopEventLoop(); | |||||
}; | }; | ||||
#endif // BITCOIN_AVALANCHE_H | #endif // BITCOIN_AVALANCHE_H |