mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
refactor: drop usage of chainstate globals in governance logic
This commit is contained in:
parent
a475f5f4e5
commit
21cc12c62a
@ -9,10 +9,10 @@
|
||||
#include <masternode/payments.h>
|
||||
|
||||
CChainstateHelper::CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, CGovernanceManager& govman,
|
||||
llmq::CQuorumBlockProcessor& qblockman, const Consensus::Params& consensus_params,
|
||||
llmq::CQuorumBlockProcessor& qblockman, const ChainstateManager& chainman, const Consensus::Params& consensus_params,
|
||||
const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler,
|
||||
const llmq::CQuorumManager& qman)
|
||||
: mn_payments{std::make_unique<CMNPaymentsProcessor>(dmnman, govman, consensus_params, mn_sync, sporkman)},
|
||||
: mn_payments{std::make_unique<CMNPaymentsProcessor>(dmnman, govman, chainman, consensus_params, mn_sync, sporkman)},
|
||||
special_tx{std::make_unique<CSpecialTxProcessor>(cpoolman, dmnman, mnhfman, qblockman, consensus_params, clhandler, qman)}
|
||||
{}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
class CCreditPoolManager;
|
||||
class CDeterministicMNManager;
|
||||
class ChainstateManager;
|
||||
class CMNHFManager;
|
||||
class CMNPaymentsProcessor;
|
||||
class CMasternodeSync;
|
||||
@ -27,7 +28,7 @@ class CChainstateHelper
|
||||
{
|
||||
public:
|
||||
explicit CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman, CMNHFManager& mnhfman, CGovernanceManager& govman,
|
||||
llmq::CQuorumBlockProcessor& qblockman, const Consensus::Params& consensus_params,
|
||||
llmq::CQuorumBlockProcessor& qblockman, const ChainstateManager& chainman, const Consensus::Params& consensus_params,
|
||||
const CMasternodeSync& mn_sync, const CSporkManager& sporkman, const llmq::CChainLocksHandler& clhandler,
|
||||
const llmq::CQuorumManager& qman);
|
||||
~CChainstateHelper();
|
||||
|
@ -362,14 +362,14 @@ bool CSuperblockManager::GetSuperblockPayments(CGovernanceManager& govman, const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSuperblockManager::IsValid(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, const CTransaction& txNew, int nBlockHeight, CAmount blockReward)
|
||||
bool CSuperblockManager::IsValid(CGovernanceManager& govman, const CChain& active_chain, const CDeterministicMNList& tip_mn_list, const CTransaction& txNew, int nBlockHeight, CAmount blockReward)
|
||||
{
|
||||
// GET BEST SUPERBLOCK, SHOULD MATCH
|
||||
LOCK(govman.cs);
|
||||
|
||||
CSuperblock_sptr pSuperblock;
|
||||
if (CSuperblockManager::GetBestSuperblock(govman, tip_mn_list, pSuperblock, nBlockHeight)) {
|
||||
return pSuperblock->IsValid(govman, txNew, nBlockHeight, blockReward);
|
||||
return pSuperblock->IsValid(govman, active_chain, txNew, nBlockHeight, blockReward);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -482,7 +482,7 @@ void CSuperblock::GetNearestSuperblocksHeights(int nBlockHeight, int& nLastSuper
|
||||
}
|
||||
}
|
||||
|
||||
CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight)
|
||||
CAmount CSuperblock::GetPaymentsLimit(const CChain& active_chain, int nBlockHeight)
|
||||
{
|
||||
const Consensus::Params& consensusParams = Params().GetConsensus();
|
||||
|
||||
@ -490,7 +490,7 @@ CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight)
|
||||
return 0;
|
||||
}
|
||||
|
||||
const CBlockIndex* pindex = ::ChainActive().Tip();
|
||||
const CBlockIndex* pindex = active_chain.Tip();
|
||||
if (pindex->nHeight > nBlockHeight) pindex = pindex->GetAncestor(nBlockHeight);
|
||||
|
||||
const auto v20_state = g_versionbitscache.State(pindex, consensusParams, Consensus::DEPLOYMENT_V20);
|
||||
@ -612,7 +612,7 @@ CAmount CSuperblock::GetPaymentsTotalAmount()
|
||||
* - Does this transaction match the superblock?
|
||||
*/
|
||||
|
||||
bool CSuperblock::IsValid(CGovernanceManager& govman, const CTransaction& txNew, int nBlockHeight, CAmount blockReward)
|
||||
bool CSuperblock::IsValid(CGovernanceManager& govman, const CChain& active_chain, const CTransaction& txNew, int nBlockHeight, CAmount blockReward)
|
||||
{
|
||||
// TODO : LOCK(cs);
|
||||
// No reason for a lock here now since this method only accesses data
|
||||
@ -646,7 +646,7 @@ bool CSuperblock::IsValid(CGovernanceManager& govman, const CTransaction& txNew,
|
||||
|
||||
// payments should not exceed limit
|
||||
CAmount nPaymentsTotalAmount = GetPaymentsTotalAmount();
|
||||
CAmount nPaymentsLimit = GetPaymentsLimit(nBlockHeight);
|
||||
CAmount nPaymentsLimit = GetPaymentsLimit(active_chain, nBlockHeight);
|
||||
if (nPaymentsTotalAmount > nPaymentsLimit) {
|
||||
LogPrintf("CSuperblock::IsValid -- ERROR: Block invalid, payments limit exceeded: payments %lld, limit %lld\n", nPaymentsTotalAmount, nPaymentsLimit);
|
||||
return false;
|
||||
|
@ -10,13 +10,13 @@
|
||||
#include <script/standard.h>
|
||||
#include <uint256.h>
|
||||
|
||||
class CChain;
|
||||
class CGovernanceManager;
|
||||
class CSuperblock;
|
||||
class CSuperblockManager;
|
||||
class CTxOut;
|
||||
class CTransaction;
|
||||
|
||||
class CSuperblock;
|
||||
class CGovernanceManager;
|
||||
class CSuperblockManager;
|
||||
|
||||
using CSuperblock_sptr = std::shared_ptr<CSuperblock>;
|
||||
|
||||
CAmount ParsePaymentAmount(const std::string& strAmount);
|
||||
@ -38,7 +38,7 @@ public:
|
||||
static bool GetSuperblockPayments(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, int nBlockHeight, std::vector<CTxOut>& voutSuperblockRet);
|
||||
static void ExecuteBestSuperblock(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, int nBlockHeight);
|
||||
|
||||
static bool IsValid(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
|
||||
static bool IsValid(CGovernanceManager& govman, const CChain& active_chain, const CDeterministicMNList& tip_mn_list, const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -105,7 +105,7 @@ public:
|
||||
|
||||
static bool IsValidBlockHeight(int nBlockHeight);
|
||||
static void GetNearestSuperblocksHeights(int nBlockHeight, int& nLastSuperblockRet, int& nNextSuperblockRet);
|
||||
static CAmount GetPaymentsLimit(int nBlockHeight);
|
||||
static CAmount GetPaymentsLimit(const CChain& active_chain, int nBlockHeight);
|
||||
|
||||
SeenObjectStatus GetStatus() const { return nStatus; }
|
||||
void SetStatus(SeenObjectStatus nStatusIn) { nStatus = nStatusIn; }
|
||||
@ -126,7 +126,7 @@ public:
|
||||
bool GetPayment(int nPaymentIndex, CGovernancePayment& paymentRet);
|
||||
CAmount GetPaymentsTotalAmount();
|
||||
|
||||
bool IsValid(CGovernanceManager& govman, const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
|
||||
bool IsValid(CGovernanceManager& govman, const CChain& active_chain, const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
|
||||
bool IsExpired(const CGovernanceManager& govman) const;
|
||||
|
||||
std::vector<uint256> GetProposalHashes() const;
|
||||
|
@ -45,11 +45,12 @@ GovernanceStore::GovernanceStore() :
|
||||
}
|
||||
|
||||
CGovernanceManager::CGovernanceManager(CMasternodeMetaMan& mn_metaman, CNetFulfilledRequestManager& netfulfilledman,
|
||||
const std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||
const ChainstateManager& chainman, const std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||
const std::unique_ptr<CMasternodeSync>& mn_sync) :
|
||||
m_db{std::make_unique<db_type>("governance.dat", "magicGovernanceCache")},
|
||||
m_mn_metaman{mn_metaman},
|
||||
m_netfulfilledman{netfulfilledman},
|
||||
m_chainman{chainman},
|
||||
m_dmnman{dmnman},
|
||||
m_mn_sync{mn_sync},
|
||||
nTimeLastDiff(0),
|
||||
@ -194,7 +195,7 @@ PeerMsgRet CGovernanceManager::ProcessMessage(CNode& peer, CConnman& connman, Pe
|
||||
// CHECK OBJECT AGAINST LOCAL BLOCKCHAIN
|
||||
|
||||
bool fMissingConfirmations = false;
|
||||
bool fIsValid = govobj.IsValidLocally(tip_mn_list, strError, fMissingConfirmations, true);
|
||||
bool fIsValid = govobj.IsValidLocally(tip_mn_list, m_chainman, strError, fMissingConfirmations, true);
|
||||
|
||||
if (fRateCheckBypassed && fIsValid && !MasternodeRateCheck(govobj, true)) {
|
||||
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECT -- masternode rate check failed (after signature verification) - %s - (current block height %d)\n", strHash, nCachedBlockHeight);
|
||||
@ -303,7 +304,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, PeerMana
|
||||
|
||||
// MAKE SURE THIS OBJECT IS OK
|
||||
|
||||
if (!govobj.IsValidLocally(tip_mn_list, strError, true)) {
|
||||
if (!govobj.IsValidLocally(tip_mn_list, m_chainman, strError, true)) {
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceManager::AddGovernanceObject -- invalid governance object - %s - (nCachedBlockHeight %d) \n", strError, nCachedBlockHeight);
|
||||
return;
|
||||
}
|
||||
@ -387,7 +388,7 @@ void CGovernanceManager::CheckAndRemove()
|
||||
// IF CACHE IS NOT DIRTY, WHY DO THIS?
|
||||
if (pObj->IsSetDirtyCache()) {
|
||||
// UPDATE LOCAL VALIDITY AGAINST CRYPTO DATA
|
||||
pObj->UpdateLocalValidity(tip_mn_list);
|
||||
pObj->UpdateLocalValidity(tip_mn_list, m_chainman);
|
||||
|
||||
// UPDATE SENTINEL SIGNALING VARIABLES
|
||||
pObj->UpdateSentinelVariables(tip_mn_list);
|
||||
@ -612,7 +613,7 @@ std::optional<const CSuperblock> CGovernanceManager::CreateSuperblockCandidate(i
|
||||
|
||||
CSuperblock::GetNearestSuperblocksHeights(nHeight, nLastSuperblock, nNextSuperblock);
|
||||
auto SBEpochTime = static_cast<int64_t>(GetTime<std::chrono::seconds>().count() + (nNextSuperblock - nHeight) * 2.62 * 60);
|
||||
auto governanceBudget = CSuperblock::GetPaymentsLimit(nNextSuperblock);
|
||||
auto governanceBudget = CSuperblock::GetPaymentsLimit(m_chainman.ActiveChain(), nNextSuperblock);
|
||||
|
||||
CAmount budgetAllocated{};
|
||||
for (const auto& proposal : approvedProposals) {
|
||||
@ -690,7 +691,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 CBlockIndex *tip = WITH_LOCK(::cs_main, return m_chainman.ActiveChain().Tip());
|
||||
const auto mnList = Assert(m_dmnman)->GetListForBlock(tip);
|
||||
const auto mn_payees = mnList.GetProjectedMNPayees(tip);
|
||||
|
||||
@ -706,7 +707,7 @@ std::optional<const CGovernanceObject> CGovernanceManager::CreateGovernanceTrigg
|
||||
gov_sb.SetMasternodeOutpoint(mn_activeman.GetOutPoint());
|
||||
gov_sb.Sign(mn_activeman);
|
||||
|
||||
if (std::string strError; !gov_sb.IsValidLocally(m_dmnman->GetListAtChainTip(), strError, true)) {
|
||||
if (std::string strError; !gov_sb.IsValidLocally(m_dmnman->GetListAtChainTip(), m_chainman, strError, true)) {
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s Created trigger is invalid:%s\n", __func__, strError);
|
||||
return std::nullopt;
|
||||
}
|
||||
@ -1140,8 +1141,8 @@ void CGovernanceManager::CheckPostponedObjects(PeerManager& peerman)
|
||||
|
||||
std::string strError;
|
||||
bool fMissingConfirmations;
|
||||
if (govobj.IsCollateralValid(strError, fMissingConfirmations)) {
|
||||
if (govobj.IsValidLocally(Assert(m_dmnman)->GetListAtChainTip(), strError, false)) {
|
||||
if (govobj.IsCollateralValid(m_chainman, strError, fMissingConfirmations)) {
|
||||
if (govobj.IsValidLocally(Assert(m_dmnman)->GetListAtChainTip(), m_chainman, strError, false)) {
|
||||
AddGovernanceObject(govobj, peerman);
|
||||
} else {
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceManager::CheckPostponedObjects -- %s invalid\n", nHash.ToString());
|
||||
|
@ -261,6 +261,7 @@ private:
|
||||
|
||||
CMasternodeMetaMan& m_mn_metaman;
|
||||
CNetFulfilledRequestManager& m_netfulfilledman;
|
||||
const ChainstateManager& m_chainman;
|
||||
const std::unique_ptr<CDeterministicMNManager>& m_dmnman;
|
||||
const std::unique_ptr<CMasternodeSync>& m_mn_sync;
|
||||
|
||||
@ -276,7 +277,7 @@ private:
|
||||
std::map<uint256, std::shared_ptr<CSuperblock>> mapTrigger;
|
||||
|
||||
public:
|
||||
explicit CGovernanceManager(CMasternodeMetaMan& mn_metaman, CNetFulfilledRequestManager& netfulfilledman,
|
||||
explicit CGovernanceManager(CMasternodeMetaMan& mn_metaman, CNetFulfilledRequestManager& netfulfilledman, const ChainstateManager& chainman,
|
||||
const std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||
const std::unique_ptr<CMasternodeSync>& mn_sync);
|
||||
~CGovernanceManager();
|
||||
|
@ -397,22 +397,22 @@ UniValue CGovernanceObject::ToJson() const
|
||||
return m_obj.ToJson();
|
||||
}
|
||||
|
||||
void CGovernanceObject::UpdateLocalValidity(const CDeterministicMNList& tip_mn_list)
|
||||
void CGovernanceObject::UpdateLocalValidity(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
// THIS DOES NOT CHECK COLLATERAL, THIS IS CHECKED UPON ORIGINAL ARRIVAL
|
||||
fCachedLocalValidity = IsValidLocally(tip_mn_list, strLocalValidityError, false);
|
||||
fCachedLocalValidity = IsValidLocally(tip_mn_list, chainman, strLocalValidityError, false);
|
||||
}
|
||||
|
||||
|
||||
bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, std::string& strError, bool fCheckCollateral) const
|
||||
bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool fCheckCollateral) const
|
||||
{
|
||||
bool fMissingConfirmations = false;
|
||||
|
||||
return IsValidLocally(tip_mn_list, strError, fMissingConfirmations, fCheckCollateral);
|
||||
return IsValidLocally(tip_mn_list, chainman, strError, fMissingConfirmations, fCheckCollateral);
|
||||
}
|
||||
|
||||
bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const
|
||||
bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
@ -433,7 +433,7 @@ bool CGovernanceObject::IsValidLocally(const CDeterministicMNList& tip_mn_list,
|
||||
strError = strprintf("Invalid proposal data, error messages: %s", validator.GetErrorMessages());
|
||||
return false;
|
||||
}
|
||||
if (fCheckCollateral && !IsCollateralValid(strError, fMissingConfirmations)) {
|
||||
if (fCheckCollateral && !IsCollateralValid(chainman, strError, fMissingConfirmations)) {
|
||||
strError = "Invalid proposal collateral";
|
||||
return false;
|
||||
}
|
||||
@ -483,7 +483,7 @@ CAmount CGovernanceObject::GetMinCollateralFee() const
|
||||
}
|
||||
}
|
||||
|
||||
bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingConfirmations) const
|
||||
bool CGovernanceObject::IsCollateralValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
@ -547,9 +547,9 @@ bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingC
|
||||
AssertLockHeld(cs_main);
|
||||
int nConfirmationsIn = 0;
|
||||
if (nBlockHash != uint256()) {
|
||||
const CBlockIndex* pindex = g_chainman.m_blockman.LookupBlockIndex(nBlockHash);
|
||||
if (pindex && ::ChainActive().Contains(pindex)) {
|
||||
nConfirmationsIn += ::ChainActive().Height() - pindex->nHeight + 1;
|
||||
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(nBlockHash);
|
||||
if (pindex && chainman.ActiveChain().Contains(pindex)) {
|
||||
nConfirmationsIn += chainman.ActiveChain().Height() - pindex->nHeight + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ class CDeterministicMNList;
|
||||
class CGovernanceManager;
|
||||
class CGovernanceObject;
|
||||
class CGovernanceVote;
|
||||
class ChainstateManager;
|
||||
class CMasternodeMetaMan;
|
||||
class CMasternodeSync;
|
||||
class CNode;
|
||||
@ -227,14 +228,14 @@ public:
|
||||
|
||||
// CORE OBJECT FUNCTIONS
|
||||
|
||||
bool IsValidLocally(const CDeterministicMNList& tip_mn_list, std::string& strError, bool fCheckCollateral) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool fCheckCollateral) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
bool IsValidLocally(const CDeterministicMNList& tip_mn_list, std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
bool IsValidLocally(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
/// Check the collateral transaction for the budget proposal/finalized budget
|
||||
bool IsCollateralValid(std::string& strError, bool& fMissingConfirmations) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
bool IsCollateralValid(const ChainstateManager& chainman, std::string& strError, bool& fMissingConfirmations) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
void UpdateLocalValidity(const CDeterministicMNList& tip_mn_list);
|
||||
void UpdateLocalValidity(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman);
|
||||
|
||||
void UpdateSentinelVariables(const CDeterministicMNList& tip_mn_list);
|
||||
|
||||
|
@ -1735,7 +1735,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
|
||||
*/
|
||||
const bool is_governance_enabled{!args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)};
|
||||
assert(!node.govman);
|
||||
node.govman = std::make_unique<CGovernanceManager>(*node.mn_metaman, *node.netfulfilledman, node.dmnman, node.mn_sync);
|
||||
node.govman = std::make_unique<CGovernanceManager>(*node.mn_metaman, *node.netfulfilledman, *node.chainman, node.dmnman, node.mn_sync);
|
||||
|
||||
assert(!node.sporkman);
|
||||
node.sporkman = std::make_unique<CSporkManager>();
|
||||
@ -2021,7 +2021,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
|
||||
node.llmq_ctx->Start();
|
||||
|
||||
node.chain_helper.reset();
|
||||
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor),
|
||||
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor), *node.chainman,
|
||||
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman));
|
||||
|
||||
if (fReset) {
|
||||
|
@ -201,7 +201,7 @@ bool CMNPaymentsProcessor::IsBlockValueValid(const CBlock& block, const int nBlo
|
||||
|
||||
LogPrint(BCLog::MNPAYMENTS, "block.vtx[0]->GetValueOut() %lld <= blockReward %lld\n", block.vtx[0]->GetValueOut(), blockReward);
|
||||
|
||||
CAmount nSuperblockMaxValue = blockReward + CSuperblock::GetPaymentsLimit(nBlockHeight);
|
||||
CAmount nSuperblockMaxValue = blockReward + CSuperblock::GetPaymentsLimit(m_chainman.ActiveChain(), nBlockHeight);
|
||||
bool isSuperblockMaxValueMet = (block.vtx[0]->GetValueOut() <= nSuperblockMaxValue);
|
||||
|
||||
LogPrint(BCLog::GOBJECT, "block.vtx[0]->GetValueOut() %lld <= nSuperblockMaxValue %lld\n", block.vtx[0]->GetValueOut(), nSuperblockMaxValue);
|
||||
@ -257,7 +257,7 @@ bool CMNPaymentsProcessor::IsBlockValueValid(const CBlock& block, const int nBlo
|
||||
}
|
||||
|
||||
// this actually also checks for correct payees and not only amount
|
||||
if (!CSuperblockManager::IsValid(m_govman, tip_mn_list, *block.vtx[0], nBlockHeight, blockReward)) {
|
||||
if (!CSuperblockManager::IsValid(m_govman, m_chainman.ActiveChain(), tip_mn_list, *block.vtx[0], nBlockHeight, blockReward)) {
|
||||
// triggered but invalid? that's weird
|
||||
LogPrintf("CMNPaymentsProcessor::%s -- ERROR! Invalid superblock detected at height %d: %s", __func__, nBlockHeight, block.vtx[0]->ToString()); /* Continued */
|
||||
// should NOT allow invalid superblocks, when superblocks are enabled
|
||||
@ -303,7 +303,7 @@ bool CMNPaymentsProcessor::IsBlockPayeeValid(const CTransaction& txNew, const CB
|
||||
if (!check_superblock) return true;
|
||||
const auto tip_mn_list = m_dmnman.GetListAtChainTip();
|
||||
if (CSuperblockManager::IsSuperblockTriggered(m_govman, tip_mn_list, nBlockHeight)) {
|
||||
if (CSuperblockManager::IsValid(m_govman, tip_mn_list, txNew, nBlockHeight, blockSubsidy + feeReward)) {
|
||||
if (CSuperblockManager::IsValid(m_govman, m_chainman.ActiveChain(), tip_mn_list, txNew, nBlockHeight, blockSubsidy + feeReward)) {
|
||||
LogPrint(BCLog::GOBJECT, "CMNPaymentsProcessor::%s -- Valid superblock at height %d: %s", __func__, nBlockHeight, txNew.ToString()); /* Continued */
|
||||
// continue validation, should also pay MN
|
||||
} else {
|
||||
|
@ -14,6 +14,7 @@ class CBlock;
|
||||
class CBlockIndex;
|
||||
class CDeterministicMNManager;
|
||||
class CGovernanceManager;
|
||||
class ChainstateManager;
|
||||
class CMasternodeSync;
|
||||
class CTransaction;
|
||||
class CSporkManager;
|
||||
@ -34,6 +35,7 @@ class CMNPaymentsProcessor
|
||||
private:
|
||||
CDeterministicMNManager& m_dmnman;
|
||||
CGovernanceManager& m_govman;
|
||||
const ChainstateManager& m_chainman;
|
||||
const Consensus::Params& m_consensus_params;
|
||||
const CMasternodeSync& m_mn_sync;
|
||||
const CSporkManager& m_sporkman;
|
||||
@ -48,9 +50,10 @@ private:
|
||||
[[nodiscard]] bool IsOldBudgetBlockValueValid(const CBlock& block, const int nBlockHeight, const CAmount blockReward, std::string& strErrorRet);
|
||||
|
||||
public:
|
||||
explicit CMNPaymentsProcessor(CDeterministicMNManager& dmnman, CGovernanceManager& govman, const Consensus::Params& consensus_params,
|
||||
const CMasternodeSync& mn_sync, const CSporkManager& sporkman) :
|
||||
m_dmnman{dmnman}, m_govman{govman}, m_consensus_params{consensus_params}, m_mn_sync{mn_sync}, m_sporkman{sporkman} {}
|
||||
explicit CMNPaymentsProcessor(CDeterministicMNManager& dmnman, CGovernanceManager& govman, const ChainstateManager& chainman,
|
||||
const Consensus::Params& consensus_params, const CMasternodeSync& mn_sync, const CSporkManager& sporkman) :
|
||||
m_dmnman{dmnman}, m_govman{govman}, m_chainman{chainman}, m_consensus_params{consensus_params}, m_mn_sync{mn_sync},
|
||||
m_sporkman{sporkman} {}
|
||||
|
||||
bool IsBlockValueValid(const CBlock& block, const int nBlockHeight, const CAmount blockReward, std::string& strErrorRet, const bool check_superblock);
|
||||
bool IsBlockPayeeValid(const CTransaction& txNew, const CBlockIndex* pindexPrev, const CAmount blockSubsidy, const CAmount feeReward, const bool check_superblock);
|
||||
|
@ -127,9 +127,9 @@ public:
|
||||
}
|
||||
bool getObjLocalValidity(const CGovernanceObject& obj, std::string& error, bool check_collateral) override
|
||||
{
|
||||
if (context().govman != nullptr && context().dmnman != nullptr) {
|
||||
if (context().govman != nullptr && context().chainman != nullptr && context().dmnman != nullptr) {
|
||||
LOCK(cs_main);
|
||||
return obj.IsValidLocally(context().dmnman->GetListAtChainTip(), error, check_collateral);
|
||||
return obj.IsValidLocally(context().dmnman->GetListAtChainTip(), *(context().chainman), error, check_collateral);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -203,12 +203,13 @@ static UniValue gobject_prepare(const JSONRPCRequest& request)
|
||||
LOCK(wallet->cs_wallet);
|
||||
|
||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
const ChainstateManager& chainman = EnsureChainman(node);
|
||||
CHECK_NONFATAL(node.dmnman);
|
||||
|
||||
{
|
||||
LOCK(cs_main);
|
||||
std::string strError = "";
|
||||
if (!govobj.IsValidLocally(node.dmnman->GetListAtChainTip(), strError, false))
|
||||
if (!govobj.IsValidLocally(node.dmnman->GetListAtChainTip(), chainman, strError, false))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + govobj.GetHash().ToString() + " - " + strError);
|
||||
}
|
||||
|
||||
@ -311,6 +312,7 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
|
||||
gobject_submit_help(request);
|
||||
|
||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
const ChainstateManager& chainman = EnsureChainman(node);
|
||||
CHECK_NONFATAL(node.dmnman);
|
||||
CHECK_NONFATAL(node.govman);
|
||||
|
||||
@ -384,7 +386,7 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
|
||||
CHECK_NONFATAL(node.dmnman);
|
||||
|
||||
std::string strError;
|
||||
if (!govobj.IsValidLocally(node.dmnman->GetListAtChainTip(), strError, fMissingConfirmations, true) && !fMissingConfirmations) {
|
||||
if (!govobj.IsValidLocally(node.dmnman->GetListAtChainTip(), chainman, strError, fMissingConfirmations, true) && !fMissingConfirmations) {
|
||||
LogPrintf("gobject(submit) -- Object submission rejected because object is not valid - hash = %s, strError = %s\n", strHash, strError);
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + strHash + " - " + strError);
|
||||
}
|
||||
@ -607,8 +609,8 @@ static UniValue gobject_vote_alias(const JSONRPCRequest& request)
|
||||
}
|
||||
#endif
|
||||
|
||||
static UniValue ListObjects(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, const std::string& strCachedSignal,
|
||||
const std::string& strType, int nStartTime)
|
||||
static UniValue ListObjects(CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman,
|
||||
const std::string& strCachedSignal, const std::string& strType, int nStartTime)
|
||||
{
|
||||
UniValue objResult(UniValue::VOBJ);
|
||||
|
||||
@ -655,7 +657,7 @@ static UniValue ListObjects(CGovernanceManager& govman, const CDeterministicMNLi
|
||||
|
||||
// REPORT VALIDITY AND CACHING FLAGS FOR VARIOUS SETTINGS
|
||||
std::string strError = "";
|
||||
bObj.pushKV("fBlockchainValidity", govObj.IsValidLocally(tip_mn_list, strError, false));
|
||||
bObj.pushKV("fBlockchainValidity", govObj.IsValidLocally(tip_mn_list, chainman, strError, false));
|
||||
bObj.pushKV("IsValidReason", strError.c_str());
|
||||
bObj.pushKV("fCachedValid", govObj.IsSetCachedValid());
|
||||
bObj.pushKV("fCachedFunding", govObj.IsSetCachedFunding());
|
||||
@ -700,10 +702,11 @@ static UniValue gobject_list(const JSONRPCRequest& request)
|
||||
return "Invalid type, should be 'proposals', 'triggers' or 'all'";
|
||||
|
||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
const ChainstateManager& chainman = EnsureChainman(node);
|
||||
CHECK_NONFATAL(node.dmnman);
|
||||
CHECK_NONFATAL(node.govman);
|
||||
|
||||
return ListObjects(*node.govman, node.dmnman->GetListAtChainTip(), strCachedSignal, strType, 0);
|
||||
return ListObjects(*node.govman, node.dmnman->GetListAtChainTip(), chainman, strCachedSignal, strType, 0);
|
||||
}
|
||||
|
||||
static void gobject_diff_help(const JSONRPCRequest& request)
|
||||
@ -738,9 +741,10 @@ static UniValue gobject_diff(const JSONRPCRequest& request)
|
||||
return "Invalid type, should be 'proposals', 'triggers' or 'all'";
|
||||
|
||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
const ChainstateManager& chainman = EnsureChainman(node);
|
||||
CHECK_NONFATAL(node.dmnman && node.govman);
|
||||
|
||||
return ListObjects(*node.govman, node.dmnman->GetListAtChainTip(), strCachedSignal, strType, node.govman->GetLastDiffTime());
|
||||
return ListObjects(*node.govman, node.dmnman->GetListAtChainTip(), chainman, strCachedSignal, strType, node.govman->GetLastDiffTime());
|
||||
}
|
||||
|
||||
static void gobject_get_help(const JSONRPCRequest& request)
|
||||
@ -768,6 +772,7 @@ static UniValue gobject_get(const JSONRPCRequest& request)
|
||||
|
||||
// FIND THE GOVERNANCE OBJECT THE USER IS LOOKING FOR
|
||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
const ChainstateManager& chainman = EnsureChainman(node);
|
||||
CHECK_NONFATAL(node.dmnman && node.govman);
|
||||
|
||||
LOCK2(cs_main, node.govman->cs);
|
||||
@ -829,7 +834,7 @@ static UniValue gobject_get(const JSONRPCRequest& request)
|
||||
|
||||
// --
|
||||
std::string strError = "";
|
||||
objResult.pushKV("fLocalValidity", pGovObj->IsValidLocally(tip_mn_list, strError, false));
|
||||
objResult.pushKV("fLocalValidity", pGovObj->IsValidLocally(tip_mn_list, chainman, strError, false));
|
||||
objResult.pushKV("IsValidReason", strError.c_str());
|
||||
objResult.pushKV("fCachedValid", pGovObj->IsSetCachedValid());
|
||||
objResult.pushKV("fCachedFunding", pGovObj->IsSetCachedFunding());
|
||||
@ -1100,7 +1105,7 @@ static UniValue getgovernanceinfo(const JSONRPCRequest& request)
|
||||
obj.pushKV("lastsuperblock", nLastSuperblock);
|
||||
obj.pushKV("nextsuperblock", nNextSuperblock);
|
||||
obj.pushKV("fundingthreshold", int(node.dmnman->GetListAtChainTip().GetValidWeightedMNsCount() / 10));
|
||||
obj.pushKV("governancebudget", ValueFromAmount(CSuperblock::GetPaymentsLimit(nNextSuperblock)));
|
||||
obj.pushKV("governancebudget", ValueFromAmount(CSuperblock::GetPaymentsLimit(chainman.ActiveChain(), nNextSuperblock)));
|
||||
|
||||
return obj;
|
||||
}
|
||||
@ -1126,7 +1131,8 @@ static UniValue getsuperblockbudget(const JSONRPCRequest& request)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
|
||||
}
|
||||
|
||||
return ValueFromAmount(CSuperblock::GetPaymentsLimit(nBlockHeight));
|
||||
const ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
return ValueFromAmount(CSuperblock::GetPaymentsLimit(chainman.ActiveChain(), nBlockHeight));
|
||||
}
|
||||
void RegisterGovernanceRPCCommands(CRPCTable &t)
|
||||
{
|
||||
|
@ -120,7 +120,7 @@ void DashTestSetup(NodeContext& node, const CChainParams& chainparams)
|
||||
node.llmq_ctx = std::make_unique<LLMQContext>(chainstate, *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool,
|
||||
/* mn_activeman = */ nullptr, *node.mn_sync, node.peerman, /* unit_tests = */ true, /* wipe = */ false);
|
||||
Assert(node.mnhf_manager)->ConnectManagers(node.llmq_ctx->qman.get());
|
||||
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor),
|
||||
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor), *node.chainman,
|
||||
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman));
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
|
||||
m_node.mn_metaman = std::make_unique<CMasternodeMetaMan>();
|
||||
m_node.netfulfilledman = std::make_unique<CNetFulfilledRequestManager>();
|
||||
m_node.sporkman = std::make_unique<CSporkManager>();
|
||||
m_node.govman = std::make_unique<CGovernanceManager>(*m_node.mn_metaman, *m_node.netfulfilledman, m_node.dmnman, m_node.mn_sync);
|
||||
m_node.govman = std::make_unique<CGovernanceManager>(*m_node.mn_metaman, *m_node.netfulfilledman, *m_node.chainman, m_node.dmnman, m_node.mn_sync);
|
||||
m_node.mn_sync = std::make_unique<CMasternodeSync>(*m_node.connman, *m_node.netfulfilledman, *m_node.govman);
|
||||
|
||||
// Start script-checking threads. Set g_parallel_script_checks to true so they are used.
|
||||
|
Loading…
Reference in New Issue
Block a user