diff --git a/src/avalanche/compactproofs.h b/src/avalanche/compactproofs.h --- a/src/avalanche/compactproofs.h +++ b/src/avalanche/compactproofs.h @@ -5,7 +5,7 @@ #ifndef BITCOIN_AVALANCHE_COMPACTPROOFS_H #define BITCOIN_AVALANCHE_COMPACTPROOFS_H -#include +#include #include #include @@ -35,7 +35,7 @@ CompactProofs() : shortproofidk0(GetRand(std::numeric_limits::max())), shortproofidk1(GetRand(std::numeric_limits::max())) {} - CompactProofs(const RadixTree &proofs); + CompactProofs(const RadixTree &proofs); uint64_t getShortID(const ProofId &proofid) const; diff --git a/src/avalanche/compactproofs.cpp b/src/avalanche/compactproofs.cpp --- a/src/avalanche/compactproofs.cpp +++ b/src/avalanche/compactproofs.cpp @@ -10,7 +10,7 @@ namespace avalanche { -CompactProofs::CompactProofs(const RadixTree &proofs) +CompactProofs::CompactProofs(const RadixTree &proofs) : CompactProofs() { proofs.forEachLeaf([&](auto pLeaf) { shortproofids.push_back(getShortID(pLeaf->proof->getId())); 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 @@ -157,19 +158,8 @@ ProofPool conflictingProofPool; ProofPool orphanProofPool; -public: - struct ProofElement { - ProofRef proof; - - ProofElement(const ProofRef &proofIn) : proof(proofIn) {} - - Uint256KeyWrapper getId() const { return proof->getId(); } - - IMPLEMENT_RCU_REFCOUNT(uint64_t); - }; - private: - RadixTree shareableProofs; + RadixTree shareableProofs; using NodeSet = boost::multi_index_container< Node, @@ -372,7 +362,7 @@ bool isOrphan(const ProofId &proofid) const; bool isInConflictingPool(const ProofId &proofid) const; - RadixTree getShareableProofsSnapshot() const { + RadixTree getShareableProofsSnapshot() const { return shareableProofs; } diff --git a/src/avalanche/peermanager.cpp b/src/avalanche/peermanager.cpp --- a/src/avalanche/peermanager.cpp +++ b/src/avalanche/peermanager.cpp @@ -314,7 +314,7 @@ assert(inserted.second); auto insertedRadixTree = - shareableProofs.insert(RCUPtr::make(proof)); + shareableProofs.insert(RCUPtr::make(proof)); assert(insertedRadixTree); RCULock::synchronize(); @@ -694,7 +694,7 @@ // Check there is no dangling proof in the radix tree bool danglingProofInRadixTree = false; - shareableProofs.forEachLeaf([&](RCUPtr pLeaf) { + shareableProofs.forEachLeaf([&](RCUPtr pLeaf) { if (!isBoundToPeer(pLeaf->proof->getId())) { danglingProofInRadixTree = true; } diff --git a/src/avalanche/prooftreeelement.h b/src/avalanche/prooftreeelement.h new file mode 100644 --- /dev/null +++ b/src/avalanche/prooftreeelement.h @@ -0,0 +1,28 @@ +// Copyright (c) 2022 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_PROOFTREEELEMENT_H +#define BITCOIN_AVALANCHE_PROOFTREEELEMENT_H + +#include +#include +#include + +#include + +namespace avalanche { + +struct ProofTreeElement { + ProofRef proof; + + ProofTreeElement(const ProofRef &proofIn) : proof(proofIn) {} + + Uint256KeyWrapper getId() const { return proof->getId(); } + + IMPLEMENT_RCU_REFCOUNT(uint64_t); +}; + +} // namespace avalanche + +#endif // BITCOIN_AVALANCHE_PROOFTREEELEMENT_H diff --git a/src/avalanche/test/compactproofs_tests.cpp b/src/avalanche/test/compactproofs_tests.cpp --- a/src/avalanche/test/compactproofs_tests.cpp +++ b/src/avalanche/test/compactproofs_tests.cpp @@ -45,11 +45,10 @@ { const size_t N = 1000; - RadixTree proofs; + RadixTree proofs; for (size_t i = 0; i < N; i++) { - BOOST_CHECK(proofs.insert( - RCUPtr::make( - buildRandomProof(MIN_VALID_PROOF_SCORE)))); + BOOST_CHECK(proofs.insert(RCUPtr::make( + buildRandomProof(MIN_VALID_PROOF_SCORE)))); } CompactProofs cpw(proofs);