Revert "Update gitian descriptors to point at stable git repo"
[novacoin.git] / src / init.cpp
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include "db.h"
6 #include "walletdb.h"
7 #include "bitcoinrpc.h"
8 #include "net.h"
9 #include "init.h"
10 #include "util.h"
11 #include "ui_interface.h"
12 #include <boost/filesystem.hpp>
13 #include <boost/filesystem/fstream.hpp>
14 #include <boost/filesystem/convenience.hpp>
15 #include <boost/interprocess/sync/file_lock.hpp>
16
17 #ifndef WIN32
18 #include <signal.h>
19 #endif
20
21 using namespace std;
22 using namespace boost;
23
24 CWallet* pwalletMain;
25
26 //////////////////////////////////////////////////////////////////////////////
27 //
28 // Shutdown
29 //
30
31 void ExitTimeout(void* parg)
32 {
33 #ifdef WIN32
34     Sleep(5000);
35     ExitProcess(0);
36 #endif
37 }
38
39 void StartShutdown()
40 {
41 #ifdef QT_GUI
42     // ensure we leave the Qt main loop for a clean GUI exit (Shutdown() is called in bitcoin.cpp afterwards)
43     QueueShutdown();
44 #else
45     // Without UI, Shutdown() can simply be started in a new thread
46     CreateThread(Shutdown, NULL);
47 #endif
48 }
49
50 void Shutdown(void* parg)
51 {
52     static CCriticalSection cs_Shutdown;
53     static bool fTaken;
54     bool fFirstThread = false;
55     {
56         TRY_LOCK(cs_Shutdown, lockShutdown);
57         if (lockShutdown)
58         {
59             fFirstThread = !fTaken;
60             fTaken = true;
61         }
62     }
63     static bool fExit;
64     if (fFirstThread)
65     {
66         fShutdown = true;
67         nTransactionsUpdated++;
68         DBFlush(false);
69         StopNode();
70         DBFlush(true);
71         boost::filesystem::remove(GetPidFile());
72         UnregisterWallet(pwalletMain);
73         delete pwalletMain;
74         CreateThread(ExitTimeout, NULL);
75         Sleep(50);
76         printf("Bitcoin exiting\n\n");
77         fExit = true;
78 #ifndef QT_GUI
79         // ensure non UI client get's exited here, but let Bitcoin-Qt reach return 0; in bitcoin.cpp
80         exit(0);
81 #endif
82     }
83     else
84     {
85         while (!fExit)
86             Sleep(500);
87         Sleep(100);
88         ExitThread(0);
89     }
90 }
91
92 void HandleSIGTERM(int)
93 {
94     fRequestShutdown = true;
95 }
96
97
98
99
100
101
102 //////////////////////////////////////////////////////////////////////////////
103 //
104 // Start
105 //
106 #if !defined(QT_GUI)
107 int main(int argc, char* argv[])
108 {
109     bool fRet = false;
110     fRet = AppInit(argc, argv);
111
112     if (fRet && fDaemon)
113         return 0;
114
115     return 1;
116 }
117 #endif
118
119 bool AppInit(int argc, char* argv[])
120 {
121     bool fRet = false;
122     try
123     {
124         fRet = AppInit2(argc, argv);
125     }
126     catch (std::exception& e) {
127         PrintException(&e, "AppInit()");
128     } catch (...) {
129         PrintException(NULL, "AppInit()");
130     }
131     if (!fRet)
132         Shutdown(NULL);
133     return fRet;
134 }
135
136 bool AppInit2(int argc, char* argv[])
137 {
138 #ifdef _MSC_VER
139     // Turn off microsoft heap dump noise
140     _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
141     _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0));
142 #endif
143 #if _MSC_VER >= 1400
144     // Disable confusing "helpful" text message on abort, ctrl-c
145     _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
146 #endif
147 #ifndef WIN32
148     umask(077);
149 #endif
150 #ifndef WIN32
151     // Clean shutdown on SIGTERM
152     struct sigaction sa;
153     sa.sa_handler = HandleSIGTERM;
154     sigemptyset(&sa.sa_mask);
155     sa.sa_flags = 0;
156     sigaction(SIGTERM, &sa, NULL);
157     sigaction(SIGINT, &sa, NULL);
158     sigaction(SIGHUP, &sa, NULL);
159 #endif
160
161     //
162     // Parameters
163     //
164     // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
165 #if !defined(QT_GUI)
166     ParseParameters(argc, argv);
167     if (!boost::filesystem::is_directory(GetDataDir(false)))
168     {
169         fprintf(stderr, "Error: Specified directory does not exist\n");
170         Shutdown(NULL);
171     }
172     ReadConfigFile(mapArgs, mapMultiArgs);
173 #endif
174
175     if (mapArgs.count("-?") || mapArgs.count("--help"))
176     {
177         string strUsage = string() +
178           _("Bitcoin version") + " " + FormatFullVersion() + "\n\n" +
179           _("Usage:") + "\t\t\t\t\t\t\t\t\t\t\n" +
180             "  bitcoind [options]                   \t  " + "\n" +
181             "  bitcoind [options] <command> [params]\t  " + _("Send command to -server or bitcoind") + "\n" +
182             "  bitcoind [options] help              \t\t  " + _("List commands") + "\n" +
183             "  bitcoind [options] help <command>    \t\t  " + _("Get help for a command") + "\n" +
184           _("Options:") + "\n" +
185             "  -conf=<file>     \t\t  " + _("Specify configuration file (default: bitcoin.conf)") + "\n" +
186             "  -pid=<file>      \t\t  " + _("Specify pid file (default: bitcoind.pid)") + "\n" +
187             "  -gen             \t\t  " + _("Generate coins") + "\n" +
188             "  -gen=0           \t\t  " + _("Don't generate coins") + "\n" +
189             "  -min             \t\t  " + _("Start minimized") + "\n" +
190             "  -splash          \t\t  " + _("Show splash screen on startup (default: 1)") + "\n" +
191             "  -datadir=<dir>   \t\t  " + _("Specify data directory") + "\n" +
192             "  -dbcache=<n>     \t\t  " + _("Set database cache size in megabytes (default: 25)") + "\n" +
193             "  -dblogsize=<n>   \t\t  " + _("Set database disk log size in megabytes (default: 100)") + "\n" +
194             "  -timeout=<n>     \t  "   + _("Specify connection timeout (in milliseconds)") + "\n" +
195             "  -proxy=<ip:port> \t  "   + _("Connect through socks4 proxy") + "\n" +
196             "  -dns             \t  "   + _("Allow DNS lookups for addnode and connect") + "\n" +
197             "  -port=<port>     \t\t  " + _("Listen for connections on <port> (default: 8333 or testnet: 18333)") + "\n" +
198             "  -maxconnections=<n>\t  " + _("Maintain at most <n> connections to peers (default: 125)") + "\n" +
199             "  -addnode=<ip>    \t  "   + _("Add a node to connect to and attempt to keep the connection open") + "\n" +
200             "  -connect=<ip>    \t\t  " + _("Connect only to the specified node") + "\n" +
201             "  -irc             \t  "   + _("Find peers using internet relay chat (default: 0)") + "\n" +
202             "  -listen          \t  "   + _("Accept connections from outside (default: 1)") + "\n" +
203 #ifdef QT_GUI
204             "  -lang=<lang>     \t\t  " + _("Set language, for example \"de_DE\" (default: system locale)") + "\n" +
205 #endif
206             "  -dnsseed         \t  "   + _("Find peers using DNS lookup (default: 1)") + "\n" +
207             "  -banscore=<n>    \t  "   + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n" +
208             "  -bantime=<n>     \t  "   + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n" +
209             "  -maxreceivebuffer=<n>\t  " + _("Maximum per-connection receive buffer, <n>*1000 bytes (default: 10000)") + "\n" +
210             "  -maxsendbuffer=<n>\t  "   + _("Maximum per-connection send buffer, <n>*1000 bytes (default: 10000)") + "\n" +
211 #ifdef USE_UPNP
212 #if USE_UPNP
213             "  -upnp            \t  "   + _("Use Universal Plug and Play to map the listening port (default: 1)") + "\n" +
214 #else
215             "  -upnp            \t  "   + _("Use Universal Plug and Play to map the listening port (default: 0)") + "\n" +
216 #endif
217             "  -detachdb        \t  "   + _("Detach block and address databases. Increases shutdown time (default: 0)") + "\n" +
218 #endif
219             "  -paytxfee=<amt>  \t  "   + _("Fee per KB to add to transactions you send") + "\n" +
220 #ifdef QT_GUI
221             "  -server          \t\t  " + _("Accept command line and JSON-RPC commands") + "\n" +
222 #endif
223 #if !defined(WIN32) && !defined(QT_GUI)
224             "  -daemon          \t\t  " + _("Run in the background as a daemon and accept commands") + "\n" +
225 #endif
226             "  -testnet         \t\t  " + _("Use the test network") + "\n" +
227             "  -debug           \t\t  " + _("Output extra debugging information") + "\n" +
228             "  -logtimestamps   \t  "   + _("Prepend debug output with timestamp") + "\n" +
229             "  -printtoconsole  \t  "   + _("Send trace/debug info to console instead of debug.log file") + "\n" +
230 #ifdef WIN32
231             "  -printtodebugger \t  "   + _("Send trace/debug info to debugger") + "\n" +
232 #endif
233             "  -rpcuser=<user>  \t  "   + _("Username for JSON-RPC connections") + "\n" +
234             "  -rpcpassword=<pw>\t  "   + _("Password for JSON-RPC connections") + "\n" +
235             "  -rpcport=<port>  \t\t  " + _("Listen for JSON-RPC connections on <port> (default: 8332)") + "\n" +
236             "  -rpcallowip=<ip> \t\t  " + _("Allow JSON-RPC connections from specified IP address") + "\n" +
237             "  -rpcconnect=<ip> \t  "   + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n" +
238             "  -blocknotify=<cmd> "     + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n" +
239             "  -upgradewallet   \t  "   + _("Upgrade wallet to latest format") + "\n" +
240             "  -keypool=<n>     \t  "   + _("Set key pool size to <n> (default: 100)") + "\n" +
241             "  -rescan          \t  "   + _("Rescan the block chain for missing wallet transactions") + "\n" +
242             "  -checkblocks=<n> \t\t  " + _("How many blocks to check at startup (default: 2500, 0 = all)") + "\n" +
243             "  -checklevel=<n>  \t\t  " + _("How thorough the block verification is (0-6, default: 1)") + "\n";
244
245         strUsage += string() +
246             _("\nSSL options: (see the Bitcoin Wiki for SSL setup instructions)") + "\n" +
247             "  -rpcssl                                \t  " + _("Use OpenSSL (https) for JSON-RPC connections") + "\n" +
248             "  -rpcsslcertificatechainfile=<file.cert>\t  " + _("Server certificate file (default: server.cert)") + "\n" +
249             "  -rpcsslprivatekeyfile=<file.pem>       \t  " + _("Server private key (default: server.pem)") + "\n" +
250             "  -rpcsslciphers=<ciphers>               \t  " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)") + "\n";
251
252         strUsage += string() +
253             "  -?               \t\t  " + _("This help message") + "\n";
254
255         // Remove tabs
256         strUsage.erase(std::remove(strUsage.begin(), strUsage.end(), '\t'), strUsage.end());
257 #if defined(QT_GUI) && defined(WIN32)
258         // On windows, show a message box, as there is no stderr
259         ThreadSafeMessageBox(strUsage, _("Usage"), wxOK | wxMODAL);
260 #else
261         fprintf(stderr, "%s", strUsage.c_str());
262 #endif
263         return false;
264     }
265
266     fTestNet = GetBoolArg("-testnet");
267     if (fTestNet)
268     {
269         SoftSetBoolArg("-irc", true);
270     }
271
272     fDebug = GetBoolArg("-debug");
273     fDetachDB = GetBoolArg("-detachdb", false);
274
275 #if !defined(WIN32) && !defined(QT_GUI)
276     fDaemon = GetBoolArg("-daemon");
277 #else
278     fDaemon = false;
279 #endif
280
281     if (fDaemon)
282         fServer = true;
283     else
284         fServer = GetBoolArg("-server");
285
286     /* force fServer when running without GUI */
287 #if !defined(QT_GUI)
288     fServer = true;
289 #endif
290     fPrintToConsole = GetBoolArg("-printtoconsole");
291     fPrintToDebugger = GetBoolArg("-printtodebugger");
292     fLogTimestamps = GetBoolArg("-logtimestamps");
293
294 #ifndef QT_GUI
295     for (int i = 1; i < argc; i++)
296         if (!IsSwitchChar(argv[i][0]) && !(strlen(argv[i]) > 7 && strncasecmp(argv[i], "bitcoin:", 8) == 0))
297             fCommandLine = true;
298
299     if (fCommandLine)
300     {
301         int ret = CommandLineRPC(argc, argv);
302         exit(ret);
303     }
304 #endif
305
306 #if !defined(WIN32) && !defined(QT_GUI)
307     if (fDaemon)
308     {
309         // Daemonize
310         pid_t pid = fork();
311         if (pid < 0)
312         {
313             fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
314             return false;
315         }
316         if (pid > 0)
317         {
318             CreatePidFile(GetPidFile(), pid);
319             return true;
320         }
321
322         pid_t sid = setsid();
323         if (sid < 0)
324             fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
325     }
326 #endif
327
328     if (!fDebug)
329         ShrinkDebugFile();
330     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
331     printf("Bitcoin version %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str());
332     printf("Default data directory %s\n", GetDefaultDataDir().string().c_str());
333
334     if (GetBoolArg("-loadblockindextest"))
335     {
336         CTxDB txdb("r");
337         txdb.LoadBlockIndex();
338         PrintBlockTree();
339         return false;
340     }
341
342     // Make sure only a single bitcoin process is using the data directory.
343     boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
344     FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
345     if (file) fclose(file);
346     static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
347     if (!lock.try_lock())
348     {
349         ThreadSafeMessageBox(strprintf(_("Cannot obtain a lock on data directory %s.  Bitcoin is probably already running."), GetDataDir().string().c_str()), _("Bitcoin"), wxOK|wxMODAL);
350         return false;
351     }
352
353     std::ostringstream strErrors;
354     //
355     // Load data files
356     //
357     if (fDaemon)
358         fprintf(stdout, "bitcoin server starting\n");
359     int64 nStart;
360
361     InitMessage(_("Loading addresses..."));
362     printf("Loading addresses...\n");
363     nStart = GetTimeMillis();
364     if (!LoadAddresses())
365         strErrors << _("Error loading addr.dat") << "\n";
366     printf(" addresses   %15"PRI64d"ms\n", GetTimeMillis() - nStart);
367
368     InitMessage(_("Loading block index..."));
369     printf("Loading block index...\n");
370     nStart = GetTimeMillis();
371     if (!LoadBlockIndex())
372         strErrors << _("Error loading blkindex.dat") << "\n";
373
374     // as LoadBlockIndex can take several minutes, it's possible the user
375     // requested to kill bitcoin-qt during the last operation. If so, exit.
376     // As the program has not fully started yet, Shutdown() is possibly overkill.
377     if (fRequestShutdown)
378     {
379         printf("Shutdown requested. Exiting.\n");
380         return false;
381     }
382     printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart);
383
384     InitMessage(_("Loading wallet..."));
385     printf("Loading wallet...\n");
386     nStart = GetTimeMillis();
387     bool fFirstRun;
388     pwalletMain = new CWallet("wallet.dat");
389     int nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun);
390     if (nLoadWalletRet != DB_LOAD_OK)
391     {
392         if (nLoadWalletRet == DB_CORRUPT)
393             strErrors << _("Error loading wallet.dat: Wallet corrupted") << "\n";
394         else if (nLoadWalletRet == DB_TOO_NEW)
395             strErrors << _("Error loading wallet.dat: Wallet requires newer version of Bitcoin") << "\n";
396         else if (nLoadWalletRet == DB_NEED_REWRITE)
397         {
398             strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n";
399             printf("%s", strErrors.str().c_str());
400             ThreadSafeMessageBox(strErrors.str(), _("Bitcoin"), wxOK | wxICON_ERROR | wxMODAL);
401             return false;
402         }
403         else
404             strErrors << _("Error loading wallet.dat") << "\n";
405     }
406
407     if (GetBoolArg("-upgradewallet", fFirstRun))
408     {
409         int nMaxVersion = GetArg("-upgradewallet", 0);
410         if (nMaxVersion == 0) // the -walletupgrade without argument case
411         {
412             printf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
413             nMaxVersion = CLIENT_VERSION;
414             pwalletMain->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
415         }
416         else
417             printf("Allowing wallet upgrade up to %i\n", nMaxVersion);
418         if (nMaxVersion < pwalletMain->GetVersion())
419             strErrors << _("Cannot downgrade wallet") << "\n";
420         pwalletMain->SetMaxVersion(nMaxVersion);
421     }
422
423     if (fFirstRun)
424     {
425         // Create new keyUser and set as default key
426         RandAddSeedPerfmon();
427
428         std::vector<unsigned char> newDefaultKey;
429         if (!pwalletMain->GetKeyFromPool(newDefaultKey, false))
430             strErrors << _("Cannot initialize keypool") << "\n";
431         pwalletMain->SetDefaultKey(newDefaultKey);
432         if (!pwalletMain->SetAddressBookName(CBitcoinAddress(pwalletMain->vchDefaultKey), ""))
433             strErrors << _("Cannot write default address") << "\n";
434     }
435
436     printf("%s", strErrors.str().c_str());
437     printf(" wallet      %15"PRI64d"ms\n", GetTimeMillis() - nStart);
438
439     RegisterWallet(pwalletMain);
440
441     CBlockIndex *pindexRescan = pindexBest;
442     if (GetBoolArg("-rescan"))
443         pindexRescan = pindexGenesisBlock;
444     else
445     {
446         CWalletDB walletdb("wallet.dat");
447         CBlockLocator locator;
448         if (walletdb.ReadBestBlock(locator))
449             pindexRescan = locator.GetBlockIndex();
450     }
451     if (pindexBest != pindexRescan)
452     {
453         InitMessage(_("Rescanning..."));
454         printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
455         nStart = GetTimeMillis();
456         pwalletMain->ScanForWalletTransactions(pindexRescan, true);
457         printf(" rescan      %15"PRI64d"ms\n", GetTimeMillis() - nStart);
458     }
459
460     InitMessage(_("Done loading"));
461     printf("Done loading\n");
462
463     //// debug print
464     printf("mapBlockIndex.size() = %d\n",   mapBlockIndex.size());
465     printf("nBestHeight = %d\n",            nBestHeight);
466     printf("setKeyPool.size() = %d\n",      pwalletMain->setKeyPool.size());
467     printf("mapWallet.size() = %d\n",       pwalletMain->mapWallet.size());
468     printf("mapAddressBook.size() = %d\n",  pwalletMain->mapAddressBook.size());
469
470     if (!strErrors.str().empty())
471     {
472         ThreadSafeMessageBox(strErrors.str(), _("Bitcoin"), wxOK | wxICON_ERROR | wxMODAL);
473         return false;
474     }
475
476     // Add wallet transactions that aren't already in a block to mapTransactions
477     pwalletMain->ReacceptWalletTransactions();
478
479     // Note: Bitcoin-QT stores several settings in the wallet, so we want
480     // to load the wallet BEFORE parsing command-line arguments, so
481     // the command-line/bitcoin.conf settings override GUI setting.
482
483     //
484     // Parameters
485     //
486     if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree"))
487     {
488         PrintBlockTree();
489         return false;
490     }
491
492     if (mapArgs.count("-timeout"))
493     {
494         int nNewTimeout = GetArg("-timeout", 5000);
495         if (nNewTimeout > 0 && nNewTimeout < 600000)
496             nConnectTimeout = nNewTimeout;
497     }
498
499     if (mapArgs.count("-printblock"))
500     {
501         string strMatch = mapArgs["-printblock"];
502         int nFound = 0;
503         for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
504         {
505             uint256 hash = (*mi).first;
506             if (strncmp(hash.ToString().c_str(), strMatch.c_str(), strMatch.size()) == 0)
507             {
508                 CBlockIndex* pindex = (*mi).second;
509                 CBlock block;
510                 block.ReadFromDisk(pindex);
511                 block.BuildMerkleTree();
512                 block.print();
513                 printf("\n");
514                 nFound++;
515             }
516         }
517         if (nFound == 0)
518             printf("No blocks matching %s were found\n", strMatch.c_str());
519         return false;
520     }
521
522     if (mapArgs.count("-proxy"))
523     {
524         fUseProxy = true;
525         addrProxy = CService(mapArgs["-proxy"], 9050);
526         if (!addrProxy.IsValid())
527         {
528             ThreadSafeMessageBox(_("Invalid -proxy address"), _("Bitcoin"), wxOK | wxMODAL);
529             return false;
530         }
531     }
532
533     bool fTor = (fUseProxy && addrProxy.GetPort() == 9050);
534     if (fTor)
535     {
536         // Use SoftSetBoolArg here so user can override any of these if they wish.
537         // Note: the GetBoolArg() calls for all of these must happen later.
538         SoftSetBoolArg("-listen", false);
539         SoftSetBoolArg("-irc", false);
540         SoftSetBoolArg("-dnsseed", false);
541         SoftSetBoolArg("-upnp", false);
542         SoftSetBoolArg("-dns", false);
543     }
544
545     fAllowDNS = GetBoolArg("-dns");
546     fNoListen = !GetBoolArg("-listen", true);
547
548     // Continue to put "/P2SH/" in the coinbase to monitor
549     // BIP16 support.
550     // This can be removed eventually...
551     const char* pszP2SH = "/P2SH/";
552     COINBASE_FLAGS << std::vector<unsigned char>(pszP2SH, pszP2SH+strlen(pszP2SH));
553
554     if (!fNoListen)
555     {
556         std::string strError;
557         if (!BindListenPort(strError))
558         {
559             ThreadSafeMessageBox(strError, _("Bitcoin"), wxOK | wxMODAL);
560             return false;
561         }
562     }
563
564     if (mapArgs.count("-addnode"))
565     {
566         BOOST_FOREACH(string strAddr, mapMultiArgs["-addnode"])
567         {
568             CAddress addr(CService(strAddr, GetDefaultPort(), fAllowDNS));
569             addr.nTime = 0; // so it won't relay unless successfully connected
570             if (addr.IsValid())
571                 addrman.Add(addr, CNetAddr("127.0.0.1"));
572         }
573     }
574
575     if (mapArgs.count("-paytxfee"))
576     {
577         if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee))
578         {
579             ThreadSafeMessageBox(_("Invalid amount for -paytxfee=<amount>"), _("Bitcoin"), wxOK | wxMODAL);
580             return false;
581         }
582         if (nTransactionFee > 0.25 * COIN)
583             ThreadSafeMessageBox(_("Warning: -paytxfee is set very high.  This is the transaction fee you will pay if you send a transaction."), _("Bitcoin"), wxOK | wxICON_EXCLAMATION | wxMODAL);
584     }
585
586     //
587     // Start the node
588     //
589     if (!CheckDiskSpace())
590         return false;
591
592     RandAddSeedPerfmon();
593
594     if (!CreateThread(StartNode, NULL))
595         ThreadSafeMessageBox(_("Error: CreateThread(StartNode) failed"), _("Bitcoin"), wxOK | wxMODAL);
596
597     if (fServer)
598         CreateThread(ThreadRPCServer, NULL);
599
600 #ifdef QT_GUI
601     if (GetStartOnSystemStartup())
602         SetStartOnSystemStartup(true); // Remove startup links
603 #endif
604
605 #if !defined(QT_GUI)
606     while (1)
607         Sleep(5000);
608 #endif
609
610     return true;
611 }
612