Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proofpool.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_PROOFPOOL_H | #ifndef BITCOIN_AVALANCHE_PROOFPOOL_H | ||||
#define BITCOIN_AVALANCHE_PROOFPOOL_H | #define BITCOIN_AVALANCHE_PROOFPOOL_H | ||||
#include <avalanche/proof.h> | #include <avalanche/proof.h> | ||||
#include <avalanche/proofcomparator.h> | |||||
#include <avalanche/proofid.h> | #include <avalanche/proofid.h> | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#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_container.hpp> | #include <boost/multi_index_container.hpp> | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
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 | ||||
}; | }; | ||||
AddProofStatus addProof(const ProofRef &proof); | using ConflictingProofSet = std::set<ProofRef, ConflictingProofComparator>; | ||||
/** | |||||
* Attempt to add a proof to the pool, and fail if there is a conflict on | |||||
* any UTXO. | |||||
*/ | |||||
AddProofStatus addProofIfNoConflict(const ProofRef &proof); | |||||
AddProofStatus addProofIfNoConflict(const ProofRef &proof, | |||||
ConflictingProofSet &conflictingProofs); | |||||
/** | |||||
* Attempt to add a proof to the pool. In case there is a conflict with one | |||||
* or more UTXO, the proof is only added if it is the best candidate over | |||||
* all the conflicting proofs according to ConflictingProofComparator. | |||||
*/ | |||||
AddProofStatus addProofIfPreferred(const ProofRef &proof); | |||||
AddProofStatus addProofIfPreferred(const ProofRef &proof, | |||||
ConflictingProofSet &conflictingProofs); | |||||
bool removeProof(ProofRef proof); | bool removeProof(ProofRef proof); | ||||
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; | ||||
size_t size() const { return pool.size(); } | size_t size() const { return pool.size(); } | ||||
}; | }; | ||||
} // namespace avalanche | } // namespace avalanche | ||||
#endif // BITCOIN_AVALANCHE_PROOFPOOL_H | #endif // BITCOIN_AVALANCHE_PROOFPOOL_H |