From 38f386ae1c51fd757cacb3cfd86affcee6847b26 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 15 Mar 2016 02:16:29 +0300 Subject: [PATCH] Few small changes: - Better log output (a bit more granular for mnb, fixing "\n"s and few other small issues) - Unify variable/class members naming a bit Closes #733 --- src/activemasternode.cpp | 4 +-- src/activemasternode.h | 12 ++++----- src/darksend.cpp | 2 +- src/httprpc.cpp | 2 +- src/main.cpp | 2 +- src/masternode-budget.h | 2 +- src/masternode-payments.cpp | 2 +- src/masternode-sync.cpp | 2 -- src/masternode.cpp | 54 ++++++++++++++++++------------------- src/masternode.h | 10 +++---- src/masternodeman.cpp | 24 ++++++++--------- 11 files changed, 57 insertions(+), 59 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 62c78e683..450c4332c 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -115,13 +115,13 @@ void CActiveMasternode::ManageStatus() if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)) { notCapableReason = "Error upon calling SetKey: " + errorMessage; - LogPrintf("Register::ManageStatus() - %s\n", notCapableReason); + LogPrintf("CActiveMasternode::ManageStatus() - %s\n", notCapableReason); return; } if(!Register(vin, service, keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, errorMessage)) { notCapableReason = "Error on Register: " + errorMessage; - LogPrintf("Register::ManageStatus() - %s\n", notCapableReason); + LogPrintf("CActiveMasternode::ManageStatus() - %s\n", notCapableReason); return; } diff --git a/src/activemasternode.h b/src/activemasternode.h index 3e1615dc7..0abdb3b4c 100644 --- a/src/activemasternode.h +++ b/src/activemasternode.h @@ -37,19 +37,19 @@ private: bool GetVinFromOutput(COutput out, CTxIn& vin, CPubKey& pubkey, CKey& secretKey); public: - // Initialized by init.cpp - // Keys for the main Masternode - CPubKey pubKeyMasternode; + // Initialized by init.cpp + // Keys for the main Masternode + CPubKey pubKeyMasternode; - // Initialized while registering Masternode - CTxIn vin; + // Initialized while registering Masternode + CTxIn vin; CService service; int status; std::string notCapableReason; CActiveMasternode() - { + { status = ACTIVE_MASTERNODE_INITIAL; } diff --git a/src/darksend.cpp b/src/darksend.cpp index 7c3c4c494..4ad28b36a 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -2148,7 +2148,7 @@ bool CDarksendQueue::CheckSignature() std::string errorMessage = ""; if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)){ - return error("CDarksendQueue::CheckSignature() - Got bad Masternode address signature %s \n", vin.ToString().c_str()); + return error("CDarksendQueue::CheckSignature() - Got bad Masternode queue signature %s", vin.ToString().c_str()); } return true; diff --git a/src/httprpc.cpp b/src/httprpc.cpp index f6fa988b9..57b3f9a09 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -215,7 +215,7 @@ static bool InitRPCAuthentication() return false; } } else { - LogPrintf("Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcuser for rpcauth auth generation."); + LogPrintf("Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcuser for rpcauth auth generation.\n"); strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]; } return true; diff --git a/src/main.cpp b/src/main.cpp index 22913a76a..91dfeedff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5190,7 +5190,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, std::string errorMessage = ""; if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)){ - LogPrintf("dstx: Got bad masternode address signature %s \n", vin.ToString()); + LogPrintf("dstx: Got bad Masternode transaction signature %s\n", vin.ToString()); //pfrom->Misbehaving(20); return false; } diff --git a/src/masternode-budget.h b/src/masternode-budget.h index 64b05478e..26f71316c 100644 --- a/src/masternode-budget.h +++ b/src/masternode-budget.h @@ -512,7 +512,7 @@ public: swap(first.nAmount, second.nAmount); swap(first.address, second.address); swap(first.nTime, second.nTime); - swap(first.nFeeTXHash, second.nFeeTXHash); + swap(first.nFeeTXHash, second.nFeeTXHash); first.mapVotes.swap(second.mapVotes); } diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index ff54c1e0a..4c87d9681 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -767,7 +767,7 @@ bool CMasternodePaymentWinner::SignatureValid() std::string errorMessage = ""; if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)){ - return error("CMasternodePaymentWinner::SignatureValid() - Got bad Masternode address signature %s \n", vinMasternode.ToString().c_str()); + return error("CMasternodePaymentWinner::SignatureValid() - Got bad Masternode payment signature %s", vinMasternode.ToString().c_str()); } return true; diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index 5c709c6a5..01ab803d7 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -242,8 +242,6 @@ void CMasternodeSync::Process() } else if (RequestedMasternodeAssets == MASTERNODE_SYNC_FAILED) { return; } - - if(fDebug) LogPrintf("CMasternodeSync::Process() - tick %d RequestedMasternodeAssets %d\n", tick, RequestedMasternodeAssets); } double nSyncProgress = double(RequestedMasternodeAttempt + (RequestedMasternodeAssets - 1) * 8) / (8*4); diff --git a/src/masternode.cpp b/src/masternode.cpp index 051c20493..0d9a9f7f4 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -64,7 +64,7 @@ CMasternode::CMasternode() addr = CService(); pubkey = CPubKey(); pubkey2 = CPubKey(); - sig = std::vector(); + vchSig = std::vector(); activeState = MASTERNODE_ENABLED; sigTime = GetAdjustedTime(); lastPing = CMasternodePing(); @@ -86,7 +86,7 @@ CMasternode::CMasternode(const CMasternode& other) addr = other.addr; pubkey = other.pubkey; pubkey2 = other.pubkey2; - sig = other.sig; + vchSig = other.vchSig; activeState = other.activeState; sigTime = other.sigTime; lastPing = other.lastPing; @@ -108,7 +108,7 @@ CMasternode::CMasternode(const CMasternodeBroadcast& mnb) addr = mnb.addr; pubkey = mnb.pubkey; pubkey2 = mnb.pubkey2; - sig = mnb.sig; + vchSig = mnb.vchSig; activeState = MASTERNODE_ENABLED; sigTime = mnb.sigTime; lastPing = mnb.lastPing; @@ -131,12 +131,12 @@ bool CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast& mnb) if(mnb.sigTime > sigTime) { pubkey2 = mnb.pubkey2; sigTime = mnb.sigTime; - sig = mnb.sig; + vchSig = mnb.vchSig; protocolVersion = mnb.protocolVersion; addr = mnb.addr; lastTimeChecked = 0; - int nDoS = 0; - if(mnb.lastPing == CMasternodePing() || (mnb.lastPing != CMasternodePing() && mnb.lastPing.CheckAndUpdate(nDoS, false))) { + int nDos = 0; + if(mnb.lastPing == CMasternodePing() || (mnb.lastPing != CMasternodePing() && mnb.lastPing.CheckAndUpdate(nDos, false))) { lastPing = mnb.lastPing; mnodeman.mapSeenMasternodePing.insert(make_pair(lastPing.GetHash(), lastPing)); } @@ -297,7 +297,7 @@ CMasternodeBroadcast::CMasternodeBroadcast() addr = CService(); pubkey = CPubKey(); pubkey2 = CPubKey(); - sig = std::vector(); + vchSig = std::vector(); activeState = MASTERNODE_ENABLED; sigTime = GetAdjustedTime(); lastPing = CMasternodePing(); @@ -317,7 +317,7 @@ CMasternodeBroadcast::CMasternodeBroadcast(CService newAddr, CTxIn newVin, CPubK addr = newAddr; pubkey = newPubkey; pubkey2 = newPubkey2; - sig = std::vector(); + vchSig = std::vector(); activeState = MASTERNODE_ENABLED; sigTime = GetAdjustedTime(); lastPing = CMasternodePing(); @@ -337,7 +337,7 @@ CMasternodeBroadcast::CMasternodeBroadcast(const CMasternode& mn) addr = mn.addr; pubkey = mn.pubkey; pubkey2 = mn.pubkey2; - sig = mn.sig; + vchSig = mn.vchSig; activeState = mn.activeState; sigTime = mn.sigTime; lastPing = mn.lastPing; @@ -355,7 +355,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) { // make sure signature isn't in the future (past is OK) if (sigTime > GetAdjustedTime() + 60 * 60) { - LogPrintf("mnb - Signature rejected, too far into the future %s\n", vin.ToString()); + LogPrintf("CMasternodeBroadcast::CheckAndUpdate - Signature rejected, too far into the future %s\n", vin.ToString()); nDos = 1; return false; } @@ -365,7 +365,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) std::string strMessage = addr.ToString() + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); if(protocolVersion < mnpayments.GetMinMasternodePaymentsProto()) { - LogPrintf("mnb - ignoring outdated Masternode %s protocol version %d\n", vin.ToString(), protocolVersion); + LogPrintf("CMasternodeBroadcast::CheckAndUpdate - ignoring outdated Masternode %s protocol version %d\n", vin.ToString(), protocolVersion); return false; } @@ -373,7 +373,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) pubkeyScript = GetScriptForDestination(pubkey.GetID()); if(pubkeyScript.size() != 25) { - LogPrintf("mnb - pubkey the wrong size\n"); + LogPrintf("CMasternodeBroadcast::CheckAndUpdate - pubkey the wrong size\n"); nDos = 100; return false; } @@ -382,19 +382,19 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) pubkeyScript2 = GetScriptForDestination(pubkey2.GetID()); if(pubkeyScript2.size() != 25) { - LogPrintf("mnb - pubkey2 the wrong size\n"); + LogPrintf("CMasternodeBroadcast::CheckAndUpdate - pubkey2 the wrong size\n"); nDos = 100; return false; } if(!vin.scriptSig.empty()) { - LogPrintf("mnb - Ignore Not Empty ScriptSig %s\n",vin.ToString()); + LogPrintf("CMasternodeBroadcast::CheckAndUpdate - Ignore Not Empty ScriptSig %s\n",vin.ToString()); return false; } std::string errorMessage = ""; - if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){ - LogPrintf("mnb - Got bad Masternode address signature\n"); + if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)){ + LogPrintf("CMasternodeBroadcast::CheckAndUpdate - Got bad Masternode address signature\n"); nDos = 100; return false; } @@ -412,7 +412,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) else { // this broadcast older than we have, it's bad. if(pmn->sigTime > sigTime) { - LogPrintf("mnb - Bad sigTime %d for Masternode %20s %105s (existing broadcast is at %d)\n", + LogPrintf("CMasternodeBroadcast::CheckAndUpdate - Bad sigTime %d for Masternode %20s %105s (existing broadcast is at %d)\n", sigTime, addr.ToString(), vin.ToString(), pmn->sigTime); return false; } @@ -424,7 +424,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) // after that they just need to match if(pmn->pubkey == pubkey && !pmn->IsBroadcastedWithin(MASTERNODE_MIN_MNB_SECONDS)) { //take the newest entry - LogPrintf("mnb - Got updated entry for %s\n", addr.ToString()); + LogPrintf("CMasternodeBroadcast::CheckAndUpdate - Got updated entry for %s\n", addr.ToString()); if(pmn->UpdateFromNewBroadcast((*this))){ pmn->Check(); if(pmn->IsEnabled()) Relay(); @@ -435,7 +435,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) return true; } -bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS) +bool CMasternodeBroadcast::CheckInputsAndAdd(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 @@ -469,16 +469,16 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS) if(!AcceptToMemoryPool(mempool, state, CTransaction(tx), false, NULL, false, true, true)) { //set nDos - LogPrint("masternode", "mnb - Failed to accepted Masternode entry tx to mempool - %s\n", tx.ToString()); - state.IsInvalid(nDoS); + LogPrint("masternode", "CMasternodeBroadcast::CheckInputsAndAdd - Failed to accepted Masternode entry tx to mempool - %s\n", tx.ToString()); + state.IsInvalid(nDos); return false; } } - LogPrint("masternode", "mnb - Accepted Masternode entry\n"); + LogPrint("masternode", "CMasternodeBroadcast::CheckInputsAndAdd - Accepted Masternode entry\n"); if(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){ - LogPrintf("mnb - Input must have at least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS); + LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Input must have at least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS); // maybe we miss few blocks, let this mnb to be checked again later mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); masternodeSync.mapSeenSyncMNB.erase(GetHash()); @@ -499,13 +499,13 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS) CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + MASTERNODE_MIN_CONFIRMATIONS - 1]; // block where tx got MASTERNODE_MIN_CONFIRMATIONS if(pConfIndex->GetBlockTime() > sigTime) { - LogPrintf("mnb - Bad sigTime %d for Masternode %20s %105s (%i conf block is at %d)\n", + LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Bad sigTime %d for Masternode %20s %105s (%i conf block is at %d)\n", sigTime, addr.ToString(), vin.ToString(), MASTERNODE_MIN_CONFIRMATIONS, pConfIndex->GetBlockTime()); return false; } } } - LogPrintf("mnb - Got NEW Masternode entry - %s - %s - %s - %lli \n", GetHash().ToString(), addr.ToString(), vin.ToString(), sigTime); + LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Got NEW Masternode entry - %s - %s - %s - %lli \n", GetHash().ToString(), addr.ToString(), vin.ToString(), sigTime); CMasternode mn(*this); mnodeman.Add(mn); @@ -539,12 +539,12 @@ bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress) std::string strMessage = addr.ToString() + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); - if(!darkSendSigner.SignMessage(strMessage, errorMessage, sig, keyCollateralAddress)) { + if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyCollateralAddress)) { LogPrintf("CMasternodeBroadcast::Sign() - Error: %s\n", errorMessage); return false; } - if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)) { + if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)) { LogPrintf("CMasternodeBroadcast::Sign() - Error: %s\n", errorMessage); return false; } diff --git a/src/masternode.h b/src/masternode.h index d438baec6..f37e30125 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -123,7 +123,7 @@ public: CService addr; CPubKey pubkey; CPubKey pubkey2; - std::vector sig; + std::vector vchSig; int activeState; int64_t sigTime; //mnb message time int cacheInputAge; @@ -152,7 +152,7 @@ public: swap(first.addr, second.addr); swap(first.pubkey, second.pubkey); swap(first.pubkey2, second.pubkey2); - swap(first.sig, second.sig); + swap(first.vchSig, second.vchSig); swap(first.activeState, second.activeState); swap(first.sigTime, second.sigTime); swap(first.lastPing, second.lastPing); @@ -192,7 +192,7 @@ public: READWRITE(addr); READWRITE(pubkey); READWRITE(pubkey2); - READWRITE(sig); + READWRITE(vchSig); READWRITE(sigTime); READWRITE(protocolVersion); READWRITE(activeState); @@ -291,7 +291,7 @@ public: CMasternodeBroadcast(CService newAddr, CTxIn newVin, CPubKey newPubkey, CPubKey newPubkey2, int protocolVersionIn); CMasternodeBroadcast(const CMasternode& mn); - bool CheckAndUpdate(int& nDoS); + bool CheckAndUpdate(int& nDos); bool CheckInputsAndAdd(int& nDos); bool Sign(CKey& keyCollateralAddress); void Relay(); @@ -304,7 +304,7 @@ public: READWRITE(addr); READWRITE(pubkey); READWRITE(pubkey2); - READWRITE(sig); + READWRITE(vchSig); READWRITE(sigTime); READWRITE(protocolVersion); READWRITE(lastPing); diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index f88ecc348..041808089 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -699,11 +699,11 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData LogPrint("masternode", "mnb - Masternode broadcast, vin: %s new\n", mnb.vin.ToString()); - int nDoS = 0; - if(!mnb.CheckAndUpdate(nDoS)){ + int nDos = 0; + if(!mnb.CheckAndUpdate(nDos)){ - if(nDoS > 0) - Misbehaving(pfrom->GetId(), nDoS); + if(nDos > 0) + Misbehaving(pfrom->GetId(), nDos); LogPrint("masternode", "mnb - Masternode broadcast, vin: %s CheckAndUpdate failed\n", mnb.vin.ToString()); @@ -721,15 +721,15 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData // make sure it's still unspent // - this is checked later by .check() in many places and by ThreadCheckDarkSendPool() - if(mnb.CheckInputsAndAdd(nDoS)) { + if(mnb.CheckInputsAndAdd(nDos)) { // use this as a peer addrman.Add(CAddress(mnb.addr), pfrom->addr, 2*60*60); masternodeSync.AddedMasternodeList(mnb.GetHash()); } else { LogPrintf("mnb - Rejected Masternode entry %s\n", mnb.addr.ToString()); - if (nDoS > 0) - Misbehaving(pfrom->GetId(), nDoS); + if (nDos > 0) + Misbehaving(pfrom->GetId(), nDos); } } @@ -742,14 +742,14 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData if(mapSeenMasternodePing.count(mnp.GetHash())) return; //seen mapSeenMasternodePing.insert(make_pair(mnp.GetHash(), mnp)); - LogPrint("masternode", "mnp - Masternode ping, vin: %s\n new", mnp.vin.ToString()); + LogPrint("masternode", "mnp - Masternode ping, vin: %s new\n", mnp.vin.ToString()); - int nDoS = 0; - if(mnp.CheckAndUpdate(nDoS)) return; + int nDos = 0; + if(mnp.CheckAndUpdate(nDos)) return; - if(nDoS > 0) { + if(nDos > 0) { // if anything significant failed, mark that node - Misbehaving(pfrom->GetId(), nDoS); + Misbehaving(pfrom->GetId(), nDos); } else { // if nothing significant failed, search existing Masternode list CMasternode* pmn = Find(mnp.vin);