Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/orphanproofpool.h
// Copyright (c) 2021 The Bitcoin developers | // Copyright (c) 2021 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_AVALANCHE_ORPHANPROOFPOOL_H | #ifndef BITCOIN_AVALANCHE_ORPHANPROOFPOOL_H | ||||
#define BITCOIN_AVALANCHE_ORPHANPROOFPOOL_H | #define BITCOIN_AVALANCHE_ORPHANPROOFPOOL_H | ||||
#include <avalanche/proof.h> | #include <avalanche/proof.h> | ||||
#include <boost/multi_index/hashed_index.hpp> | #include <boost/multi_index/hashed_index.hpp> | ||||
#include <boost/multi_index/sequenced_index.hpp> | #include <boost/multi_index/sequenced_index.hpp> | ||||
#include <boost/multi_index_container.hpp> | #include <boost/multi_index_container.hpp> | ||||
#include <memory> | |||||
namespace avalanche { | namespace avalanche { | ||||
// 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 Proof &proof) const { return proof.getId(); } | result_type operator()(const std::shared_ptr<Proof> &proof) const { | ||||
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< | ||||
Proof, | std::shared_ptr<Proof>, | ||||
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(Proof proof); | bool addProof(const std::shared_ptr<Proof> &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. | ||||
*/ | */ | ||||
const Proof *getProof(const ProofId &proofId) const; | std::shared_ptr<Proof> getProof(const ProofId &proofId) const; | ||||
// 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 |