Skip to content

Commit b966aa8

Browse files
luke-jrMarcoFalke
authored and
MarcoFalke
committed
Constrain constant values to a single location in code
1 parent 92aa731 commit b966aa8

24 files changed

+118
-78
lines changed

src/bitcoin-cli.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@
2222

2323
using namespace std;
2424

25+
static const char DEFAULT_RPCCONNECT[] = "127.0.0.1";
2526
static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
2627

2728
std::string HelpMessageCli()
2829
{
2930
string strUsage;
3031
strUsage += HelpMessageGroup(_("Options:"));
3132
strUsage += HelpMessageOpt("-?", _("This help message"));
32-
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), "bitcoin.conf"));
33+
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), BITCOIN_CONF_FILENAME));
3334
strUsage += HelpMessageOpt("-datadir=<dir>", _("Specify data directory"));
3435
AppendParamsHelpMessages(strUsage);
35-
strUsage += HelpMessageOpt("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), "127.0.0.1"));
36+
strUsage += HelpMessageOpt("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), DEFAULT_RPCCONNECT));
3637
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), 8332, 18332));
3738
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
3839
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
@@ -141,7 +142,7 @@ static void http_request_done(struct evhttp_request *req, void *ctx)
141142

142143
UniValue CallRPC(const string& strMethod, const UniValue& params)
143144
{
144-
std::string host = GetArg("-rpcconnect", "127.0.0.1");
145+
std::string host = GetArg("-rpcconnect", DEFAULT_RPCCONNECT);
145146
int port = GetArg("-rpcport", BaseParams().RPCPort());
146147

147148
// Create event base

src/init.cpp

Lines changed: 56 additions & 50 deletions
Large diffs are not rendered by default.

src/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
941941
CAmount mempoolRejectFee = pool.GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFee(nSize);
942942
if (mempoolRejectFee > 0 && nFees < mempoolRejectFee) {
943943
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "mempool min fee not met", false, strprintf("%d < %d", nFees, mempoolRejectFee));
944-
} else if (GetBoolArg("-relaypriority", true) && nFees < ::minRelayTxFee.GetFee(nSize) && !AllowFree(view.GetPriority(tx, chainActive.Height() + 1))) {
944+
} else if (GetBoolArg("-relaypriority", DEFAULT_RELAYPRIORITY) && nFees < ::minRelayTxFee.GetFee(nSize) && !AllowFree(view.GetPriority(tx, chainActive.Height() + 1))) {
945945
// Require that free transactions have sufficient priority to be mined in the next block.
946946
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "insufficient priority");
947947
}
@@ -963,7 +963,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
963963
nLastTime = nNow;
964964
// -limitfreerelay unit is thousand-bytes-per-minute
965965
// At default rate it would take over a month to fill 1GB
966-
if (dFreeCount >= GetArg("-limitfreerelay", 15)*10*1000)
966+
if (dFreeCount >= GetArg("-limitfreerelay", DEFAULT_LIMITFREERELAY) * 10 * 1000)
967967
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "rate limited free transaction");
968968
LogPrint("mempool", "Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize);
969969
dFreeCount += nSize;
@@ -1436,7 +1436,7 @@ void Misbehaving(NodeId pnode, int howmuch)
14361436
return;
14371437

14381438
state->nMisbehavior += howmuch;
1439-
int banscore = GetArg("-banscore", 100);
1439+
int banscore = GetArg("-banscore", DEFAULT_BANSCORE_THRESHOLD);
14401440
if (state->nMisbehavior >= banscore && state->nMisbehavior - howmuch < banscore)
14411441
{
14421442
LogPrintf("%s: %s (%d -> %d) BAN THRESHOLD EXCEEDED\n", __func__, state->name, state->nMisbehavior-howmuch, state->nMisbehavior);
@@ -3605,7 +3605,7 @@ bool InitBlockIndex(const CChainParams& chainparams)
36053605
return true;
36063606

36073607
// Use the provided setting for -txindex in the new database
3608-
fTxIndex = GetBoolArg("-txindex", false);
3608+
fTxIndex = GetBoolArg("-txindex", DEFAULT_TXINDEX);
36093609
pblocktree->WriteFlag("txindex", fTxIndex);
36103610
LogPrintf("Initializing databases...\n");
36113611

@@ -3936,7 +3936,7 @@ std::string GetWarnings(const std::string& strFor)
39363936
if (!CLIENT_VERSION_IS_RELEASE)
39373937
strStatusBar = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications");
39383938

3939-
if (GetBoolArg("-testsafemode", false))
3939+
if (GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
39403940
strStatusBar = strRPC = "testsafemode enabled";
39413941

39423942
// Misc warnings like out of disk space and clock is wrong

src/main.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
8686
static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
8787
/** Maximum length of reject messages. */
8888
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
89+
static const unsigned int DEFAULT_LIMITFREERELAY = 15;
90+
static const bool DEFAULT_RELAYPRIORITY = true;
91+
92+
static const bool DEFAULT_TXINDEX = false;
93+
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
94+
95+
static const bool DEFAULT_TESTSAFEMODE = false;
8996

9097
struct BlockHasher
9198
{

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
153153
// Priority order to process transactions
154154
list<COrphan> vOrphan; // list memory doesn't move
155155
map<uint256, vector<COrphan*> > mapDependers;
156-
bool fPrintPriority = GetBoolArg("-printpriority", false);
156+
bool fPrintPriority = GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY);
157157

158158
// This vector will be sorted into a priority queue:
159159
vector<TxPriority> vecPriority;

src/miner.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ class CScript;
1717
class CWallet;
1818
namespace Consensus { struct Params; };
1919

20+
static const bool DEFAULT_GENERATE = false;
2021
static const int DEFAULT_GENERATE_THREADS = 1;
2122

23+
static const bool DEFAULT_PRINTPRIORITY = false;
24+
2225
struct CBlockTemplate
2326
{
2427
CBlock block;

src/net.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,11 @@ void CNode::Ban(const CSubNet& subNet, const BanReason &banReason, int64_t banti
521521
banEntry.banReason = banReason;
522522
if (bantimeoffset <= 0)
523523
{
524-
bantimeoffset = GetArg("-bantime", 60*60*24); // Default 24-hour ban
524+
bantimeoffset = GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME);
525525
sinceUnixEpoch = false;
526526
}
527527
banEntry.nBanUntil = (sinceUnixEpoch ? 0 : GetTime() )+bantimeoffset;
528528

529-
530529
LOCK(cs_setBanned);
531530
if (setBanned[subNet].nBanUntil < banEntry.nBanUntil)
532531
setBanned[subNet] = banEntry;
@@ -1414,7 +1413,7 @@ void ThreadDNSAddressSeed()
14141413
{
14151414
// goal: only query DNS seeds if address need is acute
14161415
if ((addrman.size() > 0) &&
1417-
(!GetBoolArg("-forcednsseed", false))) {
1416+
(!GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED))) {
14181417
MilliSleep(11 * 1000);
14191418

14201419
LOCK(cs_vNodes);
@@ -2337,8 +2336,8 @@ bool CAddrDB::Read(CAddrMan& addr)
23372336
return true;
23382337
}
23392338

2340-
unsigned int ReceiveFloodSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); }
2341-
unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); }
2339+
unsigned int ReceiveFloodSize() { return 1000*GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER); }
2340+
unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER); }
23422341

23432342
CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNameIn, bool fInboundIn) :
23442343
ssSend(SER_NETWORK, INIT_PROTO_VERSION),

src/net.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
6565
/** Default for blocks only*/
6666
static const bool DEFAULT_BLOCKSONLY = false;
6767

68+
static const bool DEFAULT_FORCEDNSSEED = false;
69+
static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
70+
static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
71+
72+
// NOTE: When adjusting this, update rpcnet:setban's help ("24h")
73+
static const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24; // Default 24-hour ban
74+
6875
unsigned int ReceiveFloodSize();
6976
unsigned int SendBufferSize();
7077

src/netbase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static proxyType proxyInfo[NET_MAX];
4040
static proxyType nameProxy;
4141
static CCriticalSection cs_proxyInfos;
4242
int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
43-
bool fNameLookup = false;
43+
bool fNameLookup = true;
4444

4545
static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
4646

src/policy/policy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType)
5050
if (m < 1 || m > n)
5151
return false;
5252
} else if (whichType == TX_NULL_DATA &&
53-
(!GetBoolArg("-datacarrier", true) || scriptPubKey.size() > nMaxDatacarrierBytes))
53+
(!fAcceptDatacarrier || scriptPubKey.size() > nMaxDatacarrierBytes))
5454
return false;
5555

5656
return whichType != TX_NONSTANDARD;

src/qt/bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ int main(int argc, char *argv[])
660660
// Subscribe to global signals from core
661661
uiInterface.InitMessage.connect(InitMessage);
662662

663-
if (GetBoolArg("-splash", true) && !GetBoolArg("-min", false))
663+
if (GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !GetBoolArg("-min", false))
664664
app.createSplashScreen(networkStyle.data());
665665

666666
try

src/qt/intro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void Intro::pickDataDirectory()
162162
/* 2) Allow QSettings to override default dir */
163163
dataDir = settings.value("strDataDir", dataDir).toString();
164164

165-
if(!fs::exists(GUIUtil::qstringToBoostPath(dataDir)) || GetBoolArg("-choosedatadir", false))
165+
if(!fs::exists(GUIUtil::qstringToBoostPath(dataDir)) || GetBoolArg("-choosedatadir", DEFAULT_CHOOSE_DATADIR))
166166
{
167167
/* If current default data directory does not exist, let the user choose one */
168168
Intro intro;

src/qt/paymentrequestplus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
145145
int error = X509_STORE_CTX_get_error(store_ctx);
146146
// For testing payment requests, we allow self signed root certs!
147147
// This option is just shown in the UI options, if -help-debug is enabled.
148-
if (!(error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT && GetBoolArg("-allowselfsignedrootcertificates", false))) {
148+
if (!(error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT && GetBoolArg("-allowselfsignedrootcertificates", DEFAULT_SELFSIGNED_ROOTCERTS))) {
149149
throw SSLVerifyError(X509_verify_cert_error_string(error));
150150
} else {
151151
qDebug() << "PaymentRequestPlus::getMerchant: Allowing self signed root certificate, because -allowselfsignedrootcertificates is true.";

src/rpcmining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ UniValue getgenerate(const UniValue& params, bool fHelp)
9999
throw runtime_error(
100100
"getgenerate\n"
101101
"\nReturn if the server is set to generate coins or not. The default is false.\n"
102-
"It is set with the command line argument -gen (or bitcoin.conf setting gen)\n"
102+
"It is set with the command line argument -gen (or " + std::string(BITCOIN_CONF_FILENAME) + " setting gen)\n"
103103
"It can also be set with the setgenerate call.\n"
104104
"\nResult\n"
105105
"true|false (boolean) If the server is set to generate coins or not\n"
@@ -109,7 +109,7 @@ UniValue getgenerate(const UniValue& params, bool fHelp)
109109
);
110110

111111
LOCK(cs_main);
112-
return GetBoolArg("-gen", false);
112+
return GetBoolArg("-gen", DEFAULT_GENERATE);
113113
}
114114

115115
UniValue generate(const UniValue& params, bool fHelp)

src/script/standard.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using namespace std;
1616

1717
typedef vector<unsigned char> valtype;
1818

19+
bool fAcceptDatacarrier = true;
1920
unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY;
2021

2122
CScriptID::CScriptID(const CScript& in) : uint160(Hash160(in.begin(), in.end())) {}

src/script/standard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class CScriptID : public uint160
2626
};
2727

2828
static const unsigned int MAX_OP_RETURN_RELAY = 83; //! bytes (+1 for OP_RETURN, +2 for the pushdata opcodes)
29+
extern bool fAcceptDatacarrier;
2930
extern unsigned nMaxDatacarrierBytes;
3031

3132
/**

src/util.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ namespace boost {
9999

100100
using namespace std;
101101

102+
const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf";
103+
const char * const BITCOIN_PID_FILENAME = "bitcoind.pid";
104+
102105
map<string, string> mapArgs;
103106
map<string, vector<string> > mapMultiArgs;
104107
bool fDebug = false;
@@ -107,7 +110,7 @@ bool fPrintToDebugLog = true;
107110
bool fDaemon = false;
108111
bool fServer = false;
109112
string strMiscWarning;
110-
bool fLogTimestamps = false;
113+
bool fLogTimestamps = true;
111114
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS;
112115
bool fLogIPs = false;
113116
volatile bool fReopenDebugLog = false;
@@ -520,7 +523,7 @@ void ClearDatadirCache()
520523

521524
boost::filesystem::path GetConfigFile()
522525
{
523-
boost::filesystem::path pathConfigFile(GetArg("-conf", "bitcoin.conf"));
526+
boost::filesystem::path pathConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME));
524527
if (!pathConfigFile.is_complete())
525528
pathConfigFile = GetDataDir(false) / pathConfigFile;
526529

@@ -554,7 +557,7 @@ void ReadConfigFile(map<string, string>& mapSettingsRet,
554557
#ifndef WIN32
555558
boost::filesystem::path GetPidFile()
556559
{
557-
boost::filesystem::path pathPidFile(GetArg("-pid", "bitcoind.pid"));
560+
boost::filesystem::path pathPidFile(GetArg("-pid", BITCOIN_PID_FILENAME));
558561
if (!pathPidFile.is_complete()) pathPidFile = GetDataDir() / pathPidFile;
559562
return pathPidFile;
560563
}

src/util.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ extern bool fLogIPs;
5151
extern volatile bool fReopenDebugLog;
5252
extern CTranslationInterface translationInterface;
5353

54+
extern const char * const BITCOIN_CONF_FILENAME;
55+
extern const char * const BITCOIN_PID_FILENAME;
56+
57+
static const bool DEFAULT_SELFSIGNED_ROOTCERTS = false;
58+
static const bool DEFAULT_CHOOSE_DATADIR = false;
59+
static const bool DEFAULT_SPLASHSCREEN = true;
60+
5461
/**
5562
* Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
5663
* If no translation slot is registered, nothing is returned, and simply return the input.

src/wallet/db.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
8585
LogPrintf("CDBEnv::Open: LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string());
8686

8787
unsigned int nEnvFlags = 0;
88-
if (GetBoolArg("-privdb", true))
88+
if (GetBoolArg("-privdb", DEFAULT_WALLET_PRIVDB))
8989
nEnvFlags |= DB_PRIVATE;
9090

9191
dbenv->set_lg_dir(pathLogDir.string().c_str());

src/wallet/db.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <db_cxx.h>
2222

2323
static const unsigned int DEFAULT_WALLET_DBLOGSIZE = 100;
24+
static const bool DEFAULT_WALLET_PRIVDB = true;
2425

2526
extern unsigned int nWalletDBUpdated;
2627

src/wallet/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,7 +2260,7 @@ bool CWallet::NewKeyPool()
22602260
if (IsLocked())
22612261
return false;
22622262

2263-
int64_t nKeys = max(GetArg("-keypool", 100), (int64_t)0);
2263+
int64_t nKeys = max(GetArg("-keypool", DEFAULT_KEYPOOL_SIZE), (int64_t)0);
22642264
for (int i = 0; i < nKeys; i++)
22652265
{
22662266
int64_t nIndex = i+1;
@@ -2287,7 +2287,7 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
22872287
if (kpSize > 0)
22882288
nTargetSize = kpSize;
22892289
else
2290-
nTargetSize = max(GetArg("-keypool", 100), (int64_t) 0);
2290+
nTargetSize = max(GetArg("-keypool", DEFAULT_KEYPOOL_SIZE), (int64_t) 0);
22912291

22922292
while (setKeyPool.size() < (nTargetSize + 1))
22932293
{

src/wallet/wallet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern bool bSpendZeroConfChange;
3737
extern bool fSendFreeTransactions;
3838
extern bool fPayAtLeastCustomFee;
3939

40+
static const unsigned int DEFAULT_KEYPOOL_SIZE = 100;
4041
//! -paytxfee default
4142
static const CAmount DEFAULT_TRANSACTION_FEE = 0;
4243
//! -paytxfee will warn if called with a higher fee than this amount (in satoshis) per KB
@@ -53,6 +54,7 @@ static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 2;
5354
static const CAmount nHighTransactionMaxFeeWarning = 100 * nHighTransactionFeeWarning;
5455
//! Largest (in bytes) free transaction we're willing to create
5556
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000;
57+
static const bool DEFAULT_WALLETBROADCAST = true;
5658

5759
class CAccountingEntry;
5860
class CBlockIndex;

src/wallet/walletdb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ void ThreadFlushWalletDB(const string& strFile)
810810
if (fOneThread)
811811
return;
812812
fOneThread = true;
813-
if (!GetBoolArg("-flushwallet", true))
813+
if (!GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET))
814814
return;
815815

816816
unsigned int nLastSeen = nWalletDBUpdated;

src/wallet/walletdb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <utility>
1717
#include <vector>
1818

19+
static const bool DEFAULT_FLUSHWALLET = true;
20+
1921
class CAccount;
2022
class CAccountingEntry;
2123
struct CBlockLocator;

0 commit comments

Comments
 (0)