Skip to content

Commit

Permalink
init: move 'pEvoNotificationInterface' initialization, reset and regi…
Browse files Browse the repository at this point in the history
…ster to tiertwo/init.cpp
  • Loading branch information
furszy committed Jan 31, 2022
1 parent 922fa05 commit 7408131
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -96,8 +94,6 @@ std::unique_ptr<PeerLogicValidation> 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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -709,9 +696,8 @@ void ThreadImport(const std::vector<fs::path>& 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);
Expand Down Expand Up @@ -1443,8 +1429,7 @@ bool AppInitMain()
}
#endif

pEvoNotificationInterface = new EvoNotificationInterface();
RegisterValidationInterface(pEvoNotificationInterface);
InitTierTwoInterfaces();

// ********************************************************* Step 7: load block chain

Expand Down
30 changes: 30 additions & 0 deletions src/tiertwo/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -19,6 +20,8 @@

#include <boost/thread.hpp>

static std::unique_ptr<EvoNotificationInterface> pEvoNotificationInterface{nullptr};

std::string GetTierTwoHelpString(bool showDebug)
{
std::string strUsage = HelpMessageGroup("Masternode options:");
Expand All @@ -37,6 +40,26 @@ std::string GetTierTwoHelpString(bool showDebug)
return strUsage;
}

void InitTierTwoInterfaces()
{
pEvoNotificationInterface = std::make_unique<EvoNotificationInterface>();
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
Expand All @@ -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)
{
Expand Down
9 changes: 9 additions & 0 deletions src/tiertwo/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7408131

Please sign in to comment.