Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resolve mainnet v19 fork issues #5403

Merged
merged 10 commits into from
Jun 4, 2023
Prev Previous commit
Next Next commit
chore: drop RepopulateUniquePropertyMap
  • Loading branch information
UdjinM6 committed May 31, 2023
commit daf9ff93407f80375d444722ba28517bf9ec81a4
55 changes: 5 additions & 50 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,48 +426,6 @@ CDeterministicMNList CDeterministicMNList::ApplyDiff(const CBlockIndex* pindex,
return result;
}

// RepopulateUniquePropertyMap clears internal mnUniquePropertyMap, and repopulate it with currently MNs unique properties.
// This is needed when the v19 fork activates, we need to store again pubKeyOperator in the mnUniquePropertyMap.
// pubKeyOperator don't differ between the two schemes (legacy and basic(v19)) but their serialisation do: hence their hash.
// And because mnUniquePropertyMap store only hashes, then we need to re-calculate hashes and repopulate.
void CDeterministicMNList::RepopulateUniquePropertyMap() {
decltype(mnUniquePropertyMap) mnUniquePropertyMapEmpty;
mnUniquePropertyMap = mnUniquePropertyMapEmpty;

for (const auto &p: mnMap) {
auto dmn = p.second;
if (!AddUniqueProperty(*dmn, dmn->collateralOutpoint)) {
throw (std::runtime_error(
strprintf("%s: Can't add a masternode %s with a duplicate collateralOutpoint=%s", __func__,
dmn->proTxHash.ToString(), dmn->collateralOutpoint.ToStringShort())));
}
if (dmn->pdmnState->addr != CService() && !AddUniqueProperty(*dmn, dmn->pdmnState->addr)) {
throw (std::runtime_error(strprintf("%s: Can't add a masternode %s with a duplicate address=%s", __func__,
dmn->proTxHash.ToString(),
dmn->pdmnState->addr.ToStringIPPort(false))));
}
if (!AddUniqueProperty(*dmn, dmn->pdmnState->keyIDOwner)) {
throw (std::runtime_error(
strprintf("%s: Can't add a masternode %s with a duplicate keyIDOwner=%s", __func__,
dmn->proTxHash.ToString(), EncodeDestination(PKHash(dmn->pdmnState->keyIDOwner)))));
}
if (dmn->pdmnState->pubKeyOperator.Get().IsValid() &&
!AddUniqueProperty(*dmn, dmn->pdmnState->pubKeyOperator)) {
throw (std::runtime_error(
strprintf("%s: Can't add a masternode %s with a duplicate pubKeyOperator=%s", __func__,
dmn->proTxHash.ToString(), dmn->pdmnState->pubKeyOperator.Get().ToString())));
}

if (dmn->nType == MnType::HighPerformance) {
if (!AddUniqueProperty(*dmn, dmn->pdmnState->platformNodeID)) {
throw (std::runtime_error(
strprintf("%s: Can't add a masternode %s with a duplicate platformNodeID=%s", __func__,
dmn->proTxHash.ToString(), dmn->pdmnState->platformNodeID.ToString())));
}
}
}
}

void CDeterministicMNList::AddMN(const CDeterministicMNCPtr& dmn, bool fBumpTotalCount)
{
assert(dmn != nullptr);
Expand Down Expand Up @@ -650,17 +608,14 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde

newList.SetBlockHash(block.GetHash());

// If the fork is active for pindex block, then we need to repopulate property map
// (Check documentation of CDeterministicMNList::RepopulateUniquePropertyMap()).
// This is needed only when base list is pre-v19 fork and pindex is post-v19 fork.
bool v19_just_activated = pindex == llmq::utils::V19ActivationIndex(pindex);
if (v19_just_activated) {
newList.RepopulateUniquePropertyMap();
}

oldList = GetListForBlockInternal(pindex->pprev);
diff = oldList.BuildDiff(newList);

// NOTE: The block next to the activation is the one that is using new rules.
// If the fork was activated at pindex->prev block then current one is the first one
// using new rules. Save mn list snapsot for this block.
bool v19_just_activated = pindex->pprev == llmq::utils::V19ActivationIndex(pindex);

m_evoDb.Write(std::make_pair(DB_LIST_DIFF, newList.GetBlockHash()), diff);
if ((nHeight % DISK_SNAPSHOT_PERIOD) == 0 || oldList.GetHeight() == -1 || v19_just_activated) {
m_evoDb.Write(std::make_pair(DB_LIST_SNAPSHOT, newList.GetBlockHash()), newList);
Expand Down
2 changes: 0 additions & 2 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,6 @@ class CDeterministicMNList
[[nodiscard]] CDeterministicMNListDiff BuildDiff(const CDeterministicMNList& to) const;
[[nodiscard]] CDeterministicMNList ApplyDiff(const CBlockIndex* pindex, const CDeterministicMNListDiff& diff) const;

void RepopulateUniquePropertyMap();

void AddMN(const CDeterministicMNCPtr& dmn, bool fBumpTotalCount = true);
void UpdateMN(const CDeterministicMN& oldDmn, const std::shared_ptr<const CDeterministicMNState>& pdmnState);
void UpdateMN(const uint256& proTxHash, const std::shared_ptr<const CDeterministicMNState>& pdmnState);
Expand Down