Governance fixes (#1131)
* Added net logging messages in main.cpp * Added logging for trigger removal * Improved log message for CGovernanceManager::UpdatedBlockTip * Improved log messages in CGovernanceManager::UpdateCachesAndClean * Added more logging to CGovernanceTriggerManager * Check vote validity before pushing inventory during sync * Add triggers to map after loading governance.dat file
This commit is contained in:
parent
eb92933d52
commit
bc96f288ed
@ -164,6 +164,7 @@ bool CGovernanceTriggerManager::AddNewTrigger(uint256 nHash)
|
|||||||
|
|
||||||
void CGovernanceTriggerManager::CleanAndRemove()
|
void CGovernanceTriggerManager::CleanAndRemove()
|
||||||
{
|
{
|
||||||
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Start\n");
|
||||||
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: Start" << endl; );
|
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: Start" << endl; );
|
||||||
AssertLockHeld(governance.cs);
|
AssertLockHeld(governance.cs);
|
||||||
|
|
||||||
@ -186,24 +187,30 @@ void CGovernanceTriggerManager::CleanAndRemove()
|
|||||||
|
|
||||||
// Remove triggers that are invalid or already executed
|
// Remove triggers that are invalid or already executed
|
||||||
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: mapTrigger.size() = " << mapTrigger.size() << endl; );
|
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: mapTrigger.size() = " << mapTrigger.size() << endl; );
|
||||||
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- mapTrigger.size() = %d\n", mapTrigger.size());
|
||||||
trigger_m_it it = mapTrigger.begin();
|
trigger_m_it it = mapTrigger.begin();
|
||||||
while(it != mapTrigger.end()) {
|
while(it != mapTrigger.end()) {
|
||||||
bool remove = false;
|
bool remove = false;
|
||||||
CSuperblock_sptr& pSuperblock = it->second;
|
CSuperblock_sptr& pSuperblock = it->second;
|
||||||
if(!pSuperblock) {
|
if(!pSuperblock) {
|
||||||
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: NULL superblock marked for removal " << endl; );
|
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: NULL superblock marked for removal " << endl; );
|
||||||
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- NULL superblock marked for removal\n");
|
||||||
remove = true;
|
remove = true;
|
||||||
} else {
|
} else {
|
||||||
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: superblock status = " << pSuperblock->GetStatus() << endl; );
|
DBG( cout << "CGovernanceTriggerManager::CleanAndRemove: superblock status = " << pSuperblock->GetStatus() << endl; );
|
||||||
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- superblock status = %d\n", pSuperblock->GetStatus());
|
||||||
switch(pSuperblock->GetStatus()) {
|
switch(pSuperblock->GetStatus()) {
|
||||||
case SEEN_OBJECT_ERROR_INVALID:
|
case SEEN_OBJECT_ERROR_INVALID:
|
||||||
case SEEN_OBJECT_UNKNOWN:
|
case SEEN_OBJECT_UNKNOWN:
|
||||||
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Unknown or invalid trigger found\n");
|
||||||
remove = true;
|
remove = true;
|
||||||
break;
|
break;
|
||||||
case SEEN_OBJECT_EXECUTED:
|
case SEEN_OBJECT_EXECUTED:
|
||||||
{
|
{
|
||||||
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Executed trigger found\n");
|
||||||
CGovernanceObject* pgovobj = pSuperblock->GetGovernanceObject();
|
CGovernanceObject* pgovobj = pSuperblock->GetGovernanceObject();
|
||||||
if(pgovobj) {
|
if(pgovobj) {
|
||||||
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Expiring executed object: %s\n", pgovobj->GetHash().ToString());
|
||||||
pgovobj->fExpired = true;
|
pgovobj->fExpired = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,10 +221,13 @@ void CGovernanceTriggerManager::CleanAndRemove()
|
|||||||
int nTriggerBlock = pSuperblock->GetBlockStart();
|
int nTriggerBlock = pSuperblock->GetBlockStart();
|
||||||
// Rough approximation: a cycle of superblock ++
|
// Rough approximation: a cycle of superblock ++
|
||||||
int nExpirationBlock = nTriggerBlock + Params().GetConsensus().nSuperblockCycle + GOVERNANCE_FEE_CONFIRMATIONS;
|
int nExpirationBlock = nTriggerBlock + Params().GetConsensus().nSuperblockCycle + GOVERNANCE_FEE_CONFIRMATIONS;
|
||||||
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- nTriggerBlock = %d, nExpriartionBlock = %d\n");
|
||||||
if(governance.GetCachedBlockHeight() > nExpirationBlock) {
|
if(governance.GetCachedBlockHeight() > nExpirationBlock) {
|
||||||
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Outdated trigger found\n");
|
||||||
remove = true;
|
remove = true;
|
||||||
CGovernanceObject* pgovobj = pSuperblock->GetGovernanceObject();
|
CGovernanceObject* pgovobj = pSuperblock->GetGovernanceObject();
|
||||||
if(pgovobj) {
|
if(pgovobj) {
|
||||||
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Expiring outdated object: %s\n", pgovobj->GetHash().ToString());
|
||||||
pgovobj->fExpired = true;
|
pgovobj->fExpired = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,6 +249,7 @@ void CGovernanceTriggerManager::CleanAndRemove()
|
|||||||
<< strdata
|
<< strdata
|
||||||
<< endl;
|
<< endl;
|
||||||
);
|
);
|
||||||
|
LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Removing trigger object\n");
|
||||||
mapTrigger.erase(it++);
|
mapTrigger.erase(it++);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -300,6 +300,8 @@ void CGovernanceManager::UpdateCachesAndClean()
|
|||||||
|
|
||||||
if(!pCurrentBlockIndex) return;
|
if(!pCurrentBlockIndex) return;
|
||||||
|
|
||||||
|
LogPrint("gobject", "CGovernanceManager::UpdateCachesAndClean -- After pCurrentBlockIndex (not NULL)\n");
|
||||||
|
|
||||||
// UPDATE CACHE FOR EACH OBJECT THAT IS FLAGGED DIRTYCACHE=TRUE
|
// UPDATE CACHE FOR EACH OBJECT THAT IS FLAGGED DIRTYCACHE=TRUE
|
||||||
|
|
||||||
object_m_it it = mapObjects.begin();
|
object_m_it it = mapObjects.begin();
|
||||||
@ -332,7 +334,7 @@ void CGovernanceManager::UpdateCachesAndClean()
|
|||||||
// IF DELETE=TRUE, THEN CLEAN THE MESS UP!
|
// IF DELETE=TRUE, THEN CLEAN THE MESS UP!
|
||||||
|
|
||||||
if(pObj->fCachedDelete || pObj->fExpired) {
|
if(pObj->fCachedDelete || pObj->fExpired) {
|
||||||
LogPrintf("UpdateCachesAndClean -- erase obj %s\n", (*it).first.ToString());
|
LogPrintf("CGovernanceManager::UpdateCachesAndClean -- erase obj %s\n", (*it).first.ToString());
|
||||||
mnodeman.RemoveGovernanceObject(pObj->GetHash());
|
mnodeman.RemoveGovernanceObject(pObj->GetHash());
|
||||||
mapObjects.erase(it++);
|
mapObjects.erase(it++);
|
||||||
} else {
|
} else {
|
||||||
@ -479,6 +481,11 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp)
|
|||||||
|
|
||||||
vote_m_it it2 = mapVotesByHash.begin();
|
vote_m_it it2 = mapVotesByHash.begin();
|
||||||
while(it2 != mapVotesByHash.end()) {
|
while(it2 != mapVotesByHash.end()) {
|
||||||
|
CGovernanceVote& vote = it2->second;
|
||||||
|
if(!vote.IsValid(true)) {
|
||||||
|
// Don't relay votes that are now invalid (ie. missing MN) to avoid being banned
|
||||||
|
continue;
|
||||||
|
}
|
||||||
pfrom->PushInventory(CInv(MSG_GOVERNANCE_OBJECT_VOTE, (*it2).first));
|
pfrom->PushInventory(CInv(MSG_GOVERNANCE_OBJECT_VOTE, (*it2).first));
|
||||||
nInvCount++;
|
nInvCount++;
|
||||||
++it2;
|
++it2;
|
||||||
@ -613,6 +620,21 @@ bool CGovernanceManager::MasternodeRateCheck(const CTxIn& vin, int nObjectType)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGovernanceManager::AddCachedTriggers()
|
||||||
|
{
|
||||||
|
LOCK(cs);
|
||||||
|
|
||||||
|
for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) {
|
||||||
|
CGovernanceObject& govobj = it->second;
|
||||||
|
|
||||||
|
if(govobj.nObjectType != GOVERNANCE_OBJECT_TRIGGER) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
triggerman.AddNewTrigger(govobj.GetHash());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CGovernanceObject::CGovernanceObject()
|
CGovernanceObject::CGovernanceObject()
|
||||||
: cs(),
|
: cs(),
|
||||||
nHashParent(),
|
nHashParent(),
|
||||||
@ -1106,7 +1128,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex *pindex)
|
|||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
pCurrentBlockIndex = pindex;
|
pCurrentBlockIndex = pindex;
|
||||||
nCachedBlockHeight = pCurrentBlockIndex->nHeight;
|
nCachedBlockHeight = pCurrentBlockIndex->nHeight;
|
||||||
LogPrint("gobject", "pCurrentBlockIndex->nHeight: %d\n", pCurrentBlockIndex->nHeight);
|
LogPrint("gobject", "CGovernanceManager::UpdatedBlockTip pCurrentBlockIndex->nHeight: %d\n", pCurrentBlockIndex->nHeight);
|
||||||
|
|
||||||
// TO REPROCESS OBJECTS WE SHOULD BE SYNCED
|
// TO REPROCESS OBJECTS WE SHOULD BE SYNCED
|
||||||
|
|
||||||
|
@ -185,6 +185,9 @@ public:
|
|||||||
READWRITE(mapVotesByHash);
|
READWRITE(mapVotesByHash);
|
||||||
READWRITE(mapVotesByType);
|
READWRITE(mapVotesByType);
|
||||||
READWRITE(mapLastMasternodeTrigger);
|
READWRITE(mapLastMasternodeTrigger);
|
||||||
|
if(ser_action.ForRead()) {
|
||||||
|
AddCachedTriggers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatedBlockTip(const CBlockIndex *pindex);
|
void UpdatedBlockTip(const CBlockIndex *pindex);
|
||||||
@ -208,6 +211,9 @@ public:
|
|||||||
|
|
||||||
bool MasternodeRateCheck(const CTxIn& vin, int nObjectType);
|
bool MasternodeRateCheck(const CTxIn& vin, int nObjectType);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void AddCachedTriggers();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4976,6 +4976,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
const CInv &inv = *it;
|
const CInv &inv = *it;
|
||||||
|
LogPrint("net", "ProcessGetData -- inv = %s\n", inv.ToString());
|
||||||
{
|
{
|
||||||
boost::this_thread::interruption_point();
|
boost::this_thread::interruption_point();
|
||||||
it++;
|
it++;
|
||||||
@ -5169,6 +5170,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!pushed && inv.type == MSG_GOVERNANCE_OBJECT) {
|
if (!pushed && inv.type == MSG_GOVERNANCE_OBJECT) {
|
||||||
|
LogPrint("net", "ProcessGetData -- MSG_GOVERNANCE_OBJECT: inv = %s\n", inv.ToString());
|
||||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
bool topush = false;
|
bool topush = false;
|
||||||
{
|
{
|
||||||
@ -5179,6 +5181,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LogPrint("net", "ProcessGetData -- MSG_GOVERNANCE_OBJECT: topush = %d, inv = %s\n", topush, inv.ToString());
|
||||||
if(topush) {
|
if(topush) {
|
||||||
pfrom->PushMessage(NetMsgType::MNGOVERNANCEOBJECT, ss);
|
pfrom->PushMessage(NetMsgType::MNGOVERNANCEOBJECT, ss);
|
||||||
pushed = true;
|
pushed = true;
|
||||||
@ -5197,6 +5200,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(topush) {
|
if(topush) {
|
||||||
|
LogPrint("net", "ProcessGetData -- pushing: inv = %s\n", inv.ToString());
|
||||||
pfrom->PushMessage(NetMsgType::MNGOVERNANCEOBJECTVOTE, ss);
|
pfrom->PushMessage(NetMsgType::MNGOVERNANCEOBJECTVOTE, ss);
|
||||||
pushed = true;
|
pushed = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user