15 const ProofId &proofid = proof->getId();
18 conflictingProofs.clear();
20 auto &poolView =
pool.get<by_proofid>();
21 if (poolView.find(proofid) != poolView.end()) {
22 return AddProofStatus::DUPLICATED;
26 for (
size_t i = 0; i < proof->getStakes().size(); i++) {
27 auto p =
pool.emplace(i, proof);
30 conflictingProofs.insert(p.first->proof);
35 if (conflictingProofs.size() > 0) {
36 for (
const auto &s : proof->getStakes()) {
37 auto it =
pool.find(s.getStake().getUTXO());
41 if (it->proof->getId() == proofid) {
46 return AddProofStatus::REJECTED;
50 return AddProofStatus::SUCCEED;
60 if (status != AddProofStatus::REJECTED ||
65 for (
auto &conflictingProof : conflictingProofs) {
70 assert(status == AddProofStatus::SUCCEED);
73 return AddProofStatus::SUCCEED;
81 auto &poolView =
pool.get<by_proofid>();
82 return poolView.erase(proofid);
85std::unordered_set<ProofRef, SaltedProofHasher>
87 auto previousPool = std::move(
pool);
91 std::unordered_set<ProofRef, SaltedProofHasher> registeredProofs;
92 for (
auto &entry : previousPool) {
93 if (registeredProofs.insert(entry.proof).second) {
98 return registeredProofs;
104 auto &poolView =
pool.get<by_proofid>();
105 for (
auto it = poolView.begin(); it != poolView.end(); it++) {
106 proofIds.insert(it->proof->getId());
113 auto &poolView =
pool.get<by_proofid>();
114 auto it = poolView.find(proofid);
115 return it == poolView.end() ?
ProofRef() : it->proof;
119 auto it =
pool.find(outpoint);
124 auto &poolView =
pool.get<by_proof_score>();
125 return poolView.rbegin() == poolView.rend() ?
ProofRef()
126 : poolView.rbegin()->proof;
bool registerProof(const ProofRef &proof, ProofRegistrationState ®istrationState, RegistrationMode mode=RegistrationMode::DEFAULT)
AddProofStatus addProofIfPreferred(const ProofRef &proof, ConflictingProofSet &conflictingProofs)
Attempt to add a proof to the pool.
AddProofStatus addProofIfNoConflict(const ProofRef &proof, ConflictingProofSet &conflictingProofs)
Attempt to add a proof to the pool, and fail if there is a conflict on any UTXO.
size_t countProofs() const
bool removeProof(ProofId proofid)
void forEachProof(Callable &&func) const
ProofRef getProof(const ProofId &proofid) const
std::set< ProofRef, ConflictingProofComparator > ConflictingProofSet
ProofRef getLowestScoreProof() const
boost::multi_index_container< ProofPoolEntry, bmi::indexed_by< bmi::hashed_unique< bmi::tag< by_utxo >, bmi::const_mem_fun< ProofPoolEntry, const COutPoint &, &ProofPoolEntry::getUTXO >, SaltedOutpointHasher >, bmi::hashed_non_unique< bmi::tag< by_proofid >, ProofPoolEntryProofIdKeyExtractor, SaltedProofIdHasher >, bmi::ordered_non_unique< bmi::tag< by_proof_score >, bmi::member< ProofPoolEntry, ProofRef, &ProofPoolEntry::proof >, ProofComparatorByScore > > > pool
std::unordered_set< ProofRef, SaltedProofHasher > rescan(PeerManager &peerManager)
ProofIdSet getProofIds() const
std::unordered_set< ProofId, SaltedProofIdHasher > ProofIdSet
RCUPtr< const Proof > ProofRef
Compare conflicting proofs.