diff --git a/src/avalanche/peermanager.h b/src/avalanche/peermanager.h --- a/src/avalanche/peermanager.h +++ b/src/avalanche/peermanager.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -91,25 +92,9 @@ uint32_t getScore() const { return proof->getScore(); } }; -struct ProofPoolEntry { - size_t utxoIndex; - ProofRef proof; - - const COutPoint &getUTXO() const { - return proof->getStakes().at(utxoIndex).getStake().getUTXO(); - } - - ProofPoolEntry(size_t _utxoIndex, const ProofRef &_proof) - : utxoIndex(_utxoIndex), proof(_proof) {} -}; - -struct by_utxo; - -template struct proof_index { +struct proof_index { using result_type = ProofId; - result_type operator()(const StructWithProof &s) const { - return s.proof->getId(); - } + result_type operator()(const Peer &p) const { return p.proof->getId(); } }; struct next_request_time {}; @@ -141,29 +126,12 @@ // index by peerid bmi::hashed_unique>, // index by proof - bmi::hashed_unique, proof_index, + bmi::hashed_unique, proof_index, SaltedProofIdHasher>>>; PeerId nextPeerId = 0; PeerSet peers; - /** - * Map a proof to each utxo. A proof can be mapped with several utxos. - */ - using ProofPool = boost::multi_index_container< - ProofPoolEntry, - bmi::indexed_by< - // index by utxo - bmi::hashed_unique< - bmi::tag, - bmi::const_mem_fun, - SaltedOutpointHasher>, - // index by proofid - bmi::hashed_non_unique, - proof_index, - SaltedProofIdHasher>>>; - ProofPool validProofPool; using NodeSet = boost::multi_index_container< diff --git a/src/avalanche/proofpool.h b/src/avalanche/proofpool.h new file mode 100644 --- /dev/null +++ b/src/avalanche/proofpool.h @@ -0,0 +1,63 @@ +// Copyright (c) 2021 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_AVALANCHE_PROOFPOOL_H +#define BITCOIN_AVALANCHE_PROOFPOOL_H + +#include +#include +#include +#include + +#include +#include +#include + +#include + +namespace avalanche { + +struct ProofPoolEntry { + size_t utxoIndex; + ProofRef proof; + + const COutPoint &getUTXO() const { + return proof->getStakes().at(utxoIndex).getStake().getUTXO(); + } + + ProofPoolEntry(size_t _utxoIndex, ProofRef _proof) + : utxoIndex(_utxoIndex), proof(std::move(_proof)) {} +}; + +struct by_utxo; +struct by_proofid; + +struct ProofPoolEntryProofIdKeyExtractor { + using result_type = ProofId; + result_type operator()(const ProofPoolEntry &entry) const { + return entry.proof->getId(); + } +}; + +namespace bmi = boost::multi_index; + +/** + * Map a proof to each utxo. A proof can be mapped with several utxos. + */ +using ProofPool = boost::multi_index_container< + ProofPoolEntry, + bmi::indexed_by< + // index by utxo + bmi::hashed_unique, + bmi::const_mem_fun, + SaltedOutpointHasher>, + // index by proofid + bmi::hashed_non_unique, + ProofPoolEntryProofIdKeyExtractor, + SaltedProofIdHasher>>>; + +} // namespace avalanche + +#endif // BITCOIN_AVALANCHE_PROOFPOOL_H