Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.h
Show First 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | public: | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(invs); | READWRITE(invs); | ||||
} | } | ||||
}; | }; | ||||
class AvalancheProcessor { | class AvalancheProcessor { | ||||
private: | private: | ||||
CConnman *connman; | |||||
/** | /** | ||||
* Blocks to run avalanche on. | * Blocks to run avalanche on. | ||||
*/ | */ | ||||
RWCollection<std::map<uint256, VoteRecord>> vote_records; | RWCollection<std::map<uint256, VoteRecord>> vote_records; | ||||
/** | /** | ||||
* Keep track of peers and queries sent. | |||||
*/ | |||||
struct RequestRecord { | |||||
private: | |||||
int64_t timestamp; | |||||
std::vector<CInv> invs; | |||||
public: | |||||
RequestRecord() : timestamp(0), invs() {} | |||||
RequestRecord(int64_t timestampIn, std::vector<CInv> invIn) | |||||
: timestamp(timestampIn), invs(std::move(invIn)) {} | |||||
int64_t GetTimestamp() const { return timestamp; } | |||||
const std::vector<CInv> &GetInvs() const { return invs; } | |||||
}; | |||||
RWCollection<std::set<NodeId>> nodeids; | |||||
RWCollection<std::map<NodeId, RequestRecord>> queries; | |||||
/** | |||||
* Start stop machinery. | * Start stop machinery. | ||||
*/ | */ | ||||
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() : stopRequest(false), running(false) {} | AvalancheProcessor(CConnman *connmanIn) | ||||
: connman(connmanIn), stopRequest(false), running(false) {} | |||||
~AvalancheProcessor() { stopEventLoop(); } | ~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 registerVotes(const AvalancheResponse &response, | bool registerVotes(NodeId nodeid, const AvalancheResponse &response, | ||||
std::vector<uint256> &accepted, | std::vector<uint256> &accepted, | ||||
std::vector<uint256> &rejected); | std::vector<uint256> &rejected); | ||||
bool startEventLoop(CScheduler &scheduler); | bool startEventLoop(CScheduler &scheduler); | ||||
bool stopEventLoop(); | bool stopEventLoop(); | ||||
private: | private: | ||||
void runEventLoop(); | void runEventLoop(); | ||||
std::vector<CInv> getInvsForNextPoll() const; | std::vector<CInv> getInvsForNextPoll() const; | ||||
NodeId getSuitableNodeToQuery(); | |||||
friend struct AvalancheTest; | friend struct AvalancheTest; | ||||
}; | }; | ||||
#endif // BITCOIN_AVALANCHE_H | #endif // BITCOIN_AVALANCHE_H |