Bitcoin ABC  0.26.3
P2P Digital Currency
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
avalanche::PeerManager Class Reference

#include <peermanager.h>

Collaboration diagram for avalanche::PeerManager:
[legend]

Public Types

enum class  RegistrationMode { DEFAULT , FORCE_ACCEPT }
 Registration mode. More...
 
enum class  RejectionMode { DEFAULT , INVALIDATE }
 Rejection mode. More...
 

Public Member Functions

 PeerManager (const Amount &stakeUtxoDustThresholdIn, ChainstateManager &chainmanIn)
 
bool addNode (NodeId nodeid, const ProofId &proofid)
 Node API. More...
 
bool removeNode (NodeId nodeid)
 
size_t getNodeCount () const
 
size_t getPendingNodeCount () const
 
bool updateNextRequestTime (NodeId nodeid, TimePoint timeout)
 
bool latchAvaproofsSent (NodeId nodeid)
 Flag that a node did send its compact proofs. More...
 
NodeId selectNode ()
 
bool shouldRequestMoreNodes ()
 Returns true if we encountered a lack of node since the last call. More...
 
template<typename Callable >
bool forNode (NodeId nodeid, Callable &&func) const
 
template<typename Callable >
void forEachNode (const Peer &peer, Callable &&func) const
 
bool updateNextPossibleConflictTime (PeerId peerid, const std::chrono::seconds &nextTime)
 Proof and Peer related API. More...
 
bool setFinalized (PeerId peerid)
 Latch on that this peer has a finalized proof. More...
 
bool registerProof (const ProofRef &proof, ProofRegistrationState &registrationState, RegistrationMode mode=RegistrationMode::DEFAULT)
 
bool registerProof (const ProofRef &proof, RegistrationMode mode=RegistrationMode::DEFAULT)
 
bool rejectProof (const ProofId &proofid, RejectionMode mode=RejectionMode::DEFAULT)
 
bool exists (const ProofId &proofid) const
 
void cleanupDanglingProofs (const ProofRef &localProof)
 
template<typename Callable >
bool forPeer (const ProofId &proofid, Callable &&func) const
 
template<typename Callable >
void forEachPeer (Callable &&func) const
 
std::unordered_set< ProofRef, SaltedProofHasherupdatedBlockTip ()
 Update the peer set when a new block is connected. More...
 
void addUnbroadcastProof (const ProofId &proofid)
 Proof broadcast API. More...
 
void removeUnbroadcastProof (const ProofId &proofid)
 
auto getUnbroadcastProofs () const
 
uint32_t getTotalPeersScore () const
 
uint32_t getConnectedPeersScore () const
 
bool removePeer (const PeerId peerid)
 Remove an existing peer. More...
 
PeerId selectPeer () const
 Randomly select a peer to poll. More...
 
uint64_t compact ()
 Trigger maintenance of internal data structures. More...
 
bool verify () const
 Perform consistency check on internal data structures. More...
 
uint64_t getSlotCount () const
 
uint64_t getFragmentation () const
 
const ProofPoolgetValidProofPool () const
 
const ProofPoolgetConflictingProofPool () const
 
const ProofPoolgetImmatureProofPool () const
 
ProofRef getProof (const ProofId &proofid) const
 
bool isBoundToPeer (const ProofId &proofid) const
 
bool isImmature (const ProofId &proofid) const
 
bool isInConflictingPool (const ProofId &proofid) const
 
const ProofRadixTreegetShareableProofsSnapshot () const
 
const AmountgetStakeUtxoDustThreshold () const
 

Private Types

using PeerSet = 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 > >> >
 Several nodes can make an avalanche peer. More...
 
using ProofRadixTree = RadixTree< const Proof, ProofRadixTreeAdapter >
 
using NodeSet = 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, TimePoint, &Node::nextRequestTime > >> >>
 
using PendingNodeSet = 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 > >> >
 

Private Member Functions

template<typename ProofContainer >
void moveToConflictingPool (const ProofContainer &proofs)
 
bool addOrUpdateNode (const PeerSet::iterator &it, NodeId nodeid)
 
bool addNodeToPeer (const PeerSet::iterator &it)
 
bool removeNodeFromPeer (const PeerSet::iterator &it, uint32_t count=1)
 

Private Attributes

std::vector< Slotslots
 
uint64_t slotCount = 0
 
uint64_t fragmentation = 0
 
PeerId nextPeerId = 0
 
PeerSet peers
 
ProofPool validProofPool
 
ProofPool conflictingProofPool
 
ProofPool immatureProofPool
 
ProofRadixTree shareableProofs
 
NodeSet nodes
 
std::atomic< bool > needMoreNodes {false}
 Flag indicating that we failed to select a node and need to expand our node set. More...
 
PendingNodeSet pendingNodes
 
ProofIdSet m_unbroadcast_proofids
 Track proof ids to broadcast. More...
 
CRollingBloomFilter danglingProofIds {10000, 0.00001}
 Remember the last proofs that have been evicted because they had no node attached. More...
 
uint32_t totalPeersScore = 0
 Quorum management. More...
 
uint32_t connectedPeersScore = 0
 
Amount stakeUtxoDustThreshold
 
ChainstateManagerchainman
 

Static Private Attributes

static constexpr int SELECT_PEER_MAX_RETRY = 3
 
static constexpr int SELECT_NODE_MAX_RETRY = 3
 

Friends

struct ::avalanche::TestPeerManager
 

Detailed Description

Definition at line 153 of file peermanager.h.

Member Typedef Documentation

◆ NodeSet

using avalanche::PeerManager::NodeSet = 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, TimePoint, &Node::nextRequestTime> >> >>
private

Definition at line 183 of file peermanager.h.

◆ PeerSet

using avalanche::PeerManager::PeerSet = 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> >> >
private

Several nodes can make an avalanche peer.

In this case, all nodes are considered interchangeable parts of the same peer.

Definition at line 162 of file peermanager.h.

◆ PendingNodeSet

using avalanche::PeerManager::PendingNodeSet = 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> >> >
private

Definition at line 203 of file peermanager.h.

◆ ProofRadixTree

Definition at line 180 of file peermanager.h.

Member Enumeration Documentation

◆ RegistrationMode

Registration mode.

  • DEFAULT: Default policy, register only if the proof is unknown and has no conflict.
  • FORCE_ACCEPT: Turn a valid proof into a peer even if it has conflicts and is not the best candidate.
Enumerator
DEFAULT 
FORCE_ACCEPT 

Definition at line 313 of file peermanager.h.

◆ RejectionMode

Rejection mode.

  • DEFAULT: Default policy, reject a proof and attempt to keep it in the conflicting pool if possible.
  • INVALIDATE: Reject a proof by removing it from any of the pool.

In any case if a peer is rejected, it attempts to pull the conflicting proofs back.

Enumerator
DEFAULT 
INVALIDATE 

Definition at line 336 of file peermanager.h.

Constructor & Destructor Documentation

◆ PeerManager()

avalanche::PeerManager::PeerManager ( const Amount stakeUtxoDustThresholdIn,
ChainstateManager chainmanIn 
)
inline

Definition at line 245 of file peermanager.h.

Member Function Documentation

◆ addNode()

bool PeerManager::addNode ( NodeId  nodeid,
const ProofId proofid 
)

Node API.

Definition at line 18 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addNodeToPeer()

bool PeerManager::addNodeToPeer ( const PeerSet::iterator &  it)
private

Definition at line 63 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addOrUpdateNode()

bool PeerManager::addOrUpdateNode ( const PeerSet::iterator &  it,
NodeId  nodeid 
)
private

Definition at line 33 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addUnbroadcastProof()

void PeerManager::addUnbroadcastProof ( const ProofId proofid)

Proof broadcast API.

Definition at line 822 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanupDanglingProofs()

void PeerManager::cleanupDanglingProofs ( const ProofRef localProof)

Definition at line 429 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compact()

uint64_t PeerManager::compact ( )

Trigger maintenance of internal data structures.

Returns how much slot space was saved after compaction.

Definition at line 605 of file peermanager.cpp.

Here is the caller graph for this function:

◆ exists()

bool avalanche::PeerManager::exists ( const ProofId proofid) const
inline

Definition at line 344 of file peermanager.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ forEachNode()

template<typename Callable >
void avalanche::PeerManager::forEachNode ( const Peer peer,
Callable &&  func 
) const
inline

Definition at line 282 of file peermanager.h.

Here is the caller graph for this function:

◆ forEachPeer()

template<typename Callable >
void avalanche::PeerManager::forEachPeer ( Callable &&  func) const
inline

Definition at line 357 of file peermanager.h.

Here is the caller graph for this function:

◆ forNode()

template<typename Callable >
bool avalanche::PeerManager::forNode ( NodeId  nodeid,
Callable &&  func 
) const
inline

Definition at line 276 of file peermanager.h.

Here is the caller graph for this function:

◆ forPeer()

template<typename Callable >
bool avalanche::PeerManager::forPeer ( const ProofId proofid,
Callable &&  func 
) const
inline

Definition at line 351 of file peermanager.h.

Here is the caller graph for this function:

◆ getConflictingProofPool()

const ProofPool& avalanche::PeerManager::getConflictingProofPool ( ) const
inline

Definition at line 411 of file peermanager.h.

Here is the caller graph for this function:

◆ getConnectedPeersScore()

uint32_t avalanche::PeerManager::getConnectedPeersScore ( ) const
inline

Definition at line 379 of file peermanager.h.

Here is the caller graph for this function:

◆ getFragmentation()

uint64_t avalanche::PeerManager::getFragmentation ( ) const
inline

Definition at line 408 of file peermanager.h.

Here is the caller graph for this function:

◆ getImmatureProofPool()

const ProofPool& avalanche::PeerManager::getImmatureProofPool ( ) const
inline

Definition at line 414 of file peermanager.h.

Here is the caller graph for this function:

◆ getNodeCount()

size_t avalanche::PeerManager::getNodeCount ( ) const
inline

Definition at line 255 of file peermanager.h.

Here is the caller graph for this function:

◆ getPendingNodeCount()

size_t avalanche::PeerManager::getPendingNodeCount ( ) const
inline

Definition at line 256 of file peermanager.h.

Here is the caller graph for this function:

◆ getProof()

ProofRef PeerManager::getProof ( const ProofId proofid) const

Definition at line 517 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getShareableProofsSnapshot()

const ProofRadixTree& avalanche::PeerManager::getShareableProofsSnapshot ( ) const
inline

Definition at line 421 of file peermanager.h.

Here is the caller graph for this function:

◆ getSlotCount()

uint64_t avalanche::PeerManager::getSlotCount ( ) const
inline

Definition at line 407 of file peermanager.h.

Here is the caller graph for this function:

◆ getStakeUtxoDustThreshold()

const Amount& avalanche::PeerManager::getStakeUtxoDustThreshold ( ) const
inline

Definition at line 425 of file peermanager.h.

Here is the caller graph for this function:

◆ getTotalPeersScore()

uint32_t avalanche::PeerManager::getTotalPeersScore ( ) const
inline

Definition at line 378 of file peermanager.h.

Here is the caller graph for this function:

◆ getUnbroadcastProofs()

auto avalanche::PeerManager::getUnbroadcastProofs ( ) const
inline

Definition at line 373 of file peermanager.h.

◆ getValidProofPool()

const ProofPool& avalanche::PeerManager::getValidProofPool ( ) const
inline

Definition at line 410 of file peermanager.h.

Here is the caller graph for this function:

◆ isBoundToPeer()

bool PeerManager::isBoundToPeer ( const ProofId proofid) const

Definition at line 536 of file peermanager.cpp.

Here is the caller graph for this function:

◆ isImmature()

bool PeerManager::isImmature ( const ProofId proofid) const

Definition at line 541 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInConflictingPool()

bool PeerManager::isInConflictingPool ( const ProofId proofid) const

Definition at line 545 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ latchAvaproofsSent()

bool PeerManager::latchAvaproofsSent ( NodeId  nodeid)

Flag that a node did send its compact proofs.

Returns
True if the flag changed state, i;e. if this is the first time the message is accounted for this node.

Definition at line 156 of file peermanager.cpp.

Here is the caller graph for this function:

◆ moveToConflictingPool()

template<typename ProofContainer >
void PeerManager::moveToConflictingPool ( const ProofContainer &  proofs)
private

Definition at line 200 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerProof() [1/2]

bool PeerManager::registerProof ( const ProofRef proof,
ProofRegistrationState registrationState,
RegistrationMode  mode = RegistrationMode::DEFAULT 
)

Definition at line 212 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerProof() [2/2]

bool avalanche::PeerManager::registerProof ( const ProofRef proof,
RegistrationMode  mode = RegistrationMode::DEFAULT 
)
inline

Definition at line 321 of file peermanager.h.

Here is the call graph for this function:

◆ rejectProof()

bool PeerManager::rejectProof ( const ProofId proofid,
RejectionMode  mode = RejectionMode::DEFAULT 
)

Definition at line 379 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeNode()

bool PeerManager::removeNode ( NodeId  nodeid)

Definition at line 83 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeNodeFromPeer()

bool PeerManager::removeNodeFromPeer ( const PeerSet::iterator &  it,
uint32_t  count = 1 
)
private

Definition at line 104 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removePeer()

bool PeerManager::removePeer ( const PeerId  peerid)

Remove an existing peer.

Definition at line 549 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeUnbroadcastProof()

void PeerManager::removeUnbroadcastProof ( const ProofId proofid)

Definition at line 829 of file peermanager.cpp.

◆ selectNode()

NodeId PeerManager::selectNode ( )

Definition at line 457 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ selectPeer()

PeerId PeerManager::selectPeer ( ) const

Randomly select a peer to poll.

Definition at line 589 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFinalized()

bool PeerManager::setFinalized ( PeerId  peerid)

Latch on that this peer has a finalized proof.

Definition at line 187 of file peermanager.cpp.

◆ shouldRequestMoreNodes()

bool avalanche::PeerManager::shouldRequestMoreNodes ( )
inline

Returns true if we encountered a lack of node since the last call.

Definition at line 273 of file peermanager.h.

Here is the caller graph for this function:

◆ updatedBlockTip()

std::unordered_set< ProofRef, SaltedProofHasher > PeerManager::updatedBlockTip ( )

Update the peer set when a new block is connected.

Definition at line 483 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateNextPossibleConflictTime()

bool PeerManager::updateNextPossibleConflictTime ( PeerId  peerid,
const std::chrono::seconds &  nextTime 
)

Proof and Peer related API.

Update the time before which a proof is not allowed to have conflicting UTXO with this peer's proof.

Definition at line 170 of file peermanager.cpp.

Here is the caller graph for this function:

◆ updateNextRequestTime()

bool PeerManager::updateNextRequestTime ( NodeId  nodeid,
TimePoint  timeout 
)

Definition at line 147 of file peermanager.cpp.

Here is the caller graph for this function:

◆ verify()

bool PeerManager::verify ( ) const

Perform consistency check on internal data structures.

Definition at line 637 of file peermanager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ ::avalanche::TestPeerManager

friend struct ::avalanche::TestPeerManager
friend

Definition at line 437 of file peermanager.h.

Member Data Documentation

◆ chainman

ChainstateManager& avalanche::PeerManager::chainman
private

Definition at line 242 of file peermanager.h.

◆ conflictingProofPool

ProofPool avalanche::PeerManager::conflictingProofPool
private

Definition at line 177 of file peermanager.h.

◆ connectedPeersScore

uint32_t avalanche::PeerManager::connectedPeersScore = 0
private

Definition at line 238 of file peermanager.h.

◆ danglingProofIds

CRollingBloomFilter avalanche::PeerManager::danglingProofIds {10000, 0.00001}
private

Remember the last proofs that have been evicted because they had no node attached.

A false positive would cause the proof to fail to register if there is no previously known node that is claiming it, which is acceptable intended the low expected false positive rate.

Definition at line 232 of file peermanager.h.

◆ fragmentation

uint64_t avalanche::PeerManager::fragmentation = 0
private

Definition at line 156 of file peermanager.h.

◆ immatureProofPool

ProofPool avalanche::PeerManager::immatureProofPool
private

Definition at line 178 of file peermanager.h.

◆ m_unbroadcast_proofids

ProofIdSet avalanche::PeerManager::m_unbroadcast_proofids
private

Track proof ids to broadcast.

Definition at line 223 of file peermanager.h.

◆ needMoreNodes

std::atomic<bool> avalanche::PeerManager::needMoreNodes {false}
private

Flag indicating that we failed to select a node and need to expand our node set.

Definition at line 201 of file peermanager.h.

◆ nextPeerId

PeerId avalanche::PeerManager::nextPeerId = 0
private

Definition at line 173 of file peermanager.h.

◆ nodes

NodeSet avalanche::PeerManager::nodes
private

Definition at line 195 of file peermanager.h.

◆ peers

PeerSet avalanche::PeerManager::peers
private

Definition at line 174 of file peermanager.h.

◆ pendingNodes

PendingNodeSet avalanche::PeerManager::pendingNodes
private

Definition at line 215 of file peermanager.h.

◆ SELECT_NODE_MAX_RETRY

constexpr int avalanche::PeerManager::SELECT_NODE_MAX_RETRY = 3
staticconstexprprivate

Definition at line 218 of file peermanager.h.

◆ SELECT_PEER_MAX_RETRY

constexpr int avalanche::PeerManager::SELECT_PEER_MAX_RETRY = 3
staticconstexprprivate

Definition at line 217 of file peermanager.h.

◆ shareableProofs

ProofRadixTree avalanche::PeerManager::shareableProofs
private

Definition at line 181 of file peermanager.h.

◆ slotCount

uint64_t avalanche::PeerManager::slotCount = 0
private

Definition at line 155 of file peermanager.h.

◆ slots

std::vector<Slot> avalanche::PeerManager::slots
private

Definition at line 154 of file peermanager.h.

◆ stakeUtxoDustThreshold

Amount avalanche::PeerManager::stakeUtxoDustThreshold
private

Definition at line 240 of file peermanager.h.

◆ totalPeersScore

uint32_t avalanche::PeerManager::totalPeersScore = 0
private

Quorum management.

Definition at line 237 of file peermanager.h.

◆ validProofPool

ProofPool avalanche::PeerManager::validProofPool
private

Definition at line 176 of file peermanager.h.


The documentation for this class was generated from the following files: