Skip to content

Commit

Permalink
CMasternode: decouple CheckInputs from CheckInputsAndAdd
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Oct 1, 2021
1 parent 0c0e4c0 commit aad9139
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,17 +485,8 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos, int nChainHeight)
return true;
}

bool CMasternodeBroadcast::CheckInputsAndAdd(int nChainHeight, int& nDoS)
bool CMasternodeBroadcast::CheckInputs(int nChainHeight, int& nDoS)
{
// we are a masternode with the same vin (i.e. already activated) and this mnb is ours (matches our Masternode privkey)
// so nothing to do here for us
if (fMasterNode && activeMasternode.vin != nullopt &&
vin.prevout == activeMasternode.vin->prevout &&
pubKeyMasternode == activeMasternode.pubKeyMasternode &&
activeMasternode.GetStatus() == ACTIVE_MASTERNODE_STARTED) {
return true;
}

// incorrect ping or its sigTime
if(lastPing.IsNull() || !lastPing.CheckAndUpdate(nDoS, nChainHeight, false, true)) {
return false;
Expand Down Expand Up @@ -537,6 +528,25 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int nChainHeight, int& nDoS)
return false;
}

// Good input
return true;
}

bool CMasternodeBroadcast::CheckInputsAndAdd(int nChainHeight, int& nDoS)
{
// we are a masternode with the same vin (i.e. already activated) and this mnb is ours (matches our Masternode privkey)
// so nothing to do here for us
if (fMasterNode && activeMasternode.vin != nullopt &&
vin.prevout == activeMasternode.vin->prevout &&
pubKeyMasternode == activeMasternode.pubKeyMasternode &&
activeMasternode.GetStatus() == ACTIVE_MASTERNODE_STARTED) {
return true;
}

if (!CheckInputs(nChainHeight, nDoS)) {
return false; // error set internally
}

LogPrint(BCLog::MASTERNODE,"mnb - Got NEW Masternode entry - %s - %lli \n", vin.prevout.hash.ToString(), sigTime);
CMasternode mn(*this);
mnodeman.Add(mn);
Expand Down
1 change: 1 addition & 0 deletions src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class CMasternodeBroadcast : public CMasternode
CMasternodeBroadcast(const CMasternode& mn);

bool CheckAndUpdate(int& nDoS, int nChainHeight);
bool CheckInputs(int nChainHeight, int& nDoS);
bool CheckInputsAndAdd(int chainHeight, int& nDos);

uint256 GetHash() const;
Expand Down

0 comments on commit aad9139

Please sign in to comment.