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 "blockindexworkcomparator.h" | #include "blockindexworkcomparator.h" | ||||
#include "net.h" | #include "net.h" | ||||
#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 <atomic> | ||||
#include <chrono> | |||||
#include <condition_variable> | #include <condition_variable> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <vector> | #include <vector> | ||||
class Config; | class Config; | ||||
class CBlockIndex; | class CBlockIndex; | ||||
class CScheduler; | class CScheduler; | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | |||||
class AvalancheResponse { | class AvalancheResponse { | ||||
uint32_t cooldown; | uint32_t cooldown; | ||||
std::vector<AvalancheVote> votes; | std::vector<AvalancheVote> votes; | ||||
public: | public: | ||||
AvalancheResponse(uint32_t cooldownIn, std::vector<AvalancheVote> votesIn) | AvalancheResponse(uint32_t cooldownIn, std::vector<AvalancheVote> votesIn) | ||||
: cooldown(cooldownIn), votes(votesIn) {} | : cooldown(cooldownIn), votes(votesIn) {} | ||||
uint32_t getCooldown() const { return cooldown; } | |||||
const std::vector<AvalancheVote> &GetVotes() const { return votes; } | const std::vector<AvalancheVote> &GetVotes() const { return votes; } | ||||
// serialization support | // serialization support | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
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(cooldown); | READWRITE(cooldown); | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public: | ||||
const CBlockIndex *getBlockIndex() const { | const CBlockIndex *getBlockIndex() const { | ||||
return const_cast<AvalancheBlockUpdate *>(this)->getBlockIndex(); | return const_cast<AvalancheBlockUpdate *>(this)->getBlockIndex(); | ||||
} | } | ||||
}; | }; | ||||
typedef std::map<const CBlockIndex *, VoteRecord, CBlockIndexWorkComparator> | typedef std::map<const CBlockIndex *, VoteRecord, CBlockIndexWorkComparator> | ||||
BlockVoteMap; | BlockVoteMap; | ||||
typedef std::map<std::chrono::time_point<std::chrono::steady_clock>, NodeId> | |||||
NodeCooldownMap; | |||||
class AvalancheProcessor { | class AvalancheProcessor { | ||||
private: | private: | ||||
CConnman *connman; | CConnman *connman; | ||||
/** | /** | ||||
* Blocks to run avalanche on. | * Blocks to run avalanche on. | ||||
*/ | */ | ||||
Show All 14 Lines | public: | ||||
int64_t GetTimestamp() const { return timestamp; } | int64_t GetTimestamp() const { return timestamp; } | ||||
const std::vector<CInv> &GetInvs() const { return invs; } | const std::vector<CInv> &GetInvs() const { return invs; } | ||||
}; | }; | ||||
std::atomic<uint32_t> round; | std::atomic<uint32_t> round; | ||||
RWCollection<std::set<NodeId>> nodeids; | RWCollection<std::set<NodeId>> nodeids; | ||||
RWCollection<std::map<NodeId, RequestRecord>> queries; | RWCollection<std::map<NodeId, RequestRecord>> queries; | ||||
RWCollection<NodeCooldownMap> nodecooldown; | |||||
/** | /** | ||||
* 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; | ||||
Show All 25 Lines |