diff --git a/src/init.cpp b/src/init.cpp index d568dff0b131a..5d35f208fdb41 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -21,14 +21,12 @@ #include "checkpoints.h" #include "compat/sanity.h" #include "consensus/upgrades.h" -#include "evo/evonotificationinterface.h" #include "fs.h" #include "httpserver.h" #include "httprpc.h" #include "invalid.h" #include "key.h" #include "mapport.h" -#include "masternodeconfig.h" #include "miner.h" #include "netbase.h" #include "net_processing.h" @@ -96,8 +94,6 @@ std::unique_ptr peerLogic; static CZMQNotificationInterface* pzmqNotificationInterface = NULL; #endif -static EvoNotificationInterface* pEvoNotificationInterface = nullptr; - #ifdef WIN32 // Win32 LevelDB doesn't use filedescriptors, and the ones used for // accessing block files, don't count towards to fd_set size limit @@ -298,17 +294,8 @@ void Shutdown() } #endif - if (pEvoNotificationInterface) { - UnregisterValidationInterface(pEvoNotificationInterface); - delete pEvoNotificationInterface; - pEvoNotificationInterface = nullptr; - } - - if (activeMasternodeManager) { - UnregisterValidationInterface(activeMasternodeManager); - delete activeMasternodeManager; - activeMasternodeManager = nullptr; - } + // Tier two + ResetTierTwoInterfaces(); #if ENABLE_ZMQ if (pzmqNotificationInterface) { @@ -709,9 +696,8 @@ void ThreadImport(const std::vector& vImportFiles) StartShutdown(); } - // force UpdatedBlockTip to initialize nCachedBlockHeight for DS, MN payments and budgets - // but don't call it directly to prevent triggering of other listeners like zmq etc. - pEvoNotificationInterface->InitializeCurrentBlockTip(); + // tier two + InitTierTwoChainTip(); if (gArgs.GetBoolArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { LoadMempool(::mempool); @@ -1443,8 +1429,7 @@ bool AppInitMain() } #endif - pEvoNotificationInterface = new EvoNotificationInterface(); - RegisterValidationInterface(pEvoNotificationInterface); + InitTierTwoInterfaces(); // ********************************************************* Step 7: load block chain diff --git a/src/tiertwo/init.cpp b/src/tiertwo/init.cpp index a3241be5e4145..548f7193be98b 100644 --- a/src/tiertwo/init.cpp +++ b/src/tiertwo/init.cpp @@ -6,6 +6,7 @@ #include "budget/budgetdb.h" #include "evo/evodb.h" +#include "evo/evonotificationinterface.h" #include "flatdb.h" #include "guiinterface.h" #include "guiinterfaceutil.h" @@ -19,6 +20,8 @@ #include +static std::unique_ptr pEvoNotificationInterface{nullptr}; + std::string GetTierTwoHelpString(bool showDebug) { std::string strUsage = HelpMessageGroup("Masternode options:"); @@ -37,6 +40,26 @@ std::string GetTierTwoHelpString(bool showDebug) return strUsage; } +void InitTierTwoInterfaces() +{ + pEvoNotificationInterface = std::make_unique(); + RegisterValidationInterface(pEvoNotificationInterface.get()); +} + +void ResetTierTwoInterfaces() +{ + if (pEvoNotificationInterface) { + UnregisterValidationInterface(pEvoNotificationInterface.get()); + pEvoNotificationInterface.reset(); + } + + if (activeMasternodeManager) { + UnregisterValidationInterface(activeMasternodeManager); + delete activeMasternodeManager; + activeMasternodeManager = nullptr; + } +} + void InitTierTwoPreChainLoad(bool fReindex) { int64_t nEvoDbCache = 1024 * 1024 * 16; // TODO @@ -52,6 +75,13 @@ void InitTierTwoPostCoinsCacheLoad() llmq::InitLLMQSystem(*evoDb); } +void InitTierTwoChainTip() +{ + // force UpdatedBlockTip to initialize nCachedBlockHeight for DS, MN payments and budgets + // but don't call it directly to prevent triggering of other listeners like zmq etc. + pEvoNotificationInterface->InitializeCurrentBlockTip(); +} + // Sets the last CACHED_BLOCK_HASHES hashes into masternode manager cache static void LoadBlockHashesCache(CMasternodeMan& man) { diff --git a/src/tiertwo/init.h b/src/tiertwo/init.h index c91bf735d1855..b4efcaf630a66 100644 --- a/src/tiertwo/init.h +++ b/src/tiertwo/init.h @@ -17,12 +17,21 @@ namespace boost { std::string GetTierTwoHelpString(bool showDebug); +/** Init the interfaces objects */ +void InitTierTwoInterfaces(); + +/** Resets the interfaces objects */ +void ResetTierTwoInterfaces(); + /** Inits the tier two global objects */ void InitTierTwoPreChainLoad(bool fReindex); /** Inits the tier two global objects that require access to the coins tip cache */ void InitTierTwoPostCoinsCacheLoad(); +/** Initialize chain tip */ +void InitTierTwoChainTip(); + /** Loads from disk all the tier two related objects */ bool LoadTierTwo(int chain_active_height, bool fReindexChainState);