Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/orphanproofpool.h
Show All 13 Lines | |||||
namespace avalanche { | namespace avalanche { | ||||
class PeerManager; | class PeerManager; | ||||
// Extracts a ProofId from a Proof | // Extracts a ProofId from a Proof | ||||
struct proofid_extractor { | struct proofid_extractor { | ||||
using result_type = ProofId; | using result_type = ProofId; | ||||
result_type operator()(const std::shared_ptr<Proof> &proof) const { | result_type operator()(const ProofRef &proof) const { | ||||
return proof->getId(); | return proof->getId(); | ||||
} | } | ||||
}; | }; | ||||
struct by_sequence {}; | struct by_sequence {}; | ||||
struct by_proofid {}; | struct by_proofid {}; | ||||
using ProofContainer = boost::multi_index_container< | using ProofContainer = boost::multi_index_container< | ||||
std::shared_ptr<Proof>, | ProofRef, | ||||
boost::multi_index::indexed_by< | boost::multi_index::indexed_by< | ||||
// keep insertion order | // keep insertion order | ||||
boost::multi_index::sequenced<boost::multi_index::tag<by_sequence>>, | boost::multi_index::sequenced<boost::multi_index::tag<by_sequence>>, | ||||
// indexed by proofid | // indexed by proofid | ||||
boost::multi_index::hashed_unique<boost::multi_index::tag<by_proofid>, | boost::multi_index::hashed_unique<boost::multi_index::tag<by_proofid>, | ||||
proofid_extractor, | proofid_extractor, | ||||
SaltedProofIdHasher>>>; | SaltedProofIdHasher>>>; | ||||
Show All 18 Lines | |||||
public: | public: | ||||
OrphanProofPool(size_t maxNumberOfStakes) | OrphanProofPool(size_t maxNumberOfStakes) | ||||
: maxNumberOfStakes(maxNumberOfStakes) {} | : maxNumberOfStakes(maxNumberOfStakes) {} | ||||
/** | /** | ||||
* Add a proof to the pool. | * Add a proof to the pool. | ||||
* The caller is responsible for checking the proof. | * The caller is responsible for checking the proof. | ||||
*/ | */ | ||||
bool addProof(const std::shared_ptr<Proof> &proof); | bool addProof(const ProofRef &proof); | ||||
/** Remove a proof from the pool. */ | /** Remove a proof from the pool. */ | ||||
bool removeProof(const ProofId &proofId); | bool removeProof(const ProofId &proofId); | ||||
/** | /** | ||||
* Get a pointer to a proof by id, or nullptr if the proof is not in the | * Get a pointer to a proof by id, or nullptr if the proof is not in the | ||||
* pool. | * pool. | ||||
*/ | */ | ||||
std::shared_ptr<Proof> getProof(const ProofId &proofId) const; | ProofRef getProof(const ProofId &proofId) const; | ||||
/** | /** | ||||
* Rescan the pool to remove previously orphaned proofs that have become | * Rescan the pool to remove previously orphaned proofs that have become | ||||
* good or permanently bad. | * good or permanently bad. | ||||
*/ | */ | ||||
void rescan(PeerManager &peerManager); | void rescan(PeerManager &peerManager); | ||||
// For testing | // For testing | ||||
size_t getNProofs() const; | size_t getNProofs() const; | ||||
size_t getNStakes() const; | size_t getNStakes() const; | ||||
}; | }; | ||||
} // namespace avalanche | } // namespace avalanche | ||||
#endif // BITCOIN_AVALANCHE_ORPHANPROOFPOOL_H | #endif // BITCOIN_AVALANCHE_ORPHANPROOFPOOL_H |