Skip to content

Commit 5379fce

Browse files
UdjinM6claude
andcommitted
refactor: add CDeterministicMNList::IsEqual method
Add method to compare two masternode lists for equality while ignoring non-deterministic members (nTotalRegisteredCount, internalId). Non-deterministic members can differ between nodes due to different sync histories but don't affect consensus validity. This method is useful for verifying that masternode list states match after applying diffs. Key features: - Compares blockHash, nHeight, and mnUniquePropertyMap - Compares map sizes (but not nTotalRegisteredCount) - Iterates through all masternodes comparing deterministic fields - Uses SerializeHash for pdmnState to avoid enumerating all fields Co-authored-by: Claude (Anthropic AI) <[email protected]>
1 parent 496ed89 commit 5379fce

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/evo/deterministicmns.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,46 @@ class CDeterministicMNList
436436
return GetMN(p->first);
437437
}
438438

439+
// Compare two masternode lists for equality, ignoring non-deterministic members.
440+
// Non-deterministic members (nTotalRegisteredCount, internalId) can differ between
441+
// nodes due to different sync histories, but don't affect consensus validity.
442+
bool IsEqual(const CDeterministicMNList& rhs) const
443+
{
444+
// Compare deterministic metadata
445+
if (blockHash != rhs.blockHash ||
446+
nHeight != rhs.nHeight ||
447+
mnUniquePropertyMap != rhs.mnUniquePropertyMap) {
448+
return false;
449+
}
450+
451+
// Compare map sizes (actual entries compared below)
452+
// Note: Not comparing nTotalRegisteredCount (non-deterministic)
453+
if (mnMap.size() != rhs.mnMap.size() ||
454+
mnInternalIdMap.size() != rhs.mnInternalIdMap.size()) {
455+
return false;
456+
}
457+
458+
// Compare each masternode entry
459+
for (const auto& [proTxHash, dmn] : mnMap) {
460+
auto dmn_rhs = rhs.mnMap.find(proTxHash);
461+
if (dmn_rhs == nullptr) {
462+
return false;
463+
}
464+
465+
// Compare deterministic masternode fields
466+
// Note: Not comparing internalId (non-deterministic)
467+
if (dmn->proTxHash != dmn_rhs->get()->proTxHash ||
468+
dmn->collateralOutpoint != dmn_rhs->get()->collateralOutpoint ||
469+
dmn->nOperatorReward != dmn_rhs->get()->nOperatorReward ||
470+
dmn->nType != dmn_rhs->get()->nType ||
471+
// Use SerializeHash for pdmnState to avoid enumerating all state fields
472+
SerializeHash(*dmn->pdmnState) != SerializeHash(*dmn_rhs->get()->pdmnState)) {
473+
return false;
474+
}
475+
}
476+
return true;
477+
}
478+
439479
private:
440480
template <typename T>
441481
[[nodiscard]] uint256 GetUniquePropertyHash(const T& v) const

0 commit comments

Comments
 (0)