refactor: Add spork helpers in corresponding modules (#3859)

* Introduce AreChainLocksEnabled()

Also rename isSporkActive to isEnabled

* Introduce AreSuperblocksEnabled()

* Introduce RejectConflictingBlocks()

* Introduce IsQuorumDKGEnabled()
This commit is contained in:
UdjinM6 2020-12-09 23:33:09 +03:00 committed by GitHub
parent 3e4a2be018
commit 8e9c159e81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 51 additions and 29 deletions

View File

@ -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);
}

View File

@ -432,4 +432,6 @@ private:
};
bool AreSuperblocksEnabled();
#endif // BITCOIN_GOVERNANCE_GOVERNANCE_H

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -71,6 +71,8 @@ private:
void CleanupCache();
};
bool IsQuorumDKGEnabled();
extern CDKGSessionManager* quorumDKGSessionManager;
} // namespace llmq

View File

@ -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

View File

@ -173,6 +173,7 @@ public:
extern CInstantSendManager* quorumInstantSendManager;
bool IsInstantSendEnabled();
bool RejectConflictingBlocks();
} // namespace llmq

View File

@ -8,7 +8,6 @@
#include <masternode/masternode-sync.h>
#include <netfulfilledman.h>
#include <netmessagemaker.h>
#include <spork.h>
#include <validation.h>
#include <string>
@ -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)) {

View File

@ -21,7 +21,6 @@
#include <rpc/blockchain.h>
#include <rpc/mining.h>
#include <rpc/server.h>
#include <spork.h>
#include <txmempool.h>
#include <util.h>
#include <utilstrencodings.h>
@ -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));

View File

@ -35,7 +35,6 @@
#include <ui_interface.h>
#include <undo.h>
#include <util.h>
#include <spork.h>
#include <utilmoneystr.h>
#include <utilstrencodings.h>
#include <validationinterface.h>
@ -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