fix: Restore caching in CalcCbTxMerkleRootMNList (#4951)

This commit is contained in:
UdjinM6 2022-08-06 11:45:02 +03:00 committed by GitHub
parent abcc14b51e
commit bdfa322f1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -130,7 +130,7 @@ bool CalcCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindexPrev
static uint256 merkleRootCached;
static bool mutatedCached{false};
if (sml.mnList == smlCached.mnList) {
if (sml == smlCached) {
merkleRootRet = merkleRootCached;
if (mutatedCached) {
return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "mutated-cached-calc-cb-mnmerkleroot");

View File

@ -115,6 +115,17 @@ uint256 CSimplifiedMNList::CalcMerkleRoot(bool* pmutated) const
return ComputeMerkleRoot(leaves, pmutated);
}
bool CSimplifiedMNList::operator==(const CSimplifiedMNList& rhs) const
{
return mnList.size() == rhs.mnList.size() &&
std::equal(mnList.begin(), mnList.end(), rhs.mnList.begin(),
[](const std::unique_ptr<CSimplifiedMNListEntry>& left, const std::unique_ptr<CSimplifiedMNListEntry>& right)
{
return *left == *right;
}
);
}
CSimplifiedMNListDiff::CSimplifiedMNListDiff() = default;
CSimplifiedMNListDiff::~CSimplifiedMNListDiff() = default;

View File

@ -78,6 +78,7 @@ public:
explicit CSimplifiedMNList(const CDeterministicMNList& dmnList);
uint256 CalcMerkleRoot(bool* pmutated = nullptr) const;
bool operator==(const CSimplifiedMNList& rhs) const;
};
/// P2P messages