![]() |
Bitcoin ABC 0.31.1
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, bool stakingPreConsensus=false, 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 |
void | cleanupStakeContenders (const int requestedMinHeight) |
Make some of the contender cache API available. More... | |
void | addStakeContender (const ProofRef &proof) |
int | getStakeContenderStatus (const StakeContenderId &contenderId, BlockHash &prevblockhashout) const |
void | acceptStakeContender (const StakeContenderId &contenderId) |
void | finalizeStakeContender (const StakeContenderId &contenderId, BlockHash &prevblockhash, std::vector< std::pair< ProofId, CScript > > &newWinners) |
void | rejectStakeContender (const StakeContenderId &contenderId) |
void | promoteStakeContendersToBlock (const CBlockIndex *pindex) |
bool | setContenderStatusForLocalWinners (const CBlockIndex *prevblock, const std::vector< std::pair< ProofId, CScript > > winners, size_t maxPollable, std::vector< StakeContenderId > &pollableContenders) |
bool | setStakeContenderWinners (const CBlockIndex *pindex, const std::vector< CScript > &payoutScripts) |
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 |
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 251 of file peermanager.h.
|
strong |
Registration mode.
Enumerator | |
---|---|
DEFAULT | |
FORCE_ACCEPT |
Definition at line 376 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 399 of file peermanager.h.
|
inline |
Definition at line 306 of file peermanager.h.
void PeerManager::acceptStakeContender | ( | const StakeContenderId & | contenderId | ) |
Node API.
Definition at line 33 of file peermanager.cpp.
|
private |
Definition at line 89 of file peermanager.cpp.
|
private |
Definition at line 48 of file peermanager.cpp.
void PeerManager::addStakeContender | ( | const ProofRef & | proof | ) |
Definition at line 1415 of file peermanager.cpp.
void PeerManager::addUnbroadcastProof | ( | const ProofId & | proofid | ) |
Proof broadcast API.
Definition at line 1003 of file peermanager.cpp.
void PeerManager::cleanupDanglingProofs | ( | std::unordered_set< ProofRef, SaltedProofHasher > & | registeredProofs | ) |
Definition at line 480 of file peermanager.cpp.
void PeerManager::cleanupStakeContenders | ( | const int | requestedMinHeight | ) |
Make some of the contender cache API available.
Definition at line 1411 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 780 of file peermanager.cpp.
bool PeerManager::dumpPeersToFile | ( | const fs::path & | dumpPath | ) | const |
Definition at line 1299 of file peermanager.cpp.
|
inline |
Return true if the (valid) proof exists, but only for non-dangling proofs.
Definition at line 411 of file peermanager.h.
void PeerManager::finalizeStakeContender | ( | const StakeContenderId & | contenderId, |
BlockHash & | prevblockhash, | ||
std::vector< std::pair< ProofId, CScript > > & | newWinners | ||
) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 615 of file peermanager.cpp.
|
private |
Get the presence remote status of a proof.
proofid | The target proof id |
Definition at line 1213 of file peermanager.cpp.
std::vector< RemoteProof > PeerManager::getRemoteProofs | ( | const NodeId | nodeid | ) | const |
|
inline |
|
inline |
int PeerManager::getStakeContenderStatus | ( | const StakeContenderId & | contenderId, |
BlockHash & | prevblockhashout | ||
) | const |
Definition at line 1429 of file peermanager.cpp.
|
inline |
|
inline |
|
inline |
Definition at line 441 of file peermanager.h.
|
inline |
bool PeerManager::isBoundToPeer | ( | const ProofId & | proofid | ) | const |
bool PeerManager::isDangling | ( | const ProofId & | proofid | ) | const |
Definition at line 647 of file peermanager.cpp.
|
private |
Definition at line 1149 of file peermanager.cpp.
bool PeerManager::isImmature | ( | const ProofId & | proofid | ) | const |
Definition at line 639 of file peermanager.cpp.
bool PeerManager::isInConflictingPool | ( | const ProofId & | proofid | ) | const |
Definition at line 643 of file peermanager.cpp.
bool PeerManager::isInvalid | ( | const ProofId & | proofid | ) | const |
Definition at line 655 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 194 of file peermanager.cpp.
bool PeerManager::loadPeersFromFile | ( | const fs::path & | dumpPath, |
std::unordered_set< ProofRef, SaltedProofHasher > & | registeredProofs | ||
) |
Definition at line 1340 of file peermanager.cpp.
|
private |
Definition at line 238 of file peermanager.cpp.
void PeerManager::promoteStakeContendersToBlock | ( | const CBlockIndex * | pindex | ) |
bool PeerManager::registerProof | ( | const ProofRef & | proof, |
ProofRegistrationState & | registrationState, | ||
RegistrationMode | mode = RegistrationMode::DEFAULT |
||
) |
Definition at line 250 of file peermanager.cpp.
|
inline |
bool PeerManager::rejectProof | ( | const ProofId & | proofid, |
RejectionMode | mode = RejectionMode::DEFAULT |
||
) |
Definition at line 425 of file peermanager.cpp.
void PeerManager::rejectStakeContender | ( | const StakeContenderId & | contenderId | ) |
bool PeerManager::removeNode | ( | NodeId | nodeid | ) |
Definition at line 109 of file peermanager.cpp.
|
private |
Definition at line 135 of file peermanager.cpp.
bool PeerManager::removePeer | ( | const PeerId | peerid | ) |
Remove an existing peer.
Definition at line 723 of file peermanager.cpp.
void PeerManager::removeUnbroadcastProof | ( | const ProofId & | proofid | ) |
Definition at line 1010 of file peermanager.cpp.
bool PeerManager::saveRemoteProof | ( | const ProofId & | proofid, |
const NodeId | nodeid, | ||
const bool | present | ||
) |
Definition at line 663 of file peermanager.cpp.
NodeId PeerManager::selectNode | ( | ) |
Definition at line 534 of file peermanager.cpp.
PeerId PeerManager::selectPeer | ( | ) | const |
Randomly select a peer to poll.
Definition at line 764 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 1014 of file peermanager.cpp.
bool PeerManager::setContenderStatusForLocalWinners | ( | const CBlockIndex * | prevblock, |
const std::vector< std::pair< ProofId, CScript > > | winners, | ||
size_t | maxPollable, | ||
std::vector< StakeContenderId > & | pollableContenders | ||
) |
bool PeerManager::setFinalized | ( | PeerId | peerid | ) |
Latch on that this peer has a finalized proof.
Definition at line 225 of file peermanager.cpp.
bool PeerManager::setFlaky | ( | const ProofId & | proofid | ) |
Definition at line 1141 of file peermanager.cpp.
void PeerManager::setInvalid | ( | const ProofId & | proofid | ) |
Definition at line 651 of file peermanager.cpp.
bool PeerManager::setStakeContenderWinners | ( | const CBlockIndex * | pindex, |
const std::vector< CScript > & | payoutScripts | ||
) |
|
inline |
Returns true if we encountered a lack of node since the last call.
Definition at line 336 of file peermanager.h.
bool PeerManager::unsetFlaky | ( | const ProofId & | proofid | ) |
std::unordered_set< ProofRef, SaltedProofHasher > PeerManager::updatedBlockTip | ( | ) |
Update the peer set when a new block is connected.
Definition at line 560 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 208 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 812 of file peermanager.cpp.
|
friend |
Definition at line 565 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 297 of file peermanager.h.
|
private |
Definition at line 247 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 299 of file peermanager.h.
|
staticconstexpr |
Definition at line 304 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 283 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 301 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.