mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
refactor: pass CDeterministicMNManager by ref to CGovernanceManager
This commit is contained in:
parent
055dbba1fa
commit
6bd23f40aa
@ -43,9 +43,10 @@ GovernanceStore::GovernanceStore() :
|
||||
{
|
||||
}
|
||||
|
||||
CGovernanceManager::CGovernanceManager(CNetFulfilledRequestManager& netfulfilledman) :
|
||||
CGovernanceManager::CGovernanceManager(CNetFulfilledRequestManager& netfulfilledman, const std::unique_ptr<CDeterministicMNManager>& dmnman) :
|
||||
m_db{std::make_unique<db_type>("governance.dat", "magicGovernanceCache")},
|
||||
m_netfulfilledman{netfulfilledman},
|
||||
m_dmnman{dmnman},
|
||||
nTimeLastDiff(0),
|
||||
nCachedBlockHeight(0),
|
||||
setRequestedObjects(),
|
||||
@ -119,7 +120,7 @@ PeerMsgRet CGovernanceManager::ProcessMessage(CNode& peer, CConnman& connman, st
|
||||
if (fDisableGovernance) return {};
|
||||
if (::masternodeSync == nullptr || !::masternodeSync->IsBlockchainSynced()) return {};
|
||||
|
||||
const auto tip_mn_list = deterministicMNManager->GetListAtChainTip();
|
||||
const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip();
|
||||
// ANOTHER USER IS ASKING US TO HELP THEM SYNC GOVERNANCE OBJECT DATA
|
||||
if (msg_type == NetMsgType::MNGOVERNANCESYNC) {
|
||||
// Ignore such requests until we are fully synced.
|
||||
@ -264,7 +265,7 @@ void CGovernanceManager::CheckOrphanVotes(CGovernanceObject& govobj, CConnman& c
|
||||
ScopedLockBool guard(cs, fRateChecksEnabled, false);
|
||||
|
||||
int64_t nNow = GetAdjustedTime();
|
||||
const auto tip_mn_list = deterministicMNManager->GetListAtChainTip();
|
||||
const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip();
|
||||
for (const auto& pairVote : vecVotePairs) {
|
||||
bool fRemove = false;
|
||||
const CGovernanceVote& vote = pairVote.first;
|
||||
@ -286,7 +287,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman
|
||||
uint256 nHash = govobj.GetHash();
|
||||
std::string strHash = nHash.ToString();
|
||||
|
||||
const auto tip_mn_list = deterministicMNManager->GetListAtChainTip();
|
||||
const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip();
|
||||
|
||||
// UPDATE CACHED VARIABLES FOR THIS OBJECT AND ADD IT TO OUR MANAGED DATA
|
||||
|
||||
@ -350,7 +351,7 @@ void CGovernanceManager::UpdateCachesAndClean()
|
||||
|
||||
std::vector<uint256> vecDirtyHashes = mmetaman->GetAndClearDirtyGovernanceObjectHashes();
|
||||
|
||||
const auto tip_mn_list = deterministicMNManager->GetListAtChainTip();
|
||||
const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip();
|
||||
|
||||
LOCK2(cs_main, cs);
|
||||
|
||||
@ -496,7 +497,7 @@ std::vector<CGovernanceVote> CGovernanceManager::GetCurrentVotes(const uint256&
|
||||
if (it == mapObjects.end()) return vecResult;
|
||||
const CGovernanceObject& govobj = it->second;
|
||||
|
||||
const auto tip_mn_list = deterministicMNManager->GetListAtChainTip();
|
||||
const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip();
|
||||
std::map<COutPoint, CDeterministicMNCPtr> mapMasternodes;
|
||||
if (mnCollateralOutpointFilter.IsNull()) {
|
||||
tip_mn_list.ForEachMNShared(false, [&](const CDeterministicMNCPtr& dmn) {
|
||||
@ -565,7 +566,7 @@ std::optional<const CSuperblock> CGovernanceManager::CreateSuperblockCandidate(i
|
||||
|
||||
// A proposal is considered passing if (YES votes) >= (Total Weight of Masternodes / 10),
|
||||
// count total valid (ENABLED) masternodes to determine passing threshold.
|
||||
const auto tip_mn_list = deterministicMNManager->GetListAtChainTip();
|
||||
const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip();
|
||||
const int nWeightedMnCount = tip_mn_list.GetValidWeightedMNsCount();
|
||||
const int nAbsVoteReq = std::max(Params().GetConsensus().nGovernanceMinQuorum, nWeightedMnCount / 10);
|
||||
|
||||
@ -682,7 +683,7 @@ std::optional<const CGovernanceObject> CGovernanceManager::CreateGovernanceTrigg
|
||||
|
||||
// Nobody submitted a trigger we'd like to see, so let's do it but only if we are the payee
|
||||
const CBlockIndex *tip = WITH_LOCK(::cs_main, return ::ChainActive().Tip());
|
||||
const auto mnList = deterministicMNManager->GetListForBlock(tip);
|
||||
const auto mnList = Assert(m_dmnman)->GetListForBlock(tip);
|
||||
const auto mn_payees = mnList.GetProjectedMNPayees(tip);
|
||||
|
||||
if (mn_payees.empty()) {
|
||||
@ -700,7 +701,7 @@ std::optional<const CGovernanceObject> CGovernanceManager::CreateGovernanceTrigg
|
||||
gov_sb.Sign( *activeMasternodeInfo.blsKeyOperator);
|
||||
} // activeMasternodeInfoCs
|
||||
|
||||
if (std::string strError; !gov_sb.IsValidLocally(deterministicMNManager->GetListAtChainTip(), strError, true)) {
|
||||
if (std::string strError; !gov_sb.IsValidLocally(m_dmnman->GetListAtChainTip(), strError, true)) {
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s Created trigger is invalid:%s\n", __func__, strError);
|
||||
return std::nullopt;
|
||||
}
|
||||
@ -882,7 +883,7 @@ void CGovernanceManager::SyncSingleObjVotes(CNode& peer, const uint256& nProp, c
|
||||
}
|
||||
|
||||
const auto& fileVotes = govobj.GetVoteFile();
|
||||
const auto tip_mn_list = deterministicMNManager->GetListAtChainTip();
|
||||
const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip();
|
||||
|
||||
for (const auto& vote : fileVotes.GetVotes()) {
|
||||
uint256 nVoteHash = vote.GetHash();
|
||||
@ -1103,7 +1104,7 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool fOk = govobj.ProcessVote(*this, deterministicMNManager->GetListAtChainTip(), vote, exception) && cmapVoteToObject.Insert(nHashVote, &govobj);
|
||||
bool fOk = govobj.ProcessVote(*this, Assert(m_dmnman)->GetListAtChainTip(), vote, exception) && cmapVoteToObject.Insert(nHashVote, &govobj);
|
||||
LEAVE_CRITICAL_SECTION(cs);
|
||||
return fOk;
|
||||
}
|
||||
@ -1124,7 +1125,7 @@ void CGovernanceManager::CheckPostponedObjects(CConnman& connman)
|
||||
std::string strError;
|
||||
bool fMissingConfirmations;
|
||||
if (govobj.IsCollateralValid(strError, fMissingConfirmations)) {
|
||||
if (govobj.IsValidLocally(deterministicMNManager->GetListAtChainTip(), strError, false)) {
|
||||
if (govobj.IsValidLocally(Assert(m_dmnman)->GetListAtChainTip(), strError, false)) {
|
||||
AddGovernanceObject(govobj, connman);
|
||||
} else {
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceManager::CheckPostponedObjects -- %s invalid\n", nHash.ToString());
|
||||
@ -1231,7 +1232,7 @@ int CGovernanceManager::RequestGovernanceObjectVotes(Span<CNode*> vNodesCopy, CC
|
||||
int nMaxObjRequestsPerNode = 1;
|
||||
size_t nProjectedVotes = 2000;
|
||||
if (Params().NetworkIDString() != CBaseChainParams::MAIN) {
|
||||
nMaxObjRequestsPerNode = std::max(1, int(nProjectedVotes / std::max(1, (int)deterministicMNManager->GetListAtChainTip().GetValidMNsCount())));
|
||||
nMaxObjRequestsPerNode = std::max(1, int(nProjectedVotes / std::max(1, (int)Assert(m_dmnman)->GetListAtChainTip().GetValidMNsCount())));
|
||||
}
|
||||
|
||||
{
|
||||
@ -1477,7 +1478,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex* pindex, CConnman& co
|
||||
|
||||
CheckPostponedObjects(connman);
|
||||
|
||||
CSuperblockManager::ExecuteBestSuperblock(*this, deterministicMNManager->GetListAtChainTip(), pindex->nHeight);
|
||||
CSuperblockManager::ExecuteBestSuperblock(*this, Assert(m_dmnman)->GetListAtChainTip(), pindex->nHeight);
|
||||
}
|
||||
|
||||
void CGovernanceManager::RequestOrphanObjects(CConnman& connman)
|
||||
@ -1535,7 +1536,7 @@ void CGovernanceManager::RemoveInvalidVotes()
|
||||
|
||||
LOCK(cs);
|
||||
|
||||
const auto tip_mn_list = deterministicMNManager->GetListAtChainTip();
|
||||
const auto tip_mn_list = Assert(m_dmnman)->GetListAtChainTip();
|
||||
auto diff = lastMNListForVotingKeys->BuildDiff(tip_mn_list);
|
||||
|
||||
std::vector<COutPoint> changedKeyMNs;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <cachemap.h>
|
||||
#include <cachemultimap.h>
|
||||
#include <net_types.h>
|
||||
#include <util/check.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
@ -21,6 +22,7 @@ template<typename T>
|
||||
class CFlatDB;
|
||||
class CInv;
|
||||
|
||||
class CDeterministicMNManager;
|
||||
class CGovernanceManager;
|
||||
class CGovernanceObject;
|
||||
class CGovernanceVote;
|
||||
@ -254,6 +256,7 @@ private:
|
||||
bool is_valid{false};
|
||||
|
||||
CNetFulfilledRequestManager& m_netfulfilledman;
|
||||
const std::unique_ptr<CDeterministicMNManager>& m_dmnman;
|
||||
|
||||
int64_t nTimeLastDiff;
|
||||
// keep track of current block height
|
||||
@ -267,7 +270,7 @@ private:
|
||||
std::map<uint256, std::shared_ptr<CSuperblock>> mapTrigger;
|
||||
|
||||
public:
|
||||
explicit CGovernanceManager(CNetFulfilledRequestManager& netfulfilledman);
|
||||
explicit CGovernanceManager(CNetFulfilledRequestManager& netfulfilledman, const std::unique_ptr<CDeterministicMNManager>& dmnman);
|
||||
~CGovernanceManager();
|
||||
|
||||
bool LoadCache(bool load_cache);
|
||||
@ -340,7 +343,7 @@ public:
|
||||
{
|
||||
bool fOK = ProcessVote(nullptr, vote, exception, connman);
|
||||
if (fOK) {
|
||||
vote.Relay(connman, deterministicMNManager->GetListAtChainTip());
|
||||
vote.Relay(connman, Assert(m_dmnman)->GetListAtChainTip());
|
||||
}
|
||||
return fOK;
|
||||
}
|
||||
|
@ -1711,7 +1711,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
|
||||
node.netfulfilledman = std::make_unique<CNetFulfilledRequestManager>();
|
||||
|
||||
assert(!node.govman);
|
||||
node.govman = std::make_unique<CGovernanceManager>(*node.netfulfilledman);
|
||||
node.govman = std::make_unique<CGovernanceManager>(*node.netfulfilledman, ::deterministicMNManager);
|
||||
|
||||
assert(!node.sporkman);
|
||||
node.sporkman = std::make_unique<CSporkManager>();
|
||||
|
@ -226,7 +226,7 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
|
||||
|
||||
m_node.netfulfilledman = std::make_unique<CNetFulfilledRequestManager>();
|
||||
m_node.sporkman = std::make_unique<CSporkManager>();
|
||||
m_node.govman = std::make_unique<CGovernanceManager>(*m_node.netfulfilledman);
|
||||
m_node.govman = std::make_unique<CGovernanceManager>(*m_node.netfulfilledman, ::deterministicMNManager);
|
||||
::masternodeSync = std::make_unique<CMasternodeSync>(*m_node.connman, *m_node.netfulfilledman, *m_node.govman);
|
||||
m_node.mn_sync = ::masternodeSync.get();
|
||||
::mmetaman = std::make_unique<CMasternodeMetaMan>(/* load_cache */ false);
|
||||
|
Loading…
Reference in New Issue
Block a user