refactor: drop CSuperblock::GetGovernanceObject to simplify thread safety analysis over FindGovernanceObject

This commit is contained in:
Konstantin Akimov 2024-10-06 21:13:26 +07:00
parent 5031f29441
commit 350a5ca47c
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
3 changed files with 10 additions and 17 deletions

View File

@ -237,8 +237,7 @@ bool CGovernanceManager::IsSuperblockTriggered(const CDeterministicMNList& tip_m
continue;
}
CGovernanceObject* pObj = pSuperblock->GetGovernanceObject(*this);
CGovernanceObject* pObj = FindGovernanceObject(pSuperblock->GetGovernanceObjHash());
if (!pObj) {
LogPrintf("IsSuperblockTriggered -- pObj == nullptr, continuing\n");
continue;
@ -288,8 +287,7 @@ bool CGovernanceManager::GetBestSuperblock(const CDeterministicMNList& tip_mn_li
continue;
}
const CGovernanceObject* pObj = pSuperblock->GetGovernanceObject(*this);
const CGovernanceObject* pObj = FindGovernanceObject(pSuperblock->GetGovernanceObjHash());
if (!pObj) {
continue;
}
@ -396,7 +394,7 @@ CSuperblock::
nStatus(SeenObjectStatus::Unknown),
vecPayments()
{
const CGovernanceObject* pGovObj = GetGovernanceObject(govman);
const CGovernanceObject* pGovObj = govman.FindGovernanceObject(nGovObjHash);
if (!pGovObj) {
throw std::runtime_error("CSuperblock: Failed to find Governance Object");
@ -434,14 +432,6 @@ CSuperblock::CSuperblock(int nBlockHeight, std::vector<CGovernancePayment> vecPa
nGovObjHash = GetHash();
}
CGovernanceObject* CSuperblock::GetGovernanceObject(CGovernanceManager& govman)
{
AssertLockHeld(govman.cs);
CGovernanceObject* pObj = govman.FindGovernanceObject(nGovObjHash);
return pObj;
}
/**
* Is Valid Superblock Height
*
@ -592,6 +582,8 @@ CAmount CSuperblock::GetPaymentsTotalAmount()
bool CSuperblock::IsValid(CGovernanceManager& govman, const CChain& active_chain, const CTransaction& txNew, int nBlockHeight, CAmount blockReward)
{
AssertLockHeld(govman.cs);
// TODO : LOCK(cs);
// No reason for a lock here now since this method only accesses data
// internal to *this and since CSuperblock's are accessed only through
@ -608,8 +600,9 @@ bool CSuperblock::IsValid(CGovernanceManager& govman, const CChain& active_chain
int nPayments = CountPayments();
int nMinerAndMasternodePayments = nOutputs - nPayments;
const CGovernanceObject* obj = govman.FindGovernanceObject(nGovObjHash);
LogPrint(BCLog::GOBJECT, "CSuperblock::IsValid -- nOutputs = %d, nPayments = %d, GetDataAsHexString = %s\n",
nOutputs, nPayments, GetGovernanceObject(govman)->GetDataAsHexString());
nOutputs, nPayments, obj ? obj->GetDataAsHexString() : "");
// We require an exact match (including order) between the expected
// superblock payments and the payments actually in the block.

View File

@ -94,13 +94,13 @@ public:
// TELL THE ENGINE WE EXECUTED THIS EVENT
void SetExecuted() { nStatus = SeenObjectStatus::Executed; }
CGovernanceObject* GetGovernanceObject(CGovernanceManager& govman);
int GetBlockHeight() const
{
return nBlockHeight;
}
const uint256 GetGovernanceObjHash() const { return nGovObjHash; }
int CountPayments() const { return (int)vecPayments.size(); }
bool GetPayment(int nPaymentIndex, CGovernancePayment& paymentRet);
CAmount GetPaymentsTotalAmount();

View File

@ -795,7 +795,7 @@ void CGovernanceManager::VoteGovernanceTriggers(const std::optional<const CGover
// Vote NO-FUNDING for the rest of the active triggers
const auto activeTriggers = GetActiveTriggers();
for (const auto& trigger : activeTriggers) {
const auto govobj = trigger->GetGovernanceObject(*this);
const auto govobj = FindGovernanceObject(trigger->GetGovernanceObjHash());
const uint256 trigger_hash = govobj->GetHash();
if (trigger->GetBlockHeight() <= nCachedBlockHeight) {
// ignore triggers from the past