Reimplement CMNAuth::NotifyMasternodeListChanged to work with new interface

This commit is contained in:
Alexander Block 2019-04-09 13:28:12 +02:00
parent fa90c0204f
commit aeb4c60c8e
2 changed files with 25 additions and 14 deletions

View File

@ -114,23 +114,33 @@ void CMNAuth::ProcessMessage(CNode* pnode, const std::string& strCommand, CDataS
}
}
void CMNAuth::NotifyMasternodeListChanged(const CDeterministicMNList& newList)
void CMNAuth::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff)
{
std::unordered_set<uint256> pubKeys;
g_connman->ForEachNode([&](const CNode* pnode) {
LOCK(pnode->cs_mnauth);
if (!pnode->verifiedProRegTxHash.IsNull()) {
pubKeys.emplace(pnode->verifiedPubKeyHash);
}
});
newList.ForEachMN(true, [&](const CDeterministicMNCPtr& dmn) {
pubKeys.erase(dmn->pdmnState->pubKeyOperator.GetHash());
});
// we're only interested in updated/removed MNs. Added MNs are of no interest for us
if (diff.updatedMNs.empty() && diff.removedMns.empty()) {
return;
}
g_connman->ForEachNode([&](CNode* pnode) {
LOCK(pnode->cs_mnauth);
if (!pnode->verifiedProRegTxHash.IsNull() && pubKeys.count(pnode->verifiedPubKeyHash)) {
if (pnode->verifiedProRegTxHash.IsNull()) {
return;
}
bool doRemove = false;
if (diff.removedMns.count(pnode->verifiedProRegTxHash)) {
doRemove = true;
} else {
auto it = diff.updatedMNs.find(pnode->verifiedProRegTxHash);
if (it != diff.updatedMNs.end()) {
if (it->second->pubKeyOperator.GetHash() != pnode->verifiedPubKeyHash) {
doRemove = true;
}
}
}
if (doRemove) {
LogPrint("net", "CMNAuth::NotifyMasternodeListChanged -- Disconnecting MN %s due to key changed/removed, peer=%d\n",
pnode->verifiedProRegTxHash.ToString(), pnode->id);
pnode->verifiedProRegTxHash.ToString(), pnode->id);
pnode->fDisconnect = true;
}
});

View File

@ -12,6 +12,7 @@ class CConnman;
class CDataStream;
class CDeterministicMN;
class CDeterministicMNList;
class CDeterministicMNListDiff;
class CNode;
class UniValue;
@ -50,7 +51,7 @@ public:
static void PushMNAUTH(CNode* pnode, CConnman& connman);
static void ProcessMessage(CNode* pnode, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);
static void NotifyMasternodeListChanged(const CDeterministicMNList& newList);
static void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff);
};