Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.12.1.x governance propagation #878

Merged
65 changes: 42 additions & 23 deletions src/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
else if (strCommand == NetMsgType::MNGOVERNANCEOBJECT)

{
// MAKE SURE WE HAVE A VALID REFERENCE TO THE TIP BEFORE CONTINUING

if(!pCurrentBlockIndex) return;

CGovernanceObject govobj;
vRecv >> govobj;
Expand All @@ -157,11 +160,11 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
LogPrintf("Governance object is invalid - %s\n", strError);
return;
}

// UPDATE CACHED VARIABLES FOR THIS OBJECT AND ADD IT TO OUR MANANGED DATA

if(AddGovernanceObject(govobj))
{
govobj.Relay();
}
govobj.UpdateSentinelVariables(pCurrentBlockIndex);
if(AddGovernanceObject(govobj)) govobj.Relay();

mapSeenGovernanceObjects.insert(make_pair(govobj.GetHash(), SEEN_OBJECT_IS_VALID));
masternodeSync.AddedBudgetItem(govobj.GetHash());
Expand Down Expand Up @@ -254,36 +257,32 @@ void CGovernanceManager::CheckAndRemove()
{
LogPrintf("CGovernanceManager::CheckAndRemove \n");

// DOUBLE CHECK THAT WE HAVE A VALID POINTER TO TIP

if(!pCurrentBlockIndex) return;

// DELETE OBJECTS WHICH MASTERNODE HAS FLAGGED DELETE=TRUE

std::map<uint256, CGovernanceObject>::iterator it = mapObjects.begin();
while(it != mapObjects.end())
{
{
CGovernanceObject* pObj = &((*it).second);

// UPDATE LOCAL VALIDITY AGAINST CRYPTO DATA
pObj->UpdateLocalValidity(pCurrentBlockIndex);
// UPDATE SENTINEL SIGNALING VARIABLES
pObj->UpdateSentinelVariables(pCurrentBlockIndex);
++it;
}

// UPDATE CACHING MECHANISMS FOR GOVERNANCE OBJECTS
// SHOULD WE DELETE THIS OBJECT FROM MEMORY

if(!pCurrentBlockIndex) return;
/*
- delete objects from memory where fCachedDelete is true
- this should be robust enough that if someone sends us the proposal later, we should know it was deleted
*/

std::string strError = "";

std::map<uint256, CGovernanceObject>::iterator it2 = mapObjects.begin();
while(it2 != mapObjects.end())
{
CGovernanceObject* pObj = &((*it2).second);

// UPDATE LOCAL VALIDITY AGAINST CRYPTO DATA
pObj->UpdateLocalValidity(pCurrentBlockIndex);

// UPDATE SENTINEL SIGNALING VARIABLES
pObj->UpdateSentinelVariables(pCurrentBlockIndex);
++it2;
++it;
}

}

CGovernanceObject *CGovernanceManager::FindGovernanceObject(const std::string &strName)
Expand Down Expand Up @@ -536,6 +535,12 @@ bool CGovernanceManager::AddOrUpdateVote(const CGovernanceVote& vote, std::strin

mapVotesByType[nTypeHash] = vote;
mapVotesByHash[nHash] = vote;

// // SET CACHE AS DIRTY / WILL BE UPDATED NEXT BLOCK

// CGovernanceObject* pGovObj = FindGovernanceObject(vote.GetParentHash());
// if(pGovObj) pGovObj->fDirtyCache = true;

return true;
}

Expand All @@ -553,7 +558,7 @@ CGovernanceObject::CGovernanceObject()
fCachedValid = true;
fCachedDelete = false;
fCachedEndorsed = false;

//fDirtyCache = true;
}

CGovernanceObject::CGovernanceObject(uint256 nHashParentIn, int nRevisionIn, std::string strNameIn, int64_t nTimeIn, uint256 nFeeTXHashIn)
Expand All @@ -563,6 +568,13 @@ CGovernanceObject::CGovernanceObject(uint256 nHashParentIn, int nRevisionIn, std
strName = strNameIn;
nTime = nTimeIn;
nFeeTXHash = nFeeTXHashIn; //fee-tx

// caching
fCachedFunding = false;
fCachedValid = true;
fCachedDelete = false;
fCachedEndorsed = false;
//fDirtyCache = true;
}

CGovernanceObject::CGovernanceObject(const CGovernanceObject& other)
Expand All @@ -575,6 +587,13 @@ CGovernanceObject::CGovernanceObject(const CGovernanceObject& other)
nTime = other.nTime;
nFeeTXHash = other.nFeeTXHash;
strData = other.strData;

// caching
fCachedFunding = other.fCachedFunding;
fCachedValid = other.fCachedValid;
fCachedDelete = other.fCachedDelete;
fCachedEndorsed = other.fCachedEndorsed;
//fDirtyCache = other.fDirtyCache;
}

bool CGovernanceObject::IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral)
Expand Down
14 changes: 8 additions & 6 deletions src/governance.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,12 @@ class CGovernanceObject
std::string strLocalValidityError;

// set via sentinel voting mechanisms
// caching -- one per voting mechanism -- see governance-vote.h for more information
bool fCachedFunding;
bool fCachedValid;
bool fCachedDelete;
bool fCachedEndorsed;
// caching -- one per voting mechanism -- see below for more information
bool fCachedFunding; // true == minimum network support has been reached for this object to be funded (doesn't mean it will for sure though)
bool fCachedValid; // true == minimum network has been reached flagging this object as a valid and understood goverance object (e.g, the serialized data is correct format, etc)
bool fCachedDelete; // true == minimum network support has been reached saying this object should be deleted from the system entirely
bool fCachedEndorsed; // true == minimum network support has been reached flagging this object as endorsed by an elected representative body (e.g. business review board / technecial review board /etc)
// bool fDirtyCache; // object was updated and cached values should be updated soon

CGovernanceObject();
CGovernanceObject(uint256 nHashParentIn, int nRevisionIn, std::string strNameIn, int64_t nTime, uint256 nFeeTXHashIn);
Expand Down Expand Up @@ -257,7 +258,6 @@ class CGovernanceObject
void CleanAndRemove(bool fSignatureCheck);
void Relay();


uint256 GetHash(){

// CREATE HASH OF ALL IMPORTANT PIECES OF DATA
Expand Down Expand Up @@ -310,6 +310,8 @@ class CGovernanceObject
READWRITE(nTime);
READWRITE(nFeeTXHash);
READWRITE(strData);

// AFTER DESERIALIZATION OCCURS, CACHED VARIABLES MUST BE CALCULATED MANUALLY
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/rpcmasternode-budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError)));
bObj.push_back(Pair("IsValidReason", strError.c_str()));
bObj.push_back(Pair("fCachedValid", pbudgetProposal->fCachedValid));
bObj.push_back(Pair("fCachedFunding", pbudgetProposal->fCachedFunding));
bObj.push_back(Pair("fCachedDelete", pbudgetProposal->fCachedDelete));
bObj.push_back(Pair("fCachedEndorsed", pbudgetProposal->fCachedEndorsed));

resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj));
}
Expand Down