Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.h
Show First 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | |||||
using BlockVoteMap = | using BlockVoteMap = | ||||
std::map<const CBlockIndex *, VoteRecord, CBlockIndexWorkComparator>; | std::map<const CBlockIndex *, VoteRecord, CBlockIndexWorkComparator>; | ||||
struct next_request_time {}; | struct next_request_time {}; | ||||
struct query_timeout {}; | struct query_timeout {}; | ||||
class AvalancheProcessor { | class AvalancheProcessor { | ||||
public: | |||||
using TimePoint = std::chrono::time_point<std::chrono::steady_clock>; | |||||
struct Node { | |||||
NodeId nodeid; | |||||
int64_t score; | |||||
TimePoint nextRequestTime; | |||||
CPubKey pubkey; | |||||
}; | |||||
private: | private: | ||||
CConnman *connman; | CConnman *connman; | ||||
std::chrono::milliseconds queryTimeoutDuration; | 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. | ||||
*/ | */ | ||||
std::atomic<uint64_t> round; | std::atomic<uint64_t> round; | ||||
using TimePoint = std::chrono::time_point<std::chrono::steady_clock>; | |||||
struct Peer { | |||||
NodeId nodeid; | |||||
int64_t score; | |||||
TimePoint nextRequestTime; | |||||
CPubKey pubkey; | |||||
}; | |||||
using PeerSet = boost::multi_index_container< | using PeerSet = boost::multi_index_container< | ||||
Peer, boost::multi_index::indexed_by< | Node, boost::multi_index::indexed_by< | ||||
// index by nodeid | // index by nodeid | ||||
boost::multi_index::hashed_unique< | boost::multi_index::hashed_unique< | ||||
boost::multi_index::member<Peer, NodeId, &Peer::nodeid>>, | boost::multi_index::member<Node, NodeId, &Node::nodeid>>, | ||||
// sorted by nextRequestTime | // sorted by nextRequestTime | ||||
boost::multi_index::ordered_non_unique< | boost::multi_index::ordered_non_unique< | ||||
boost::multi_index::tag<next_request_time>, | boost::multi_index::tag<next_request_time>, | ||||
boost::multi_index::member<Peer, TimePoint, | boost::multi_index::member<Node, TimePoint, | ||||
&Peer::nextRequestTime>>>>; | &Node::nextRequestTime>>>>; | ||||
RWCollection<PeerSet> peerSet; | RWCollection<PeerSet> peerSet; | ||||
struct Query { | struct Query { | ||||
NodeId nodeid; | NodeId nodeid; | ||||
uint64_t round; | uint64_t round; | ||||
TimePoint timeout; | TimePoint timeout; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public: | ||||
int getConfidence(const CBlockIndex *pindex) const; | int getConfidence(const CBlockIndex *pindex) const; | ||||
// TDOD: Refactor the API to remove the dependency on avalanche/protocol.h | // TDOD: Refactor the API to remove the dependency on avalanche/protocol.h | ||||
void sendResponse(CNode *pfrom, AvalancheResponse response) const; | void sendResponse(CNode *pfrom, AvalancheResponse response) 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, int64_t score, CPubKey pubkey); | bool addPeer(NodeId nodeid, int64_t score, CPubKey pubkey); | ||||
CPubKey getPubKey(NodeId nodeid) const; | bool forNode(NodeId nodeid, std::function<bool(const Node &n)> func) const; | ||||
CPubKey getSessionPubKey() const { return sessionKey.GetPubKey(); } | CPubKey getSessionPubKey() const { return sessionKey.GetPubKey(); } | ||||
bool startEventLoop(CScheduler &scheduler); | bool startEventLoop(CScheduler &scheduler); | ||||
bool stopEventLoop(); | bool stopEventLoop(); | ||||
private: | private: | ||||
void runEventLoop(); | void runEventLoop(); | ||||
Show All 13 Lines |