Skip to content

Commit

Permalink
Prepare for migration to 12.1 (#848)
Browse files Browse the repository at this point in the history
* Implement 12.1 MN signatures
* Remove redundant parts from v11->v12 migration
  • Loading branch information
UdjinM6 authored and schinzelh committed Jun 1, 2016
1 parent 376c7d3 commit 822c4ba
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 373 deletions.
70 changes: 0 additions & 70 deletions src/activemasternode.cpp
Expand Up @@ -190,38 +190,6 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage) {

mnp.Relay();

/*
* IT'S SAFE TO REMOVE THIS IN FURTHER VERSIONS
* AFTER MIGRATION TO V12 IS DONE
*/

if(IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return true;
// for migration purposes ping our node on old masternodes network too
std::string retErrorMessage;
std::vector<unsigned char> vchMasterNodeSignature;
int64_t masterNodeSignatureTime = GetAdjustedTime();

std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(masterNodeSignatureTime) + boost::lexical_cast<std::string>(false);

if(!darkSendSigner.SignMessage(strMessage, retErrorMessage, vchMasterNodeSignature, keyMasternode)) {
errorMessage = "dseep sign message failed: " + retErrorMessage;
return false;
}

if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchMasterNodeSignature, strMessage, retErrorMessage)) {
errorMessage = "dseep verify message failed: " + retErrorMessage;
return false;
}

LogPrint("masternode", "dseep - relaying from active mn, %s \n", vin.ToString().c_str());
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
pnode->PushMessage("dseep", vin, vchMasterNodeSignature, masterNodeSignatureTime, false);

/*
* END OF "REMOVE"
*/

return true;
}
else
Expand Down Expand Up @@ -314,44 +282,6 @@ bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateral
LogPrintf("CActiveMasternode::Register() - RelayElectionEntry vin = %s\n", vin.ToString());
mnb.Relay();

/*
* IT'S SAFE TO REMOVE THIS IN FURTHER VERSIONS
* AFTER MIGRATION TO V12 IS DONE
*/

if(IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return true;
// for migration purposes inject our node in old masternodes' list too
std::string retErrorMessage;
std::vector<unsigned char> vchMasterNodeSignature;
int64_t masterNodeSignatureTime = GetAdjustedTime();
std::string donationAddress = "";
int donationPercantage = 0;

std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end());
std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end());

std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(masterNodeSignatureTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(PROTOCOL_VERSION) + donationAddress + boost::lexical_cast<std::string>(donationPercantage);

if(!darkSendSigner.SignMessage(strMessage, retErrorMessage, vchMasterNodeSignature, keyCollateralAddress)) {
errorMessage = "dsee sign message failed: " + retErrorMessage;
LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str());
return false;
}

if(!darkSendSigner.VerifyMessage(pubKeyCollateralAddress, vchMasterNodeSignature, strMessage, retErrorMessage)) {
errorMessage = "dsee verify message failed: " + retErrorMessage;
LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str());
return false;
}

LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
pnode->PushMessage("dsee", vin, service, vchMasterNodeSignature, masterNodeSignatureTime, pubKeyCollateralAddress, pubKeyMasternode, -1, -1, masterNodeSignatureTime, PROTOCOL_VERSION, donationAddress, donationPercantage);

/*
* END OF "REMOVE"
*/

return true;
}

Expand Down
25 changes: 13 additions & 12 deletions src/masternode.cpp
Expand Up @@ -73,8 +73,6 @@ CMasternode::CMasternode()
nScanningErrorCount = 0;
nLastScanningErrorBlockHeight = 0;
lastTimeChecked = 0;
nLastDsee = 0;// temporary, do not save. Remove after migration to v12
nLastDseep = 0;// temporary, do not save. Remove after migration to v12
}

CMasternode::CMasternode(const CMasternode& other)
Expand All @@ -97,8 +95,6 @@ CMasternode::CMasternode(const CMasternode& other)
nScanningErrorCount = other.nScanningErrorCount;
nLastScanningErrorBlockHeight = other.nLastScanningErrorBlockHeight;
lastTimeChecked = 0;
nLastDsee = other.nLastDsee;// temporary, do not save. Remove after migration to v12
nLastDseep = other.nLastDseep;// temporary, do not save. Remove after migration to v12
}

CMasternode::CMasternode(const CMasternodeBroadcast& mnb)
Expand All @@ -121,8 +117,6 @@ CMasternode::CMasternode(const CMasternodeBroadcast& mnb)
nScanningErrorCount = 0;
nLastScanningErrorBlockHeight = 0;
lastTimeChecked = 0;
nLastDsee = 0;// temporary, do not save. Remove after migration to v12
nLastDseep = 0;// temporary, do not save. Remove after migration to v12
}

//
Expand Down Expand Up @@ -352,10 +346,6 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
return false;
}

std::string vchPubKey(pubkey.begin(), pubkey.end());
std::string vchPubKey2(pubkey2.begin(), pubkey2.end());
std::string strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);

if(protocolVersion < masternodePayments.GetMinMasternodePaymentsProto()) {
LogPrintf("mnb - ignoring outdated Masternode %s protocol version %d\n", vin.ToString(), protocolVersion);
return false;
Expand Down Expand Up @@ -384,11 +374,22 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
return false;
}

std::string strMessage;
if(protocolVersion < 70201) {
std::string vchPubKey(pubkey.begin(), pubkey.end());
std::string vchPubKey2(pubkey2.begin(), pubkey2.end());
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
} else {
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) +
pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
boost::lexical_cast<std::string>(protocolVersion);
}

std::string errorMessage = "";
if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
LogPrintf("mnb - Got bad Masternode address signature\n");
// There is a bug in MN signatures, ignore such MN but do not ban the peer we got this from
// nDos = 100;
// There is a bug in old MN signatures, ignore such MN but do not ban the peer we got this from
nDos = protocolVersion < 70201 ? 0 : 100;
return false;
}

Expand Down
3 changes: 0 additions & 3 deletions src/masternode.h
Expand Up @@ -135,9 +135,6 @@ class CMasternode
int nLastScanningErrorBlockHeight;
CMasternodePing lastPing;

int64_t nLastDsee;// temporary, do not save. Remove after migration to v12
int64_t nLastDseep;// temporary, do not save. Remove after migration to v12

CMasternode();
CMasternode(const CMasternode& other);
CMasternode(const CMasternodeBroadcast& mnb);
Expand Down

0 comments on commit 822c4ba

Please sign in to comment.