CSuperblock:: CSuperblock(uint256& nHash) : nGovObjHash(nHash), nBlockHeight(0), nStatus(SEEN_OBJECT_UNKNOWN), vecPayments() { CGovernanceObject* pGovObj = GetGovernanceObject(); if (!pGovObj) { throw std::runtime_error("CSuperblock: Failed to find Governance Object"); } LogPrint("gobject", "CSuperblock -- Constructor pGovObj: %s, nObjectType = %d\n", pGovObj->GetDataAsPlainString(), pGovObj->GetObjectType()); if (pGovObj->GetObjectType() != GOVERNANCE_OBJECT_TRIGGER) { throw std::runtime_error("CSuperblock: Governance Object not a trigger"); } UniValue obj = pGovObj->GetJSONObject(); // FIRST WE GET THE START HEIGHT, THE BLOCK HEIGHT AT WHICH THE PAYMENT SHALL OCCUR nBlockHeight = obj["event_block_height"].get_int(); // NEXT WE GET THE PAYMENT INFORMATION AND RECONSTRUCT THE PAYMENT VECTOR std::string strAddresses = obj["payment_addresses"].get_str(); std::string strAmounts = obj["payment_amounts"].get_str(); ParsePaymentSchedule(strAddresses, strAmounts); LogPrint("gobject", "CSuperblock -- nBlockHeight = %d, strAddresses = %s, strAmounts = %s, vecPayments.size() = %d\n", nBlockHeight, strAddresses, strAmounts, vecPayments.size()); }
void CGovernanceTriggerManager::CleanAndRemove() { AssertLockHeld(governance.cs); // Remove triggers that are invalid or expired LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- mapTrigger.size() = %d\n", mapTrigger.size()); trigger_m_it it = mapTrigger.begin(); while (it != mapTrigger.end()) { bool remove = false; CGovernanceObject* pObj = nullptr; CSuperblock_sptr& pSuperblock = it->second; if (!pSuperblock) { LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- NULL superblock marked for removal\n"); remove = true; } else { pObj = governance.FindGovernanceObject(it->first); if (!pObj || pObj->GetObjectType() != GOVERNANCE_OBJECT_TRIGGER) { LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Unknown or non-trigger superblock\n"); pSuperblock->SetStatus(SEEN_OBJECT_ERROR_INVALID); } LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- superblock status = %d\n", pSuperblock->GetStatus()); switch (pSuperblock->GetStatus()) { case SEEN_OBJECT_ERROR_INVALID: case SEEN_OBJECT_UNKNOWN: LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Unknown or invalid trigger found\n"); remove = true; break; case SEEN_OBJECT_IS_VALID: case SEEN_OBJECT_EXECUTED: remove = pSuperblock->IsExpired(); break; default: break; } } LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- %smarked for removal\n", remove ? "" : "NOT "); if (remove) { std::string strDataAsPlainString = "NULL"; if (pObj) { strDataAsPlainString = pObj->GetDataAsPlainString(); } LogPrint("gobject", "CGovernanceTriggerManager::CleanAndRemove -- Removing trigger object %s\n", strDataAsPlainString); // mark corresponding object for deletion if (pObj) { pObj->fCachedDelete = true; if (pObj->nDeletionTime == 0) { pObj->nDeletionTime = GetAdjustedTime(); } } // delete the trigger mapTrigger.erase(it++); } else { ++it; } } }
bool CSuperblockManager::IsSuperblockTriggered(int nBlockHeight) { LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- Start nBlockHeight = %d\n", nBlockHeight); if (!CSuperblock::IsValidBlockHeight(nBlockHeight)) { return false; } LOCK(governance.cs); // GET ALL ACTIVE TRIGGERS std::vector<CSuperblock_sptr> vecTriggers = triggerman.GetActiveTriggers(); LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- vecTriggers.size() = %d\n", vecTriggers.size()); for (const auto& pSuperblock : vecTriggers) { if (!pSuperblock) { LogPrintf("CSuperblockManager::IsSuperblockTriggered -- Non-superblock found, continuing\n"); continue; } CGovernanceObject* pObj = pSuperblock->GetGovernanceObject(); if (!pObj) { LogPrintf("CSuperblockManager::IsSuperblockTriggered -- pObj == nullptr, continuing\n"); continue; } LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- data = %s\n", pObj->GetDataAsPlainString()); // note : 12.1 - is epoch calculation correct? if (nBlockHeight != pSuperblock->GetBlockHeight()) { LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- block height doesn't match nBlockHeight = %d, blockStart = %d, continuing\n", nBlockHeight, pSuperblock->GetBlockHeight()); continue; } // MAKE SURE THIS TRIGGER IS ACTIVE VIA FUNDING CACHE FLAG pObj->UpdateSentinelVariables(); if (pObj->IsSetCachedFunding()) { LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- fCacheFunding = true, returning true\n"); return true; } else { LogPrint("gobject", "CSuperblockManager::IsSuperblockTriggered -- fCacheFunding = false, continuing\n"); } } return false; }