From ba8d8ae027af246582511ac78806bf1df3d2d426 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 3 Jan 2017 22:32:52 +0400 Subject: [PATCH] remove unused pindex from IsValidLocally, fix cs_main in rpc (#1243) --- src/governance-object.cpp | 14 +++++--------- src/governance-object.h | 6 +++--- src/governance.cpp | 12 ++++++------ src/rpcgovernance.cpp | 31 +++++-------------------------- 4 files changed, 19 insertions(+), 44 deletions(-) diff --git a/src/governance-object.cpp b/src/governance-object.cpp index 628735c6a..410edbdbe 100644 --- a/src/governance-object.cpp +++ b/src/governance-object.cpp @@ -404,27 +404,23 @@ std::string CGovernanceObject::GetDataAsString() return s; } -void CGovernanceObject::UpdateLocalValidity(const CBlockIndex *pCurrentBlockIndex) +void CGovernanceObject::UpdateLocalValidity() { // THIS DOES NOT CHECK COLLATERAL, THIS IS CHECKED UPON ORIGINAL ARRIVAL - fCachedLocalValidity = IsValidLocally(pCurrentBlockIndex, strLocalValidityError, false); + fCachedLocalValidity = IsValidLocally(strLocalValidityError, false); }; -bool CGovernanceObject::IsValidLocally(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral) +bool CGovernanceObject::IsValidLocally(std::string& strError, bool fCheckCollateral) { bool fMissingMasternode = false; - return IsValidLocally(pindex, strError, fMissingMasternode, fCheckCollateral); + return IsValidLocally(strError, fMissingMasternode, fCheckCollateral); } -bool CGovernanceObject::IsValidLocally(const CBlockIndex* pindex, std::string& strError, bool& fMissingMasternode, bool fCheckCollateral) +bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMasternode, bool fCheckCollateral) { fMissingMasternode = false; - if(!pindex) { - strError = "Tip is NULL"; - return true; - } if(fUnparsable) { strError = "Object data unparseable"; diff --git a/src/governance-object.h b/src/governance-object.h index fc67ec0fe..ba9d8fb7d 100644 --- a/src/governance-object.h +++ b/src/governance-object.h @@ -255,14 +255,14 @@ public: // CORE OBJECT FUNCTIONS - bool IsValidLocally(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral); + bool IsValidLocally(std::string& strError, bool fCheckCollateral); - bool IsValidLocally(const CBlockIndex* pindex, std::string& strError, bool& fMissingMasternode, bool fCheckCollateral); + bool IsValidLocally(std::string& strError, bool& fMissingMasternode, bool fCheckCollateral); /// Check the collateral transaction for the budget proposal/finalized budget bool IsCollateralValid(std::string& strError); - void UpdateLocalValidity(const CBlockIndex *pCurrentBlockIndex); + void UpdateLocalValidity(); void UpdateSentinelVariables(); diff --git a/src/governance.cpp b/src/governance.cpp index dec391f04..53d31b158 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -173,7 +173,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C // CHECK OBJECT AGAINST LOCAL BLOCKCHAIN bool fMasternodeMissing = false; - bool fIsValid = govobj.IsValidLocally(pCurrentBlockIndex, strError, fMasternodeMissing, true); + bool fIsValid = govobj.IsValidLocally(strError, fMasternodeMissing, true); if(fMasternodeMissing) { mapMasternodeOrphanObjects.insert(std::make_pair(nHash, object_time_pair_t(govobj, GetAdjustedTime() + GOVERNANCE_ORPHAN_EXPIRATION_TIME))); @@ -293,8 +293,8 @@ bool CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj) // MAKE SURE THIS OBJECT IS OK - if(!govobj.IsValidLocally(pCurrentBlockIndex, strError, true)) { - LogPrintf("CGovernanceManager::AddGovernanceObject -- invalid governance object - %s - (pCurrentBlockIndex nHeight %d) \n", strError, pCurrentBlockIndex->nHeight); + if(!govobj.IsValidLocally(strError, true)) { + LogPrintf("CGovernanceManager::AddGovernanceObject -- invalid governance object - %s - (nCachedBlockHeight %d) \n", strError, nCachedBlockHeight); return false; } @@ -407,7 +407,7 @@ void CGovernanceManager::UpdateCachesAndClean() // IF CACHE IS NOT DIRTY, WHY DO THIS? if(pObj->IsSetDirtyCache()) { // UPDATE LOCAL VALIDITY AGAINST CRYPTO DATA - pObj->UpdateLocalValidity(pCurrentBlockIndex); + pObj->UpdateLocalValidity(); // UPDATE SENTINEL SIGNALING VARIABLES pObj->UpdateSentinelVariables(); @@ -668,7 +668,7 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp) LogPrint("gobject", "CGovernanceManager::Sync -- attempting to sync govobj: %s, peer=%d\n", strHash, pfrom->id); std::string strError; - bool fIsValid = govobj.IsValidLocally(pCurrentBlockIndex, strError, true); + bool fIsValid = govobj.IsValidLocally(strError, true); if(!fIsValid) { LogPrintf("CGovernanceManager::Sync -- not syncing invalid govobj: %s, strError = %s, fCachedValid = %d, peer=%d\n", strHash, strError, govobj.IsSetCachedValid(), pfrom->id); @@ -887,7 +887,7 @@ void CGovernanceManager::CheckMasternodeOrphanObjects() string strError; bool fMasternodeMissing = false; - bool fIsValid = govobj.IsValidLocally(pCurrentBlockIndex, strError, fMasternodeMissing, true); + bool fIsValid = govobj.IsValidLocally(strError, fMasternodeMissing, true); if(!fIsValid) { if(!fMasternodeMissing) { mapMasternodeOrphanObjects.erase(it++); diff --git a/src/rpcgovernance.cpp b/src/rpcgovernance.cpp index 7d5e6fb94..4df4fd9fa 100644 --- a/src/rpcgovernance.cpp +++ b/src/rpcgovernance.cpp @@ -84,15 +84,6 @@ UniValue gobject(const UniValue& params, bool fHelp) // ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS - CBlockIndex* pindex = NULL; - { - LOCK(cs_main); - pindex = chainActive.Tip(); - } - - std::vector mnEntries; - mnEntries = masternodeConfig.getEntries(); - uint256 hashParent; // -- attach to root node (root node doesn't really exist, but has a hash of zero) @@ -118,7 +109,7 @@ UniValue gobject(const UniValue& params, bool fHelp) } std::string strError = ""; - if(!govobj.IsValidLocally(pindex, strError, false)) + if(!govobj.IsValidLocally(strError, false)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + govobj.GetHash().ToString() + " - " + strError); CWalletTx wtx; @@ -161,12 +152,6 @@ UniValue gobject(const UniValue& params, bool fHelp) // ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS - CBlockIndex* pindex = NULL; - { - LOCK(cs_main); - pindex = chainActive.Tip(); - } - uint256 txidFee; if(params.size() == 6) { @@ -217,7 +202,7 @@ UniValue gobject(const UniValue& params, bool fHelp) std::string strHash = govobj.GetHash().ToString(); std::string strError = ""; - if(!govobj.IsValidLocally(pindex, strError, true)) { + if(!govobj.IsValidLocally(strError, true)) { LogPrintf("gobject(submit) -- Object submission rejected because object is not valid - hash = %s, strError = %s\n", strHash, strError); throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + strHash + " - " + strError); } @@ -575,17 +560,11 @@ UniValue gobject(const UniValue& params, bool fHelp) // SETUP BLOCK INDEX VARIABLE / RESULTS VARIABLE - CBlockIndex* pindex = NULL; - { - LOCK(cs_main); - pindex = chainActive.Tip(); - } - UniValue objResult(UniValue::VOBJ); // GET MATCHING GOVERNANCE OBJECTS - LOCK(governance.cs); + LOCK2(cs_main, governance.cs); std::vector objs = governance.GetAllNewerThan(nStartTime); governance.UpdateLastDiffTime(GetTime()); @@ -619,7 +598,7 @@ UniValue gobject(const UniValue& params, bool fHelp) // REPORT VALIDITY AND CACHING FLAGS FOR VARIOUS SETTINGS std::string strError = ""; - bObj.push_back(Pair("fBlockchainValidity", pGovObj->IsValidLocally(pindex , strError, false))); + bObj.push_back(Pair("fBlockchainValidity", pGovObj->IsValidLocally(strError, false))); bObj.push_back(Pair("IsValidReason", strError.c_str())); bObj.push_back(Pair("fCachedValid", pGovObj->IsSetCachedValid())); bObj.push_back(Pair("fCachedFunding", pGovObj->IsSetCachedFunding())); @@ -698,7 +677,7 @@ UniValue gobject(const UniValue& params, bool fHelp) // -- std::string strError = ""; - objResult.push_back(Pair("fLocalValidity", pGovObj->IsValidLocally(chainActive.Tip(), strError, false))); + objResult.push_back(Pair("fLocalValidity", pGovObj->IsValidLocally(strError, false))); objResult.push_back(Pair("IsValidReason", strError.c_str())); objResult.push_back(Pair("fCachedValid", pGovObj->IsSetCachedValid())); objResult.push_back(Pair("fCachedFunding", pGovObj->IsSetCachedFunding()));