mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
better naming/readability (Find)
This commit is contained in:
parent
259752c627
commit
0d51e1c90d
@ -201,10 +201,10 @@ bool CActiveMasternode::Dseep(CTxIn vin, CService service, CKey keyMasternode, C
|
||||
}
|
||||
|
||||
// Update Last Seen timestamp in masternode list
|
||||
CMasternode* mn = mnodeman.Find(vin);
|
||||
if(mn)
|
||||
CMasternode* pmn = mnodeman.Find(vin);
|
||||
if(pmn != NULL)
|
||||
{
|
||||
mn->UpdateLastSeen();
|
||||
pmn->UpdateLastSeen();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -267,8 +267,8 @@ bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateral
|
||||
return false;
|
||||
}
|
||||
|
||||
CMasternode* mn = mnodeman.Find(vin);
|
||||
if(!mn)
|
||||
CMasternode* pmn = mnodeman.Find(vin);
|
||||
if(pmn == NULL)
|
||||
{
|
||||
LogPrintf("CActiveMasternode::Register() - Adding to masternode list service: %s - vin: %s\n", service.ToString().c_str(), vin.ToString().c_str());
|
||||
CMasternode mn(service, vin, pubKeyCollateralAddress, vchMasterNodeSignature, masterNodeSignatureTime, pubKeyMasternode, PROTOCOL_VERSION);
|
||||
|
@ -121,8 +121,8 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
|
||||
vRecv >> nDenom >> txCollateral;
|
||||
|
||||
std::string error = "";
|
||||
CMasternode* mn = mnodeman.Find(activeMasternode.vin);
|
||||
if(!mn)
|
||||
CMasternode* pmn = mnodeman.Find(activeMasternode.vin);
|
||||
if(pmn == NULL)
|
||||
{
|
||||
std::string strError = _("Not in the masternode list.");
|
||||
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, strError);
|
||||
@ -130,9 +130,9 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
|
||||
}
|
||||
|
||||
if(darkSendPool.sessionUsers == 0) {
|
||||
if(mn->nLastDsq != 0 &&
|
||||
mn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(darkSendPool.MIN_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
|
||||
LogPrintf("dsa -- last dsq too recent, must wait. %s \n", mn->addr.ToString().c_str());
|
||||
if(pmn->nLastDsq != 0 &&
|
||||
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(darkSendPool.MIN_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
|
||||
LogPrintf("dsa -- last dsq too recent, must wait. %s \n", pmn->addr.ToString().c_str());
|
||||
std::string strError = _("Last Darksend was too recent.");
|
||||
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, strError);
|
||||
return;
|
||||
@ -165,8 +165,8 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
|
||||
|
||||
if(dsq.IsExpired()) return;
|
||||
|
||||
CMasternode* mn = mnodeman.Find(dsq.vin);
|
||||
if(!mn) return;
|
||||
CMasternode* pmn = mnodeman.Find(dsq.vin);
|
||||
if(pmn == NULL) return;
|
||||
|
||||
// if the queue is ready, submit if we can
|
||||
if(dsq.ready) {
|
||||
@ -182,16 +182,16 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
|
||||
if(q.vin == dsq.vin) return;
|
||||
}
|
||||
|
||||
if(fDebug) LogPrintf("dsq last %d last2 %d count %d\n", mn->nLastDsq, mn->nLastDsq + mnodeman.size()/5, darkSendPool.nDsqCount);
|
||||
if(fDebug) LogPrintf("dsq last %d last2 %d count %d\n", pmn->nLastDsq, pmn->nLastDsq + mnodeman.size()/5, darkSendPool.nDsqCount);
|
||||
//don't allow a few nodes to dominate the queuing process
|
||||
if(mn->nLastDsq != 0 &&
|
||||
mn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(darkSendPool.MIN_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
|
||||
if(fDebug) LogPrintf("dsq -- masternode sending too many dsq messages. %s \n", mn->addr.ToString().c_str());
|
||||
if(pmn->nLastDsq != 0 &&
|
||||
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(darkSendPool.MIN_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
|
||||
if(fDebug) LogPrintf("dsq -- masternode sending too many dsq messages. %s \n", pmn->addr.ToString().c_str());
|
||||
return;
|
||||
}
|
||||
darkSendPool.nDsqCount++;
|
||||
mn->nLastDsq = darkSendPool.nDsqCount;
|
||||
mn->allowFreeTx = true;
|
||||
pmn->nLastDsq = darkSendPool.nDsqCount;
|
||||
pmn->allowFreeTx = true;
|
||||
|
||||
if(fDebug) LogPrintf("dsq - new darksend queue object - %s\n", addr.ToString().c_str());
|
||||
vecDarksendQueue.push_back(dsq);
|
||||
@ -2131,14 +2131,14 @@ bool CDarksendQueue::Relay()
|
||||
|
||||
bool CDarksendQueue::CheckSignature()
|
||||
{
|
||||
CMasternode* mn = mnodeman.Find(vin);
|
||||
CMasternode* pmn = mnodeman.Find(vin);
|
||||
|
||||
if(mn)
|
||||
if(pmn != NULL)
|
||||
{
|
||||
std::string strMessage = vin.ToString() + boost::lexical_cast<std::string>(nDenom) + boost::lexical_cast<std::string>(time) + boost::lexical_cast<std::string>(ready);
|
||||
|
||||
std::string errorMessage = "";
|
||||
if(!darkSendSigner.VerifyMessage(mn->pubkey2, vchSig, strMessage, errorMessage)){
|
||||
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)){
|
||||
return error("CDarksendQueue::CheckSignature() - Got bad masternode address signature %s \n", vin.ToString().c_str());
|
||||
}
|
||||
|
||||
|
@ -157,10 +157,10 @@ public:
|
||||
|
||||
bool GetAddress(CService &addr)
|
||||
{
|
||||
CMasternode* mn = mnodeman.Find(vin);
|
||||
if(mn)
|
||||
CMasternode* pmn = mnodeman.Find(vin);
|
||||
if(pmn != NULL)
|
||||
{
|
||||
addr = mn->addr;
|
||||
addr = pmn->addr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -168,10 +168,10 @@ public:
|
||||
|
||||
bool GetProtocolVersion(int &protocolVersion)
|
||||
{
|
||||
CMasternode* mn = mnodeman.Find(vin);
|
||||
if(mn)
|
||||
CMasternode* pmn = mnodeman.Find(vin);
|
||||
if(pmn != NULL)
|
||||
{
|
||||
protocolVersion = mn->protocolVersion;
|
||||
protocolVersion = pmn->protocolVersion;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -309,10 +309,10 @@ bool ProcessConsensusVote(CConsensusVote& ctx)
|
||||
{
|
||||
int n = mnodeman.GetMasternodeRank(ctx.vinMasternode, ctx.nBlockHeight, MIN_INSTANTX_PROTO_VERSION);
|
||||
|
||||
CMasternode* mn = mnodeman.Find(ctx.vinMasternode);
|
||||
if(mn)
|
||||
CMasternode* pmn = mnodeman.Find(ctx.vinMasternode);
|
||||
if(pmn != NULL)
|
||||
{
|
||||
if(fDebug) LogPrintf("InstantX::ProcessConsensusVote - Masternode ADDR %s %d\n", mn->addr.ToString().c_str(), n);
|
||||
if(fDebug) LogPrintf("InstantX::ProcessConsensusVote - Masternode ADDR %s %d\n", pmn->addr.ToString().c_str(), n);
|
||||
}
|
||||
|
||||
if(n == -1)
|
||||
@ -481,9 +481,9 @@ bool CConsensusVote::SignatureValid()
|
||||
std::string strMessage = txHash.ToString().c_str() + boost::lexical_cast<std::string>(nBlockHeight);
|
||||
//LogPrintf("verify strMessage %s \n", strMessage.c_str());
|
||||
|
||||
CMasternode* mn = mnodeman.Find(vinMasternode);
|
||||
CMasternode* pmn = mnodeman.Find(vinMasternode);
|
||||
|
||||
if(!mn)
|
||||
if(pmn == NULL)
|
||||
{
|
||||
LogPrintf("InstantX::CConsensusVote::SignatureValid() - Unknown Masternode\n");
|
||||
return false;
|
||||
@ -494,13 +494,13 @@ bool CConsensusVote::SignatureValid()
|
||||
//LogPrintf("verify addr %d %s \n", n, vecMasternodes[n].addr.ToString().c_str());
|
||||
|
||||
CScript pubkey;
|
||||
pubkey.SetDestination(mn->pubkey2.GetID());
|
||||
pubkey.SetDestination(pmn->pubkey2.GetID());
|
||||
CTxDestination address1;
|
||||
ExtractDestination(pubkey, address1);
|
||||
CBitcoinAddress address2(address1);
|
||||
//LogPrintf("verify pubkey2 %s \n", address2.ToString().c_str());
|
||||
|
||||
if(!darkSendSigner.VerifyMessage(mn->pubkey2, vchMasterNodeSignature, strMessage, errorMessage)) {
|
||||
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchMasterNodeSignature, strMessage, errorMessage)) {
|
||||
LogPrintf("InstantX::CConsensusVote::SignatureValid() - Verify message failed\n");
|
||||
return false;
|
||||
}
|
||||
|
10
src/main.cpp
10
src/main.cpp
@ -4457,10 +4457,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
//these allow masternodes to publish a limited amount of free transactions
|
||||
vRecv >> tx >> vin >> vchSig >> sigTime;
|
||||
|
||||
CMasternode* mn = mnodeman.Find(vin);
|
||||
if(mn)
|
||||
CMasternode* pmn = mnodeman.Find(vin);
|
||||
if(pmn != NULL)
|
||||
{
|
||||
if(!mn->allowFreeTx){
|
||||
if(!pmn->allowFreeTx){
|
||||
//multiple peers can send us a valid masternode transaction
|
||||
if(fDebug) LogPrintf("dstx: Masternode sending too many transactions %s\n", tx.GetHash().ToString().c_str());
|
||||
return true;
|
||||
@ -4469,7 +4469,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
std::string strMessage = tx.GetHash().ToString() + boost::lexical_cast<std::string>(sigTime);
|
||||
|
||||
std::string errorMessage = "";
|
||||
if(!darkSendSigner.VerifyMessage(mn->pubkey2, vchSig, strMessage, errorMessage)){
|
||||
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)){
|
||||
LogPrintf("dstx: Got bad masternode address signature %s \n", vin.ToString().c_str());
|
||||
//pfrom->Misbehaving(20);
|
||||
return false;
|
||||
@ -4478,7 +4478,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
LogPrintf("dstx: Got Masternode transaction %s\n", tx.GetHash().ToString().c_str());
|
||||
|
||||
allowFree = true;
|
||||
mn->allowFreeTx = false;
|
||||
pmn->allowFreeTx = false;
|
||||
|
||||
if(!mapDarksendBroadcastTxes.count(tx.GetHash())){
|
||||
CDarksendBroadcastTx dstx;
|
||||
|
@ -381,13 +381,13 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
|
||||
vecLastPayments.push_back(winner.vin);
|
||||
}
|
||||
|
||||
CMasternode* mn = mnodeman.FindNotInVec(vecLastPayments);
|
||||
if(mn)
|
||||
CMasternode *pmn = mnodeman.FindNotInVec(vecLastPayments);
|
||||
if(pmn != NULL)
|
||||
{
|
||||
newWinner.score = 0;
|
||||
newWinner.nBlockHeight = nBlockHeight;
|
||||
newWinner.vin = mn->vin;
|
||||
newWinner.payee.SetDestination(mn->pubkey.GetID());
|
||||
newWinner.vin = pmn->vin;
|
||||
newWinner.payee.SetDestination(pmn->pubkey.GetID());
|
||||
}
|
||||
|
||||
//if we can't find new MN to get paid, pick first active MN counting back from the end of vecLastPayments list
|
||||
@ -395,16 +395,16 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
|
||||
{
|
||||
BOOST_REVERSE_FOREACH(CTxIn& vinLP, vecLastPayments)
|
||||
{
|
||||
CMasternode* mn = mnodeman.Find(vinLP);
|
||||
if(mn)
|
||||
CMasternode* pmn = mnodeman.Find(vinLP);
|
||||
if(pmn != NULL)
|
||||
{
|
||||
mn->Check();
|
||||
if(!mn->IsEnabled()) continue;
|
||||
pmn->Check();
|
||||
if(!pmn->IsEnabled()) continue;
|
||||
|
||||
newWinner.score = 0;
|
||||
newWinner.nBlockHeight = nBlockHeight;
|
||||
newWinner.vin = mn->vin;
|
||||
newWinner.payee.SetDestination(mn->pubkey.GetID());
|
||||
newWinner.vin = pmn->vin;
|
||||
newWinner.payee.SetDestination(pmn->pubkey.GetID());
|
||||
break; // we found active MN
|
||||
}
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ bool CMasternodeMan::Add(CMasternode &mn)
|
||||
|
||||
CMasternode *pmn = Find(mn.vin);
|
||||
|
||||
if (!pmn)
|
||||
if (pmn == NULL)
|
||||
{
|
||||
vMasternodes.push_back(mn);
|
||||
UpdateLastTimeChanged();
|
||||
@ -390,26 +390,26 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
}
|
||||
|
||||
//search existing masternode list, this is where we update existing masternodes with new dsee broadcasts
|
||||
CMasternode* mn = this->Find(vin);
|
||||
if(mn)
|
||||
CMasternode* pmn = this->Find(vin);
|
||||
if(pmn != NULL)
|
||||
{
|
||||
// count == -1 when it's a new entry
|
||||
// e.g. We don't want the entry relayed/time updated when we're syncing the list
|
||||
// mn.pubkey = pubkey, IsVinAssociatedWithPubkey is validated once below,
|
||||
// after that they just need to match
|
||||
if(count == -1 && mn->pubkey == pubkey && !mn->UpdatedWithin(MASTERNODE_MIN_DSEE_SECONDS)){
|
||||
mn->UpdateLastSeen();
|
||||
if(count == -1 && pmn->pubkey == pubkey && !pmn->UpdatedWithin(MASTERNODE_MIN_DSEE_SECONDS)){
|
||||
pmn->UpdateLastSeen();
|
||||
UpdateLastTimeChanged();
|
||||
|
||||
if(mn->now < sigTime){ //take the newest entry
|
||||
if(pmn->now < sigTime){ //take the newest entry
|
||||
LogPrintf("dsee - Got updated entry for %s\n", addr.ToString().c_str());
|
||||
mn->pubkey2 = pubkey2;
|
||||
mn->now = sigTime;
|
||||
mn->sig = vchSig;
|
||||
mn->protocolVersion = protocolVersion;
|
||||
mn->addr = addr;
|
||||
mn->Check();
|
||||
if(mn->IsEnabled())
|
||||
pmn->pubkey2 = pubkey2;
|
||||
pmn->now = sigTime;
|
||||
pmn->sig = vchSig;
|
||||
pmn->protocolVersion = protocolVersion;
|
||||
pmn->addr = addr;
|
||||
pmn->Check();
|
||||
if(pmn->IsEnabled())
|
||||
RelayDarkSendElectionEntry(vin, addr, vchSig, sigTime, pubkey, pubkey2, count, current, lastUpdated, protocolVersion);
|
||||
}
|
||||
}
|
||||
@ -495,34 +495,34 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
}
|
||||
|
||||
// see if we have this masternode
|
||||
CMasternode* mn = this->Find(vin);
|
||||
if(mn)
|
||||
CMasternode* pmn = this->Find(vin);
|
||||
if(pmn != NULL)
|
||||
{
|
||||
// LogPrintf("dseep - Found corresponding mn for vin: %s\n", vin.ToString().c_str());
|
||||
// take this only if it's newer
|
||||
if(mn->lastDseep < sigTime)
|
||||
if(pmn->lastDseep < sigTime)
|
||||
{
|
||||
std::string strMessage = mn->addr.ToString() + boost::lexical_cast<std::string>(sigTime) + boost::lexical_cast<std::string>(stop);
|
||||
std::string strMessage = pmn->addr.ToString() + boost::lexical_cast<std::string>(sigTime) + boost::lexical_cast<std::string>(stop);
|
||||
|
||||
std::string errorMessage = "";
|
||||
if(!darkSendSigner.VerifyMessage(mn->pubkey2, vchSig, strMessage, errorMessage))
|
||||
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage))
|
||||
{
|
||||
LogPrintf("dseep - Got bad masternode address signature %s \n", vin.ToString().c_str());
|
||||
//Misbehaving(pfrom->GetId(), 100);
|
||||
return;
|
||||
}
|
||||
|
||||
mn->lastDseep = sigTime;
|
||||
pmn->lastDseep = sigTime;
|
||||
|
||||
if(!mn->UpdatedWithin(MASTERNODE_MIN_DSEEP_SECONDS))
|
||||
if(!pmn->UpdatedWithin(MASTERNODE_MIN_DSEEP_SECONDS))
|
||||
{
|
||||
UpdateLastTimeChanged();
|
||||
if(stop) mn->Disable();
|
||||
if(stop) pmn->Disable();
|
||||
else
|
||||
{
|
||||
mn->UpdateLastSeen();
|
||||
mn->Check();
|
||||
if(!mn->IsEnabled()) return;
|
||||
pmn->UpdateLastSeen();
|
||||
pmn->Check();
|
||||
if(!pmn->IsEnabled()) return;
|
||||
}
|
||||
RelayDarkSendElectionEntryPing(vin, vchSig, sigTime, stop);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user