Bitcoin ABC 0.30.5
P2P Digital Currency
|
#include <peermanager.h>
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, const ProofRef &localProofIn=ProofRef()) | |
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, SteadyMilliseconds 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 ®istrationState, 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 |
Return true if the (valid) proof exists, but only for non-dangling proofs. More... | |
void | cleanupDanglingProofs (std::unordered_set< ProofRef, SaltedProofHasher > ®isteredProofs) |
template<typename Callable > | |
bool | forPeer (const ProofId &proofid, Callable &&func) const |
template<typename Callable > | |
void | forEachPeer (Callable &&func) const |
std::unordered_set< ProofRef, SaltedProofHasher > | updatedBlockTip () |
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 | saveRemoteProof (const ProofId &proofid, const NodeId nodeid, const bool present) |
std::vector< RemoteProof > | getRemoteProofs (const NodeId nodeid) const |
bool | isRemoteProof (const ProofId &proofid) const |
bool | setFlaky (const ProofId &proofid) |
bool | unsetFlaky (const ProofId &proofid) |
template<typename Callable > | |
void | forEachFlakyProof (Callable &&func) const |
template<typename Callable > | |
void | updateAvailabilityScores (const double decayFactor, Callable &&getNodeAvailabilityScore) |
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 ProofPool & | getValidProofPool () const |
const ProofPool & | getConflictingProofPool () const |
const ProofPool & | getImmatureProofPool () 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 |
bool | isDangling (const ProofId &proofid) const |
void | setInvalid (const ProofId &proofid) |
bool | isInvalid (const ProofId &proofid) const |
void | clearAllInvalid () |
const ProofRadixTree & | getShareableProofsSnapshot () const |
const Amount & | getStakeUtxoDustThreshold () const |
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. More... | |
bool | dumpPeersToFile (const fs::path &dumpPath) const |
bool | loadPeersFromFile (const fs::path &dumpPath, std::unordered_set< ProofRef, SaltedProofHasher > ®isteredProofs) |
Static Public Attributes | |
static constexpr size_t | MAX_REMOTE_PROOFS {100} |
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, SteadyMilliseconds, &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 > > > > |
using | RemoteProofSet = 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 > > > > > |
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) |
std::optional< bool > | getRemotePresenceStatus (const ProofId &proofid) const |
Get the presence remote status of a proof. More... | |
bool | isFlaky (const ProofId &proofid) const |
Private Attributes | |
std::vector< Slot > | slots |
uint64_t | slotCount = 0 |
uint64_t | fragmentation = 0 |
PeerId | nextPeerId = 0 |
PeerSet | peers |
ProofPool | validProofPool |
ProofPool | conflictingProofPool |
ProofPool | immatureProofPool |
ProofPool | danglingProofPool |
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... | |
uint32_t | totalPeersScore = 0 |
Quorum management. More... | |
uint32_t | connectedPeersScore = 0 |
Amount | stakeUtxoDustThreshold |
ChainstateManager & | chainman |
ProofRef | localProof |
RemoteProofSet | remoteProofs |
Remember which node sent which proof so we have an image of the proof set of our peers. More... | |
CRollingBloomFilter | invalidProofs {100000, 0.000001} |
Filter for proofs that are consensus-invalid or were recently invalidated by avalanche (finalized rejection). More... | |
std::unordered_set< ProofId, SaltedProofIdHasher > | manualFlakyProofids |
Static Private Attributes | |
static constexpr int | SELECT_PEER_MAX_RETRY = 3 |
static constexpr int | SELECT_NODE_MAX_RETRY = 3 |
Friends | |
struct | ::avalanche::TestPeerManager |
Definition at line 162 of file peermanager.h.
|
private |
Definition at line 193 of file peermanager.h.
|
private |
Several nodes can make an avalanche peer.
In this case, all nodes are considered interchangeable parts of the same peer.
Definition at line 171 of file peermanager.h.
|
private |
Definition at line 213 of file peermanager.h.
|
private |
Definition at line 190 of file peermanager.h.
|
private |
Definition at line 249 of file peermanager.h.
|
strong |
Registration mode.
Enumerator | |
---|---|
DEFAULT | |
FORCE_ACCEPT |
Definition at line 371 of file peermanager.h.
|
strong |
Rejection mode.
In any case if a peer is rejected, it attempts to pull the conflicting proofs back.
Enumerator | |
---|---|
DEFAULT | |
INVALIDATE |
Definition at line 394 of file peermanager.h.
|
inline |
Definition at line 302 of file peermanager.h.
Node API.
Definition at line 31 of file peermanager.cpp.
|
private |
Definition at line 87 of file peermanager.cpp.
|
private |
Definition at line 46 of file peermanager.cpp.
void PeerManager::addUnbroadcastProof | ( | const ProofId & | proofid | ) |
Proof broadcast API.
Definition at line 984 of file peermanager.cpp.
void PeerManager::cleanupDanglingProofs | ( | std::unordered_set< ProofRef, SaltedProofHasher > & | registeredProofs | ) |
Definition at line 474 of file peermanager.cpp.
void PeerManager::clearAllInvalid | ( | ) |
uint64_t PeerManager::compact | ( | ) |
Trigger maintenance of internal data structures.
Returns how much slot space was saved after compaction.
Definition at line 761 of file peermanager.cpp.
bool PeerManager::dumpPeersToFile | ( | const fs::path & | dumpPath | ) | const |
Definition at line 1285 of file peermanager.cpp.
|
inline |
Return true if the (valid) proof exists, but only for non-dangling proofs.
Definition at line 406 of file peermanager.h.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 609 of file peermanager.cpp.
|
private |
Get the presence remote status of a proof.
proofid | The target proof id |
Definition at line 1199 of file peermanager.cpp.
std::vector< RemoteProof > PeerManager::getRemoteProofs | ( | const NodeId | nodeid | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 436 of file peermanager.h.
|
inline |
bool PeerManager::isBoundToPeer | ( | const ProofId & | proofid | ) | const |
bool PeerManager::isDangling | ( | const ProofId & | proofid | ) | const |
Definition at line 641 of file peermanager.cpp.
|
private |
Definition at line 1135 of file peermanager.cpp.
bool PeerManager::isImmature | ( | const ProofId & | proofid | ) | const |
Definition at line 633 of file peermanager.cpp.
bool PeerManager::isInConflictingPool | ( | const ProofId & | proofid | ) | const |
Definition at line 637 of file peermanager.cpp.
bool PeerManager::isInvalid | ( | const ProofId & | proofid | ) | const |
Definition at line 649 of file peermanager.cpp.
bool PeerManager::isRemoteProof | ( | const ProofId & | proofid | ) | const |
bool PeerManager::latchAvaproofsSent | ( | NodeId | nodeid | ) |
Flag that a node did send its compact proofs.
Definition at line 192 of file peermanager.cpp.
bool PeerManager::loadPeersFromFile | ( | const fs::path & | dumpPath, |
std::unordered_set< ProofRef, SaltedProofHasher > & | registeredProofs | ||
) |
Definition at line 1326 of file peermanager.cpp.
|
private |
Definition at line 236 of file peermanager.cpp.
bool PeerManager::registerProof | ( | const ProofRef & | proof, |
ProofRegistrationState & | registrationState, | ||
RegistrationMode | mode = RegistrationMode::DEFAULT |
||
) |
Definition at line 248 of file peermanager.cpp.
|
inline |
bool PeerManager::rejectProof | ( | const ProofId & | proofid, |
RejectionMode | mode = RejectionMode::DEFAULT |
||
) |
Definition at line 419 of file peermanager.cpp.
bool PeerManager::removeNode | ( | NodeId | nodeid | ) |
Definition at line 107 of file peermanager.cpp.
|
private |
Definition at line 133 of file peermanager.cpp.
bool PeerManager::removePeer | ( | const PeerId | peerid | ) |
Remove an existing peer.
Definition at line 704 of file peermanager.cpp.
void PeerManager::removeUnbroadcastProof | ( | const ProofId & | proofid | ) |
Definition at line 991 of file peermanager.cpp.
NodeId PeerManager::selectNode | ( | ) |
Definition at line 528 of file peermanager.cpp.
PeerId PeerManager::selectPeer | ( | ) | const |
Randomly select a peer to poll.
Definition at line 745 of file peermanager.cpp.
bool PeerManager::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.
Definition at line 995 of file peermanager.cpp.
bool PeerManager::setFinalized | ( | PeerId | peerid | ) |
Latch on that this peer has a finalized proof.
Definition at line 223 of file peermanager.cpp.
bool PeerManager::setFlaky | ( | const ProofId & | proofid | ) |
Definition at line 1127 of file peermanager.cpp.
void PeerManager::setInvalid | ( | const ProofId & | proofid | ) |
Definition at line 645 of file peermanager.cpp.
|
inline |
Returns true if we encountered a lack of node since the last call.
Definition at line 331 of file peermanager.h.
bool PeerManager::unsetFlaky | ( | const ProofId & | proofid | ) |
|
inline |
Definition at line 458 of file peermanager.h.
std::unordered_set< ProofRef, SaltedProofHasher > PeerManager::updatedBlockTip | ( | ) |
Update the peer set when a new block is connected.
Definition at line 554 of file peermanager.cpp.
bool PeerManager::updateNextPossibleConflictTime | ( | PeerId | peerid, |
const std::chrono::seconds & | nextTime | ||
) |
Update the time before which a proof is not allowed to have conflicting UTXO with this peer's proof.
Definition at line 206 of file peermanager.cpp.
bool PeerManager::updateNextRequestTime | ( | NodeId | nodeid, |
SteadyMilliseconds | timeout | ||
) |
bool PeerManager::verify | ( | ) | const |
Perform consistency check on internal data structures.
Definition at line 793 of file peermanager.cpp.
|
friend |
Definition at line 561 of file peermanager.h.
|
private |
Definition at line 243 of file peermanager.h.
|
private |
Definition at line 186 of file peermanager.h.
|
private |
Definition at line 239 of file peermanager.h.
|
private |
Definition at line 188 of file peermanager.h.
|
private |
Definition at line 165 of file peermanager.h.
|
private |
Definition at line 187 of file peermanager.h.
|
private |
Filter for proofs that are consensus-invalid or were recently invalidated by avalanche (finalized rejection).
These are not rerequested until they are rolled out of the filter.
Without this filter we'd be re-requesting proofs from each of our peers, increasing bandwidth consumption considerably.
Decreasing the false positive rate is fairly cheap, so we pick one in a million to make it highly unlikely for users to have issues with this filter.
Definition at line 295 of file peermanager.h.
|
private |
Definition at line 245 of file peermanager.h.
|
private |
Track proof ids to broadcast.
Definition at line 233 of file peermanager.h.
|
private |
Definition at line 297 of file peermanager.h.
|
staticconstexpr |
Definition at line 300 of file peermanager.h.
|
private |
Flag indicating that we failed to select a node and need to expand our node set.
Definition at line 211 of file peermanager.h.
|
private |
Definition at line 182 of file peermanager.h.
|
private |
Definition at line 205 of file peermanager.h.
|
private |
Definition at line 183 of file peermanager.h.
|
private |
Definition at line 225 of file peermanager.h.
|
private |
Remember which node sent which proof so we have an image of the proof set of our peers.
Definition at line 281 of file peermanager.h.
|
staticconstexprprivate |
Definition at line 228 of file peermanager.h.
|
staticconstexprprivate |
Definition at line 227 of file peermanager.h.
|
private |
Definition at line 191 of file peermanager.h.
|
private |
Definition at line 164 of file peermanager.h.
|
private |
Definition at line 163 of file peermanager.h.
|
private |
Definition at line 241 of file peermanager.h.
|
private |
Quorum management.
Definition at line 238 of file peermanager.h.
|
private |
Definition at line 185 of file peermanager.h.