refactor: move out helper IsDIP3Enforced from deterministicmns

This commit is contained in:
Konstantin Akimov 2023-12-05 00:58:13 +07:00 committed by PastaPastaPasta
parent 5a84eb0f0a
commit a79aa56d9b
9 changed files with 20 additions and 18 deletions

View File

@ -52,4 +52,10 @@ inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::Deploy
return params.vDeployments[dep].nTimeout != 0;
}
/** this function is convenient helper for DIP0003 because 'active' and 'enforced' are different statuses for DIP0003 */
constexpr bool DeploymentDIP0003Enforced(const int nHeight, const Consensus::Params& params)
{
return nHeight >= params.DIP0003EnforcementHeight;
}
#endif // BITCOIN_DEPLOYMENTSTATUS_H

View File

@ -1118,11 +1118,6 @@ bool CDeterministicMNManager::IsProTxWithCollateral(const CTransactionRef& tx, u
return true;
}
bool CDeterministicMNManager::IsDIP3Enforced(int nHeight)
{
return nHeight >= Params().GetConsensus().DIP0003EnforcementHeight;
}
void CDeterministicMNManager::CleanupCache(int nHeight)
{
AssertLockHeld(cs);
@ -1612,7 +1607,7 @@ bool CheckProRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pin
}
}
if (!deterministicMNManager->IsDIP3Enforced(pindexPrev->nHeight)) {
if (!DeploymentDIP0003Enforced(pindexPrev->nHeight, Params().GetConsensus())) {
if (ptx.keyIDOwner != ptx.keyIDVoting) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-key-not-same");
}
@ -1749,7 +1744,7 @@ bool CheckProUpRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> p
}
}
if (!deterministicMNManager->IsDIP3Enforced(pindexPrev->nHeight)) {
if (!DeploymentDIP0003Enforced(pindexPrev->nHeight, Params().GetConsensus())) {
if (dmn->pdmnState->keyIDOwner != ptx.keyIDVoting) {
return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-key-not-same");
}

View File

@ -622,8 +622,6 @@ public:
// Test if given TX is a ProRegTx which also contains the collateral at index n
static bool IsProTxWithCollateral(const CTransactionRef& tx, uint32_t n);
bool IsDIP3Enforced(int nHeight);
bool MigrateDBIfNeeded();
bool MigrateDBIfNeeded2();

View File

@ -8,6 +8,7 @@
#include <chain.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <evo/deterministicmns.h>
#include <flat-database.h>
#include <governance/classes.h>
@ -1461,7 +1462,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex* pindex, CConnman& co
nCachedBlockHeight = pindex->nHeight;
LogPrint(BCLog::GOBJECT, "CGovernanceManager::UpdatedBlockTip -- nCachedBlockHeight: %d\n", nCachedBlockHeight);
if (deterministicMNManager->IsDIP3Enforced(pindex->nHeight)) {
if (DeploymentDIP0003Enforced(pindex->nHeight, Params().GetConsensus())) {
RemoveInvalidVotes();
}

View File

@ -12,6 +12,7 @@
#include <evo/deterministicmns.h>
#include <deploymentstatus.h>
#include <masternode/node.h>
#include <chainparams.h>
#include <net_processing.h>
@ -168,7 +169,7 @@ bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex)
{
curSession = std::make_unique<CDKGSession>(params, blsWorker, dkgManager, dkgDebugManager, connman);
if (!deterministicMNManager->IsDIP3Enforced(pQuorumBaseBlockIndex->nHeight)) {
if (!DeploymentDIP0003Enforced(pQuorumBaseBlockIndex->nHeight, Params().GetConsensus())) {
return false;
}

View File

@ -7,10 +7,10 @@
#include <llmq/quorums.h>
#include <llmq/utils.h>
#include <evo/deterministicmns.h>
#include <chainparams.h>
#include <dbwrapper.h>
#include <deploymentstatus.h>
#include <evo/deterministicmns.h>
#include <net_processing.h>
#include <spork.h>
#include <util/irange.h>
@ -162,7 +162,7 @@ void CDKGSessionManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fIni
if (fInitialDownload)
return;
if (!deterministicMNManager->IsDIP3Enforced(pindexNew->nHeight))
if (!DeploymentDIP0003Enforced(pindexNew->nHeight, Params().GetConsensus()))
return;
if (!IsQuorumDKGEnabled(spork_manager))
return;

View File

@ -7,6 +7,7 @@
#include <evo/deterministicmns.h>
#include <chainparams.h>
#include <deploymentstatus.h>
#include <net.h>
#include <netbase.h>
#include <protocol.h>
@ -68,7 +69,7 @@ void CActiveMasternodeManager::Init(const CBlockIndex* pindex)
if (!fMasternodeMode) return;
if (!deterministicMNManager->IsDIP3Enforced(pindex->nHeight)) return;
if (!DeploymentDIP0003Enforced(pindex->nHeight, Params().GetConsensus())) return;
// Check that our local network configuration is correct
if (!fListen && Params().RequireRoutableExternalIP()) {
@ -141,7 +142,7 @@ void CActiveMasternodeManager::UpdatedBlockTip(const CBlockIndex* pindexNew, con
if (!fMasternodeMode) return;
if (!deterministicMNManager->IsDIP3Enforced(pindexNew->nHeight)) return;
if (!DeploymentDIP0003Enforced(pindexNew->nHeight, Params().GetConsensus())) return;
if (state == MASTERNODE_READY) {
auto oldMNList = deterministicMNManager->GetListForBlock(pindexNew->pprev);

View File

@ -98,7 +98,7 @@
[[nodiscard]] static bool IsTransactionValid(const CTransaction& txNew, const CBlockIndex* const pindexPrev, const CAmount blockSubsidy, const CAmount feeReward)
{
const int nBlockHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;
if (!deterministicMNManager->IsDIP3Enforced(nBlockHeight)) {
if (!DeploymentDIP0003Enforced(nBlockHeight, Params().GetConsensus())) {
// can't verify historical blocks here
return true;
}

View File

@ -150,7 +150,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
CScript coinbasePubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
BOOST_ASSERT(deterministicMNManager->IsDIP3Enforced(WITH_LOCK(cs_main, return m_node.chainman->ActiveChain().Height())));
BOOST_ASSERT(DeploymentDIP0003Enforced(WITH_LOCK(cs_main, return m_node.chainman->ActiveChain().Height()), consensus_params));
// Register one MN
CKey ownerKey;