Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proofpool.h
Show All 12 Lines | |||||
#include <boost/multi_index/hashed_index.hpp> | #include <boost/multi_index/hashed_index.hpp> | ||||
#include <boost/multi_index/mem_fun.hpp> | #include <boost/multi_index/mem_fun.hpp> | ||||
#include <boost/multi_index/member.hpp> | #include <boost/multi_index/member.hpp> | ||||
#include <boost/multi_index/ordered_index.hpp> | #include <boost/multi_index/ordered_index.hpp> | ||||
#include <boost/multi_index_container.hpp> | #include <boost/multi_index_container.hpp> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <functional> | |||||
namespace avalanche { | namespace avalanche { | ||||
class PeerManager; | class PeerManager; | ||||
struct ProofPoolEntry { | struct ProofPoolEntry { | ||||
size_t utxoIndex; | size_t utxoIndex; | ||||
ProofRef proof; | ProofRef proof; | ||||
const COutPoint &getUTXO() const { | const COutPoint &getUTXO() const { | ||||
return proof->getStakes().at(utxoIndex).getStake().getUTXO(); | return proof->getStakes().at(utxoIndex).getStake().getUTXO(); | ||||
} | } | ||||
ProofPoolEntry(size_t _utxoIndex, ProofRef _proof) | ProofPoolEntry(size_t _utxoIndex, ProofRef _proof) | ||||
: utxoIndex(_utxoIndex), proof(std::move(_proof)) {} | : utxoIndex(_utxoIndex), proof(std::move(_proof)) {} | ||||
}; | }; | ||||
struct by_utxo; | struct by_utxo; | ||||
struct by_proofid; | struct by_proofid; | ||||
struct by_proof_score; | struct by_proof_score; | ||||
struct by_registration_time; | |||||
struct ProofPoolEntryProofIdKeyExtractor { | struct ProofPoolEntryProofIdKeyExtractor { | ||||
using result_type = ProofId; | using result_type = ProofId; | ||||
result_type operator()(const ProofPoolEntry &entry) const { | result_type operator()(const ProofPoolEntry &entry) const { | ||||
return entry.proof->getId(); | return entry.proof->getId(); | ||||
} | } | ||||
}; | }; | ||||
Show All 21 Lines | boost::multi_index_container< | ||||
bmi::tag<by_proof_score>, | bmi::tag<by_proof_score>, | ||||
bmi::member<ProofPoolEntry, ProofRef, &ProofPoolEntry::proof>, | bmi::member<ProofPoolEntry, ProofRef, &ProofPoolEntry::proof>, | ||||
ProofComparatorByScore>>> | ProofComparatorByScore>>> | ||||
pool; | pool; | ||||
bool cacheClean = true; | bool cacheClean = true; | ||||
size_t cacheProofCount = 0; | size_t cacheProofCount = 0; | ||||
struct ProofRegistrationTime { | |||||
ProofId proofid; | |||||
// std::chrono::duration is not hashable by default, so use an integer | |||||
int64_t registrationTime; | |||||
ProofRegistrationTime(const ProofId &proofidIn, | |||||
int64_t registrationTimeIn) | |||||
: proofid(proofidIn), registrationTime(registrationTimeIn) {} | |||||
}; | |||||
using ProofRegistrationTimeSet = boost::multi_index_container< | |||||
ProofRegistrationTime, | |||||
bmi::indexed_by< | |||||
// index by proofid | |||||
bmi::hashed_unique<bmi::tag<by_proofid>, | |||||
bmi::member<ProofRegistrationTime, ProofId, | |||||
&ProofRegistrationTime::proofid>, | |||||
SaltedProofIdHasher>, | |||||
// ordered by registrationTime | |||||
bmi::ordered_non_unique< | |||||
bmi::tag<by_registration_time>, | |||||
bmi::member<ProofRegistrationTime, int64_t, | |||||
&ProofRegistrationTime::registrationTime>>>>; | |||||
ProofRegistrationTimeSet registrationTimes; | |||||
public: | public: | ||||
enum AddProofStatus { | enum AddProofStatus { | ||||
REJECTED = 0, //!< Rejected due to conflicts | REJECTED = 0, //!< Rejected due to conflicts | ||||
SUCCEED = 1, //!< Added successfully | SUCCEED = 1, //!< Added successfully | ||||
DUPLICATED = 2, //!< Already in pool | DUPLICATED = 2, //!< Already in pool | ||||
}; | }; | ||||
using ConflictingProofSet = std::set<ProofRef, ConflictingProofComparator>; | using ConflictingProofSet = std::set<ProofRef, ConflictingProofComparator>; | ||||
Show All 24 Lines | public: | ||||
bool removeProof(ProofId proofid); | bool removeProof(ProofId proofid); | ||||
void rescan(PeerManager &peerManager); | void rescan(PeerManager &peerManager); | ||||
ProofRef getProof(const ProofId &proofid) const; | ProofRef getProof(const ProofId &proofid) const; | ||||
ProofRef getProof(const COutPoint &outpoint) const; | ProofRef getProof(const COutPoint &outpoint) const; | ||||
ProofRef getLowestScoreProof() const; | ProofRef getLowestScoreProof() const; | ||||
std::optional<std::chrono::seconds> | |||||
getRegistrationTime(const ProofId &proofid) const; | |||||
size_t size() const { return pool.size(); } | size_t size() const { return pool.size(); } | ||||
size_t countProofs(); | size_t countProofs(); | ||||
}; | }; | ||||
} // namespace avalanche | } // namespace avalanche | ||||
#endif // BITCOIN_AVALANCHE_PROOFPOOL_H | #endif // BITCOIN_AVALANCHE_PROOFPOOL_H |