mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
refactor: drop CSuperblock::GetGovernanceObject to simplify thread safety analysis over FindGovernanceObject
This commit is contained in:
parent
5031f29441
commit
350a5ca47c
@ -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.
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user