diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -543,6 +543,7 @@ avalanche/peermanager.cpp avalanche/processor.cpp avalanche/proof.cpp + avalanche/proofid.cpp avalanche/proofbuilder.cpp banman.cpp blockencodings.cpp diff --git a/src/avalanche/proof.cpp b/src/avalanche/proof.cpp --- a/src/avalanche/proof.cpp +++ b/src/avalanche/proof.cpp @@ -58,12 +58,7 @@ } limitedProofId = LimitedProofId(ss.GetHash()); - - CHashWriter ss2(SER_GETHASH, 0); - ss2 << limitedProofId; - ss2 << master; - - proofid = ProofId(ss2.GetHash()); + proofid = limitedProofId.computeProofId(master); } uint32_t Proof::getScore() const { diff --git a/src/avalanche/proofid.h b/src/avalanche/proofid.h --- a/src/avalanche/proofid.h +++ b/src/avalanche/proofid.h @@ -10,28 +10,32 @@ #include +class CPubKey; + namespace avalanche { -struct LimitedProofId : public uint256 { - explicit LimitedProofId() : uint256() {} - explicit LimitedProofId(const uint256 &b) : uint256(b) {} +struct ProofId : public uint256 { + explicit ProofId() : uint256() {} + explicit ProofId(const uint256 &b) : uint256(b) {} - static LimitedProofId fromHex(const std::string &str) { - LimitedProofId r; + static ProofId fromHex(const std::string &str) { + ProofId r; r.SetHex(str); return r; } }; -struct ProofId : public uint256 { - explicit ProofId() : uint256() {} - explicit ProofId(const uint256 &b) : uint256(b) {} +struct LimitedProofId : public uint256 { + explicit LimitedProofId() : uint256() {} + explicit LimitedProofId(const uint256 &b) : uint256(b) {} - static ProofId fromHex(const std::string &str) { - ProofId r; + static LimitedProofId fromHex(const std::string &str) { + LimitedProofId r; r.SetHex(str); return r; } + + ProofId computeProofId(const CPubKey &proofMaster) const; }; class SaltedProofIdHasher : private SaltedUint256Hasher { diff --git a/src/avalanche/proofid.cpp b/src/avalanche/proofid.cpp new file mode 100644 --- /dev/null +++ b/src/avalanche/proofid.cpp @@ -0,0 +1,19 @@ +// 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. + +#include + +#include +#include + +namespace avalanche { + +ProofId LimitedProofId::computeProofId(const CPubKey &proofMaster) const { + CHashWriter ss(SER_GETHASH, 0); + ss << *this; + ss << proofMaster; + return ProofId(ss.GetHash()); +} + +} // namespace avalanche