Bitcoin ABC 0.31.0
P2P Digital Currency
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
peermanager.h
Go to the documentation of this file.
1// Copyright (c) 2020 The Bitcoin developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_AVALANCHE_PEERMANAGER_H
6#define BITCOIN_AVALANCHE_PEERMANAGER_H
7
8#include <avalanche/node.h>
9#include <avalanche/proof.h>
10#include <avalanche/proofpool.h>
13#include <coins.h>
14#include <common/bloom.h>
16#include <pubkey.h>
17#include <radix.h>
18#include <util/fs.h>
19#include <util/hasher.h>
20#include <util/time.h>
21
22#include <boost/multi_index/composite_key.hpp>
23#include <boost/multi_index/hashed_index.hpp>
24#include <boost/multi_index/mem_fun.hpp>
25#include <boost/multi_index/member.hpp>
26#include <boost/multi_index/ordered_index.hpp>
27#include <boost/multi_index_container.hpp>
28
29#include <atomic>
30#include <chrono>
31#include <cstdint>
32#include <memory>
33#include <vector>
34
36class CScheduler;
37
38namespace avalanche {
39
46static constexpr uint32_t AVALANCHE_MAX_IMMATURE_PROOFS = 4000;
47
48class Delegation;
49
50namespace {
51 struct TestPeerManager;
52}
53
54struct Slot {
55private:
56 uint64_t start;
57 uint32_t score;
59
60public:
61 Slot(uint64_t startIn, uint32_t scoreIn, PeerId peeridIn)
62 : start(startIn), score(scoreIn), peerid(peeridIn) {}
63
64 Slot withStart(uint64_t startIn) const {
65 return Slot(startIn, score, peerid);
66 }
67 Slot withScore(uint64_t scoreIn) const {
68 return Slot(start, scoreIn, peerid);
69 }
70 Slot withPeerId(PeerId peeridIn) const {
71 return Slot(start, score, peeridIn);
72 }
73
74 uint64_t getStart() const { return start; }
75 uint64_t getStop() const { return start + score; }
76 uint32_t getScore() const { return score; }
77 PeerId getPeerId() const { return peerid; }
78
79 bool contains(uint64_t slot) const {
80 return getStart() <= slot && slot < getStop();
81 }
82 bool precedes(uint64_t slot) const { return slot >= getStop(); }
83 bool follows(uint64_t slot) const { return getStart() > slot; }
84};
85
86struct Peer {
88 uint32_t index = -1;
89 uint32_t node_count = 0;
90
92 bool hasFinalized = false;
93
94 // The network stack uses timestamp in seconds, so we oblige.
95 std::chrono::seconds registration_time;
96 std::chrono::seconds nextPossibleConflictTime;
97
102 static constexpr auto DANGLING_TIMEOUT = 15min;
103
104 Peer(PeerId peerid_, ProofRef proof_,
105 std::chrono::seconds nextPossibleConflictTime_)
106 : peerid(peerid_), proof(std::move(proof_)),
107 registration_time(GetTime<std::chrono::seconds>()),
108 nextPossibleConflictTime(std::move(nextPossibleConflictTime_)) {}
109
110 const ProofId &getProofId() const { return proof->getId(); }
111 uint32_t getScore() const { return proof->getScore(); }
112};
113
116 result_type operator()(const Peer &p) const { return p.proof->getId(); }
117};
118
120 using result_type = uint32_t;
121 result_type operator()(const Peer &p) const { return p.getScore(); }
122};
123
125
129
130 PendingNode(ProofId proofid_, NodeId nodeid_)
131 : proofid(proofid_), nodeid(nodeid_){};
132};
133
134struct by_proofid;
135struct by_nodeid;
136struct by_score;
137
141 std::chrono::seconds lastUpdate;
143};
144
146 NONE = 0,
148 IMMATURE,
149 INVALID,
151 REJECTED,
153 DANGLING,
155};
156
157class ProofRegistrationState : public ValidationState<ProofRegistrationResult> {
158};
159
160namespace bmi = boost::multi_index;
161
163 std::vector<Slot> slots;
164 uint64_t slotCount = 0;
165 uint64_t fragmentation = 0;
166
171 using PeerSet = boost::multi_index_container<
172 Peer, bmi::indexed_by<
173 // index by peerid
174 bmi::hashed_unique<bmi::member<Peer, PeerId, &Peer::peerid>>,
175 // index by proof
176 bmi::hashed_unique<bmi::tag<by_proofid>, proof_index,
178 // ordered by score, decreasing order
179 bmi::ordered_non_unique<bmi::tag<by_score>, score_index,
180 std::greater<uint32_t>>>>;
181
184
189
192
193 using NodeSet = boost::multi_index_container<
194 Node, bmi::indexed_by<
195 // index by nodeid
196 bmi::hashed_unique<bmi::member<Node, NodeId, &Node::nodeid>>,
197 // sorted by peerid/nextRequestTime
198 bmi::ordered_non_unique<
199 bmi::tag<next_request_time>,
200 bmi::composite_key<
201 Node, bmi::member<Node, PeerId, &Node::peerid>,
202 bmi::member<Node, SteadyMilliseconds,
204
206
211 std::atomic<bool> needMoreNodes{false};
212
213 using PendingNodeSet = boost::multi_index_container<
215 bmi::indexed_by<
216 // index by proofid
217 bmi::hashed_non_unique<
218 bmi::tag<by_proofid>,
219 bmi::member<PendingNode, ProofId, &PendingNode::proofid>,
221 // index by nodeid
222 bmi::hashed_unique<
223 bmi::tag<by_nodeid>,
224 bmi::member<PendingNode, NodeId, &PendingNode::nodeid>>>>;
226
227 static constexpr int SELECT_PEER_MAX_RETRY = 3;
228 static constexpr int SELECT_NODE_MAX_RETRY = 3;
229
234
238 uint32_t totalPeersScore = 0;
240
242
244
245 const bool m_stakingPreConsensus{false};
246
248
249 struct by_lastUpdate;
250
251 using RemoteProofSet = boost::multi_index_container<
253 bmi::indexed_by<
254 // index by proofid/nodeid pair
255 bmi::hashed_unique<
256 bmi::composite_key<
258 bmi::member<RemoteProof, ProofId, &RemoteProof::proofid>,
259 bmi::member<RemoteProof, NodeId, &RemoteProof::nodeid>>,
260 bmi::composite_key_hash<SaltedProofIdHasher,
261 boost::hash<NodeId>>>,
262 // index by proofid
263 bmi::hashed_non_unique<
264 bmi::tag<by_proofid>,
265 bmi::member<RemoteProof, ProofId, &RemoteProof::proofid>,
267 // index by nodeid
268 bmi::hashed_non_unique<
269 bmi::tag<by_nodeid>,
270 bmi::member<RemoteProof, NodeId, &RemoteProof::nodeid>>,
271 bmi::ordered_non_unique<
272 bmi::tag<by_lastUpdate>,
273 bmi::composite_key<
275 bmi::member<RemoteProof, NodeId, &RemoteProof::nodeid>,
276 bmi::member<RemoteProof, std::chrono::seconds,
278
284
298
299 std::unordered_set<ProofId, SaltedProofIdHasher> manualFlakyProofids;
300
302
303public:
304 static constexpr size_t MAX_REMOTE_PROOFS{100};
305
306 PeerManager(const Amount &stakeUtxoDustThresholdIn,
307 ChainstateManager &chainmanIn, bool stakingPreConsensus = false,
308 const ProofRef &localProofIn = ProofRef())
309 : stakeUtxoDustThreshold(stakeUtxoDustThresholdIn),
310 chainman(chainmanIn), m_stakingPreConsensus(stakingPreConsensus),
311 localProof(localProofIn){};
312
316 bool addNode(NodeId nodeid, const ProofId &proofid);
317 bool removeNode(NodeId nodeid);
318 size_t getNodeCount() const { return nodes.size(); }
319 size_t getPendingNodeCount() const { return pendingNodes.size(); }
320
321 // Update when a node is to be polled next.
322 bool updateNextRequestTime(NodeId nodeid, SteadyMilliseconds timeout);
328 bool latchAvaproofsSent(NodeId nodeid);
329
330 // Randomly select a node to poll.
332
336 bool shouldRequestMoreNodes() { return needMoreNodes.exchange(false); }
337
338 template <typename Callable>
339 bool forNode(NodeId nodeid, Callable &&func) const {
340 auto it = nodes.find(nodeid);
341 return it != nodes.end() && func(*it);
342 }
343
344 template <typename Callable>
345 void forEachNode(const Peer &peer, Callable &&func) const {
346 auto &nview = nodes.get<next_request_time>();
347 auto range = nview.equal_range(peer.peerid);
348 for (auto it = range.first; it != range.second; ++it) {
349 func(*it);
350 }
351 }
352
362 const std::chrono::seconds &nextTime);
363
367 bool setFinalized(PeerId peerid);
368
376 enum class RegistrationMode {
377 DEFAULT,
378 FORCE_ACCEPT,
379 };
380
381 bool registerProof(const ProofRef &proof,
382 ProofRegistrationState &registrationState,
384 bool registerProof(const ProofRef &proof,
387 return registerProof(proof, dummy, mode);
388 }
389
399 enum class RejectionMode {
400 DEFAULT,
401 INVALIDATE,
402 };
403
404 bool rejectProof(const ProofId &proofid,
406
411 bool exists(const ProofId &proofid) const {
412 return getProof(proofid) != nullptr;
413 }
414
416 std::unordered_set<ProofRef, SaltedProofHasher> &registeredProofs);
417
418 template <typename Callable>
419 bool forPeer(const ProofId &proofid, Callable &&func) const {
420 auto &pview = peers.get<by_proofid>();
421 auto it = pview.find(proofid);
422 return it != pview.end() && func(*it);
423 }
424
425 template <typename Callable> void forEachPeer(Callable &&func) const {
426 for (const auto &p : peers) {
427 func(p);
428 }
429 }
430
434 std::unordered_set<ProofRef, SaltedProofHasher> updatedBlockTip();
435
439 void addUnbroadcastProof(const ProofId &proofid);
440 void removeUnbroadcastProof(const ProofId &proofid);
442
443 /*
444 * Quorum management
445 */
446 uint32_t getTotalPeersScore() const { return totalPeersScore; }
447 uint32_t getConnectedPeersScore() const { return connectedPeersScore; }
448
449 bool saveRemoteProof(const ProofId &proofid, const NodeId nodeid,
450 const bool present);
451 std::vector<RemoteProof> getRemoteProofs(const NodeId nodeid) const;
452 bool isRemoteProof(const ProofId &proofid) const;
453
454 bool setFlaky(const ProofId &proofid);
455 bool unsetFlaky(const ProofId &proofid);
456 template <typename Callable> void forEachFlakyProof(Callable &&func) const {
457 for (const auto &p : manualFlakyProofids) {
458 func(p);
459 }
460 }
461
463 void cleanupStakeContenders(const int requestedMinHeight);
464 void addStakeContender(const ProofRef &proof);
465 int getStakeContenderStatus(const StakeContenderId &contenderId,
466 BlockHash &prevblockhashout) const;
467 void acceptStakeContender(const StakeContenderId &contenderId);
469 const StakeContenderId &contenderId, BlockHash &prevblockhash,
470 std::vector<std::pair<ProofId, CScript>> &newWinners);
471 void rejectStakeContender(const StakeContenderId &contenderId);
472 void promoteStakeContendersToBlock(const CBlockIndex *pindex);
474 const CBlockIndex *prevblock,
475 const std::vector<std::pair<ProofId, CScript>> winners,
476 size_t maxPollable, std::vector<StakeContenderId> &pollableContenders);
477 bool setStakeContenderWinners(const CBlockIndex *pindex,
478 const std::vector<CScript> &payoutScripts);
479
480 /****************************************************
481 * Functions which are public for testing purposes. *
482 ****************************************************/
483
487 bool removePeer(const PeerId peerid);
488
492 PeerId selectPeer() const;
493
498 uint64_t compact();
499
503 bool verify() const;
504
505 // Accessors.
506 uint64_t getSlotCount() const { return slotCount; }
507 uint64_t getFragmentation() const { return fragmentation; }
508
509 const ProofPool &getValidProofPool() const { return validProofPool; }
512 }
514
515 ProofRef getProof(const ProofId &proofid) const;
516 bool isBoundToPeer(const ProofId &proofid) const;
517 bool isImmature(const ProofId &proofid) const;
518 bool isInConflictingPool(const ProofId &proofid) const;
519 bool isDangling(const ProofId &proofid) const;
520
521 void setInvalid(const ProofId &proofid);
522 bool isInvalid(const ProofId &proofid) const;
523 void clearAllInvalid();
524
526 return shareableProofs;
527 }
528
531 }
532
538 const CBlockIndex *pprev,
539 std::vector<std::pair<ProofId, CScript>> &winners);
540
541 bool dumpPeersToFile(const fs::path &dumpPath) const;
543 const fs::path &dumpPath,
544 std::unordered_set<ProofRef, SaltedProofHasher> &registeredProofs);
545
546private:
547 template <typename ProofContainer>
548 void moveToConflictingPool(const ProofContainer &proofs);
549
550 bool addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid);
551 bool addNodeToPeer(const PeerSet::iterator &it);
552 bool removeNodeFromPeer(const PeerSet::iterator &it, uint32_t count = 1);
553
561 std::optional<bool> getRemotePresenceStatus(const ProofId &proofid) const;
562
563 bool isFlaky(const ProofId &proofid) const;
564
565 friend struct ::avalanche::TestPeerManager;
566};
567
571PeerId selectPeerImpl(const std::vector<Slot> &slots, const uint64_t slot,
572 const uint64_t max);
573
574} // namespace avalanche
575
576#endif // BITCOIN_AVALANCHE_PEERMANAGER_H
uint32_t PeerId
Definition: node.h:15
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:25
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition: bloom.h:115
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:41
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1147
Template for capturing information about block/transaction validation.
Definition: validation.h:89
bool selectStakingRewardWinner(const CBlockIndex *pprev, std::vector< std::pair< ProofId, CScript > > &winners)
Deterministically select a list of payout scripts based on the proof set and the previous block hash.
uint32_t connectedPeersScore
Definition: peermanager.h:239
boost::multi_index_container< PendingNode, bmi::indexed_by< bmi::hashed_non_unique< bmi::tag< by_proofid >, bmi::member< PendingNode, ProofId, &PendingNode::proofid >, SaltedProofIdHasher >, bmi::hashed_unique< bmi::tag< by_nodeid >, bmi::member< PendingNode, NodeId, &PendingNode::nodeid > > > > PendingNodeSet
Definition: peermanager.h:224
std::vector< RemoteProof > getRemoteProofs(const NodeId nodeid) const
bool removeNode(NodeId nodeid)
bool setFinalized(PeerId peerid)
Latch on that this peer has a finalized proof.
bool dumpPeersToFile(const fs::path &dumpPath) const
RemoteProofSet remoteProofs
Remember which node sent which proof so we have an image of the proof set of our peers.
Definition: peermanager.h:283
uint64_t getFragmentation() const
Definition: peermanager.h:507
uint32_t getConnectedPeersScore() const
Definition: peermanager.h:447
bool isDangling(const ProofId &proofid) const
bool updateNextRequestTime(NodeId nodeid, SteadyMilliseconds timeout)
bool unsetFlaky(const ProofId &proofid)
std::optional< bool > getRemotePresenceStatus(const ProofId &proofid) const
Get the presence remote status of a proof.
bool addNodeToPeer(const PeerSet::iterator &it)
Definition: peermanager.cpp:89
bool shouldRequestMoreNodes()
Returns true if we encountered a lack of node since the last call.
Definition: peermanager.h:336
bool exists(const ProofId &proofid) const
Return true if the (valid) proof exists, but only for non-dangling proofs.
Definition: peermanager.h:411
bool isRemoteProof(const ProofId &proofid) const
size_t getNodeCount() const
Definition: peermanager.h:318
PendingNodeSet pendingNodes
Definition: peermanager.h:225
const ProofPool & getValidProofPool() const
Definition: peermanager.h:509
bool verify() const
Perform consistency check on internal data structures.
bool forNode(NodeId nodeid, Callable &&func) const
Definition: peermanager.h:339
bool forPeer(const ProofId &proofid, Callable &&func) const
Definition: peermanager.h:419
boost::multi_index_container< Node, bmi::indexed_by< bmi::hashed_unique< bmi::member< Node, NodeId, &Node::nodeid > >, bmi::ordered_non_unique< bmi::tag< next_request_time >, bmi::composite_key< Node, bmi::member< Node, PeerId, &Node::peerid >, bmi::member< Node, SteadyMilliseconds, &Node::nextRequestTime > > > > > NodeSet
Definition: peermanager.h:203
uint32_t getTotalPeersScore() const
Definition: peermanager.h:446
void finalizeStakeContender(const StakeContenderId &contenderId, BlockHash &prevblockhash, std::vector< std::pair< ProofId, CScript > > &newWinners)
bool latchAvaproofsSent(NodeId nodeid)
Flag that a node did send its compact proofs.
bool registerProof(const ProofRef &proof, RegistrationMode mode=RegistrationMode::DEFAULT)
Definition: peermanager.h:384
void cleanupStakeContenders(const int requestedMinHeight)
Make some of the contender cache API available.
bool addNode(NodeId nodeid, const ProofId &proofid)
Node API.
Definition: peermanager.cpp:33
uint64_t getSlotCount() const
Definition: peermanager.h:506
static constexpr int SELECT_PEER_MAX_RETRY
Definition: peermanager.h:227
ProofIdSet m_unbroadcast_proofids
Track proof ids to broadcast.
Definition: peermanager.h:233
bool loadPeersFromFile(const fs::path &dumpPath, std::unordered_set< ProofRef, SaltedProofHasher > &registeredProofs)
RejectionMode
Rejection mode.
Definition: peermanager.h:399
void addUnbroadcastProof(const ProofId &proofid)
Proof broadcast API.
std::unordered_set< ProofRef, SaltedProofHasher > updatedBlockTip()
Update the peer set when a new block is connected.
void removeUnbroadcastProof(const ProofId &proofid)
PeerManager(const Amount &stakeUtxoDustThresholdIn, ChainstateManager &chainmanIn, bool stakingPreConsensus=false, const ProofRef &localProofIn=ProofRef())
Definition: peermanager.h:306
void promoteStakeContendersToBlock(const CBlockIndex *pindex)
const ProofRadixTree & getShareableProofsSnapshot() const
Definition: peermanager.h:525
bool isBoundToPeer(const ProofId &proofid) const
bool setContenderStatusForLocalWinners(const CBlockIndex *prevblock, const std::vector< std::pair< ProofId, CScript > > winners, size_t maxPollable, std::vector< StakeContenderId > &pollableContenders)
boost::multi_index_container< RemoteProof, bmi::indexed_by< bmi::hashed_unique< bmi::composite_key< RemoteProof, bmi::member< RemoteProof, ProofId, &RemoteProof::proofid >, bmi::member< RemoteProof, NodeId, &RemoteProof::nodeid > >, bmi::composite_key_hash< SaltedProofIdHasher, boost::hash< NodeId > > >, bmi::hashed_non_unique< bmi::tag< by_proofid >, bmi::member< RemoteProof, ProofId, &RemoteProof::proofid >, SaltedProofIdHasher >, bmi::hashed_non_unique< bmi::tag< by_nodeid >, bmi::member< RemoteProof, NodeId, &RemoteProof::nodeid > >, bmi::ordered_non_unique< bmi::tag< by_lastUpdate >, bmi::composite_key< RemoteProof, bmi::member< RemoteProof, NodeId, &RemoteProof::nodeid >, bmi::member< RemoteProof, std::chrono::seconds, &RemoteProof::lastUpdate > > > > > RemoteProofSet
Definition: peermanager.h:277
size_t getPendingNodeCount() const
Definition: peermanager.h:319
const ProofPool & getImmatureProofPool() const
Definition: peermanager.h:513
ProofRadixTree shareableProofs
Definition: peermanager.h:191
bool saveRemoteProof(const ProofId &proofid, const NodeId nodeid, const bool present)
CRollingBloomFilter invalidProofs
Filter for proofs that are consensus-invalid or were recently invalidated by avalanche (finalized rej...
Definition: peermanager.h:297
uint64_t compact()
Trigger maintenance of internal data structures.
std::vector< Slot > slots
Definition: peermanager.h:163
uint32_t totalPeersScore
Quorum management.
Definition: peermanager.h:238
ProofPool danglingProofPool
Definition: peermanager.h:188
void forEachPeer(Callable &&func) const
Definition: peermanager.h:425
StakeContenderCache stakeContenderCache
Definition: peermanager.h:301
void setInvalid(const ProofId &proofid)
void forEachNode(const Peer &peer, Callable &&func) const
Definition: peermanager.h:345
int getStakeContenderStatus(const StakeContenderId &contenderId, BlockHash &prevblockhashout) const
const Amount & getStakeUtxoDustThreshold() const
Definition: peermanager.h:529
void forEachFlakyProof(Callable &&func) const
Definition: peermanager.h:456
bool isFlaky(const ProofId &proofid) const
ChainstateManager & chainman
Definition: peermanager.h:243
bool isInvalid(const ProofId &proofid) const
std::unordered_set< ProofId, SaltedProofIdHasher > manualFlakyProofids
Definition: peermanager.h:299
bool removePeer(const PeerId peerid)
Remove an existing peer.
const bool m_stakingPreConsensus
Definition: peermanager.h:245
bool isImmature(const ProofId &proofid) const
bool addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid)
Definition: peermanager.cpp:48
bool rejectProof(const ProofId &proofid, RejectionMode mode=RejectionMode::DEFAULT)
ProofPool immatureProofPool
Definition: peermanager.h:187
RegistrationMode
Registration mode.
Definition: peermanager.h:376
ProofPool conflictingProofPool
Definition: peermanager.h:186
const ProofPool & getConflictingProofPool() const
Definition: peermanager.h:510
static constexpr size_t MAX_REMOTE_PROOFS
Definition: peermanager.h:304
bool setFlaky(const ProofId &proofid)
void addStakeContender(const ProofRef &proof)
std::atomic< bool > needMoreNodes
Flag indicating that we failed to select a node and need to expand our node set.
Definition: peermanager.h:211
PeerId selectPeer() const
Randomly select a peer to poll.
boost::multi_index_container< Peer, bmi::indexed_by< bmi::hashed_unique< bmi::member< Peer, PeerId, &Peer::peerid > >, bmi::hashed_unique< bmi::tag< by_proofid >, proof_index, SaltedProofIdHasher >, bmi::ordered_non_unique< bmi::tag< by_score >, score_index, std::greater< uint32_t > > > > PeerSet
Several nodes can make an avalanche peer.
Definition: peermanager.h:180
auto getUnbroadcastProofs() const
Definition: peermanager.h:441
bool isInConflictingPool(const ProofId &proofid) const
static constexpr int SELECT_NODE_MAX_RETRY
Definition: peermanager.h:228
void cleanupDanglingProofs(std::unordered_set< ProofRef, SaltedProofHasher > &registeredProofs)
void acceptStakeContender(const StakeContenderId &contenderId)
ProofRef getProof(const ProofId &proofid) const
bool registerProof(const ProofRef &proof, ProofRegistrationState &registrationState, RegistrationMode mode=RegistrationMode::DEFAULT)
void rejectStakeContender(const StakeContenderId &contenderId)
bool removeNodeFromPeer(const PeerSet::iterator &it, uint32_t count=1)
bool updateNextPossibleConflictTime(PeerId peerid, const std::chrono::seconds &nextTime)
Proof and Peer related API.
void moveToConflictingPool(const ProofContainer &proofs)
bool setStakeContenderWinners(const CBlockIndex *pindex, const std::vector< CScript > &payoutScripts)
Map a proof to each utxo.
Definition: proofpool.h:57
Cache to track stake contenders for recent blocks.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:30
ProofRegistrationResult
Definition: peermanager.h:145
static constexpr uint32_t AVALANCHE_MAX_IMMATURE_PROOFS
Maximum number of immature proofs the peer manager will accept from the network.
Definition: peermanager.h:46
std::unordered_set< ProofId, SaltedProofIdHasher > ProofIdSet
Definition: proofpool.h:52
PeerId selectPeerImpl(const std::vector< Slot > &slots, const uint64_t slot, const uint64_t max)
Internal methods that are exposed for testing purposes.
RCUPtr< const Proof > ProofRef
Definition: proof.h:186
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:259
int64_t NodeId
Definition: nodeid.h:10
Definition: amount.h:19
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
SteadyMilliseconds nextRequestTime
Definition: node.h:23
std::chrono::seconds registration_time
Definition: peermanager.h:95
std::chrono::seconds nextPossibleConflictTime
Definition: peermanager.h:96
uint32_t node_count
Definition: peermanager.h:89
static constexpr auto DANGLING_TIMEOUT
Consider dropping the peer if no node is attached after this timeout expired.
Definition: peermanager.h:102
const ProofId & getProofId() const
Definition: peermanager.h:110
uint32_t index
Definition: peermanager.h:88
uint32_t getScore() const
Definition: peermanager.h:111
ProofRef proof
Definition: peermanager.h:91
Peer(PeerId peerid_, ProofRef proof_, std::chrono::seconds nextPossibleConflictTime_)
Definition: peermanager.h:104
PendingNode(ProofId proofid_, NodeId nodeid_)
Definition: peermanager.h:130
std::chrono::seconds lastUpdate
Definition: peermanager.h:141
Slot(uint64_t startIn, uint32_t scoreIn, PeerId peeridIn)
Definition: peermanager.h:61
uint32_t score
Definition: peermanager.h:57
uint64_t start
Definition: peermanager.h:56
Slot withPeerId(PeerId peeridIn) const
Definition: peermanager.h:70
uint32_t getScore() const
Definition: peermanager.h:76
bool follows(uint64_t slot) const
Definition: peermanager.h:83
Slot withScore(uint64_t scoreIn) const
Definition: peermanager.h:67
Slot withStart(uint64_t startIn) const
Definition: peermanager.h:64
uint64_t getStop() const
Definition: peermanager.h:75
uint64_t getStart() const
Definition: peermanager.h:74
PeerId getPeerId() const
Definition: peermanager.h:77
bool precedes(uint64_t slot) const
Definition: peermanager.h:82
bool contains(uint64_t slot) const
Definition: peermanager.h:79
StakeContenderIds are unique for each block to ensure that the peer polling for their acceptance has ...
result_type operator()(const Peer &p) const
Definition: peermanager.h:116
result_type operator()(const Peer &p) const
Definition: peermanager.h:121
static int count
Definition: tests.c:31
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
Definition: time.cpp:109
std::chrono::time_point< std::chrono::steady_clock, std::chrono::milliseconds > SteadyMilliseconds
Definition: time.h:31