forked from gridcoin-community/Gridcoin-Research
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.cpp
executable file
·1420 lines (1207 loc) · 61.7 KB
/
init.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "chainparams.h"
#include "util.h"
#include "net.h"
#include "txdb.h"
#include "wallet/walletdb.h"
#include "banman.h"
#include "rpc/server.h"
#include "init.h"
#include "ui_interface.h"
#include "scheduler.h"
#include "gridcoin/gridcoin.h"
#include "miner.h"
#include <boost/algorithm/string/predicate.hpp>
#include <openssl/crypto.h>
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
static boost::thread_group threadGroup;
static CScheduler scheduler;
extern void ThreadAppInit2(void* parg);
#ifndef WIN32
#include <signal.h>
#include <sys/stat.h>
#endif
using namespace std;
CWallet* pwalletMain;
CClientUIInterface uiInterface;
extern bool fQtActive;
extern bool bGridcoinCoreInitComplete;
extern bool fConfChange;
extern bool fEnforceCanonical;
extern unsigned int nNodeLifespan;
extern unsigned int nDerivationMethodIndex;
extern unsigned int nMinerSleep;
extern bool fUseFastIndex;
// Dump addresses to banlist.dat every 5 minutes (300 s)
static constexpr int DUMP_BANS_INTERVAL = 300;
std::unique_ptr<BanMan> g_banman;
/**
* The PID file facilities.
*/
static const char* GRIDCOIN_PID_FILENAME = "gridcoinresearchd.pid";
static fs::path GetPidFile(const ArgsManager& args)
{
return AbsPathForConfigVal(fs::path(args.GetArg("-pid", GRIDCOIN_PID_FILENAME)));
}
//////////////////////////////////////////////////////////////////////////////
//
// Shutdown
//
bool ShutdownRequested()
{
return fRequestShutdown;
}
void StartShutdown()
{
LogPrintf("Calling start shutdown...");
if(fQtActive)
// ensure we leave the Qt main loop for a clean GUI exit (Shutdown() is called in bitcoin.cpp afterwards)
uiInterface.QueueShutdown();
else
// Without UI, shutdown is initiated and shutdown() is called in AppInit
fRequestShutdown = true;
}
void Shutdown(void* parg)
{
static CCriticalSection cs_Shutdown;
static bool fTaken;
// Make this thread recognisable as the shutdown thread
RenameThread("grc-shutoff");
bool fFirstThread = false;
{
TRY_LOCK(cs_Shutdown, lockShutdown);
if (lockShutdown)
{
fFirstThread = !fTaken;
fTaken = true;
}
}
static bool fExit;
if (fFirstThread)
{
LogPrintf("gridcoinresearch exiting...");
fShutdown = true;
// clean up the threads running serviceQueue:
threadGroup.interrupt_all();
threadGroup.join_all();
bitdb.Flush(false);
StopNode();
bitdb.Flush(true);
StopRPCThreads();
// This is necessary here to prevent a snapshot download from failing at the cleanup
// step because of a write lock on accrual/registry.dat.
GRC::CloseResearcherRegistryFile();
fs::remove(GetPidFile(gArgs));
UnregisterWallet(pwalletMain);
delete pwalletMain;
// close transaction database to prevent lock issue on restart
// This causes issues on daemons where it tries to create a second
// lock file.
//CTxDB().Close();
MilliSleep(50);
LogPrintf("Gridcoin exited");
fExit = true;
}
else
{
while (!fExit)
MilliSleep(100);
}
}
#ifndef WIN32
static void HandleSIGTERM(int)
{
fRequestShutdown = true;
}
static void HandleSIGHUP(int)
{
fReopenDebugLog = true;
}
#else
static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType)
{
fRequestShutdown = true;
Sleep(INFINITE);
return true;
}
#endif
#ifndef WIN32
static void registerSignalHandler(int signal, void(*handler)(int))
{
struct sigaction sa;
sa.sa_handler = handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(signal, &sa, nullptr);
}
#endif
bool static InitError(const std::string &str)
{
uiInterface.ThreadSafeMessageBox(str, _("Gridcoin"), CClientUIInterface::OK | CClientUIInterface::MODAL);
return false;
}
bool static InitWarning(const std::string &str)
{
uiInterface.ThreadSafeMessageBox(str, _("Gridcoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL);
return true;
}
bool static Bind(const CService &addr, bool fError = true) {
if (IsLimited(addr))
return false;
std::string strError;
if (!BindListenPort(addr, strError)) {
if (fError)
return InitError(strError);
return false;
}
return true;
}
static void CreateNewConfigFile()
{
fsbridge::ofstream myConfig;
myConfig.open(GetConfigFile());
myConfig
<< "addnode=addnode-us-central.cycy.me\n"
<< "addnode=ec2-3-81-39-58.compute-1.amazonaws.com\n"
<< "addnode=gridcoin.ddns.net\n"
<< "addnode=seeds.gridcoin.ifoggz-network.xyz\n"
<< "addnode=seed.gridcoin.pl\n"
<< "addnode=www.grcpool.com\n";
}
void AddLoggingArgs(ArgsManager& argsman)
{
argsman.AddArg("-debuglogfile=<file>", strprintf("Specify location of debug log file. Relative paths will be prefixed "
"by a net-specific datadir location. (-nodebuglogfile to disable; "
"default: %s)",
DEFAULT_DEBUGLOGFILE),
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-debug=<category>", "Output debugging information (default: -nodebug, supplying <category> is optional). "
"If <category> is not supplied or if <category> = 1, output all debugging information. <category> can be: "
+ ListLogCategories() + ". This option can be specified multiple times to output multiple categories.",
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-debugexclude=<category>", strprintf("Exclude debugging information for a category. Can be used in"
" conjunction with -debug=1 to output debug logs for all categories"
" except the specified category. This option can be specified"
" multiple times to exclude multiple categories."),
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS),
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
#ifdef HAVE_THREAD_LOCAL
argsman.AddArg("-logthreadnames", strprintf("Prepend debug output with name of the originating thread (only available on"
" platforms supporting thread_local) (default: %u)", DEFAULT_LOGTHREADNAMES),
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
#else
argsman.AddHiddenArgs({"-logthreadnames"});
#endif
argsman.AddArg("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)",
DEFAULT_LOGTIMEMICROS),
ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 0) )",
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-printtodebugger", "Send trace/debug info to debugger (default: 0)",
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-shrinkdebugfile", "Shrink debug.log file on client startup (default: 1 when no -debug)",
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-logarchivedaily", "Archive log file to compressed archive daily (default: 1)",
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-deleteoldlogarchives", "Delete oldest log archive files in excess of -logarchiveretainnumfiles "
"setting",
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-logarchiveretainnumfiles=<num>", "Specify number of compressed log archive files to retain"
" (default: 30)",
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-org=<string>", "Set organization name for identification (default: not set). Required for use "
"on testnet. Do not set this for a wallet on mainnet.",
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
}
void SetupServerArgs()
{
ArgsManager& argsman = gArgs;
SetupHelpOptions(argsman);
argsman.AddArg("-help-debug", "Print help message with debugging options and exit",
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
AddLoggingArgs(argsman);
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
const auto defaultChainParams = CreateChainParams(CBaseChainParams::MAIN);
const auto testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET);
// Hidden Options
std::vector<std::string> hidden_args = {
"-dbcrashratio", "-forcecompactdb", "-fastindex",
// GUI args. These will be overwritten by SetupUIArgs for the GUI
"-choosedatadir", "-lang=<lang>", "-min", "-resetguisettings",
"-splash", "-style", "-suppressnetworkgraph", "-showorphans"};
// Listed Options
// General
argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
// TODO: Read-only config file?
argsman.AddArg("-conf=<file>", strprintf("Specify path to read-only configuration file. Relative paths will be prefixed"
" by datadir location. (default: %s)", GRIDCOIN_CONF_FILENAME),
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-pid=<file>", strprintf("Specify pid file. Relative paths will be prefixed by a net-specific datadir"
" location. (default: %s)", GRIDCOIN_PID_FILENAME),
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-wallet=<dir>", "Specify wallet file (within data directory)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-dbcache=<n>", "Set database cache size in megabytes (default: 25)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-dblogsize=<n>", "Set database disk log size in megabytes (default: 100)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-synctime", "Sync time with other nodes. Disable if time on your system is precise e.g. syncing with"
" NTP (default: 1)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-paytxfee=<amt>", "Fee per KB to add to transactions you send",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-mintxfee=<amt>", "Minimum transaction fee for transactions you send or process (default: 0.001 GRC)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-mininput=<amt>", "When creating transactions, ignore inputs with value less than this (default: 0.01)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-daemon", "Run in the background as a daemon and accept commands",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-testnet", "Use the test network", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-blocknotify=<cmd>", "Execute command when the best block changes (%s in cmd is replaced by block hash)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-walletnotify=<cmd>", "Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-confchange", "Require confirmations for change (default: 0)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-enforcecanonical", "Enforce transaction scripts to use canonical PUSH operators (default: 1)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-alertnotify=<cmd>", "Execute command when a relevant alert is received or we see a really long fork"
" (%s in cmd is replaced by message)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-blockminsize=<n>", "Set minimum block size in bytes (default: 0)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-blockmaxsize=<n>", strprintf("Set maximum block size in bytes (default: %u)", MAX_BLOCK_SIZE_GEN/2),
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-blockprioritysize=<n>", "Set maximum size of high-priority/low-fee transactions in bytes"
" (default: 27000)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-snapshotdownload", "Download and apply latest snapshot",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-snapshoturl=<url>", "Optional: URL for the snapshot.zip file (ex: "
"https://sub.domain.com/location/snapshot.zip)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-snapshotsha256url=<url>", "Optional: URL for the snapshot.sha256 file (ex: "
"https://sub.domain.com/location/snapshot.sha256)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-disableupdatecheck", "Optional: Disable update checks by wallet",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-updatecheckinterval=<n>", "Optional: Check for updates every <n> hours (default: 120, minimum: 1)",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-updatecheckurl=<url>", "Optional: URL for the update version checks (ex: "
"https://sub.domain.com/location/latest",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-resetblockchaindata", "Reset blockchain data. This argument will remove all previous blockchain data",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-loadblock=<file>", "Imports blocks from external file on startup",
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
//TODO: Implement reindex option
//argsman.AddArg("-reindex", "Rebuild chain state and block index from the blk*.dat files on disk",
// ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-settings=<file>", strprintf("Specify path to dynamic settings data file. Can be disabled with"
" -nosettings. File is written at runtime and not meant to be edited by"
" users (use %s instead for custom settings). Relative paths will be"
" prefixed by datadir location. (default: %s)",
GRIDCOIN_CONF_FILENAME, GRIDCOIN_SETTINGS_FILENAME),
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
//TODO: Implement startupnotify option
//argsman.AddArg("-startupnotify=<cmd>", "Execute command on startup.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
// Staking
argsman.AddArg("-enablesidestaking", "Enable side staking functionality (default: 0)",
ArgsManager::ALLOW_ANY | ArgsManager::IMMEDIATE_EFFECT, OptionsCategory::STAKING);
argsman.AddArg("-staking", "Allow wallet to stake if conditions to stake are met (default: 1)",
ArgsManager::ALLOW_ANY | ArgsManager::IMMEDIATE_EFFECT, OptionsCategory::STAKING);
argsman.AddArg("-sidestake=<address,percent>", "Sidestake destination and allocation entry. There can be as many "
"specified as desired. Only six per stake can be sent. If more than "
"six are specified. Six are randomly chosen for each stake. Only active "
"if -enablesidestaking is set. These settings are overridden if "
"-sidestakeaddresses and -stakestakeallocations are set.",
ArgsManager::ALLOW_ANY | ArgsManager::IMMEDIATE_EFFECT, OptionsCategory::STAKING);
argsman.AddArg("-sidestakeaddresses=<address1,address2,...,addressN>", "Sidestake destination entry. There can be as many "
"specified as desired. Only six per stake can be sent. If more than "
"six are specified. Six are randomly chosen for each stake. Only active "
"if -enablesidestaking is set. If set along with -sidestakeallocations "
"overrides the -sidestake entries.",
ArgsManager::ALLOW_ANY | ArgsManager::IMMEDIATE_EFFECT, OptionsCategory::STAKING);
argsman.AddArg("-sidestakeallocations=percent1,percent2,...,percentN>", "Sidestake allocation entry. There can be as many "
"specified as desired. Only six per stake can be sent. If more than "
"six are specified. Six are randomly chosen for each stake. Only active "
"if -enablesidestaking is set. If set along with -sidestakeaddresses "
"overrides the -sidestake entries.",
ArgsManager::ALLOW_ANY | ArgsManager::IMMEDIATE_EFFECT, OptionsCategory::STAKING);
argsman.AddArg("-enablestakesplit", "Enable unspent output spitting when staking to optimize staking efficiency "
"(default: 0",
ArgsManager::ALLOW_ANY | ArgsManager::IMMEDIATE_EFFECT, OptionsCategory::STAKING);
argsman.AddArg("-stakingefficiency=<percent>", "Specify target staking efficiency for stake splitting (default: 90, "
"clamped to [75, 98])",
ArgsManager::ALLOW_ANY | ArgsManager::IMMEDIATE_EFFECT, OptionsCategory::STAKING);
argsman.AddArg("-minstakesplitvalue=<n>", strprintf("Specify minimum output value for post split output when stake "
"splitting (default: %" PRId64 "GRC)", MIN_STAKE_SPLIT_VALUE_GRC),
ArgsManager::ALLOW_ANY | ArgsManager::IMMEDIATE_EFFECT, OptionsCategory::STAKING);
// Scraper
argsman.AddArg("-scraper", "Activate scraper for statistics downloads. This will only work if the node has a wallet "
"key that is authorized by the network (default: 0).",
ArgsManager::ALLOW_ANY, OptionsCategory::SCRAPER);
argsman.AddArg("-explorer", "Activate extended statistics file retention for the scraper. This will only work if the"
"node is authorized for scraping and the scraper is activated (default: 0)",
ArgsManager::ALLOW_ANY, OptionsCategory::SCRAPER);
argsman.AddArg("-scraperkey=<address>", "Manually specify scraper public key in address form. This is not necessary "
"and will not work if the private key is not present in the scraper wallet file.",
ArgsManager::ALLOW_ANY, OptionsCategory::SCRAPER);
// Researcher
argsman.AddArg("-email=<email>", "Email address to use for CPID detection. Must match your BOINC account email",
ArgsManager::ALLOW_ANY, OptionsCategory::RESEARCHER);
argsman.AddArg("-boincdatadir=<path>", "Path to the BOINC data directory for CPID detection when the BOINC client uses"
" a non-default directory",
ArgsManager::ALLOW_ANY, OptionsCategory::RESEARCHER);
argsman.AddArg("-forcecpid=<cpid>", "Override automatic CPID detection with the specified CPID",
ArgsManager::ALLOW_ANY, OptionsCategory::RESEARCHER);
argsman.AddArg("-investor", "Disable CPID detection and do not participate in the research reward system",
ArgsManager::ALLOW_ANY, OptionsCategory::RESEARCHER);
argsman.AddArg("-pooloperator", "Skip pool CPID checks for staking nodes run by pool administrators",
ArgsManager::ALLOW_ANY, OptionsCategory::RESEARCHER);
// Wallet
argsman.AddArg("-upgradewallet", "Upgrade wallet to latest format",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-keypool=<n>", "Set key pool size to <n> (default: 100)",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-rescan", "Rescan the block chain for missing wallet transactions",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-salvagewallet", "Attempt to recover private keys from a corrupt wallet.dat",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-zapwallettxes", "Delete all wallet transactions and only recover those parts of the blockchain through"
" -rescan on startup",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-checkblocks=<n>", "How many blocks to check at startup (default: 2500, 0 = all)",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-checklevel=<n>", "How thorough the block verification is (0-6, default: 1)",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-walletbackupinterval=<n>", "DEPRECATED: Optional: Create a wallet backup every <n> blocks. Zero"
" disables backups",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-walletbackupintervalsecs=<n>", "Optional: Create a wallet backup every <n> seconds. Zero disables"
" backups (default: 86400)",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-backupdir=<path>", "Specify backup directory for wallet backups (default: walletbackups).",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-maintainbackupretention", "Activate retention management of backup files (default: 0)",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-walletbackupretainnumfiles=<n>", "Specify maximum number of backup files to retain (default: 365). "
"Note that the actual files retained is the greater of this setting "
"and the other setting -walletbackupretainnumdays.",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-walletbackupretainnumdays=<n>", "Specify maximum number of backup files to retain (default: 365). "
"Note that the actual files retained is the greater of this setting "
"and the other setting -walletbackupretainnumfiles.",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-enableaccounts", "DEPRECATED: Enable accounting functionality (default: 0)",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-maxsigcachesize=<n>", "Set maximum size for signature cache (default: 50000)",
ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
// Connections
argsman.AddArg("-timeout=<n>", "Specify connection timeout in milliseconds (default: 5000)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-peertimeout=<n>", "Specify p2p connection timeout in seconds. This option determines the amount of time"
" a peer may be inactive before the connection to it is dropped. (minimum: 1, default:"
" 45)",
ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CONNECTION);
argsman.AddArg("-proxy=<ip:port>", "Connect through socks proxy", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-socks=<n>", "Select the version of socks proxy to use (4-5, default: 5)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-tor=<ip:port>", "Use proxy to reach tor hidden services (default: same as -proxy)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-dns", "Allow DNS lookups for -addnode, -seednode and -connect",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-port=<port>", "Listen for connections on <port> (default: 32749 or testnet: 32748)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-maxconnections=<n>", "Maintain at most <n> connections to peers (default: 125)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-maxoutboundconnections=<n>", "Maximum number of outbound connections (default: 8)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-addnode=<ip>", "Add a node to connect to and attempt to keep the connection open",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-connect=<ip>", "Connect only to the specified node(s)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-seednode=<ip>", "Connect to a node to retrieve peer addresses, and disconnect",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-externalip=<ip>", "Specify your own public address",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-onlynet=<net>", "Only connect to nodes in network <net> (IPv4, IPv6 or Tor)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-discover", "Discover own IP address (default: 1 when listening and no -externalip)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-listen", "Accept connections from outside (default: 1 if no -proxy or -connect)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-bind=<addr>[:<port>][=onion]", "Bind to given address. Use [host]:port notation for IPv6",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-dnsseed", "Find peers using DNS lookup (default: 1)",
ArgsManager::ALLOW_BOOL, OptionsCategory::CONNECTION);
argsman.AddArg("-banscore=<n>", "Threshold for disconnecting misbehaving peers (default: 100)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-bantime=<n>", strprintf("Default duration (in seconds) of manually configured bans (default: %u)",
DEFAULT_MISBEHAVING_BANTIME),
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-maxreceivebuffer=<n>", "Maximum per-connection receive buffer, <n>*1000 bytes (default: 5000)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-maxsendbuffer=<n>", "Maximum per-connection send buffer, <n>*1000 bytes (default: 1000)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#ifdef USE_UPNP
#if USE_UPNP
argsman.AddArg("-upnp", "Use UPnP to map the listening port (default: 1 when listening and no -proxy)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#else
argsman.AddArg("-upnp", "Use UPnP to map the listening port (default: 0)",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
#endif
#else
hidden_args.emplace_back("-upnp");
#endif
// RPC
argsman.AddArg("-server", "Accept command line and JSON-RPC commands",
ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcuser=<user>", "Username for JSON-RPC connections",
ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
argsman.AddArg("-rpcpassword=<pw>", "Password for JSON-RPC connections",
ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
argsman.AddArg("-rpcport=<port>", strprintf("Listen for JSON-RPC connections on <port> (default: %u, testnet: %u)",
defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort()),
ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcallowip=<ip>", "Allow JSON-RPC connections from specified IP address",
ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcconnect=<ip>", "Send commands to node running on <ip> (default: 127.0.0.1)",
ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcthreads=<n>", "Set the number of threads to service RPC calls (default: 4)",
ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcssl", "Use OpenSSL (https) for JSON-RPC connections", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcsslcertificatechainfile=<file.cert>", "Server certificate file (default: server.cert)",
ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcsslprivatekeyfile=<file.pem>", "Server private key (default: server.pem)",
ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcsslciphers=<ciphers>",
"Acceptable ciphers (default: TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH)",
ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
// Additional hidden options
hidden_args.emplace_back("-devbuild");
hidden_args.emplace_back("-scrapersleep");
hidden_args.emplace_back("-activebeforesb");
hidden_args.emplace_back("-clearbeaconhistory");
// -boinckey should now be removed entirely. It is put here to prevent the executable erroring out on
// an invalid parameter for old clients that may have left the argument in.
hidden_args.emplace_back("-boinckey");
hidden_args.emplace_back("-printstakemodifier");
hidden_args.emplace_back("-printpriority");
hidden_args.emplace_back("-printkeypool");
// -limitfreerelay is probably destined for the trash-heap on the next fee rewrite.
hidden_args.emplace_back("-limitfreerelay");
// Rob?
hidden_args.emplace_back("-autoban");
// These probably should be removed
hidden_args.emplace_back("-printcoinage");
hidden_args.emplace_back("-privdb");
// This is hidden because it defaults to true and should NEVER be changed unless you know what you are doing.
hidden_args.emplace_back("-flushwallet");
SetupChainParamsBaseOptions(argsman);
// Add the hidden options
argsman.AddHiddenArgs(hidden_args);
}
std::string VersionMessage()
{
// Note: this prints the version of the binary. It does not necessarily
// match the version of the running wallet when using the CLI to invoke
// RPC functions on a remote server.
//
return "Gridcoin Core " + FormatFullVersion() + "\n";
}
/** Sanity checks
* Ensure that Bitcoin is running in a usable environment with all
* necessary library support.
*/
bool InitSanityCheck(void)
{
// The below sanity check is still required for OpenSSL via key.cpp until Bitcoin's secp256k1 is ported over. For now we have
// only ported the accelerated hashing.
if(!ECC_InitSanityCheck()) {
InitError("OpenSSL appears to lack support for elliptic curve cryptography. For more "
"information, visit https://en.bitcoin.it/wiki/OpenSSL_and_EC_Libraries");
return false;
}
return true;
}
/**
* Initialize global loggers.
*
* Note that this is called very early in the process lifetime, so you should be
* careful about what global state you rely on here.
*/
void InitLogging()
{
fPrintToConsole = gArgs.GetBoolArg("-printtoconsole");
fPrintToDebugger = gArgs.GetBoolArg("-printtodebugger");
fLogTimestamps = gArgs.GetBoolArg("-logtimestamps", true);
LogInstance().m_print_to_file = !gArgs.IsArgNegated("-debuglogfile");
LogInstance().m_file_path = AbsPathForConfigVal(gArgs.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));
LogInstance().m_print_to_console = fPrintToConsole;
LogInstance().m_log_timestamps = fLogTimestamps;
LogInstance().m_log_time_micros = gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
LogInstance().m_log_threadnames = gArgs.GetBoolArg("-logthreadnames", DEFAULT_LOGTHREADNAMES);
fLogIPs = gArgs.GetBoolArg("-logips", DEFAULT_LOGIPS);
if (LogInstance().m_print_to_file)
{
// Only shrink debug file at start if log archiving is set to false.
if (!gArgs.GetBoolArg("-logarchivedaily", true) && gArgs.GetBoolArg("-shrinkdebugfile", LogInstance().DefaultShrinkDebugFile()))
{
// Do this first since it both loads a bunch of debug.log into memory,
// and because this needs to happen before any other debug.log printing
LogInstance().ShrinkDebugFile();
}
}
if (gArgs.IsArgSet("-debug"))
{
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
std::vector<std::string> categories;
if (gArgs.GetArgs("-debug").size())
{
for (auto const& sSubParam : gArgs.GetArgs("-debug"))
{
categories.push_back(sSubParam);
}
}
if (std::none_of(categories.begin(), categories.end(),
[](std::string cat){return cat == "0" || cat == "none";}))
{
for (const auto& cat : categories)
{
if (!LogInstance().EnableCategory(cat))
{
InitWarning(strprintf("Unsupported logging category %s=%s.", "-debug", cat));
}
}
}
}
std::vector<std::string> excluded_categories;
if (gArgs.GetArgs("-debugexclude").size())
{
for (auto const& sSubParam : gArgs.GetArgs("-debugexclude"))
{
excluded_categories.push_back(sSubParam);
}
}
// Now remove the logging categories which were explicitly excluded
for (const std::string& cat : excluded_categories)
{
if (!LogInstance().DisableCategory(cat))
{
InitWarning(strprintf("Unsupported logging category %s=%s.", "-debugexclude", cat));
}
}
if (!LogInstance().StartLogging())
{
strprintf("Could not open debug log file %s", LogInstance().m_file_path.string());
}
if (!LogInstance().m_log_timestamps)
{
LogPrintf("Startup time: %s\n", FormatISO8601DateTime(GetTime()));
}
LogPrintf("Default data directory %s\n", GetDefaultDataDir().string());
LogPrintf("Using data directory %s\n", GetDataDir().string());
std::string build_type;
#ifdef DEBUG
build_type = "debug build";
#else
build_type = "release build";
#endif
LogPrintf(PACKAGE_NAME " version %s (%s - %s)", FormatFullVersion(), build_type, CLIENT_DATE);
}
void ThreadAppInit2(ThreadHandlerPtr th)
{
// Make this thread recognisable
RenameThread("grc-appinit2");
bGridcoinCoreInitComplete = false;
LogPrintf("Initializing Core...");
if (!AppInit2(th)) {
fRequestShutdown = true;
}
LogPrintf("Core Initialized...");
bGridcoinCoreInitComplete = true;
}
/** Initialize Gridcoin.
* @pre Parameters should be parsed and config file should be read.
*/
bool AppInit2(ThreadHandlerPtr threads)
{
g_timer.InitTimer("init", false);
// ********************************************************* Step 1: setup
#ifdef _MSC_VER
// Turn off Microsoft heap dump noise
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, 0));
#endif
#if _MSC_VER >= 1400
// Disable confusing "helpful" text message on abort, Ctrl-C
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
#endif
#ifdef WIN32
// Enable Data Execution Prevention (DEP)
// Minimum supported OS versions: WinXP SP3, WinVista >= SP1, Win Server 2008
// A failure is non-critical and needs no further attention!
#ifndef PROCESS_DEP_ENABLE
// We define this here, because GCCs winbase.h limits this to _WIN32_WINNT >= 0x0601 (Windows 7),
// which is not correct. Can be removed, when GCCs winbase.h is fixed!
#define PROCESS_DEP_ENABLE 0x00000001
#endif
typedef BOOL (WINAPI *PSETPROCDEPPOL)(DWORD);
PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy");
if (setProcDEPPol != nullptr) setProcDEPPol(PROCESS_DEP_ENABLE);
#endif
#ifndef WIN32
umask(077);
// Clean shutdown on SIGTERM
registerSignalHandler(SIGTERM, HandleSIGTERM);
registerSignalHandler(SIGINT, HandleSIGTERM);
// Reopen debug.log on SIGHUP
registerSignalHandler(SIGHUP, HandleSIGHUP);
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
signal(SIGPIPE, SIG_IGN);
#else
SetConsoleCtrlHandler(consoleCtrlHandler, true);
#endif
// ********************************************************* Step 2: parameter interactions
if (IsConfigFileEmpty())
{
try
{
CreateNewConfigFile();
std::string error_msg;
if (!gArgs.ReadConfigFiles(error_msg, true))
{
throw error_msg;
}
}
catch (const std::exception& e)
{
LogPrintf("WARNING: failed to create configuration file: %s", e.what());
}
}
//6-10-2014: R Halford: Updating Boost version to 1.5.5 to prevent sync issues; print the boost version to verify:
//5-04-2018: J Owens: Boost now needs to be 1.65 or higher to avoid thread sleep problems with system clock resets.
std::string boost_version = "";
std::ostringstream s;
s << boost_version << "Using Boost "
<< BOOST_VERSION / 100000 << "." // major version
<< BOOST_VERSION / 100 % 1000 << "." // minior version
<< BOOST_VERSION % 100 // patch level
<< "\n";
LogPrintf("Boost Version: %s", s.str());
nNodeLifespan = gArgs.GetArg("-addrlifespan", 7);
fUseFastIndex = gArgs.GetBoolArg("-fastindex", false);
nMinerSleep = gArgs.GetArg("-minersleep", 8000);
nDerivationMethodIndex = 0;
fTestNet = gArgs.GetBoolArg("-testnet");
if (gArgs.GetArgs("-bind").size()) {
// when specifying an explicit binding address, you want to listen on it
// even when -connect or -proxy is specified
gArgs.SoftSetBoolArg("-listen", true);
}
if (gArgs.GetArgs("-connect").size()) {
// when only connecting to trusted nodes, do not seed via DNS, or listen by default
gArgs.SoftSetBoolArg("-dnsseed", false);
gArgs.SoftSetBoolArg("-listen", false);
}
if (gArgs.GetArgs("-proxy").size()) {
// to protect privacy, do not listen by default if a proxy server is specified
gArgs.SoftSetBoolArg("-listen", false);
}
if (!gArgs.GetBoolArg("-listen", true)) {
// do not map ports or try to retrieve public IP when not listening (pointless)
gArgs.SoftSetBoolArg("-upnp", false);
gArgs.SoftSetBoolArg("-discover", false);
}
if (gArgs.GetArgs("-externalip").size()) {
// if an explicit public IP is specified, do not try to find others
gArgs.SoftSetBoolArg("-discover", false);
}
if (gArgs.GetBoolArg("-salvagewallet")) {
// Rewrite just private keys: rescan to find transactions
gArgs.SoftSetBoolArg("-rescan", true);
}
if (gArgs.GetBoolArg("-zapwallettxes", false)) {
// -zapwallettx implies a rescan
gArgs.SoftSetBoolArg("-rescan", true);
}
// Verify testnet is using the testnet directory for the config file:
std::string sTestNetSpecificArg = gArgs.GetArg("-testnetarg", "default");
LogPrintf("Using specific arg %s", sTestNetSpecificArg);
// ********************************************************* Step 3: parameter-to-internal-flags
if (gArgs.GetArg("-debug", "false") == "true")
{
LogPrintf("Enabling debug category VERBOSE from legacy debug.");
LogInstance().EnableCategory(BCLog::LogFlags::VERBOSE);
}
#if defined(WIN32)
fDaemon = false;
#else
if(fQtActive)
fDaemon = false;
else
fDaemon = gArgs.GetBoolArg("-daemon");
#endif
if (fDaemon)
fServer = true;
else
fServer = gArgs.GetBoolArg("-server");
/* force fServer when running without GUI */
if(!fQtActive)
fServer = true;
if (gArgs.IsArgSet("-timeout"))
{
int nNewTimeout = gArgs.GetArg("-timeout", 5000);
if (nNewTimeout > 0 && nNewTimeout < 600000)
nConnectTimeout = nNewTimeout;
}
if (gArgs.IsArgSet("-peertimeout"))
{
int nNewPeerTimeout = gArgs.GetArg("-peertimeout", 45);
if (nNewPeerTimeout <= 0)
InitError(strprintf(_("Invalid amount for -peertimeout=<amount>: '%s'"), gArgs.GetArg("-peertimeout", "")));
PEER_TIMEOUT = nNewPeerTimeout;
}
if (gArgs.IsArgSet("-paytxfee"))
{
if (!ParseMoney(gArgs.GetArg("-paytxfee", ""), nTransactionFee))
return InitError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s'"), gArgs.GetArg("-paytxfee", "")));
if (nTransactionFee > 0.25 * COIN)
InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction."));
}
fConfChange = gArgs.GetBoolArg("-confchange", false);
fEnforceCanonical = gArgs.GetBoolArg("-enforcecanonical", true);
if (gArgs.IsArgSet("-mininput"))
{
if (!ParseMoney(gArgs.GetArg("-mininput", ""), nMinimumInputValue))
return InitError(strprintf(_("Invalid amount for -mininput=<amount>: '%s'"), gArgs.GetArg("-mininput", "")));
}
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
// Sanity check
if (!InitSanityCheck())
return InitError(_("Initialization sanity check failed. Gridcoin is shutting down."));
// Initialize internal hashing code with SSE/AVX2 optimizations. In the future we will also have ARM/NEON optimizations.
std::string sha256_algo = SHA256AutoDetect();
LogPrintf("Using the '%s' SHA256 implementation\n", sha256_algo);
LogPrintf("Block version 11 hard fork configured for block %d", Params().GetConsensus().BlockV11Height);
fs::path datadir = GetDataDir();
fs::path walletFileName = gArgs.GetArg("-wallet", "wallet.dat");
LogPrintf("INFO %s: DataDir = %s.", __func__, datadir.string());
// WalletFileName must be a plain filename without a directory
if (walletFileName != walletFileName.filename())
return InitError(strprintf(_("Wallet %s resides outside data directory %s."), walletFileName.string(), datadir.string()));
// Make sure only a single Bitcoin process is using the data directory.
if (!DirIsWritable(datadir)) {
return InitError(strprintf(_("Cannot write to data directory '%s'; check permissions."), datadir.string()));
}
if (!LockDirectory(datadir, ".lock", false)) {
return InitError(strprintf(_("Cannot obtain a lock on data directory %s. %s is probably already running."), datadir.string(), PACKAGE_NAME));
}
#if !defined(WIN32)
if (fDaemon)
{
// Daemonize
pid_t pid = fork();
if (pid < 0)
{
fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
return false;
}
if (pid > 0)
{
CreatePidFile(GetPidFile(gArgs), pid);
// Now that we are forked we can request a shutdown so the parent
// exits while the child lives on.
StartShutdown();
return true;
}
pid_t sid = setsid();
if (sid < 0)
fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
}
#endif
LogPrintf("Using OpenSSL version %s", SSLeay_version(SSLEAY_VERSION));
std::ostringstream strErrors;
fDevbuildCripple = false;
if ((CLIENT_VERSION_BUILD != 0) && !fTestNet)
{
fDevbuildCripple = true;
if ((gArgs.GetArg("-devbuild", "") == "override"))
{
LogInstance().EnableCategory(BCLog::LogFlags::VERBOSE);
fDevbuildCripple = false;
LogPrintf("WARNING: Running development version outside of testnet in override mode!\n"
"VERBOSE logging is enabled.");
}
else
{
LogPrintf("WARNING: Running development version outside of testnet!\n"
"Staking and sending transactions will be disabled.");
}
}
if (fDaemon)
fprintf(stdout, "Gridcoin server starting\n");
// ********************************************************* Step 5: verify database integrity
uiInterface.InitMessage(_("Verifying database integrity..."));
g_timer.LogTimer("init", true);
g_timer.GetTimes("Starting verify of database integrity", "init");
if (!bitdb.Open(GetDataDir()))
{