diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 038f33bf58..cb2d4346c0 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -1303,3 +1303,8 @@ void CGovernanceManager::RemoveInvalidVotes() // store current MN list for the next run so that we can determine which keys changed lastMNListForVotingKeys = curMNList; } + +bool AreSuperblocksEnabled() +{ + return sporkManager.IsSporkActive(SPORK_9_SUPERBLOCKS_ENABLED); +} diff --git a/src/governance/governance.h b/src/governance/governance.h index a85d57daa5..62c4a0e2ef 100644 --- a/src/governance/governance.h +++ b/src/governance/governance.h @@ -432,4 +432,6 @@ private: }; +bool AreSuperblocksEnabled(); + #endif // BITCOIN_GOVERNANCE_GOVERNANCE_H diff --git a/src/llmq/quorums_chainlocks.cpp b/src/llmq/quorums_chainlocks.cpp index edbe36e927..3000670041 100644 --- a/src/llmq/quorums_chainlocks.cpp +++ b/src/llmq/quorums_chainlocks.cpp @@ -90,7 +90,7 @@ CChainLockSig CChainLocksHandler::GetBestChainLock() void CChainLocksHandler::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman) { - if (!sporkManager.IsSporkActive(SPORK_19_CHAINLOCKS_ENABLED)) { + if (!AreChainLocksEnabled()) { return; } @@ -230,8 +230,8 @@ void CChainLocksHandler::CheckActiveState() LOCK(cs); bool oldIsEnforced = isEnforced; - isSporkActive = sporkManager.IsSporkActive(SPORK_19_CHAINLOCKS_ENABLED); - isEnforced = (fDIP0008Active && isSporkActive); + isEnabled = AreChainLocksEnabled(); + isEnforced = (fDIP0008Active && isEnabled); if (!oldIsEnforced && isEnforced) { // ChainLocks got activated just recently, but it's possible that it was already running before, leaving @@ -273,7 +273,7 @@ void CChainLocksHandler::TrySignChainTip() { LOCK(cs); - if (!isSporkActive) { + if (!isEnabled) { return; } @@ -300,7 +300,7 @@ void CChainLocksHandler::TrySignChainTip() // considered safe when it is islocked or at least known since 10 minutes (from mempool or block). These checks are // performed for the tip (which we try to sign) and the previous 5 blocks. If a ChainLocked block is found on the // way down, we consider all TXs to be safe. - if (IsInstantSendEnabled() && sporkManager.IsSporkActive(SPORK_3_INSTANTSEND_BLOCK_FILTERING)) { + if (IsInstantSendEnabled() && RejectConflictingBlocks()) { auto pindexWalk = pindex; while (pindexWalk) { if (pindex->nHeight - pindexWalk->nHeight > 5) { @@ -459,7 +459,7 @@ CChainLocksHandler::BlockTxs::mapped_type CChainLocksHandler::GetBlockTxs(const bool CChainLocksHandler::IsTxSafeForMining(const uint256& txid) { - if (!sporkManager.IsSporkActive(SPORK_3_INSTANTSEND_BLOCK_FILTERING)) { + if (!RejectConflictingBlocks()) { return true; } if (!IsInstantSendEnabled()) { @@ -469,7 +469,7 @@ bool CChainLocksHandler::IsTxSafeForMining(const uint256& txid) int64_t txAge = 0; { LOCK(cs); - if (!isSporkActive || !isEnforced) { + if (!isEnabled || !isEnforced) { return true; } auto it = txFirstSeenTime.find(txid); @@ -568,7 +568,7 @@ void CChainLocksHandler::HandleNewRecoveredSig(const llmq::CRecoveredSig& recove { LOCK(cs); - if (!isSporkActive) { + if (!isEnabled) { return; } @@ -727,4 +727,9 @@ void CChainLocksHandler::Cleanup() lastCleanupTime = GetTimeMillis(); } +bool AreChainLocksEnabled() +{ + return sporkManager.IsSporkActive(SPORK_19_CHAINLOCKS_ENABLED); +} + } // namespace llmq diff --git a/src/llmq/quorums_chainlocks.h b/src/llmq/quorums_chainlocks.h index a10b3bc414..32faa8a37d 100644 --- a/src/llmq/quorums_chainlocks.h +++ b/src/llmq/quorums_chainlocks.h @@ -57,7 +57,7 @@ private: boost::thread* scheduler_thread; CCriticalSection cs; bool tryLockChainTipScheduled{false}; - bool isSporkActive{false}; + bool isEnabled{false}; bool isEnforced{false}; uint256 bestChainLockHash; @@ -122,6 +122,7 @@ private: extern CChainLocksHandler* chainLocksHandler; +bool AreChainLocksEnabled(); } // namespace llmq diff --git a/src/llmq/quorums_dkgsessionmgr.cpp b/src/llmq/quorums_dkgsessionmgr.cpp index 5fe2f36f84..63abba543b 100644 --- a/src/llmq/quorums_dkgsessionmgr.cpp +++ b/src/llmq/quorums_dkgsessionmgr.cpp @@ -56,7 +56,7 @@ void CDKGSessionManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fIni return; if (!deterministicMNManager->IsDIP3Enforced(pindexNew->nHeight)) return; - if (!sporkManager.IsSporkActive(SPORK_17_QUORUM_DKG_ENABLED)) + if (!IsQuorumDKGEnabled()) return; for (auto& qt : dkgSessionHandlers) { @@ -66,7 +66,7 @@ void CDKGSessionManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fIni void CDKGSessionManager::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman) { - if (!sporkManager.IsSporkActive(SPORK_17_QUORUM_DKG_ENABLED)) + if (!IsQuorumDKGEnabled()) return; if (strCommand != NetMsgType::QCONTRIB @@ -101,7 +101,7 @@ void CDKGSessionManager::ProcessMessage(CNode* pfrom, const std::string& strComm bool CDKGSessionManager::AlreadyHave(const CInv& inv) const { - if (!sporkManager.IsSporkActive(SPORK_17_QUORUM_DKG_ENABLED)) + if (!IsQuorumDKGEnabled()) return false; for (const auto& p : dkgSessionHandlers) { @@ -118,7 +118,7 @@ bool CDKGSessionManager::AlreadyHave(const CInv& inv) const bool CDKGSessionManager::GetContribution(const uint256& hash, CDKGContribution& ret) const { - if (!sporkManager.IsSporkActive(SPORK_17_QUORUM_DKG_ENABLED)) + if (!IsQuorumDKGEnabled()) return false; for (const auto& p : dkgSessionHandlers) { @@ -138,7 +138,7 @@ bool CDKGSessionManager::GetContribution(const uint256& hash, CDKGContribution& bool CDKGSessionManager::GetComplaint(const uint256& hash, CDKGComplaint& ret) const { - if (!sporkManager.IsSporkActive(SPORK_17_QUORUM_DKG_ENABLED)) + if (!IsQuorumDKGEnabled()) return false; for (const auto& p : dkgSessionHandlers) { @@ -158,7 +158,7 @@ bool CDKGSessionManager::GetComplaint(const uint256& hash, CDKGComplaint& ret) c bool CDKGSessionManager::GetJustification(const uint256& hash, CDKGJustification& ret) const { - if (!sporkManager.IsSporkActive(SPORK_17_QUORUM_DKG_ENABLED)) + if (!IsQuorumDKGEnabled()) return false; for (const auto& p : dkgSessionHandlers) { @@ -178,7 +178,7 @@ bool CDKGSessionManager::GetJustification(const uint256& hash, CDKGJustification bool CDKGSessionManager::GetPrematureCommitment(const uint256& hash, CDKGPrematureCommitment& ret) const { - if (!sporkManager.IsSporkActive(SPORK_17_QUORUM_DKG_ENABLED)) + if (!IsQuorumDKGEnabled()) return false; for (const auto& p : dkgSessionHandlers) { @@ -272,4 +272,9 @@ void CDKGSessionManager::CleanupCache() } } +bool IsQuorumDKGEnabled() +{ + return sporkManager.IsSporkActive(SPORK_17_QUORUM_DKG_ENABLED); +} + } // namespace llmq diff --git a/src/llmq/quorums_dkgsessionmgr.h b/src/llmq/quorums_dkgsessionmgr.h index 26df8a8de7..4e8728365f 100644 --- a/src/llmq/quorums_dkgsessionmgr.h +++ b/src/llmq/quorums_dkgsessionmgr.h @@ -71,6 +71,8 @@ private: void CleanupCache(); }; +bool IsQuorumDKGEnabled(); + extern CDKGSessionManager* quorumDKGSessionManager; } // namespace llmq diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index cd2a380305..eec77396de 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -1154,7 +1154,7 @@ void CInstantSendManager::UpdatedBlockTip(const CBlockIndex* pindexNew) // TODO remove this after DIP8 has activated bool fDIP0008Active = VersionBitsState(pindexNew->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0008, versionbitscache) == ThresholdState::ACTIVE; - if (sporkManager.IsSporkActive(SPORK_19_CHAINLOCKS_ENABLED) && fDIP0008Active) { + if (AreChainLocksEnabled() && fDIP0008Active) { // Nothing to do here. We should keep all islocks and let chainlocks handle them. return; } @@ -1534,4 +1534,9 @@ bool IsInstantSendEnabled() return sporkManager.IsSporkActive(SPORK_2_INSTANTSEND_ENABLED); } +bool RejectConflictingBlocks() +{ + return sporkManager.IsSporkActive(SPORK_3_INSTANTSEND_BLOCK_FILTERING); +} + } // namespace llmq diff --git a/src/llmq/quorums_instantsend.h b/src/llmq/quorums_instantsend.h index 19ecee9be2..6ab6378b09 100644 --- a/src/llmq/quorums_instantsend.h +++ b/src/llmq/quorums_instantsend.h @@ -173,6 +173,7 @@ public: extern CInstantSendManager* quorumInstantSendManager; bool IsInstantSendEnabled(); +bool RejectConflictingBlocks(); } // namespace llmq diff --git a/src/masternode/masternode-payments.cpp b/src/masternode/masternode-payments.cpp index e64935e39f..ff15cd02ba 100644 --- a/src/masternode/masternode-payments.cpp +++ b/src/masternode/masternode-payments.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -119,7 +118,7 @@ bool IsBlockValueValid(const CBlock& block, int nBlockHeight, CAmount blockRewar // we are synced and possibly on a superblock now - if (!sporkManager.IsSporkActive(SPORK_9_SUPERBLOCKS_ENABLED)) { + if (!AreSuperblocksEnabled()) { // should NOT allow superblocks at all, when superblocks are disabled // revert to block reward limits in this case LogPrint(BCLog::GOBJECT, "%s -- Superblocks are disabled, no superblocks allowed\n", __func__); @@ -177,7 +176,7 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount bloc // superblocks started // SEE IF THIS IS A VALID SUPERBLOCK - if(sporkManager.IsSporkActive(SPORK_9_SUPERBLOCKS_ENABLED)) { + if(AreSuperblocksEnabled()) { if(CSuperblockManager::IsSuperblockTriggered(nBlockHeight)) { if(CSuperblockManager::IsValid(txNew, nBlockHeight, blockReward)) { LogPrint(BCLog::GOBJECT, "%s -- Valid superblock at height %d: %s", __func__, nBlockHeight, txNew.ToString()); /* Continued */ @@ -209,10 +208,9 @@ void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blo { // only create superblocks if spork is enabled AND if superblock is actually triggered // (height should be validated inside) - if(sporkManager.IsSporkActive(SPORK_9_SUPERBLOCKS_ENABLED) && - CSuperblockManager::IsSuperblockTriggered(nBlockHeight)) { - LogPrint(BCLog::GOBJECT, "%s -- triggered superblock creation at height %d\n", __func__, nBlockHeight); - CSuperblockManager::GetSuperblockPayments(nBlockHeight, voutSuperblockPaymentsRet); + if(AreSuperblocksEnabled() && CSuperblockManager::IsSuperblockTriggered(nBlockHeight)) { + LogPrint(BCLog::GOBJECT, "%s -- triggered superblock creation at height %d\n", __func__, nBlockHeight); + CSuperblockManager::GetSuperblockPayments(nBlockHeight, voutSuperblockPaymentsRet); } if (!CMasternodePayments::GetMasternodeTxOuts(nBlockHeight, blockReward, voutMasternodePaymentsRet)) { diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 6adced15b0..6a22055445 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -472,7 +471,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) mnpayments.GetBlockTxOuts(chainActive.Height() + 1, 0, voutMasternodePayments); // next bock is a superblock and we need governance info to correctly construct it - if (sporkManager.IsSporkActive(SPORK_9_SUPERBLOCKS_ENABLED) + if (AreSuperblocksEnabled() && !masternodeSync.IsSynced() && CSuperblock::IsValidBlockHeight(chainActive.Height() + 1)) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Dash Core is syncing with network..."); @@ -704,7 +703,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) } result.pushKV("superblock", superblockObjArray); result.pushKV("superblocks_started", pindexPrev->nHeight + 1 > consensusParams.nSuperblockStartBlock); - result.pushKV("superblocks_enabled", sporkManager.IsSporkActive(SPORK_9_SUPERBLOCKS_ENABLED)); + result.pushKV("superblocks_enabled", AreSuperblocksEnabled()); result.pushKV("coinbase_payload", HexStr(pblock->vtx[0]->vExtraPayload)); diff --git a/src/validation.cpp b/src/validation.cpp index abba6062b1..775d5f0e74 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -2313,7 +2312,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl // DASH : CHECK TRANSACTIONS FOR INSTANTSEND - if (sporkManager.IsSporkActive(SPORK_3_INSTANTSEND_BLOCK_FILTERING)) { + if (llmq::RejectConflictingBlocks()) { // Require other nodes to comply, send them some data in case they are missing it. for (const auto& tx : block.vtx) { // skip txes that have no inputs