Skip to content

Commit a42370d

Browse files
committed
refactor: remove fDisableGovernance global, define default in variable
1 parent b152759 commit a42370d

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/governance/governance.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CNetFulfilledRequestManager;
3333
class CSporkManager;
3434

3535
static constexpr int RATE_BUFFER_SIZE = 5;
36+
static constexpr bool DEFAULT_GOVERNANCE_ENABLE{true};
3637

3738
class CDeterministicMNList;
3839
using CDeterministicMNListPtr = std::shared_ptr<CDeterministicMNList>;

src/init.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
12301230
return InitError(_("Prune mode is incompatible with -txindex."));
12311231
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX))
12321232
return InitError(_("Prune mode is incompatible with -coinstatsindex."));
1233-
if (!args.GetBoolArg("-disablegovernance", false)) {
1233+
if (!args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)) {
12341234
return InitError(_("Prune mode is incompatible with -disablegovernance=false."));
12351235
}
12361236
}
@@ -1454,15 +1454,15 @@ bool AppInitParameterInteraction(const ArgsManager& args)
14541454
if (args.GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS) < DEFAULT_MAX_PEER_CONNECTIONS) {
14551455
return InitError(strprintf(Untranslated("Masternode must be able to handle at least %d connections, set -maxconnections=%d"), DEFAULT_MAX_PEER_CONNECTIONS, DEFAULT_MAX_PEER_CONNECTIONS));
14561456
}
1457-
if (args.GetBoolArg("-disablegovernance", false)) {
1457+
if (args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)) {
14581458
return InitError(_("You can not disable governance validation on a masternode."));
14591459
}
14601460
}
14611461

1462-
fDisableGovernance = args.GetBoolArg("-disablegovernance", false);
1463-
LogPrintf("fDisableGovernance %d\n", fDisableGovernance);
1462+
const bool is_governance_enabled{!args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)};
1463+
LogPrintf("fDisableGovernance %d\n", !is_governance_enabled);
14641464

1465-
if (fDisableGovernance) {
1465+
if (!is_governance_enabled) {
14661466
InitWarning(_("You are starting with governance validation disabled.") +
14671467
(fPruneMode ?
14681468
Untranslated(" ") + _("This is expected because you are running a pruned node.") :
@@ -1684,6 +1684,15 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
16841684
assert(!node.netfulfilledman);
16851685
node.netfulfilledman = std::make_unique<CNetFulfilledRequestManager>();
16861686

1687+
/**
1688+
* The manager needs to be constructed regardless of whether governance
1689+
* validation is needed or not.
1690+
*
1691+
* Instead, we decide whether to initialize its database based on whether we
1692+
* need it or not further down and then query if the database is initialized
1693+
* to check if validation is enabled.
1694+
*/
1695+
const bool is_governance_enabled{!args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE)};
16871696
assert(!node.govman);
16881697
node.govman = std::make_unique<CGovernanceManager>(*node.mn_metaman, *node.netfulfilledman, node.dmnman, node.mn_sync);
16891698

@@ -1988,7 +1997,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
19881997
break;
19891998
}
19901999

1991-
if (!fDisableGovernance && !args.GetBoolArg("-txindex", DEFAULT_TXINDEX) && chainparams.NetworkIDString() != CBaseChainParams::REGTEST) { // TODO remove this when pruning is fixed. See https://github.com/dashpay/dash/pull/1817 and https://github.com/dashpay/dash/pull/1743
2000+
if (is_governance_enabled && !args.GetBoolArg("-txindex", DEFAULT_TXINDEX) && chainparams.NetworkIDString() != CBaseChainParams::REGTEST) { // TODO remove this when pruning is fixed. See https://github.com/dashpay/dash/pull/1817 and https://github.com/dashpay/dash/pull/1743
19922001
return InitError(_("Transaction index can't be disabled with governance validation enabled. Either start with -disablegovernance command line switch or enable transaction index."));
19932002
}
19942003

@@ -2234,10 +2243,10 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
22342243
return InitError(strprintf(_("Failed to clear masternode cache at %s"), file_path));
22352244
}
22362245

2237-
if (!fDisableGovernance) {
2246+
if (is_governance_enabled) {
22382247
if (!node.govman->LoadCache(fLoadCacheFiles)) {
22392248
auto file_path = (GetDataDir() / "governance.dat").string();
2240-
if (fLoadCacheFiles && !fDisableGovernance) {
2249+
if (fLoadCacheFiles) {
22412250
return InitError(strprintf(_("Failed to load governance cache from %s"), file_path));
22422251
}
22432252
return InitError(strprintf(_("Failed to clear governance cache at %s"), file_path));

src/util/system.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ const int64_t nStartupTime = GetTime();
8080

8181
//Dash only features
8282
bool fMasternodeMode = false;
83-
bool fDisableGovernance = false;
8483
const std::string gCoinJoinName = "CoinJoin";
8584

8685
/**

src/util/system.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
//Dash only features
3838

3939
extern bool fMasternodeMode;
40-
extern bool fDisableGovernance;
4140
extern int nWalletBackups;
4241
extern const std::string gCoinJoinName;
4342

0 commit comments

Comments
 (0)