Bitcoin ABC 0.34.2
P2P Digital Currency
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>
12#include <avalanche/protocol.h>
14#include <common/bloom.h>
16#include <radix.h>
17#include <util/fs.h>
18#include <util/hasher.h>
19#include <util/time.h>
20
21#include <boost/multi_index/composite_key.hpp>
22#include <boost/multi_index/hashed_index.hpp>
23#include <boost/multi_index/mem_fun.hpp>
24#include <boost/multi_index/member.hpp>
25#include <boost/multi_index/ordered_index.hpp>
26#include <boost/multi_index_container.hpp>
27
28#include <atomic>
29#include <chrono>
30#include <cstdint>
31#include <memory>
32#include <vector>
33
35
36namespace avalanche {
37
44static constexpr uint32_t AVALANCHE_MAX_IMMATURE_PROOFS = 4000;
45
46class Delegation;
47
48namespace {
49 struct TestPeerManager;
50}
51
52struct Slot {
53private:
54 uint64_t start;
55 uint32_t score;
57
58public:
59 Slot(uint64_t startIn, uint32_t scoreIn, PeerId peeridIn)
60 : start(startIn), score(scoreIn), peerid(peeridIn) {}
61
62 Slot withStart(uint64_t startIn) const {
63 return Slot(startIn, score, peerid);
64 }
65 Slot withScore(uint64_t scoreIn) const {
66 return Slot(start, scoreIn, peerid);
67 }
68 Slot withPeerId(PeerId peeridIn) const {
69 return Slot(start, score, peeridIn);
70 }
71
72 uint64_t getStart() const { return start; }
73 uint64_t getStop() const { return start + score; }
74 uint32_t getScore() const { return score; }
75 PeerId getPeerId() const { return peerid; }
76
77 bool contains(uint64_t slot) const {
78 return getStart() <= slot && slot < getStop();
79 }
80 bool precedes(uint64_t slot) const { return slot >= getStop(); }
81 bool follows(uint64_t slot) const { return getStart() > slot; }
82};
83
84struct Peer {
86 uint32_t index = -1;
87 uint32_t node_count = 0;
88
90 bool hasFinalized = false;
91
92 // The network stack uses timestamp in seconds, so we oblige.
93 std::chrono::seconds registration_time;
94 std::chrono::seconds nextPossibleConflictTime;
95
100 static constexpr auto DANGLING_TIMEOUT = 15min;
101
102 Peer(PeerId peerid_, ProofRef proof_,
103 std::chrono::seconds nextPossibleConflictTime_)
104 : peerid(peerid_), proof(std::move(proof_)),
105 registration_time(GetTime<std::chrono::seconds>()),
106 nextPossibleConflictTime(std::move(nextPossibleConflictTime_)) {}
107
108 const ProofId &getProofId() const { return proof->getId(); }
109 uint32_t getScore() const { return proof->getScore(); }
110};
111
114 result_type operator()(const Peer &p) const { return p.proof->getId(); }
115};
116
118 using result_type = uint32_t;
119 result_type operator()(const Peer &p) const { return p.getScore(); }
120};
121
123
128
129 PendingNode(ProofId proofid_, NodeId nodeid_, size_t max_elements_)
130 : proofid(proofid_), nodeid(nodeid_), max_elements(max_elements_) {};
131};
132
133struct by_proofid;
134struct by_nodeid;
135struct by_score;
136
140 std::chrono::seconds lastUpdate;
142};
143
145 NONE = 0,
147 IMMATURE,
148 INVALID,
150 REJECTED,
152 DANGLING,
154};
155
156class ProofRegistrationState : public ValidationState<ProofRegistrationResult> {
157};
158
159namespace bmi = boost::multi_index;
160
162 std::vector<Slot> slots;
163 uint64_t slotCount = 0;
164 uint64_t fragmentation = 0;
165
170 using PeerSet = boost::multi_index_container<
171 Peer, bmi::indexed_by<
172 // index by peerid
173 bmi::hashed_unique<bmi::member<Peer, PeerId, &Peer::peerid>>,
174 // index by proof
175 bmi::hashed_unique<bmi::tag<by_proofid>, proof_index,
177 // ordered by score, decreasing order
178 bmi::ordered_non_unique<bmi::tag<by_score>, score_index,
179 std::greater<uint32_t>>>>;
180
183
188
191
192 using NodeSet = boost::multi_index_container<
193 Node, bmi::indexed_by<
194 // index by nodeid
195 bmi::hashed_unique<bmi::member<Node, NodeId, &Node::nodeid>>,
196 // sorted by peerid/nextRequestTime
197 bmi::ordered_non_unique<
198 bmi::tag<next_request_time>,
199 bmi::composite_key<
200 Node, bmi::member<Node, PeerId, &Node::peerid>,
201 bmi::member<Node, SteadyMilliseconds,
203
205
210 std::atomic<bool> needMoreNodes{false};
211
212 using PendingNodeSet = boost::multi_index_container<
214 bmi::indexed_by<
215 // index by proofid
216 bmi::hashed_non_unique<
217 bmi::tag<by_proofid>,
218 bmi::member<PendingNode, ProofId, &PendingNode::proofid>,
220 // index by nodeid
221 bmi::hashed_unique<
222 bmi::tag<by_nodeid>,
223 bmi::member<PendingNode, NodeId, &PendingNode::nodeid>>>>;
225
226 static constexpr int SELECT_PEER_MAX_RETRY = 3;
227 static constexpr int SELECT_NODE_MAX_RETRY = 3;
228
233
237 uint32_t totalPeersScore = 0;
239
241
243
244 const bool m_stakingPreConsensus{false};
245
247
248 struct by_lastUpdate;
249
250 using RemoteProofSet = boost::multi_index_container<
252 bmi::indexed_by<
253 // index by proofid/nodeid pair
254 bmi::hashed_unique<
255 bmi::composite_key<
257 bmi::member<RemoteProof, ProofId, &RemoteProof::proofid>,
258 bmi::member<RemoteProof, NodeId, &RemoteProof::nodeid>>,
259 bmi::composite_key_hash<SaltedProofIdHasher,
260 boost::hash<NodeId>>>,
261 // index by proofid
262 bmi::hashed_non_unique<
263 bmi::tag<by_proofid>,
264 bmi::member<RemoteProof, ProofId, &RemoteProof::proofid>,
266 // index by nodeid
267 bmi::hashed_non_unique<
268 bmi::tag<by_nodeid>,
269 bmi::member<RemoteProof, NodeId, &RemoteProof::nodeid>>,
270 bmi::ordered_non_unique<
271 bmi::tag<by_lastUpdate>,
272 bmi::composite_key<
274 bmi::member<RemoteProof, NodeId, &RemoteProof::nodeid>,
275 bmi::member<RemoteProof, std::chrono::seconds,
277
283
297
298 std::unordered_set<ProofId, SaltedProofIdHasher> manualFlakyProofids;
299 // Proofs whose stake contender was rejected for
300 // rejectedContenderPrevBlockHash. selectStakingRewardWinner keeps
301 // collecting alternatives past these for that prevblock only.
302 std::unordered_set<ProofId, SaltedProofIdHasher> rejectedContenderProofids;
304
306
307public:
308 static constexpr size_t MAX_REMOTE_PROOFS{100};
309
310 PeerManager(const Amount &stakeUtxoDustThresholdIn,
311 ChainstateManager &chainmanIn, bool stakingPreConsensus = false,
312 const ProofRef &localProofIn = ProofRef())
313 : stakeUtxoDustThreshold(stakeUtxoDustThresholdIn),
314 chainman(chainmanIn), m_stakingPreConsensus(stakingPreConsensus),
315 localProof(localProofIn) {};
316
320 bool addNode(NodeId nodeid, const ProofId &proofid, size_t max_elements);
321 bool removeNode(NodeId nodeid);
322 size_t getNodeCount() const { return nodes.size(); }
323 size_t getPendingNodeCount() const { return pendingNodes.size(); }
324
325 // Update when a node is to be polled next.
327 uint64_t round);
329 const Response &response);
335 bool latchAvaproofsSent(NodeId nodeid);
336
337 // Randomly select a node to poll.
339
343 bool shouldRequestMoreNodes() { return needMoreNodes.exchange(false); }
344
345 template <typename Callable>
346 bool forNode(NodeId nodeid, Callable &&func) const {
347 auto it = nodes.find(nodeid);
348 return it != nodes.end() && func(*it);
349 }
350
351 template <typename Callable>
352 void forEachNode(const Peer &peer, Callable &&func) const {
353 auto &nview = nodes.get<next_request_time>();
354 auto range = nview.equal_range(peer.peerid);
355 for (auto it = range.first; it != range.second; ++it) {
356 func(*it);
357 }
358 }
359
369 const std::chrono::seconds &nextTime);
370
374 bool setFinalized(PeerId peerid);
375
383 enum class RegistrationMode {
384 DEFAULT,
385 FORCE_ACCEPT,
386 };
387
388 bool registerProof(const ProofRef &proof,
389 ProofRegistrationState &registrationState,
391 bool registerProof(const ProofRef &proof,
394 return registerProof(proof, dummy, mode);
395 }
396
406 enum class RejectionMode {
407 DEFAULT,
408 INVALIDATE,
409 };
410
411 bool rejectProof(const ProofId &proofid,
413
418 bool exists(const ProofId &proofid) const {
419 return getProof(proofid) != nullptr;
420 }
421
423 std::unordered_set<ProofRef, SaltedProofHasher> &registeredProofs);
424
425 template <typename Callable>
426 bool forPeer(const ProofId &proofid, Callable &&func) const {
427 auto &pview = peers.get<by_proofid>();
428 auto it = pview.find(proofid);
429 return it != pview.end() && func(*it);
430 }
431
432 template <typename Callable> void forEachPeer(Callable &&func) const {
433 for (const auto &p : peers) {
434 func(p);
435 }
436 }
437
441 std::unordered_set<ProofRef, SaltedProofHasher> updatedBlockTip();
442
446 void addUnbroadcastProof(const ProofId &proofid);
447 void removeUnbroadcastProof(const ProofId &proofid);
449
450 /*
451 * Quorum management
452 */
453 uint32_t getTotalPeersScore() const { return totalPeersScore; }
454 uint32_t getConnectedPeersScore() const { return connectedPeersScore; }
455
456 bool saveRemoteProof(const ProofId &proofid, const NodeId nodeid,
457 const bool present);
458 std::vector<RemoteProof> getRemoteProofs(const NodeId nodeid) const;
459 bool hasRemoteProofStatus(const ProofId &proofid) const;
460 bool isRemotelyPresentProof(const ProofId &proofid) const;
461 void clearRemoteProofs(NodeId nodeid);
462
463 bool setFlaky(const ProofId &proofid);
464 bool unsetFlaky(const ProofId &proofid);
465 template <typename Callable> void forEachFlakyProof(Callable &&func) const {
466 for (const auto &p : manualFlakyProofids) {
467 func(p);
468 }
469 }
470
475 bool addRejectedContender(const ProofId &proofid,
476 const BlockHash &prevblockhash);
477
479 void cleanupStakeContenders(const int requestedMinHeight);
480 void addStakeContender(const ProofRef &proof);
481 int getStakeContenderStatus(const StakeContenderId &contenderId,
482 BlockHash &prevblockhashout) const;
483 void acceptStakeContender(const StakeContenderId &contenderId);
485 const StakeContenderId &contenderId, BlockHash &prevblockhash,
486 std::vector<std::pair<ProofId, CScript>> &newWinners);
487 void rejectStakeContender(const StakeContenderId &contenderId);
488 std::optional<StakeContenderCacheInfo>
489 getStakeContenderInfo(const StakeContenderId &contenderId) const;
490 bool hasAcceptedStakeWinner(const BlockHash &prevblockhash) const;
492 const BlockHash &prevblockhash,
493 std::vector<std::pair<ProofId, CScript>> &winners) const;
494 void promoteStakeContendersToBlock(const CBlockIndex *pindex);
496 const CBlockIndex *prevblock,
497 const std::vector<std::pair<ProofId, CScript>> winners,
498 size_t maxPollable, std::vector<StakeContenderId> &pollableContenders);
499 bool setStakeContenderWinners(const CBlockIndex *pindex,
500 const std::vector<CScript> &payoutScripts);
501
502 /****************************************************
503 * Functions which are public for testing purposes. *
504 ****************************************************/
505
509 bool removePeer(const PeerId peerid);
510
514 PeerId selectPeer() const;
515
520 uint64_t compact();
521
525 bool verify() const;
526
527 // Accessors.
528 uint64_t getSlotCount() const { return slotCount; }
529 uint64_t getFragmentation() const { return fragmentation; }
530
531 const ProofPool &getValidProofPool() const { return validProofPool; }
534 }
537
538 ProofRef getProof(const ProofId &proofid) const;
539 bool isBoundToPeer(const ProofId &proofid) const;
540 bool isImmature(const ProofId &proofid) const;
541 bool isInConflictingPool(const ProofId &proofid) const;
542 bool isDangling(const ProofId &proofid) const;
543
544 void setInvalid(const ProofId &proofid);
545 bool isInvalid(const ProofId &proofid) const;
546 void clearAllInvalid();
547
549 return shareableProofs;
550 }
551
554 }
555
561 const CBlockIndex *pprev,
562 std::vector<std::pair<ProofId, CScript>> &winners);
563
564 bool dumpPeersToFile(const fs::path &dumpPath) const;
566 const fs::path &dumpPath,
567 std::unordered_set<ProofRef, SaltedProofHasher> &registeredProofs);
568
569private:
571
572 template <typename ProofContainer>
573 void moveToConflictingPool(const ProofContainer &proofs);
574
575 bool addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid,
576 size_t max_elements);
577 bool addNodeToPeer(const PeerSet::iterator &it);
578 bool removeNodeFromPeer(const PeerSet::iterator &it, uint32_t count = 1);
579
587 std::optional<bool> getRemotePresenceStatus(const ProofId &proofid) const;
588
589 bool isFlaky(const ProofId &proofid) const;
590
593 }
594
595 friend struct ::avalanche::TestPeerManager;
596};
597
601PeerId selectPeerImpl(const std::vector<Slot> &slots, const uint64_t slot,
602 const uint64_t max);
603
604} // namespace avalanche
605
606#endif // BITCOIN_AVALANCHE_PEERMANAGER_H
uint32_t PeerId
Definition: node.h:14
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
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1176
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:238
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:223
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:282
uint64_t getFragmentation() const
Definition: peermanager.h:529
uint32_t getConnectedPeersScore() const
Definition: peermanager.h:454
bool updateNextRequestTimeForResponse(NodeId nodeid, const Response &response)
bool isDangling(const ProofId &proofid) const
bool addNode(NodeId nodeid, const ProofId &proofid, size_t max_elements)
Node API.
Definition: peermanager.cpp:33
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:91
bool shouldRequestMoreNodes()
Returns true if we encountered a lack of node since the last call.
Definition: peermanager.h:343
bool exists(const ProofId &proofid) const
Return true if the (valid) proof exists, but only for non-dangling proofs.
Definition: peermanager.h:418
size_t getNodeCount() const
Definition: peermanager.h:322
PendingNodeSet pendingNodes
Definition: peermanager.h:224
BlockHash rejectedContenderPrevBlockHash
Definition: peermanager.h:303
const ProofPool & getValidProofPool() const
Definition: peermanager.h:531
bool verify() const
Perform consistency check on internal data structures.
bool forNode(NodeId nodeid, Callable &&func) const
Definition: peermanager.h:346
bool hasRemoteProofStatus(const ProofId &proofid) const
std::optional< StakeContenderCacheInfo > getStakeContenderInfo(const StakeContenderId &contenderId) const
bool forPeer(const ProofId &proofid, Callable &&func) const
Definition: peermanager.h:426
void clearRemoteProofs(NodeId nodeid)
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:202
uint32_t getTotalPeersScore() const
Definition: peermanager.h:453
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:391
void cleanupStakeContenders(const int requestedMinHeight)
Make some of the contender cache API available.
bool updateNextRequestTimeForPoll(NodeId nodeid, SteadyMilliseconds timeout, uint64_t round)
uint64_t getSlotCount() const
Definition: peermanager.h:528
static constexpr int SELECT_PEER_MAX_RETRY
Definition: peermanager.h:226
ProofIdSet m_unbroadcast_proofids
Track proof ids to broadcast.
Definition: peermanager.h:232
bool loadPeersFromFile(const fs::path &dumpPath, std::unordered_set< ProofRef, SaltedProofHasher > &registeredProofs)
RejectionMode
Rejection mode.
Definition: peermanager.h:406
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:310
void promoteStakeContendersToBlock(const CBlockIndex *pindex)
const ProofRadixTree & getShareableProofsSnapshot() const
Definition: peermanager.h:548
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:276
size_t getPendingNodeCount() const
Definition: peermanager.h:323
const ProofPool & getImmatureProofPool() const
Definition: peermanager.h:535
ProofRadixTree shareableProofs
Definition: peermanager.h:190
bool saveRemoteProof(const ProofId &proofid, const NodeId nodeid, const bool present)
bool getStakeContenderWinners(const BlockHash &prevblockhash, std::vector< std::pair< ProofId, CScript > > &winners) const
CRollingBloomFilter invalidProofs
Filter for proofs that are consensus-invalid or were recently invalidated by avalanche (finalized rej...
Definition: peermanager.h:296
bool addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid, size_t max_elements)
Definition: peermanager.cpp:49
uint64_t compact()
Trigger maintenance of internal data structures.
bool addRejectedContender(const ProofId &proofid, const BlockHash &prevblockhash)
Record a rejected stake contender for prevblockhash.
std::vector< Slot > slots
Definition: peermanager.h:162
uint32_t totalPeersScore
Quorum management.
Definition: peermanager.h:237
ProofPool danglingProofPool
Definition: peermanager.h:187
void forEachPeer(Callable &&func) const
Definition: peermanager.h:432
StakeContenderCache stakeContenderCache
Definition: peermanager.h:305
bool hasAcceptedStakeWinner(const BlockHash &prevblockhash) const
void setInvalid(const ProofId &proofid)
void forEachNode(const Peer &peer, Callable &&func) const
Definition: peermanager.h:352
int getStakeContenderStatus(const StakeContenderId &contenderId, BlockHash &prevblockhashout) const
const Amount & getStakeUtxoDustThreshold() const
Definition: peermanager.h:552
void forEachFlakyProof(Callable &&func) const
Definition: peermanager.h:465
bool isFlaky(const ProofId &proofid) const
ChainstateManager & chainman
Definition: peermanager.h:242
bool isInvalid(const ProofId &proofid) const
std::unordered_set< ProofId, SaltedProofIdHasher > manualFlakyProofids
Definition: peermanager.h:298
bool removePeer(const PeerId peerid)
Remove an existing peer.
const bool m_stakingPreConsensus
Definition: peermanager.h:244
bool isImmature(const ProofId &proofid) const
bool rejectProof(const ProofId &proofid, RejectionMode mode=RejectionMode::DEFAULT)
ProofPool immatureProofPool
Definition: peermanager.h:186
RegistrationMode
Registration mode.
Definition: peermanager.h:383
const ProofPool & getDanglingProofPool() const
Definition: peermanager.h:536
ProofPool conflictingProofPool
Definition: peermanager.h:185
const ProofPool & getConflictingProofPool() const
Definition: peermanager.h:532
bool isStakingPreconsensusActivated() const
Definition: peermanager.h:591
static constexpr size_t MAX_REMOTE_PROOFS
Definition: peermanager.h:308
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:210
PeerId selectPeer() const
Randomly select a peer to poll.
std::unordered_set< ProofId, SaltedProofIdHasher > rejectedContenderProofids
Definition: peermanager.h:302
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:179
auto getUnbroadcastProofs() const
Definition: peermanager.h:448
bool isInConflictingPool(const ProofId &proofid) const
bool isRemotelyPresentProof(const ProofId &proofid) const
static constexpr int SELECT_NODE_MAX_RETRY
Definition: peermanager.h:227
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:56
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:30
int64_t NodeId
Definition: eviction.h:16
ProofRegistrationResult
Definition: peermanager.h:144
static constexpr uint32_t AVALANCHE_MAX_IMMATURE_PROOFS
Maximum number of immature proofs the peer manager will accept from the network.
Definition: peermanager.h:44
std::unordered_set< ProofId, SaltedProofIdHasher > ProofIdSet
Definition: proofpool.h:51
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:183
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:259
Response response
Definition: processor.cpp:537
Definition: amount.h:23
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
SteadyMilliseconds nextRequestTime
Definition: node.h:22
std::chrono::seconds registration_time
Definition: peermanager.h:93
std::chrono::seconds nextPossibleConflictTime
Definition: peermanager.h:94
uint32_t node_count
Definition: peermanager.h:87
static constexpr auto DANGLING_TIMEOUT
Consider dropping the peer if no node is attached after this timeout expired.
Definition: peermanager.h:100
const ProofId & getProofId() const
Definition: peermanager.h:108
uint32_t index
Definition: peermanager.h:86
uint32_t getScore() const
Definition: peermanager.h:109
ProofRef proof
Definition: peermanager.h:89
Peer(PeerId peerid_, ProofRef proof_, std::chrono::seconds nextPossibleConflictTime_)
Definition: peermanager.h:102
PendingNode(ProofId proofid_, NodeId nodeid_, size_t max_elements_)
Definition: peermanager.h:129
std::chrono::seconds lastUpdate
Definition: peermanager.h:140
Slot(uint64_t startIn, uint32_t scoreIn, PeerId peeridIn)
Definition: peermanager.h:59
uint32_t score
Definition: peermanager.h:55
uint64_t start
Definition: peermanager.h:54
Slot withPeerId(PeerId peeridIn) const
Definition: peermanager.h:68
uint32_t getScore() const
Definition: peermanager.h:74
bool follows(uint64_t slot) const
Definition: peermanager.h:81
Slot withScore(uint64_t scoreIn) const
Definition: peermanager.h:65
Slot withStart(uint64_t startIn) const
Definition: peermanager.h:62
uint64_t getStop() const
Definition: peermanager.h:73
uint64_t getStart() const
Definition: peermanager.h:72
PeerId getPeerId() const
Definition: peermanager.h:75
bool precedes(uint64_t slot) const
Definition: peermanager.h:80
bool contains(uint64_t slot) const
Definition: peermanager.h:77
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:114
result_type operator()(const Peer &p) const
Definition: peermanager.h:119
static int count
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
Definition: time.cpp:80
std::chrono::time_point< std::chrono::steady_clock, std::chrono::milliseconds > SteadyMilliseconds
Definition: time.h:33