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

Call CheckMnbAndUpdateMasternodeList when starting MN #1945

Merged
merged 2 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,28 +1493,6 @@ std::string CMasternodeMan::ToString() const
return info.str();
}

void CMasternodeMan::UpdateMasternodeList(CMasternodeBroadcast mnb, CConnman& connman)
{
LOCK2(cs_main, cs);
mapSeenMasternodePing.insert(std::make_pair(mnb.lastPing.GetHash(), mnb.lastPing));
mapSeenMasternodeBroadcast.insert(std::make_pair(mnb.GetHash(), std::make_pair(GetTime(), mnb)));

LogPrintf("CMasternodeMan::UpdateMasternodeList -- masternode=%s addr=%s\n", mnb.outpoint.ToStringShort(), mnb.addr.ToString());

CMasternode* pmn = Find(mnb.outpoint);
if(pmn == NULL) {
if(Add(mnb)) {
masternodeSync.BumpAssetLastTime("CMasternodeMan::UpdateMasternodeList - new");
}
} else {
CMasternodeBroadcast mnbOld = mapSeenMasternodeBroadcast[CMasternodeBroadcast(*pmn).GetHash()].second;
if(pmn->UpdateFromNewBroadcast(mnb, connman)) {
masternodeSync.BumpAssetLastTime("CMasternodeMan::UpdateMasternodeList - seen");
mapSeenMasternodeBroadcast.erase(mnbOld.GetHash());
}
}
}

bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBroadcast mnb, int& nDos, CConnman& connman)
{
// Need to lock cs_main here to ensure consistent locking order because the SimpleCheck call below locks cs_main
Expand Down
4 changes: 1 addition & 3 deletions src/masternodeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ class CMasternodeMan

std::string ToString() const;

/// Update masternode list and maps using provided CMasternodeBroadcast
void UpdateMasternodeList(CMasternodeBroadcast mnb, CConnman& connman);
/// Perform complete check and only then update list and maps
/// Perform complete check and only then update masternode list and maps using provided CMasternodeBroadcast
bool CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBroadcast mnb, int& nDos, CConnman& connman);
bool IsMnbRecoveryRequested(const uint256& hash) { return mMnbRecoveryRequests.count(hash); }

Expand Down
16 changes: 12 additions & 4 deletions src/qt/masternodelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,14 @@ void MasternodeList::StartAlias(std::string strAlias)

bool fSuccess = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb);

int nDoS;
if (fSuccess && !mnodeman.CheckMnbAndUpdateMasternodeList(NULL, mnb, nDoS, *g_connman)) {
strError = "Failed to verify MNB";
fSuccess = false;
}

if(fSuccess) {
strStatusHtml += "<br>Successfully started masternode.";
mnodeman.UpdateMasternodeList(mnb, *g_connman);
mnb.Relay(*g_connman);
mnodeman.NotifyMasternodeUpdates(*g_connman);
} else {
strStatusHtml += "<br>Failed to start masternode.<br>Error: " + strError;
Expand Down Expand Up @@ -152,10 +156,14 @@ void MasternodeList::StartAll(std::string strCommand)

bool fSuccess = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb);

int nDoS;
if (fSuccess && !mnodeman.CheckMnbAndUpdateMasternodeList(NULL, mnb, nDoS, *g_connman)) {
strError = "Failed to verify MNB";
fSuccess = false;
}

if(fSuccess) {
nCountSuccessful++;
mnodeman.UpdateMasternodeList(mnb, *g_connman);
mnb.Relay(*g_connman);
mnodeman.NotifyMasternodeUpdates(*g_connman);
} else {
nCountFailed++;
Expand Down
33 changes: 16 additions & 17 deletions src/rpc/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,14 @@ UniValue masternode(const JSONRPCRequest& request)

bool fResult = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb);

int nDoS;
if (fResult && !mnodeman.CheckMnbAndUpdateMasternodeList(NULL, mnb, nDoS, *g_connman)) {
strError = "Failed to verify MNB";
fResult = false;
}

statusObj.push_back(Pair("result", fResult ? "successful" : "failed"));
if(fResult) {
mnodeman.UpdateMasternodeList(mnb, *g_connman);
mnb.Relay(*g_connman);
} else {
if(!fResult) {
statusObj.push_back(Pair("errorMessage", strError));
}
mnodeman.NotifyMasternodeUpdates(*g_connman);
Expand Down Expand Up @@ -327,14 +330,18 @@ UniValue masternode(const JSONRPCRequest& request)

bool fResult = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb);

int nDoS;
if (fResult && !mnodeman.CheckMnbAndUpdateMasternodeList(NULL, mnb, nDoS, *g_connman)) {
strError = "Failed to verify MNB";
fResult = false;
}

UniValue statusObj(UniValue::VOBJ);
statusObj.push_back(Pair("alias", mne.getAlias()));
statusObj.push_back(Pair("result", fResult ? "successful" : "failed"));

if (fResult) {
nSuccessful++;
mnodeman.UpdateMasternodeList(mnb, *g_connman);
mnb.Relay(*g_connman);
} else {
nFailed++;
statusObj.push_back(Pair("errorMessage", strError));
Expand Down Expand Up @@ -793,10 +800,9 @@ UniValue masternodebroadcast(const JSONRPCRequest& request)
if (strCommand == "relay")
{
if (request.params.size() < 2 || request.params.size() > 3)
throw JSONRPCError(RPC_INVALID_PARAMETER, "masternodebroadcast relay \"hexstring\" ( fast )\n"
throw JSONRPCError(RPC_INVALID_PARAMETER, "masternodebroadcast relay \"hexstring\"\n"
"\nArguments:\n"
"1. \"hex\" (string, required) Broadcast messages hex string\n"
"2. fast (string, optional) If none, using safe method\n");
"1. \"hex\" (string, required) Broadcast messages hex string\n");

std::vector<CMasternodeBroadcast> vecMnb;

Expand All @@ -805,7 +811,6 @@ UniValue masternodebroadcast(const JSONRPCRequest& request)

int nSuccessful = 0;
int nFailed = 0;
bool fSafe = request.params.size() == 2;
UniValue returnObj(UniValue::VOBJ);

// verify all signatures first, bailout if any of them broken
Expand All @@ -818,13 +823,7 @@ UniValue masternodebroadcast(const JSONRPCRequest& request)
int nDos = 0;
bool fResult;
if (mnb.CheckSignature(nDos)) {
if (fSafe) {
fResult = mnodeman.CheckMnbAndUpdateMasternodeList(NULL, mnb, nDos, *g_connman);
} else {
mnodeman.UpdateMasternodeList(mnb, *g_connman);
mnb.Relay(*g_connman);
fResult = true;
}
fResult = mnodeman.CheckMnbAndUpdateMasternodeList(NULL, mnb, nDos, *g_connman);
mnodeman.NotifyMasternodeUpdates(*g_connman);
} else fResult = false;

Expand Down