Skip to content

Commit d3dfdf3

Browse files
kwvgPastaPastaPasta
authored andcommitted
refactor: use aliases of globals in initialization logic
We must pass ::deterministicMNManager to CDSNotificationInterface as we are passing a const ref of the smart pointer object, because it is init'ed further down the line. The alias in NodeContext is a raw pointer that is assigned after init and is unsuitable for this purpose.
1 parent bb7fe58 commit d3dfdf3

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/init.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
17161716

17171717
assert(!node.peerman);
17181718
node.peerman = PeerManager::make(chainparams, *node.connman, *node.addrman, node.banman.get(),
1719-
*node.scheduler, chainman, *node.mempool, *::governance,
1719+
*node.scheduler, chainman, *node.mempool, *node.govman,
17201720
node.cj_ctx, node.llmq_ctx, ignores_incoming_txs);
17211721
RegisterValidationInterface(node.peerman.get());
17221722

@@ -1731,25 +1731,25 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
17311731
vSporkAddresses = Params().SporkAddresses();
17321732
}
17331733
for (const auto& address: vSporkAddresses) {
1734-
if (!::sporkManager->SetSporkAddress(address)) {
1734+
if (!node.sporkman->SetSporkAddress(address)) {
17351735
return InitError(_("Invalid spork address specified with -sporkaddr"));
17361736
}
17371737
}
17381738

17391739
int minsporkkeys = args.GetArg("-minsporkkeys", Params().MinSporkKeys());
1740-
if (!::sporkManager->SetMinSporkKeys(minsporkkeys)) {
1740+
if (!node.sporkman->SetMinSporkKeys(minsporkkeys)) {
17411741
return InitError(_("Invalid minimum number of spork signers specified with -minsporkkeys"));
17421742
}
17431743

17441744

17451745
if (args.IsArgSet("-sporkkey")) { // spork priv key
1746-
if (!::sporkManager->SetPrivKey(args.GetArg("-sporkkey", ""))) {
1746+
if (!node.sporkman->SetPrivKey(args.GetArg("-sporkkey", ""))) {
17471747
return InitError(_("Unable to sign spork message, wrong key?"));
17481748
}
17491749
}
17501750

17511751
assert(!::masternodeSync);
1752-
::masternodeSync = std::make_unique<CMasternodeSync>(*node.connman, *::governance);
1752+
::masternodeSync = std::make_unique<CMasternodeSync>(*node.connman, *node.govman);
17531753
node.mn_sync = ::masternodeSync.get();
17541754

17551755
// sanitize comments per BIP-0014, format user agent and check total size
@@ -1873,7 +1873,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
18731873
#endif
18741874

18751875
pdsNotificationInterface = new CDSNotificationInterface(
1876-
*node.connman, *::masternodeSync, ::deterministicMNManager, *::governance, node.llmq_ctx, node.cj_ctx
1876+
*node.connman, *node.mn_sync, ::deterministicMNManager, *node.govman, node.llmq_ctx, node.cj_ctx
18771877
);
18781878
RegisterValidationInterface(pdsNotificationInterface);
18791879

@@ -1885,7 +1885,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
18851885

18861886
// ********************************************************* Step 7a: Load sporks
18871887

1888-
if (!::sporkManager->LoadCache()) {
1888+
if (!node.sporkman->LoadCache()) {
18891889
auto file_path = (GetDataDir() / "sporks.dat").string();
18901890
return InitError(strprintf(_("Failed to load sporks cache from %s"), file_path));
18911891
}
@@ -1978,7 +1978,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
19781978
node.llmq_ctx->Stop();
19791979
}
19801980
node.llmq_ctx.reset();
1981-
node.llmq_ctx.reset(new LLMQContext(chainman.ActiveChainstate(), *node.connman, *node.evodb, *::sporkManager, *node.mempool, node.peerman, false, fReset || fReindexChainState));
1981+
node.llmq_ctx.reset(new LLMQContext(chainman.ActiveChainstate(), *node.connman, *node.evodb, *node.sporkman, *node.mempool, node.peerman, false, fReset || fReindexChainState));
19821982
// Have to start it early to let VerifyDB check ChainLock signatures in coinbase
19831983
node.llmq_ctx->Start();
19841984

@@ -2111,11 +2111,11 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
21112111
break; // out of the chainstate activation do-while
21122112
}
21132113

2114-
if (!deterministicMNManager->MigrateDBIfNeeded()) {
2114+
if (!node.dmnman->MigrateDBIfNeeded()) {
21152115
strLoadError = _("Error upgrading evo database");
21162116
break;
21172117
}
2118-
if (!deterministicMNManager->MigrateDBIfNeeded2()) {
2118+
if (!node.dmnman->MigrateDBIfNeeded2()) {
21192119
strLoadError = _("Error upgrading evo database");
21202120
break;
21212121
}
@@ -2219,7 +2219,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
22192219

22202220
// ********************************************************* Step 7c: Setup CoinJoin
22212221

2222-
node.cj_ctx = std::make_unique<CJContext>(chainman.ActiveChainstate(), *node.connman, *node.mempool, *::masternodeSync, !ignores_incoming_txs);
2222+
node.cj_ctx = std::make_unique<CJContext>(chainman.ActiveChainstate(), *node.connman, *node.mempool, *node.mn_sync, !ignores_incoming_txs);
22232223

22242224
#ifdef ENABLE_WALLET
22252225
node.coinjoin_loader = interfaces::MakeCoinJoinLoader(*node.cj_ctx->walletman);
@@ -2231,7 +2231,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
22312231
bool fLoadCacheFiles = !(fReindex || fReindexChainState) && (::ChainActive().Tip() != nullptr);
22322232

22332233
if (!fDisableGovernance) {
2234-
if (!::governance->LoadCache(fLoadCacheFiles)) {
2234+
if (!node.govman->LoadCache(fLoadCacheFiles)) {
22352235
auto file_path = (GetDataDir() / "governance.dat").string();
22362236
if (fLoadCacheFiles && !fDisableGovernance) {
22372237
return InitError(strprintf(_("Failed to load governance cache from %s"), file_path));
@@ -2247,7 +2247,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
22472247
assert(!::mmetaman);
22482248
::mmetaman = std::make_unique<CMasternodeMetaMan>(fLoadCacheFiles);
22492249
node.mn_metaman = ::mmetaman.get();
2250-
if (!::mmetaman->IsValid()) {
2250+
if (!node.mn_metaman->IsValid()) {
22512251
auto file_path = (GetDataDir() / "mncache.dat").string();
22522252
if (fLoadCacheFiles) {
22532253
return InitError(strprintf(_("Failed to load masternode cache from %s"), file_path));
@@ -2258,7 +2258,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
22582258
assert(!::netfulfilledman);
22592259
::netfulfilledman = std::make_unique<CNetFulfilledRequestManager>(fLoadCacheFiles);
22602260
node.netfulfilledman = ::netfulfilledman.get();
2261-
if (!::netfulfilledman->IsValid()) {
2261+
if (!node.netfulfilledman->IsValid()) {
22622262
auto file_path = (GetDataDir() / "netfulfilled.dat").string();
22632263
if (fLoadCacheFiles) {
22642264
return InitError(strprintf(_("Failed to load fulfilled requests cache from %s"), file_path));
@@ -2329,13 +2329,13 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
23292329

23302330
// ********************************************************* Step 10a: schedule Dash-specific tasks
23312331

2332-
node.scheduler->scheduleEvery(std::bind(&CNetFulfilledRequestManager::DoMaintenance, std::ref(*netfulfilledman)), std::chrono::minutes{1});
2333-
node.scheduler->scheduleEvery(std::bind(&CMasternodeSync::DoMaintenance, std::ref(*::masternodeSync)), std::chrono::seconds{1});
2334-
node.scheduler->scheduleEvery(std::bind(&CMasternodeUtils::DoMaintenance, std::ref(*node.connman), std::ref(*::masternodeSync), std::ref(*node.cj_ctx)), std::chrono::minutes{1});
2335-
node.scheduler->scheduleEvery(std::bind(&CDeterministicMNManager::DoMaintenance, std::ref(*deterministicMNManager)), std::chrono::seconds{10});
2332+
node.scheduler->scheduleEvery(std::bind(&CNetFulfilledRequestManager::DoMaintenance, std::ref(*node.netfulfilledman)), std::chrono::minutes{1});
2333+
node.scheduler->scheduleEvery(std::bind(&CMasternodeSync::DoMaintenance, std::ref(*node.mn_sync)), std::chrono::seconds{1});
2334+
node.scheduler->scheduleEvery(std::bind(&CMasternodeUtils::DoMaintenance, std::ref(*node.connman), std::ref(*node.mn_sync), std::ref(*node.cj_ctx)), std::chrono::minutes{1});
2335+
node.scheduler->scheduleEvery(std::bind(&CDeterministicMNManager::DoMaintenance, std::ref(*node.dmnman)), std::chrono::seconds{10});
23362336

23372337
if (!fDisableGovernance) {
2338-
node.scheduler->scheduleEvery(std::bind(&CGovernanceManager::DoMaintenance, std::ref(*::governance), std::ref(*node.connman)), std::chrono::minutes{5});
2338+
node.scheduler->scheduleEvery(std::bind(&CGovernanceManager::DoMaintenance, std::ref(*node.govman), std::ref(*node.connman)), std::chrono::minutes{5});
23392339
}
23402340

23412341
if (fMasternodeMode) {

0 commit comments

Comments
 (0)