Skip to content
This repository
Browse code

Gavin's TEST network as -testnet switch, misc fixes

git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@168 1a98c847-1fd6-4fd8-948a-caf3550aa51b
  • Loading branch information...
commit 5cbf75324d1509a1262b65c5073314a4da3f6d77 1 parent 2fad3d3
s_nakamoto authored
2  base58.h
@@ -152,7 +152,7 @@ inline bool DecodeBase58Check(const string& str, vector<unsigned char>& vchRet)
152 152
153 153
154 154
155   -static const unsigned char ADDRESSVERSION = 0;
  155 +#define ADDRESSVERSION ((unsigned char)(fTestNet ? 111 : 0))
156 156
157 157 inline string Hash160ToAddress(uint160 hash160)
158 158 {
9 db.cpp
@@ -846,10 +846,13 @@ void BackupWallet(const string& strDest)
846 846 }
847 847 }
848 848
  849 +
849 850 void CWalletDB::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool)
850 851 {
851 852 nIndex = -1;
852 853 keypool.vchPubKey.clear();
  854 + CRITICAL_BLOCK(cs_main)
  855 + CRITICAL_BLOCK(cs_mapWallet)
853 856 CRITICAL_BLOCK(cs_setKeyPool)
854 857 {
855 858 // Top up key pool
@@ -881,7 +884,11 @@ void CWalletDB::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool)
881 884 void CWalletDB::KeepKey(int64 nIndex)
882 885 {
883 886 // Remove from key pool
884   - Erase(make_pair(string("pool"), nIndex));
  887 + CRITICAL_BLOCK(cs_main)
  888 + CRITICAL_BLOCK(cs_mapWallet)
  889 + {
  890 + Erase(make_pair(string("pool"), nIndex));
  891 + }
885 892 printf("keypool keep %"PRI64d"\n", nIndex);
886 893 }
887 894
3  db.h
@@ -455,7 +455,8 @@ class CReserveKey
455 455
456 456 ~CReserveKey()
457 457 {
458   - ReturnKey();
  458 + if (!fShutdown)
  459 + ReturnKey();
459 460 }
460 461
461 462 vector<unsigned char> GetReservedKey()
38 init.cpp
@@ -165,22 +165,22 @@ bool AppInit2(int argc, char* argv[])
165 165 " bitcoin [options] help \t\t " + _("List commands\n") +
166 166 " bitcoin [options] help <command> \t\t " + _("Get help for a command\n") +
167 167 _("Options:\n") +
168   - " -conf=<file> \t " + _("Specify configuration file (default: bitcoin.conf)\n") +
169   - " -gen \t " + _("Generate coins\n") +
170   - " -gen=0 \t " + _("Don't generate coins\n") +
171   - " -min \t " + _("Start minimized\n") +
172   - " -datadir=<dir> \t " + _("Specify data directory\n") +
173   - " -proxy=<ip:port> \t " + _("Connect through socks4 proxy\n") +
174   - " -addnode=<ip> \t " + _("Add a node to connect to\n") +
175   - " -connect=<ip> \t " + _("Connect only to the specified node\n") +
176   - " -server \t " + _("Accept command line and JSON-RPC commands\n") +
177   - " -daemon \t " + _("Run in the background as a daemon and accept commands\n") +
178   - " -rpcuser=<user> \t " + _("Username for JSON-RPC connections\n") +
179   - " -rpcpassword=<pw>\t " + _("Password for JSON-RPC connections\n") +
180   - " -rpcport=<port> \t " + _("Listen for JSON-RPC connections on <port>\n") +
181   - " -rpcallowip=<ip> \t " + _("Allow JSON-RPC connections from specified IP address\n") +
182   - " -rpcconnect=<ip> \t " + _("Send commands to node running on <ip>\n") +
183   - " -? \t " + _("This help message\n");
  168 + " -conf=<file> \t\t " + _("Specify configuration file (default: bitcoin.conf)\n") +
  169 + " -gen \t\t " + _("Generate coins\n") +
  170 + " -gen=0 \t\t " + _("Don't generate coins\n") +
  171 + " -min \t\t " + _("Start minimized\n") +
  172 + " -datadir=<dir> \t\t " + _("Specify data directory\n") +
  173 + " -proxy=<ip:port> \t " + _("Connect through socks4 proxy\n") +
  174 + " -addnode=<ip> \t " + _("Add a node to connect to\n") +
  175 + " -connect=<ip> \t\t " + _("Connect only to the specified node\n") +
  176 + " -server \t\t " + _("Accept command line and JSON-RPC commands\n") +
  177 + " -daemon \t\t " + _("Run in the background as a daemon and accept commands\n") +
  178 + " -testnet \t\t " + _("Use the test network\n") +
  179 + " -rpcuser=<user> \t " + _("Username for JSON-RPC connections\n") +
  180 + " -rpcpassword=<pw>\t " + _("Password for JSON-RPC connections\n") +
  181 + " -rpcport=<port> \t\t " + _("Listen for JSON-RPC connections on <port>\n") +
  182 + " -rpcallowip=<ip> \t\t " + _("Allow JSON-RPC connections from specified IP address\n") +
  183 + " -rpcconnect=<ip> \t " + _("Send commands to node running on <ip>\n");
184 184
185 185 #ifdef USE_SSL
186 186 strUsage += string() +
@@ -191,6 +191,9 @@ bool AppInit2(int argc, char* argv[])
191 191 " -rpcsslciphers=<ciphers> \t " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)\n");
192 192 #endif
193 193
  194 + strUsage += string() +
  195 + " -? \t\t " + _("This help message\n");
  196 +
194 197 #if defined(__WXMSW__) && defined(GUI)
195 198 // Tabs make the columns line up in the message box
196 199 wxMessageBox(strUsage, "Bitcoin", wxOK);
@@ -208,6 +211,9 @@ bool AppInit2(int argc, char* argv[])
208 211 if (mapArgs.count("-printtodebugger"))
209 212 fPrintToDebugger = true;
210 213
  214 + if (mapArgs.count("-testnet"))
  215 + fTestNet = true;
  216 +
211 217 if (fCommandLine)
212 218 {
213 219 int ret = CommandLineRPC(argc, argv);
4 irc.cpp
@@ -252,8 +252,8 @@ void ThreadIRCSeed2(void* parg)
252 252 }
253 253 Sleep(500);
254 254
255   - Send(hSocket, "JOIN #bitcoin\r");
256   - Send(hSocket, "WHO #bitcoin\r");
  255 + Send(hSocket, fTestNet ? "JOIN #bitcoinTEST\r" : "JOIN #bitcoin\r");
  256 + Send(hSocket, fTestNet ? "WHO #bitcoinTEST\r" : "WHO #bitcoin\r");
257 257
258 258 int64 nStart = GetTime();
259 259 string strLine;
102 main.cpp
@@ -21,7 +21,8 @@ unsigned int nTransactionsUpdated = 0;
21 21 map<COutPoint, CInPoint> mapNextTx;
22 22
23 23 map<uint256, CBlockIndex*> mapBlockIndex;
24   -const uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f");
  24 +uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f");
  25 +CBigNum bnProofOfWorkLimit(~uint256(0) >> 32);
25 26 CBlockIndex* pindexGenesisBlock = NULL;
26 27 int nBestHeight = -1;
27 28 CBigNum bnBestChainWork = 0;
@@ -1487,12 +1488,13 @@ bool CBlock::AcceptBlock()
1487 1488 return error("AcceptBlock() : contains a non-final transaction");
1488 1489
1489 1490 // Check that the block chain matches the known block chain up to a checkpoint
1490   - if ((nHeight == 11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) ||
1491   - (nHeight == 33333 && hash != uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")) ||
1492   - (nHeight == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a")) ||
1493   - (nHeight == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a")) ||
1494   - (nHeight == 74000 && hash != uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")))
1495   - return error("AcceptBlock() : rejected by checkpoint lockin at %d", nHeight);
  1491 + if (!fTestNet)
  1492 + if ((nHeight == 11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) ||
  1493 + (nHeight == 33333 && hash != uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")) ||
  1494 + (nHeight == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a")) ||
  1495 + (nHeight == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a")) ||
  1496 + (nHeight == 74000 && hash != uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")))
  1497 + return error("AcceptBlock() : rejected by checkpoint lockin at %d", nHeight);
1496 1498
1497 1499 // Write block to history file
1498 1500 if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK)))
@@ -1683,6 +1685,16 @@ FILE* AppendBlockFile(unsigned int& nFileRet)
1683 1685
1684 1686 bool LoadBlockIndex(bool fAllowNew)
1685 1687 {
  1688 + if (fTestNet)
  1689 + {
  1690 + hashGenesisBlock = uint256("0x0000000224b1593e3ff16a0e3b61285bbc393a39f78c8aa48c456142671f7110");
  1691 + bnProofOfWorkLimit = CBigNum(~uint256(0) >> 28);
  1692 + pchMessageStart[0] = 0xfa;
  1693 + pchMessageStart[1] = 0xbf;
  1694 + pchMessageStart[2] = 0xb5;
  1695 + pchMessageStart[3] = 0xda;
  1696 + }
  1697 +
1686 1698 //
1687 1699 // Load block index
1688 1700 //
@@ -1723,13 +1735,19 @@ bool LoadBlockIndex(bool fAllowNew)
1723 1735 block.nBits = 0x1d00ffff;
1724 1736 block.nNonce = 2083236893;
1725 1737
1726   - //// debug print
1727   - printf("%s\n", block.GetHash().ToString().c_str());
1728   - printf("%s\n", hashGenesisBlock.ToString().c_str());
1729   - printf("%s\n", block.hashMerkleRoot.ToString().c_str());
1730   - assert(block.hashMerkleRoot == uint256("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
1731   - block.print();
  1738 + if (fTestNet)
  1739 + {
  1740 + block.nTime = 1279232055;
  1741 + block.nBits = 0x1d07fff8;
  1742 + block.nNonce = 81622180;
  1743 + }
1732 1744
  1745 + //// debug print
  1746 + printf("%s\n", block.GetHash().ToString().c_str());
  1747 + printf("%s\n", hashGenesisBlock.ToString().c_str());
  1748 + printf("%s\n", block.hashMerkleRoot.ToString().c_str());
  1749 + assert(block.hashMerkleRoot == uint256("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
  1750 + block.print();
1733 1751 assert(block.GetHash() == hashGenesisBlock);
1734 1752
1735 1753 // Start new block file
@@ -1963,7 +1981,10 @@ bool AlreadyHave(CTxDB& txdb, const CInv& inv)
1963 1981
1964 1982
1965 1983
1966   -
  1984 +// The message start string is designed to be unlikely to occur in normal data.
  1985 +// The characters are rarely used upper ascii, not valid as UTF-8, and produce
  1986 +// a large 4-byte int at any alignment.
  1987 +char pchMessageStart[4] = { 0xf9, 0xbe, 0xb4, 0xd9 };
1967 1988
1968 1989
1969 1990 bool ProcessMessages(CNode* pfrom)
@@ -2022,19 +2043,14 @@ bool ProcessMessages(CNode* pfrom)
2022 2043 if (nMessageSize > vRecv.size())
2023 2044 {
2024 2045 // Rewind and wait for rest of message
2025   - ///// need a mechanism to give up waiting for overlong message size error
2026 2046 vRecv.insert(vRecv.begin(), vHeaderSave.begin(), vHeaderSave.end());
2027 2047 break;
2028 2048 }
2029 2049
2030   - // Copy message to its own buffer
2031   - CDataStream vMsg(vRecv.begin(), vRecv.begin() + nMessageSize, vRecv.nType, vRecv.nVersion);
2032   - vRecv.ignore(nMessageSize);
2033   -
2034 2050 // Checksum
2035 2051 if (vRecv.GetVersion() >= 209)
2036 2052 {
2037   - uint256 hash = Hash(vMsg.begin(), vMsg.end());
  2053 + uint256 hash = Hash(vRecv.begin(), vRecv.begin() + nMessageSize);
2038 2054 unsigned int nChecksum = 0;
2039 2055 memcpy(&nChecksum, &hash, sizeof(nChecksum));
2040 2056 if (nChecksum != hdr.nChecksum)
@@ -2045,6 +2061,10 @@ bool ProcessMessages(CNode* pfrom)
2045 2061 }
2046 2062 }
2047 2063
  2064 + // Copy message to its own buffer
  2065 + CDataStream vMsg(vRecv.begin(), vRecv.begin() + nMessageSize, vRecv.nType, vRecv.nVersion);
  2066 + vRecv.ignore(nMessageSize);
  2067 +
2048 2068 // Process message
2049 2069 bool fRet = false;
2050 2070 try
@@ -2208,20 +2228,27 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
2208 2228 addr.nTime -= 5 * 24 * 60 * 60;
2209 2229 AddAddress(addr);
2210 2230 pfrom->AddAddressKnown(addr);
2211   - if (!pfrom->fGetAddr && addr.IsRoutable())
  2231 + if (!pfrom->fGetAddr && vAddr.size() <= 10 && addr.IsRoutable())
2212 2232 {
2213 2233 // Relay to a limited number of other nodes
2214 2234 CRITICAL_BLOCK(cs_vNodes)
2215 2235 {
2216   - // Use deterministic randomness to send to
2217   - // the same places for 12 hours at a time
  2236 + // Use deterministic randomness to send to the same nodes for 24 hours
  2237 + // at a time so the setAddrKnowns of the chosen nodes prevent repeats
2218 2238 static uint256 hashSalt;
2219 2239 if (hashSalt == 0)
2220 2240 RAND_bytes((unsigned char*)&hashSalt, sizeof(hashSalt));
2221   - uint256 hashRand = addr.ip ^ ((GetTime()+addr.ip)/(12*60*60)) ^ hashSalt;
  2241 + uint256 hashRand = hashSalt ^ (((int64)addr.ip)<<32) ^ ((GetTime()+addr.ip)/(24*60*60));
  2242 + hashRand = Hash(BEGIN(hashRand), END(hashRand));
2222 2243 multimap<uint256, CNode*> mapMix;
2223 2244 foreach(CNode* pnode, vNodes)
2224   - mapMix.insert(make_pair(hashRand = Hash(BEGIN(hashRand), END(hashRand)), pnode));
  2245 + {
  2246 + unsigned int nPointer;
  2247 + memcpy(&nPointer, &pnode, sizeof(nPointer));
  2248 + uint256 hashKey = hashRand ^ nPointer;
  2249 + hashKey = Hash(BEGIN(hashKey), END(hashKey));
  2250 + mapMix.insert(make_pair(hashKey, pnode));
  2251 + }
2225 2252 int nRelayNodes = 2;
2226 2253 for (multimap<uint256, CNode*>::iterator mi = mapMix.begin(); mi != mapMix.end() && nRelayNodes-- > 0; ++mi)
2227 2254 ((*mi).second)->PushAddress(addr);
@@ -2446,7 +2473,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
2446 2473 foreach(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses)
2447 2474 {
2448 2475 const CAddress& addr = item.second;
2449   - if (addr.nTime > nSince && GetRand(nCount) < 2000)
  2476 + if (addr.nTime > nSince && GetRand(nCount) < 2500)
2450 2477 pfrom->PushAddress(addr);
2451 2478 }
2452 2479 }
@@ -2931,10 +2958,12 @@ void BitcoinMiner()
2931 2958 f4WaySSE2 = (mapArgs["-4way"] != "0");
2932 2959
2933 2960 CReserveKey reservekey;
2934   - CBigNum bnExtraNonce = 0;
  2961 + unsigned int nExtraNonce = 0;
  2962 + int64 nPrevTime = 0;
2935 2963 while (fGenerateBitcoins)
2936 2964 {
2937   - Sleep(50);
  2965 + if (AffinityBugWorkaround(ThreadBitcoinMiner))
  2966 + return;
2938 2967 if (fShutdown)
2939 2968 return;
2940 2969 while (vNodes.empty() || IsInitialBlockDownload())
@@ -2957,7 +2986,13 @@ void BitcoinMiner()
2957 2986 CTransaction txNew;
2958 2987 txNew.vin.resize(1);
2959 2988 txNew.vin[0].prevout.SetNull();
2960   - txNew.vin[0].scriptSig << ++bnExtraNonce;
  2989 + int64 nNow = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
  2990 + if (nNow > nPrevTime+1 && ++nExtraNonce >= 0x7f)
  2991 + {
  2992 + nExtraNonce = 1;
  2993 + nPrevTime = nNow;
  2994 + }
  2995 + txNew.vin[0].scriptSig << nBits << CBigNum(nExtraNonce);
2961 2996 txNew.vout.resize(1);
2962 2997 txNew.vout[0].scriptPubKey << reservekey.GetReservedKey() << OP_CHECKSIG;
2963 2998
@@ -3045,9 +3080,9 @@ void BitcoinMiner()
3045 3080 tmpworkspace& tmp = *(tmpworkspace*)alignup<16>(tmpbuf);
3046 3081
3047 3082 tmp.block.nVersion = pblock->nVersion;
3048   - tmp.block.hashPrevBlock = pblock->hashPrevBlock = (pindexPrev ? pindexPrev->GetBlockHash() : 0);
  3083 + tmp.block.hashPrevBlock = pblock->hashPrevBlock = pindexPrev->GetBlockHash();
3049 3084 tmp.block.hashMerkleRoot = pblock->hashMerkleRoot = pblock->BuildMerkleTree();
3050   - tmp.block.nTime = pblock->nTime = max((pindexPrev ? pindexPrev->GetMedianTimePast()+1 : 0), GetAdjustedTime());
  3085 + tmp.block.nTime = pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
3051 3086 tmp.block.nBits = pblock->nBits = nBits;
3052 3087 tmp.block.nNonce = pblock->nNonce = 0;
3053 3088
@@ -3177,10 +3212,7 @@ void BitcoinMiner()
3177 3212 break;
3178 3213
3179 3214 // Update nTime every few seconds
3180   - int64 nNewTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
3181   - if (nNewTime != pblock->nTime && bnExtraNonce > 10)
3182   - bnExtraNonce = 0;
3183   - pblock->nTime = nNewTime;
  3215 + pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
3184 3216 tmp.block.nTime = ByteReverse(pblock->nTime);
3185 3217 }
3186 3218 }
4 main.h
@@ -22,7 +22,6 @@ static const int64 CENT = 1000000;
22 22 static const int64 MAX_MONEY = 21000000 * COIN;
23 23 inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
24 24 static const int COINBASE_MATURITY = 100;
25   -static const CBigNum bnProofOfWorkLimit(~uint256(0) >> 32);
26 25
27 26
28 27
@@ -31,7 +30,8 @@ static const CBigNum bnProofOfWorkLimit(~uint256(0) >> 32);
31 30
32 31 extern CCriticalSection cs_main;
33 32 extern map<uint256, CBlockIndex*> mapBlockIndex;
34   -extern const uint256 hashGenesisBlock;
  33 +extern uint256 hashGenesisBlock;
  34 +extern CBigNum bnProofOfWorkLimit;
35 35 extern CBlockIndex* pindexGenesisBlock;
36 36 extern int nBestHeight;
37 37 extern CBigNum bnBestChainWork;
2  net.cpp
@@ -937,7 +937,7 @@ void ThreadOpenConnections2(void* parg)
937 937 // Add seed nodes if IRC isn't working
938 938 static bool fSeedUsed;
939 939 bool fTOR = (fUseProxy && addrProxy.port == htons(9050));
940   - if (mapAddresses.empty() && (GetTime() - nStart > 60 || fTOR))
  940 + if (mapAddresses.empty() && (GetTime() - nStart > 60 || fTOR) && !fTestNet)
941 941 {
942 942 for (int i = 0; i < ARRAYLEN(pnSeed); i++)
943 943 {
5 net.h
@@ -48,10 +48,7 @@ bool StopNode();
48 48 // (4) size
49 49 // (4) checksum
50 50
51   -// The message start string is designed to be unlikely to occur in normal data.
52   -// The characters are rarely used upper ascii, not valid as UTF-8, and produce
53   -// a large 4-byte int at any alignment.
54   -static const char pchMessageStart[4] = { 0xf9, 0xbe, 0xb4, 0xd9 };
  51 +extern char pchMessageStart[4];
55 52
56 53 class CMessageHeader
57 54 {
13 script.cpp
@@ -776,16 +776,11 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
776 776 return false;
777 777
778 778 int nKeysCount = CastToBigNum(stacktop(-i)).getint();
779   - if (nKeysCount < 0)
  779 + if (nKeysCount < 0 || nKeysCount > 20)
  780 + return false;
  781 + nOpCount += nKeysCount;
  782 + if (nOpCount > 201)
780 783 return false;
781   - if (nBestHeight > 84000)
782   - {
783   - if (nKeysCount > 20)
784   - return false;
785   - nOpCount += nKeysCount;
786   - if (nOpCount > 201)
787   - return false;
788   - }
789 784 int ikey = ++i;
790 785 i += nKeysCount;
791 786 if (stack.size() < i)
2  serialize.h
@@ -22,7 +22,7 @@ class CDataStream;
22 22 class CAutoFile;
23 23 static const unsigned int MAX_SIZE = 0x02000000;
24 24
25   -static const int VERSION = 31304;
  25 +static const int VERSION = 31305;
26 26 static const char* pszSubVer = "";
27 27
28 28
1  ui.cpp
@@ -763,6 +763,7 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
763 763 SingleLine(strDescription),
764 764 FormatMoney(-nValue, true),
765 765 "");
  766 + nIndex = -1;
766 767 wtx.nLinesDisplayed++;
767 768 }
768 769 }
27 util.cpp
@@ -16,6 +16,7 @@ bool fShutdown = false;
16 16 bool fDaemon = false;
17 17 bool fCommandLine = false;
18 18 string strMiscWarning;
  19 +bool fTestNet = false;
19 20
20 21
21 22
@@ -649,15 +650,11 @@ string GetDefaultDataDir()
649 650 void GetDataDir(char* pszDir)
650 651 {
651 652 // pszDir must be at least MAX_PATH length.
  653 + int nVariation;
652 654 if (pszSetDataDir[0] != 0)
653 655 {
654 656 strlcpy(pszDir, pszSetDataDir, MAX_PATH);
655   - static bool fMkdirDone;
656   - if (!fMkdirDone)
657   - {
658   - fMkdirDone = true;
659   - filesystem::create_directory(pszDir);
660   - }
  657 + nVariation = 0;
661 658 }
662 659 else
663 660 {
@@ -665,11 +662,23 @@ void GetDataDir(char* pszDir)
665 662 // value so we don't have to do memory allocations after that.
666 663 static char pszCachedDir[MAX_PATH];
667 664 if (pszCachedDir[0] == 0)
668   - {
669 665 strlcpy(pszCachedDir, GetDefaultDataDir().c_str(), sizeof(pszCachedDir));
670   - filesystem::create_directory(pszCachedDir);
671   - }
672 666 strlcpy(pszDir, pszCachedDir, MAX_PATH);
  667 + nVariation = 1;
  668 + }
  669 + if (fTestNet)
  670 + {
  671 + char* p = pszDir + strlen(pszDir);
  672 + if (p > pszDir && p[-1] != '/' && p[-1] != '\\')
  673 + *p++ = '/';
  674 + strcpy(p, "testnet");
  675 + nVariation += 2;
  676 + }
  677 + static bool pfMkdir[4];
  678 + if (!pfMkdir[nVariation])
  679 + {
  680 + pfMkdir[nVariation] = true;
  681 + filesystem::create_directory(pszDir);
673 682 }
674 683 }
675 684
25 util.h
@@ -145,6 +145,7 @@ extern bool fShutdown;
145 145 extern bool fDaemon;
146 146 extern bool fCommandLine;
147 147 extern string strMiscWarning;
  148 +extern bool fTestNet;
148 149
149 150 void RandAddSeed();
150 151 void RandAddSeedPerfmon();
@@ -621,3 +622,27 @@ inline void ExitThread(unsigned int nExitCode)
621 622 pthread_exit((void*)nExitCode);
622 623 }
623 624 #endif
  625 +
  626 +
  627 +
  628 +
  629 +
  630 +inline bool AffinityBugWorkaround(void(*pfn)(void*))
  631 +{
  632 +#ifdef __WXMSW__
  633 + // Sometimes after a few hours affinity gets stuck on one processor
  634 + DWORD dwProcessAffinityMask = -1;
  635 + DWORD dwSystemAffinityMask = -1;
  636 + GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSystemAffinityMask);
  637 + DWORD dwPrev1 = SetThreadAffinityMask(GetCurrentThread(), dwProcessAffinityMask);
  638 + DWORD dwPrev2 = SetThreadAffinityMask(GetCurrentThread(), dwProcessAffinityMask);
  639 + if (dwPrev2 != dwProcessAffinityMask)
  640 + {
  641 + printf("AffinityBugWorkaround() : SetThreadAffinityMask=%d, ProcessAffinityMask=%d, restarting thread\n", dwPrev2, dwProcessAffinityMask);
  642 + if (!CreateThread(pfn, NULL))
  643 + printf("Error: CreateThread() failed\n");
  644 + return true;
  645 + }
  646 +#endif
  647 + return false;
  648 +}

0 comments on commit 5cbf753

Please sign in to comment.
Something went wrong with that request. Please try again.