all signers:
antecedents:
press order:
patch:
(2139 . 12)(2139 . 12)- 565FAF3EF371F5E2178AE30C45B08B93415EEB92263486E68F2AC2E8F4C7900056E628804BF5C0707A90BE946E0AEAEBFCD0A391AAB40DE2E5D56E6BCBDCCB1E
5 vnThreadsRunning[4]--;
6 PrintException(NULL, "ThreadRPCServer()");
7 }
8 printf("ThreadRPCServer exiting\n");
9 printf(SINF SNET "rpc server thread exiting\n");
10 }
11
12 void ThreadRPCServer2(void* parg)
13 {
14 printf("ThreadRPCServer started\n");
15 printf(SINF SNET "rpc server thread started\n");
16
17 strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"];
18 if (strRPCUserColonPass == ":")
(2207 . 7)(2207 . 7)
20 if (!api_caller.timed_join(boost::posix_time::seconds(GetArg("-rpctimeout", 30))))
21 { // Timed out:
22 acceptor.cancel();
23 printf("ThreadRPCServer ReadHTTP timeout\n");
24 printf(SINF SNET "rpc server thread timeout\n");
25 continue;
26 }
27
(2219 . 7)(2219 . 7)
29 }
30 if (!HTTPAuthorized(mapHeaders))
31 {
32 printf("ThreadRPCServer incorrect password attempt from %s\n",peer.address().to_string().c_str());
33 printf(SWAR SNET "incorrect rpc password attempt from %s\n",peer.address().to_string().c_str());
34 /* Deter brute-forcing short passwords.
35 If this results in a DOS the user really
36 shouldn't have their RPC port exposed.*/
(2250 . 7)(2250 . 7)
38 throw JSONRPCError(-32600, "Method must be a string");
39 string strMethod = valMethod.get_str();
40 if (strMethod != "getwork" && strMethod != "getmemorypool")
41 printf("ThreadRPCServer method=%s\n", strMethod.c_str());
42 printf(SINF SNET "rpc server received request using method %s\n", strMethod.c_str());
43
44 // Parse params
45 Value valParams = find_value(request, "params");
(40 . 7)(40 . 7)- 3AD5A434F08B5029A39BB0E57216A37AE0047CAF1F05CB2984796E9C80FC4CEB9FB9FFE3CA067C9BFFB12FFE465E3D92408A79A5E940C66253A358F393B6C29F
50 }
51 catch (const DbException& e)
52 {
53 printf("EnvShutdown exception: %s (%d)\n", e.what(), e.get_errno());
54 printf(SWAR SPRC "shutdown exception: %s (%d)\n", e.what(), e.get_errno());
55 }
56 DbEnv(0).remove(GetDataDir().c_str(), 0);
57 }
(81 . 7)(81 . 8)
59 string strLogDir = strDataDir + "/database";
60 filesystem::create_directory(strLogDir.c_str());
61 string strErrorFile = strDataDir + "/db.log";
62 printf("dbenv.open strLogDir=%s strErrorFile=%s\n", strLogDir.c_str(), strErrorFile.c_str());
63 printf(SINF SBLK "using database directory: %s\n", strLogDir.c_str());
64 printf(SINF SBLK "using database log: %s\n", strErrorFile.c_str());
65
66 dbenv.set_lg_dir(strLogDir.c_str());
67 dbenv.set_lg_max(1000000);
(196 . 7)(197 . 7)
69 mapFileUseCount.erase(strFile);
70
71 bool fSuccess = true;
72 printf("Rewriting %s...\n", strFile.c_str());
73 printf(SWAR SBLK "rewriting database file %s\n", strFile.c_str());
74 string strFileRes = strFile + ".rewrite";
75 { // surround usage of db with extra {}
76 CDB db(strFile.c_str(), "r");
(210 . 7)(211 . 7)
78 0);
79 if (ret > 0)
80 {
81 printf("Cannot create database file %s\n", strFileRes.c_str());
82 printf(SERR SBLK "can't create database file %s\n", strFileRes.c_str());
83 fSuccess = false;
84 }
85
(266 . 7)(267 . 7)
87 fSuccess = false;
88 }
89 if (!fSuccess)
90 printf("Rewriting of %s FAILED!\n", strFileRes.c_str());
91 printf(SERR SBLK "rewriting of database file %s\n", strFileRes.c_str());
92 return fSuccess;
93 }
94 }
(280 . 7)(281 . 7)
96 {
97 // Flush log data to the actual data file
98 // on all files that are not in use
99 printf("DBFlush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started");
100 printf(SINF SBLK "flushing log data. %s\n", fShutdown ? "shutting down" : "");
101 if (!fDbEnvInit)
102 return;
103 CRITICAL_BLOCK(cs_db)
(290 . 13)(291 . 13)
105 {
106 string strFile = (*mi).first;
107 int nRefCount = (*mi).second;
108 printf("%s refcount=%d\n", strFile.c_str(), nRefCount);
109 printf(SINF SBLK "database file %s has refcount %d\n", strFile.c_str(), nRefCount);
110 if (nRefCount == 0)
111 {
112 // Move log data to the dat file
113 CloseDb(strFile);
114 dbenv.txn_checkpoint(0, 0, 0);
115 printf("%s flush\n", strFile.c_str());
116 printf(SINF SBLK "flushing database file %s\n", strFile.c_str());
117 dbenv.lsn_reset(strFile.c_str(), 0);
118 mapFileUseCount.erase(mi++);
119 }
(540 . 7)(541 . 7)
121 pindexGenesisBlock = pindexNew;
122
123 if (!pindexNew->CheckIndex())
124 return error("LoadBlockIndex() : CheckIndex failed at %d", pindexNew->nHeight);
125 return error(SBLK "block index check failed at height %d", pindexNew->nHeight);
126 }
127 else
128 {
(569 . 14)(570 . 14)
130 {
131 if (pindexGenesisBlock == NULL)
132 return true;
133 return error("CTxDB::LoadBlockIndex() : hashBestChain not loaded");
134 return error(SBLK "chain tip loading failed");
135 }
136 if (!mapBlockIndex.count(hashBestChain))
137 return error("CTxDB::LoadBlockIndex() : hashBestChain not found in the block index");
138 return error(SBLK "chain tip %s not found in the block index", hashBestChain.ToString().c_str());
139 pindexBest = mapBlockIndex[hashBestChain];
140 nBestHeight = pindexBest->nHeight;
141 bnBestChainWork = pindexBest->bnChainWork;
142 printf("LoadBlockIndex(): hashBestChain=%s height=%d\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight);
143 printf(SINF SBLK "chain tip %s at height %d\n", hashBestChain.ToString().c_str(), nBestHeight);
144
145 // Load bnBestInvalidWork, OK if it doesn't exist
146 ReadBestInvalidWork(bnBestInvalidWork);
(589 . 20)(590 . 22)
148 break;
149 CBlock block;
150 if (!block.ReadFromDisk(pindex))
151 return error("LoadBlockIndex() : block.ReadFromDisk failed");
152 return error(SBLK "block loading from disk failed");
153 if (!block.CheckBlock())
154 {
155 printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
156 printf(SWAR SBLK "found bad block %s at height %d\n",
157 pindex->GetBlockHash().ToString().c_str(), pindex->nHeight);
158 pindexFork = pindex->pprev;
159 }
160 }
161 if (pindexFork)
162 {
163 // Reorg back to the fork
164 printf("LoadBlockIndex() : *** moving best chain pointer back to block %d\n", pindexFork->nHeight);
165 printf(SINF SBLK "setting best chain pointer to block %s at height %d\n",
166 pindexFork->GetBlockHash().ToString().c_str(), pindexFork->nHeight);
167 CBlock block;
168 if (!block.ReadFromDisk(pindexFork))
169 return error("LoadBlockIndex() : block.ReadFromDisk failed");
170 return error(SBLK "block loading from disk failed");
171 CTxDB txdb;
172 block.SetBestChain(txdb, pindexFork);
173 }
(660 . 7)(663 . 7)
175 }
176 pcursor->close();
177
178 printf("Loaded %d addresses\n", mapAddresses.size());
179 printf(SINF SADR "loaded %d addresses\n", mapAddresses.size());
180 }
181
182 return true;
(814 . 7)(817 . 7)
184 wtx.pwallet = pwallet;
185
186 if (wtx.GetHash() != hash)
187 printf("Error in wallet.dat, hash mismatch\n");
188 printf(SERR SWAL "hash mismatch in wallet.dat\n");
189
190 // Undo serialize changes in 31600
191 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
(824 . 12)(827 . 12)
193 char fTmp;
194 char fUnused;
195 ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
196 printf("LoadWallet() upgrading tx ver=%d %d '%s' %s\n", wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount.c_str(), hash.ToString().c_str());
197 printf(SINF SWAL "upgrading tx version to %d\n", wtx.fTimeReceivedIsTxTime);
198 wtx.fTimeReceivedIsTxTime = fTmp;
199 }
200 else
201 {
202 printf("LoadWallet() repairing tx ver=%d %s\n", wtx.fTimeReceivedIsTxTime, hash.ToString().c_str());
203 printf(SWAR SWAL "repairing tx version %d\n", wtx.fTimeReceivedIsTxTime);
204 wtx.fTimeReceivedIsTxTime = 0;
205 }
206 vWalletUpgrade.push_back(hash);
(943 . 13)(946 . 15)
208 BOOST_FOREACH(uint256 hash, vWalletUpgrade)
209 WriteTx(hash, pwallet->mapWallet[hash]);
210
211 printf("nFileVersion = %d\n", nFileVersion);
212 printf("fGenerateBitcoins = %d\n", fGenerateBitcoins);
213 printf("nTransactionFee = %"PRI64d"\n", nTransactionFee);
214 printf("fMinimizeToTray = %d\n", fMinimizeToTray);
215 printf("fMinimizeOnClose = %d\n", fMinimizeOnClose);
216 printf("fUseProxy = %d\n", fUseProxy);
217 printf("addrProxy = %s\n", addrProxy.ToString().c_str());
218 printf(SINF SWAL "file version is %d\n", nFileVersion);
219
220 if (fGenerateBitcoins)
221 printf(SINF SMIN "miner was activated\n");
222
223 printf(SINF SMEM "transaction fee is %"PRI64d"\n", nTransactionFee);
224
225 if (fUseProxy)
226 printf(SINF SNET "connecting through proxy on address %s\n", addrProxy.ToString().c_str());
227
228 // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
229 if (fIsEncrypted && (nFileVersion == 40000 || nFileVersion == 50000))
(1008 . 8)(1013 . 7)
231 map<string, int>::iterator mi = mapFileUseCount.find(strFile);
232 if (mi != mapFileUseCount.end())
233 {
234 printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
235 printf("Flushing wallet.dat\n");
236 printf(SWAR SWAL "flushing wallet.dat\n");
237 nLastFlushed = nWalletDBUpdated;
238 int64 nStart = GetTimeMillis();
239
(1019 . 7)(1023 . 7)
241 dbenv.lsn_reset(strFile.c_str(), 0);
242
243 mapFileUseCount.erase(mi++);
244 printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart);
245 printf(SWAR SWAL "flushed wallet.dat in %"PRI64d"ms\n", GetTimeMillis() - nStart);
246 }
247 }
248 }
(1053 . 7)(1057 . 7)
250 #else
251 filesystem::copy_file(pathSrc, pathDest);
252 #endif
253 printf("copied wallet.dat to %s\n", pathDest.string().c_str());
254 printf(SINF SWAL "copied wallet.dat to %s\n", pathDest.string().c_str());
255
256 return true;
257 }
(50 . 7)(50 . 7)- 02CCC72E42939509FC180861DB7FFEC50563A84869F35671FCF720090F9782674EDCC89C4174175691566FAC7277F1EBE0F50253D1E4A995EB960F5B43CCE2A3
262 delete pwalletMain;
263 CreateThread(ExitTimeout, NULL);
264 Sleep(50);
265 printf("Bitcoin exiting\n\n");
266 printf(SINF SPRC "bitcoind exiting\n");
267 fExit = true;
268 exit(0);
269 }
(262 . 9)(262 . 8)
271 fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
272 }
273
274 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
275 printf("Bitcoin version %s\n", FormatFullVersion().c_str());
276 printf("Default data directory %s\n", GetDefaultDataDir().c_str());
277 printf(SINF SPRC "bitcoind %s starting\n", FormatFullVersion().c_str());
278 printf(SINF SPRC "using data directory: %s\n", GetDataDir().c_str());
279
280 if (GetBoolArg("-loadblockindextest"))
281 {
(296 . 21)(295 . 21)
283 int64 nStart;
284
285 InitMessage(_("Loading addresses..."));
286 printf("Loading addresses...\n");
287 printf(SINF SADR "loading addresses\n");
288 nStart = GetTimeMillis();
289 if (!LoadAddresses())
290 strErrors += _("Error loading addr.dat \n");
291 printf(" addresses %15"PRI64d"ms\n", GetTimeMillis() - nStart);
292 printf(SINF SADR "loaded addresses in %"PRI64d"ms\n", GetTimeMillis() - nStart);
293
294 InitMessage(_("Loading block index..."));
295 printf("Loading block index...\n");
296 printf(SINF SBLK "loading block index\n");
297 nStart = GetTimeMillis();
298 if (!LoadBlockIndex())
299 strErrors += _("Error loading blkindex.dat \n");
300 printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart);
301 printf(SINF SBLK "loaded block index in %"PRI64d"ms\n", GetTimeMillis() - nStart);
302
303 InitMessage(_("Loading wallet..."));
304 printf("Loading wallet...\n");
305 printf(SINF SWAL "loading wallet\n");
306 nStart = GetTimeMillis();
307 bool fFirstRun;
308 pwalletMain = new CWallet("wallet.dat");
(330 . 7)(329 . 7)
310 else
311 strErrors += _("Error loading wallet.dat \n");
312 }
313 printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart);
314 printf(SINF SWAL "loaded wallet in %"PRI64d"ms\n", GetTimeMillis() - nStart);
315
316 RegisterWallet(pwalletMain);
317
(347 . 21)(346 . 21)
319 if (pindexBest != pindexRescan)
320 {
321 InitMessage(_("Rescanning..."));
322 printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
323 printf(SINF SBLK "rescanning last %i blocks from block %i\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
324 nStart = GetTimeMillis();
325 pwalletMain->ScanForWalletTransactions(pindexRescan, true);
326 printf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart);
327 printf(SINF SBLK "rescanned in %"PRI64d"ms\n", GetTimeMillis() - nStart);
328 }
329
330 InitMessage(_("Done loading"));
331 printf("Done loading\n");
332 printf(SINF SPRC "done loading\n");
333
334 //// debug print
335 printf("mapBlockIndex.size() = %d\n", mapBlockIndex.size());
336 printf("nBestHeight = %d\n", nBestHeight);
337 printf("setKeyPool.size() = %d\n", pwalletMain->setKeyPool.size());
338 printf("mapWallet.size() = %d\n", pwalletMain->mapWallet.size());
339 printf("mapAddressBook.size() = %d\n", pwalletMain->mapAddressBook.size());
340 printf(SINF SBLK "block index size: %d\n", mapBlockIndex.size());
341 printf(SINF SBLK "best height: %d\n", nBestHeight);
342 printf(SINF SWAL "keypool size: %d\n", pwalletMain->setKeyPool.size());
343 printf(SINF SWAL "wallet size: %d\n", pwalletMain->mapWallet.size());
344 printf(SINF SADR "address index size: %d\n", pwalletMain->mapAddressBook.size());
345
346 if (!strErrors.empty())
347 {
(406 . 12)(405 . 11)
349 block.ReadFromDisk(pindex);
350 block.BuildMerkleTree();
351 block.print();
352 printf("\n");
353 nFound++;
354 }
355 }
356 if (nFound == 0)
357 printf("No blocks matching %s were found\n", strMatch.c_str());
358 printf(SERR SBLK "no blocks matching %s were found\n", strMatch.c_str());
359 return false;
360 }
361
(213 . 7)(213 . 7)- FF2BF8F8147DD8DF5E1EF1BCEA9B0159D3F83C1E30BEFEF56415B99305AA99161AC1C05EFB48BE87A383FFB6D621FD3761BFB3E4952CA244A6E1398CA3C71DC6
366 {
367 vMerkleBranch.clear();
368 nIndex = -1;
369 printf("ERROR: SetMerkleBranch() : couldn't find tx in block\n");
370 printf(SERR SBLK "couldn't set merkle branch, tx not included in a block\n");
371 return 0;
372 }
373
(242 . 24)(242 . 29)
375 {
376 // Basic checks that don't depend on any context
377 if (vin.empty())
378 return DoS(10, error("CTransaction::CheckTransaction() : vin empty"));
379 return DoS(10, error(SMEM "tx %s validation failed, no inputs",
380 GetHash().ToString().c_str()));
381 if (vout.empty())
382 return DoS(10, error("CTransaction::CheckTransaction() : vout empty"));
383 return DoS(10, error(SMEM "tx %s validation failed, no ouputs",
384 GetHash().ToString().c_str()));
385 // Size limits
386 if (::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE)
387 return DoS(100, error("CTransaction::CheckTransaction() : size limits failed"));
388
389 return DoS(100, error(SMEM "tx %s validation failed, size limits failed",
390 GetHash().ToString().c_str()));
391 // Check for negative or overflow output values
392 int64 nValueOut = 0;
393 BOOST_FOREACH(const CTxOut& txout, vout)
394 {
395 if (txout.nValue < 0)
396 return DoS(100, error("CTransaction::CheckTransaction() : txout.nValue negative"));
397 return DoS(100, error(SMEM "tx %s validation failed, output amount is negative",
398 GetHash().ToString().c_str()));
399 if (txout.nValue > MAX_MONEY)
400 return DoS(100, error("CTransaction::CheckTransaction() : txout.nValue too high"));
401 return DoS(100, error(SMEM "tx %s validation failed, output amount out of range",
402 GetHash().ToString().c_str()));
403 nValueOut += txout.nValue;
404 if (!MoneyRange(nValueOut))
405 return DoS(100, error("CTransaction::CheckTransaction() : txout total out of range"));
406 return DoS(100, error(SMEM "tx %s validation failed, total output amount out of range",
407 GetHash().ToString().c_str()));
408 }
409
410 // Check for duplicate inputs
(267 . 20)(272 . 23)
412 BOOST_FOREACH(const CTxIn& txin, vin)
413 {
414 if (vInOutPoints.count(txin.prevout))
415 return false;
416 return error(SMEM "tx %s validation failed, duplicate input found",
417 GetHash().ToString().c_str());
418 vInOutPoints.insert(txin.prevout);
419 }
420
421 if (IsCoinBase())
422 {
423 if (vin[0].scriptSig.size() < 2 || vin[0].scriptSig.size() > 100)
424 return DoS(100, error("CTransaction::CheckTransaction() : coinbase script size"));
425 return DoS(100, error(SMEM "tx %s validation failed, coinbase script size out of range",
426 GetHash().ToString().c_str()));
427 }
428 else
429 {
430 BOOST_FOREACH(const CTxIn& txin, vin)
431 if (txin.prevout.IsNull())
432 return DoS(10, error("CTransaction::CheckTransaction() : prevout is null"));
433 return DoS(10, error(SMEM "tx %s validation failed, input specifies no previous output",
434 GetHash().ToString().c_str()));
435 }
436
437 return true;
(292 . 15)(300 . 17)
439 *pfMissingInputs = false;
440
441 if (!CheckTransaction())
442 return error("AcceptToMemoryPool() : CheckTransaction failed");
443 return error(SMEM "tx %s rejected", GetHash().ToString().c_str());
444
445 // Coinbase is only valid in a block, not as a loose transaction
446 if (IsCoinBase())
447 return DoS(100, error("AcceptToMemoryPool() : coinbase as individual tx"));
448 return DoS(100, error(SMEM "tx %s rejected, coinbase individual tx",
449 GetHash().ToString().c_str()));
450
451 // To help v0.1.5 clients who would see it as a negative number
452 if ((int64)nLockTime > INT_MAX)
453 return error("AcceptToMemoryPool() : not accepting nLockTime beyond 2038 yet");
454 return error(SMEM "tx %s rejected, locktime out of range",
455 GetHash().ToString().c_str());
456
457 // Safety limits
458 unsigned int nSize = ::GetSerializeSize(*this, SER_NETWORK);
(309 . 11)(319 . 13)
460 // 34 bytes because a TxOut is:
461 // 20-byte address + 8 byte bitcoin amount + 5 bytes of ops + 1 byte script length
462 if (GetSigOpCount() > nSize / 34 || nSize < 100)
463 return error("AcceptToMemoryPool() : transaction with out-of-bounds SigOpCount");
464 return error(SMEM "tx %s rejected, sigop count out of range",
465 GetHash().ToString().c_str());
466
467 // Rather not work on nonstandard transactions
468 if (!IsStandard())
469 return error("AcceptToMemoryPool() : nonstandard transaction type");
470 return error(SMEM "tx %s rejected, non-standard tx",
471 GetHash().ToString().c_str());
472
473 // Do we already have it?
474 uint256 hash = GetHash();
(361 . 13)(373 . 13)
476 if (!ConnectInputs(txdb, mapUnused, CDiskTxPos(1,1,1), pindexBest, nFees, false, false, 0, fInvalid))
477 {
478 if (fInvalid)
479 return error("AcceptToMemoryPool() : FetchInputs found invalid tx %s", hash.ToString().substr(0,10).c_str());
480 return error("AcceptToMemoryPool() : ConnectInputs failed %s", hash.ToString().substr(0,10).c_str());
481 return error(SMEM "tx %s rejected, invalid input", hash.ToString().c_str());
482 return error(SMEM "tx %s rejected, input not found", hash.ToString().c_str());
483 }
484
485 // Don't accept it if it can't get into a block
486 if (nFees < GetMinFee(1000, true, true))
487 return error("AcceptToMemoryPool() : not enough fees");
488 return error(SMEM "tx %s rejected, not enough fees", hash.ToString().c_str());
489
490 // Continuously rate-limit free transactions
491 // This mitigates 'penny-flooding' -- sending thousands of free transactions just to
(387 . 9)(399 . 10)
493 // -limitfreerelay unit is thousand-bytes-per-minute
494 // At default rate it would take over a month to fill 1GB
495 if (dFreeCount > GetArg("-limitfreerelay", 15)*10*1000 && !IsFromMe(*this))
496 return error("AcceptToMemoryPool() : free transaction rejected by rate limiter");
497 return error(SMEM "tx %s rejected, free tx",
498 hash.ToString().c_str());
499 if (fDebug)
500 printf("Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize);
501 printf(SINF SMEM "updated free tx rate limit from %g to %g\n", dFreeCount, dFreeCount+nSize);
502 dFreeCount += nSize;
503 }
504 }
(400 . 7)(413 . 8)
506 {
507 if (ptxOld)
508 {
509 printf("AcceptToMemoryPool() : replacing tx %s with new version\n", ptxOld->GetHash().ToString().c_str());
510 printf(SWAR SMEM "replacing tx %s with new tx %s\n", ptxOld->GetHash().ToString().c_str(),
511 hash.ToString().c_str());
512 ptxOld->RemoveFromMemoryPool();
513 }
514 AddToMemoryPoolUnchecked();
(411 . 7)(425 . 7)
516 if (ptxOld)
517 EraseFromWallets(ptxOld->GetHash());
518
519 printf("AcceptToMemoryPool(): accepted %s\n", hash.ToString().substr(0,10).c_str());
520 printf(SINF SMEM "accepted tx %s\n", hash.ToString().c_str());
521 return true;
522 }
523
(576 . 7)(590 . 7)
525 if (!ReadFromDisk(pindex->nFile, pindex->nBlockPos, fReadTransactions))
526 return false;
527 if (GetHash() != pindex->GetBlockHash())
528 return error("CBlock::ReadFromDisk() : GetHash() doesn't match index");
529 return error(SBLK "block %s doesn't match index", GetHash().ToString().c_str());
530 return true;
531 }
532
(636 . 7)(650 . 7)
534
535 // Limit adjustment step
536 int64 nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
537 printf(" nActualTimespan = %"PRI64d" before bounds\n", nActualTimespan);
538 printf(SINF SBLK "actual timestamp before bounds is %"PRI64d"\n", nActualTimespan);
539 if (nActualTimespan < nTargetTimespan/4)
540 nActualTimespan = nTargetTimespan/4;
541 if (nActualTimespan > nTargetTimespan*4)
(652 . 10)(666 . 11)
543 bnNew = bnProofOfWorkLimit;
544
545 /// debug print
546 printf("GetNextWorkRequired RETARGET\n");
547 printf("nTargetTimespan = %"PRI64d" nActualTimespan = %"PRI64d"\n", nTargetTimespan, nActualTimespan);
548 printf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString().c_str());
549 printf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str());
550 printf(SINF SBLK "retargetting\n");
551 printf(SINF SBLK "target timestamp is %"PRI64d" and actual timespan is %"PRI64d"\n", nTargetTimespan, nActualTimespan);
552 printf(SINF SBLK "before: %08x %s\n", pindexLast->nBits,
553 CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString().c_str());
554 printf(SINF SBLK "after: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str());
555
556 return bnNew.GetCompact();
557 }
(667 . 11)(682 . 11)
559
560 // Check range
561 if (bnTarget <= 0 || bnTarget > bnProofOfWorkLimit)
562 return error("CheckProofOfWork() : nBits below minimum work");
563 return error(SBLK "pow %s work below minimum (%u)", hash.ToString().c_str(), nBits);
564
565 // Check proof of work matches claimed amount
566 if (hash > bnTarget.getuint256())
567 return error("CheckProofOfWork() : hash doesn't match nBits");
568 return error(SBLK "pow %s hash doesn't match work (%u)", hash.ToString().c_str(), nBits);
569
570 return true;
571 }
(705 . 10)(720 . 13)
573 CTxDB().WriteBestInvalidWork(bnBestInvalidWork);
574 MainFrameRepaint();
575 }
576 printf("InvalidChainFound: invalid block=%s height=%d work=%s\n", pindexNew->GetBlockHash().ToString().substr(0,20).c_str(), pindexNew->nHeight, pindexNew->bnChainWork.ToString().c_str());
577 printf("InvalidChainFound: current best=%s height=%d work=%s\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight, bnBestChainWork.ToString().c_str());
578 printf(SERR SBLK "invalid chain tip %s at height %d with work %s\n",
579 pindexNew->GetBlockHash().ToString().c_str(), pindexNew->nHeight,
580 pindexNew->bnChainWork.ToString().c_str());
581 printf(SINF SBLK "best chain tip %s at height %d with work %s\n",
582 hashBestChain.ToString().c_str(), nBestHeight, bnBestChainWork.ToString().c_str());
583 if (pindexBest && bnBestInvalidWork > bnBestChainWork + pindexBest->GetBlockWork() * 6)
584 printf("InvalidChainFound: WARNING: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.\n");
585 printf(SWAR SBLK "displayed transactions may not be correct, there's chain discrepancy between this and other nodes\n");
586 }
587
588
(733 . 17)(751 . 19)
590 // Get prev txindex from disk
591 CTxIndex txindex;
592 if (!txdb.ReadTxIndex(prevout.hash, txindex))
593 return error("DisconnectInputs() : ReadTxIndex failed");
594 return error(SMEM "input referenced non-existing output %d from tx %s",
595 prevout.n, prevout.hash.ToString().c_str());
596
597 if (prevout.n >= txindex.vSpent.size())
598 return error("DisconnectInputs() : prevout.n out of range");
599 return error(SMEM "input referenced out of range output %d from tx %s ",
600 prevout.n, prevout.hash.ToString().c_str());
601
602 // Mark outpoint as not spent
603 txindex.vSpent[prevout.n].SetNull();
604
605 // Write back
606 if (!txdb.UpdateTxIndex(prevout.hash, txindex))
607 return error("DisconnectInputs() : UpdateTxIndex failed");
608 return error(SMEM "tx index can't be updated");
609 }
610 }
611
(792 . 7)(812 . 8)
613 fFound = txdb.ReadTxIndex(prevout.hash, txindex);
614 }
615 if (!fFound && (fBlock || fMiner))
616 return fMiner ? false : error("ConnectInputs() : %s prev tx %s index entry not found", GetHash().ToString().substr(0,10).c_str(), prevout.hash.ToString().substr(0,10).c_str());
617 return fMiner ? false : error(SMEM "tx %s not found in index",
618 prevout.hash.ToString().c_str());
619
620 // Read txPrev
621 CTransaction txPrev;
(802 . 7)(823 . 8)
623 CRITICAL_BLOCK(cs_mapTransactions)
624 {
625 if (!mapTransactions.count(prevout.hash))
626 return error("ConnectInputs() : %s mapTransactions prev not found %s", GetHash().ToString().substr(0,10).c_str(), prevout.hash.ToString().substr(0,10).c_str());
627 return error(SMEM "tx %s not found in memory pool",
628 prevout.hash.ToString().c_str());
629 txPrev = mapTransactions[prevout.hash];
630 }
631 if (!fFound)
(812 . 7)(834 . 8)
633 {
634 // Get prev tx from disk
635 if (!txPrev.ReadFromDisk(txindex.pos))
636 return error("ConnectInputs() : %s ReadFromDisk prev tx %s failed", GetHash().ToString().substr(0,10).c_str(), prevout.hash.ToString().substr(0,10).c_str());
637 return error(SMEM "tx %s not found in disk",
638 prevout.hash.ToString().c_str());
639 }
640
641 if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size())
(820 . 14)(843 . 16)
643 // Revisit this if/when transaction replacement is implemented and allows
644 // adding inputs:
645 fInvalid = true;
646 return DoS(100, error("ConnectInputs() : %s prevout.n out of range %d %d %d prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str()));
647 return DoS(100, error(SMEM "output %d from tx %s is out of range",
648 prevout.n, prevout.hash.ToString().c_str()));
649 }
650
651 // If prev is coinbase, check that it's matured
652 if (txPrev.IsCoinBase())
653 for (CBlockIndex* pindex = pindexBlock; pindex && pindexBlock->nHeight - pindex->nHeight < COINBASE_MATURITY; pindex = pindex->pprev)
654 if (pindex->nBlockPos == txindex.pos.nBlockPos && pindex->nFile == txindex.pos.nFile)
655 return error("ConnectInputs() : tried to spend coinbase at depth %d", pindexBlock->nHeight - pindex->nHeight);
656 return error(SMEM "tx %s tried to spend coinbase at depth %d",
657 GetHash().ToString().c_str(), pindexBlock->nHeight - pindex->nHeight);
658
659 // Skip ECDSA signature verification when connecting blocks (fBlock=true)
660 // before the last blockchain checkpoint. This is safe because block merkle hashes are
(835 . 18)(860 . 21)
662 if (fVerifyAll || (!(fBlock && (nBestHeight < Checkpoints::GetTotalBlocksEstimate()))))
663 // Verify signature
664 if (!VerifySignature(txPrev, *this, i))
665 return DoS(100,error("ConnectInputs() : %s VerifySignature failed", GetHash().ToString().substr(0,10).c_str()));
666 return DoS(100,error(SMEM "tx %s signature verification failed",
667 GetHash().ToString().c_str()));
668
669 // Check for conflicts (double-spend)
670 // This doesn't trigger the DoS code on purpose; if it did, it would make it easier
671 // for an attacker to attempt to split the network.
672 if (!txindex.vSpent[prevout.n].IsNull())
673 return fMiner ? false : error("ConnectInputs() : %s prev tx already used at %s", GetHash().ToString().substr(0,10).c_str(), txindex.vSpent[prevout.n].ToString().c_str());
674 return fMiner ? false : error(SMEM "output %d from tx %s already spent",
675 prevout.n, prevout.hash.ToString().c_str());
676
677 // Check for negative or overflow input values
678 nValueIn += txPrev.vout[prevout.n].nValue;
679 if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn))
680 return DoS(100, error("ConnectInputs() : txin values out of range"));
681 return DoS(100, error(SMEM "output %d from tx %s contains out of range amount",
682 prevout.n, prevout.hash.ToString().c_str()));
683
684 // Mark outpoints as spent
685 txindex.vSpent[prevout.n] = posThisTx;
(858 . 18)(886 . 20)
687 }
688 }
689
690 if (nValueIn < GetValueOut())
691 return DoS(100, error("ConnectInputs() : %s value in < value out", GetHash().ToString().substr(0,10).c_str()));
692 int64 nValueOut = GetValueOut();
693 if (nValueIn < nValueOut)
694 return DoS(100, error(SMEM "tx %s output amount is greater than input amount",
695 GetHash().ToString().c_str()));
696
697 // Tally transaction fees
698 int64 nTxFee = nValueIn - GetValueOut();
699 int64 nTxFee = nValueIn - nValueOut;
700 if (nTxFee < 0)
701 return DoS(100, error("ConnectInputs() : %s nTxFee < 0", GetHash().ToString().substr(0,10).c_str()));
702 return DoS(100, error(SMEM "tx %s fee is negative", GetHash().ToString().c_str()));
703 if (nTxFee < nMinFee)
704 return false;
705 nFees += nTxFee;
706 if (!MoneyRange(nFees))
707 return DoS(100, error("ConnectInputs() : nFees out of range"));
708 return DoS(100, error(SMEM "tx %s fee is out of range", GetHash().ToString().c_str()));
709 }
710
711 if (fBlock)
(909 . 7)(939 . 8)
713
714 // Verify signature
715 if (!VerifySignature(txPrev, *this, i))
716 return error("ConnectInputs() : VerifySignature failed");
717 return error(SMEM "tx %s signature verification against tx %s failed",
718 GetHash().ToString().c_str(), txPrev.GetHash().ToString().c_str());
719
720 ///// this is redundant with the mapNextTx stuff, not sure which I want to get rid of
721 ///// this has to go away now that posNext is gone
(923 . 7)(954 . 8)
723 nValueIn += txPrev.vout[prevout.n].nValue;
724
725 if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn))
726 return error("ClientConnectInputs() : txin values out of range");
727 return error(SMEM "tx %s input amounts are out of range",
728 GetHash().ToString().c_str());
729 }
730 if (GetValueOut() > nValueIn)
731 return false;
(949 . 7)(981 . 7)
733 CDiskBlockIndex blockindexPrev(pindex->pprev);
734 blockindexPrev.hashNext = 0;
735 if (!txdb.WriteBlockIndex(blockindexPrev))
736 return error("DisconnectBlock() : WriteBlockIndex failed");
737 return error(SBLK "writing to block index failed while disconnecting block");
738 }
739
740 return true;
(998 . 7)(1030 . 7)
742 for (map<uint256, CTxIndex>::iterator mi = mapQueuedChanges.begin(); mi != mapQueuedChanges.end(); ++mi)
743 {
744 if (!txdb.UpdateTxIndex((*mi).first, (*mi).second))
745 return error("ConnectBlock() : UpdateTxIndex failed");
746 return error(SMEM "tx index update failed");
747 }
748
749 if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees))
(1011 . 7)(1043 . 7)
751 CDiskBlockIndex blockindexPrev(pindex->pprev);
752 blockindexPrev.hashNext = pindex->GetBlockHash();
753 if (!txdb.WriteBlockIndex(blockindexPrev))
754 return error("ConnectBlock() : WriteBlockIndex failed");
755 return error(SBLK "writing to block index failed while connecting block");
756 }
757
758 // Watch for transactions paying to me
(1023 . 7)(1055 . 7)
760
761 bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew)
762 {
763 printf("REORGANIZE\n");
764 printf(SINF SBLK "reorganizing block index\n");
765
766 // Find the fork
767 CBlockIndex* pfork = pindexBest;
(1032 . 11)(1064 . 11)
769 {
770 while (plonger->nHeight > pfork->nHeight)
771 if (!(plonger = plonger->pprev))
772 return error("Reorganize() : plonger->pprev is null");
773 return error(SBLK "invalid pointer to previous block from longest chain tip");
774 if (pfork == plonger)
775 break;
776 if (!(pfork = pfork->pprev))
777 return error("Reorganize() : pfork->pprev is null");
778 return error(SBLK "invalid pointer to previous block from new longest chain tip");
779 }
780
781 // List of what to disconnect
(1056 . 9)(1088 . 9)
783 {
784 CBlock block;
785 if (!block.ReadFromDisk(pindex))
786 return error("Reorganize() : ReadFromDisk for disconnect failed");
787 return error(SBLK "block loading from disk failed while trying to disconnect block");
788 if (!block.DisconnectBlock(txdb, pindex))
789 return error("Reorganize() : DisconnectBlock failed");
790 return error(SBLK "block index reorganization failed while trying to disconnect block");
791
792 // Queue memory transactions to resurrect
793 BOOST_FOREACH(const CTransaction& tx, block.vtx)
(1073 . 12)(1105 . 12)
795 CBlockIndex* pindex = vConnect[i];
796 CBlock block;
797 if (!block.ReadFromDisk(pindex))
798 return error("Reorganize() : ReadFromDisk for connect failed");
799 return error(SBLK "block loading from disk failed while trying to connect block");
800 if (!block.ConnectBlock(txdb, pindex))
801 {
802 // Invalid block
803 txdb.TxnAbort();
804 return error("Reorganize() : ConnectBlock failed");
805 return error(SBLK "block index reorganization failed while trying to connect block");
806 }
807
808 // Queue memory transactions to delete
(1086 . 11)(1118 . 11)
810 vDelete.push_back(tx);
811 }
812 if (!txdb.WriteHashBestChain(pindexNew->GetBlockHash()))
813 return error("Reorganize() : WriteHashBestChain failed");
814 return error(SBLK "block writing to index failed while trying to save best chain");
815
816 // Make sure it's successfully written to disk before changing memory structure
817 if (!txdb.TxnCommit())
818 return error("Reorganize() : TxnCommit failed");
819 return error(SMEM "tx index commitment failed while reorganizing block index");
820
821 // Disconnect shorter branch
822 BOOST_FOREACH(CBlockIndex* pindex, vDisconnect)
(1123 . 7)(1155 . 7)
824 {
825 txdb.WriteHashBestChain(hash);
826 if (!txdb.TxnCommit())
827 return error("SetBestChain() : TxnCommit failed");
828 return error(SMEM "tx index commitment failed while setting best chain");
829 pindexGenesisBlock = pindexNew;
830 }
831 else if (hashPrevBlock == hashBestChain)
(1133 . 10)(1165 . 10)
833 {
834 txdb.TxnAbort();
835 InvalidChainFound(pindexNew);
836 return error("SetBestChain() : ConnectBlock failed");
837 return error(SBLK "block connecting failed while setting best chain");
838 }
839 if (!txdb.TxnCommit())
840 return error("SetBestChain() : TxnCommit failed");
841 return error(SMEM "tx index commitment failed while setting best chain");
842
843 // Add to current best branch
844 pindexNew->pprev->pnext = pindexNew;
(1152 . 7)(1184 . 7)
846 {
847 txdb.TxnAbort();
848 InvalidChainFound(pindexNew);
849 return error("SetBestChain() : Reorganize failed");
850 return error(SBLK "block reorganization failed while setting best chain");
851 }
852 }
853
(1170 . 7)(1202 . 7)
855 bnBestChainWork = pindexNew->bnChainWork;
856 nTimeBestReceived = GetTime();
857 nTransactionsUpdated++;
858 printf("SetBestChain: new best=%s height=%d work=%s\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight, bnBestChainWork.ToString().c_str());
859 printf(SINF SBLK "chain tip %s at height %d\n", hashBestChain.ToString().c_str(), nBestHeight);
860
861 return true;
862 }
(1181 . 12)(1213 . 12)
864 // Check for duplicate
865 uint256 hash = GetHash();
866 if (mapBlockIndex.count(hash))
867 return error("AddToBlockIndex() : %s already exists", hash.ToString().substr(0,20).c_str());
868 return error(SBLK "block %s already exists in block index", hash.ToString().c_str());
869
870 // Construct new block index object
871 CBlockIndex* pindexNew = new CBlockIndex(nFile, nBlockPos, *this);
872 if (!pindexNew)
873 return error("AddToBlockIndex() : new CBlockIndex failed");
874 return error(SBLK "block index initialization failed");
875 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
876 pindexNew->phashBlock = &((*mi).first);
877 map<uint256, CBlockIndex*>::iterator miPrev = mapBlockIndex.find(hashPrevBlock);
(1232 . 35)(1264 . 36)
879
880 // Size limits
881 if (vtx.empty() || vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE)
882 return DoS(100, error("CheckBlock() : size limits failed"));
883 return DoS(100, error(SBLK "block %s size is out of range", GetHash().ToString().c_str()));
884
885 // Check proof of work matches claimed amount
886 if (!CheckProofOfWork(GetHash(), nBits))
887 return DoS(50, error("CheckBlock() : proof of work failed"));
888 uint256 hash = GetHash();
889 if (!CheckProofOfWork(hash, nBits))
890 return DoS(50, error(SBLK "block %s proof of work is invalid", hash.ToString().c_str()));
891
892 // Check timestamp
893 if (GetBlockTime() > GetAdjustedTime() + 2 * 60 * 60)
894 return error("CheckBlock() : block timestamp too far in the future");
895 return error(SBLK "block %s timestamp is too far in the future", hash.ToString().c_str());
896
897 // First transaction must be coinbase, the rest must not be
898 if (vtx.empty() || !vtx[0].IsCoinBase())
899 return DoS(100, error("CheckBlock() : first tx is not coinbase"));
900 return DoS(100, error(SBLK "block %s first tx is not a coinbase tx", hash.ToString().c_str()));
901 for (int i = 1; i < vtx.size(); i++)
902 if (vtx[i].IsCoinBase())
903 return DoS(100, error("CheckBlock() : more than one coinbase"));
904 return DoS(100, error(SBLK "block %s has more than one coinbase tx", hash.ToString().c_str()));
905
906 // Check transactions
907 BOOST_FOREACH(const CTransaction& tx, vtx)
908 if (!tx.CheckTransaction())
909 return DoS(tx.nDoS, error("CheckBlock() : CheckTransaction failed"));
910 return DoS(tx.nDoS, error(SBLK "block %s tx check failed", hash.ToString().c_str()));
911
912 // Check that it's not full of nonstandard transactions
913 if (GetSigOpCount() > MAX_BLOCK_SIGOPS)
914 return DoS(100, error("CheckBlock() : out-of-bounds SigOpCount"));
915 return DoS(100, error(SBLK "block %s sigopt count out of range", hash.ToString().c_str()));
916
917 // Check merkleroot
918 if (hashMerkleRoot != BuildMerkleTree())
919 return DoS(100, error("CheckBlock() : hashMerkleRoot mismatch"));
920 return DoS(100, error(SBLK "block %s merkle root hash mistmatch", hash.ToString().c_str()));
921
922 return true;
923 }
(1270 . 41)(1303 . 42)
925 // Check for duplicate
926 uint256 hash = GetHash();
927 if (mapBlockIndex.count(hash))
928 return error("AcceptBlock() : block already in mapBlockIndex");
929 return error(SBLK "block %s already in block index", hash.ToString().c_str());
930
931 // Get prev block index
932 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashPrevBlock);
933 if (mi == mapBlockIndex.end())
934 return DoS(10, error("AcceptBlock() : prev block not found"));
935 return DoS(10, error(SBLK "block %s not found in index",
936 hashPrevBlock.ToString().c_str()));
937 CBlockIndex* pindexPrev = (*mi).second;
938 int nHeight = pindexPrev->nHeight+1;
939
940 // Check proof of work
941 if (nBits != GetNextWorkRequired(pindexPrev, this))
942 return DoS(100, error("AcceptBlock() : incorrect proof of work"));
943 return DoS(100, error(SBLK "block %s proof of work is invalid", hash.ToString().c_str()));
944
945 // Check timestamp against prev
946 if (GetBlockTime() <= pindexPrev->GetMedianTimePast())
947 return error("AcceptBlock() : block's timestamp is too early");
948 return error(SBLK "block %s timestamp is too early", hash.ToString().c_str());
949
950 // Check that all transactions are finalized
951 BOOST_FOREACH(const CTransaction& tx, vtx)
952 if (!tx.IsFinal(nHeight, GetBlockTime()))
953 return DoS(10, error("AcceptBlock() : contains a non-final transaction"));
954 return DoS(10, error(SBLK "block %s contains a non-final tx", hash.ToString().c_str()));
955
956 // Check that the block chain matches the known block chain up to a checkpoint
957 if (!Checkpoints::CheckBlock(nHeight, hash))
958 return DoS(100, error("AcceptBlock() : rejected by checkpoint lockin at %d", nHeight));
959 return DoS(100, error(SBLK "block %s rejected by checkpoint locking at height %d", hash.ToString().c_str(), nHeight));
960
961 // Write block to history file
962 if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK)))
963 return error("AcceptBlock() : out of disk space");
964 return error(SBLK "block %s writing to disk failure due out of space", hash.ToString().c_str());
965 unsigned int nFile = -1;
966 unsigned int nBlockPos = 0;
967 if (!WriteToDisk(nFile, nBlockPos))
968 return error("AcceptBlock() : WriteToDisk failed");
969 return error(SBLK "block %s writing to disk failure", hash.ToString().c_str());
970 if (!AddToBlockIndex(nFile, nBlockPos))
971 return error("AcceptBlock() : AddToBlockIndex failed");
972 return error(SBLK "block %s write to block index failure", hash.ToString().c_str());
973
974 // Relay inventory, but don't relay old inventory during initial block download
975 if (hashBestChain == hash)
(1321 . 11)(1355 . 12)
977 // Check for duplicate
978 uint256 hash = pblock->GetHash();
979 if (mapBlockIndex.count(hash))
980 return error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString().substr(0,20).c_str());
981 return error(SBLK "block %s already in index at height %d",
982 hash.ToString().c_str(), mapBlockIndex[hash]->nHeight);
983
984 // Preliminary checks
985 if (!pblock->CheckBlock())
986 return error("ProcessBlock() : CheckBlock FAILED");
987 return error(SBLK "block %s check failed", hash.ToString().c_str());
988
989 CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(mapBlockIndex);
990 if (pcheckpoint && pblock->hashPrevBlock != hashBestChain)
(1336 . 7)(1371 . 8)
992 {
993 if (pfrom)
994 pfrom->Misbehaving(100);
995 return error("ProcessBlock() : block with timestamp before last checkpoint");
996 return error(SBLK "block %s timestamp is lower than last checkpint",
997 hash.ToString().c_str());
998 }
999 CBigNum bnNewBlock;
1000 bnNewBlock.SetCompact(pblock->nBits);
(1346 . 14)(1382 . 16)
1002 {
1003 if (pfrom)
1004 pfrom->Misbehaving(100);
1005 return error("ProcessBlock() : block with too little proof-of-work");
1006 return error(SBLK "block %s proof-of-work is insufficient",
1007 hash.ToString().c_str());
1008 }
1009 }
1010
1011 // If don't already have its previous block, throw it out!
1012 if (!mapBlockIndex.count(pblock->hashPrevBlock))
1013 {
1014 printf("ProcessBlock: BASTARD BLOCK, prev=%s, DISCARDED\n", pblock->hashPrevBlock.ToString().substr(0,20).c_str());
1015 printf(SWAR SBLK "found bastard block %s referencing previous block %s, will now be discarded\n",
1016 hash.ToString().c_str(), pblock->hashPrevBlock.ToString().c_str());
1017
1018 // Ask this guy to fill in what we're missing
1019 if (pfrom)
(1364 . 9)(1402 . 9)
1021
1022 // Store to disk
1023 if (!pblock->AcceptBlock())
1024 return error("ProcessBlock() : AcceptBlock FAILED");
1025 return error(SBLK "block %s rejected", hash.ToString().c_str());
1026
1027 printf("ProcessBlock: ACCEPTED\n");
1028 printf(SINF SBLK "block %s accepted\n", hash.ToString().c_str());
1029 return true;
1030 }
1031
(1385 . 10)(1423 . 7)
1033 if (nFreeBytesAvailable < (uint64)15000000 + nAdditionalBytes)
1034 {
1035 fShutdown = true;
1036 string strMessage = _("Warning: Disk space is low ");
1037 strMiscWarning = strMessage;
1038 printf("*** %s\n", strMessage.c_str());
1039 ThreadSafeMessageBox(strMessage, "Bitcoin", wxOK | wxICON_EXCLAMATION);
1040 printf(SWAR SPRC "disk space low\n");
1041 CreateThread(Shutdown, NULL);
1042 return false;
1043 }
(1479 . 9)(1514 . 9)
1045 block.nNonce = 2083236893;
1046
1047 //// debug print
1048 printf("%s\n", block.GetHash().ToString().c_str());
1049 printf("%s\n", hashGenesisBlock.ToString().c_str());
1050 printf("%s\n", block.hashMerkleRoot.ToString().c_str());
1051 printf(SINF SBLK "loaded genesis block %s\n", block.GetHash().ToString().c_str());
1052 printf(SINF SBLK "block hash should be %s\n", hashGenesisBlock.ToString().c_str());
1053 printf(SINF SBLK "merkle root is %s\n", block.hashMerkleRoot.ToString().c_str());
1054 assert(block.hashMerkleRoot == uint256("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
1055 block.print();
1056 assert(block.GetHash() == hashGenesisBlock);
(1490 . 9)(1525 . 9)
1058 unsigned int nFile;
1059 unsigned int nBlockPos;
1060 if (!block.WriteToDisk(nFile, nBlockPos))
1061 return error("LoadBlockIndex() : writing genesis block to disk failed");
1062 return error(SBLK "genesis block writing to disk failure");
1063 if (!block.AddToBlockIndex(nFile, nBlockPos))
1064 return error("LoadBlockIndex() : genesis block not accepted");
1065 return error(SBLK "genesis block rejected");
1066 }
1067
1068 return true;
(1549 . 7)(1584 . 7)
1070 pindex->nHeight,
1071 pindex->nFile,
1072 pindex->nBlockPos,
1073 block.GetHash().ToString().substr(0,20).c_str(),
1074 block.GetHash().ToString().c_str(),
1075 DateTimeStrFormat("%x %H:%M:%S", block.GetBlockTime()).c_str(),
1076 block.vtx.size());
1077
(1641 . 12)(1676 . 11)
1079 static map<unsigned int, vector<unsigned char> > mapReuseKey;
1080 RandAddSeedPerfmon();
1081 if (fDebug) {
1082 printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
1083 printf("received: %s (%d bytes)\n", strCommand.c_str(), vRecv.size());
1084 printf(SINF SNET "received %s (%d bytes)\n", strCommand.c_str(), vRecv.size());
1085 }
1086 if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
1087 {
1088 printf("dropmessagestest DROPPING RECV MESSAGE\n");
1089 printf(SWAR SNET "dropping test message\n");
1090 return true;
1091 }
1092
(1683 . 7)(1717 . 7)
1094 // Disconnect if we connected to ourself
1095 if (nNonce == nLocalHostNonce && nNonce > 1)
1096 {
1097 printf("connected to self at %s, disconnecting\n", pfrom->addr.ToString().c_str());
1098 printf(SINF SNET "connected to self at %s, disconnecting\n", pfrom->addr.ToString().c_str());
1099 pfrom->fDisconnect = true;
1100 return true;
1101 }
(1733 . 7)(1767 . 7)
1103
1104 pfrom->fSuccessfullyConnected = true;
1105
1106 printf("version message: version %d, blocks=%d\n", pfrom->nVersion, pfrom->nStartingHeight);
1107 printf(SINF SNET "received version %d, height %d\n", pfrom->nVersion, pfrom->nStartingHeight);
1108
1109 cPeerBlockCounts.input(pfrom->nStartingHeight);
1110 }
(1766 . 7)(1800 . 7)
1112 if (vAddr.size() > 1000)
1113 {
1114 pfrom->Misbehaving(20);
1115 return error("message addr size() = %d", vAddr.size());
1116 return error(SNET "addr message size out of range. (%d)", vAddr.size());
1117 }
1118
1119 // Store the new addresses
(1827 . 7)(1861 . 7)
1121 if (vInv.size() > 50000)
1122 {
1123 pfrom->Misbehaving(20);
1124 return error("message inv size() = %d", vInv.size());
1125 return error(SNET "inv message size out of range. (%d)", vInv.size());
1126 }
1127
1128 CTxDB txdb("r");
(1839 . 7)(1873 . 8)
1130
1131 bool fAlreadyHave = AlreadyHave(txdb, inv);
1132 if (fDebug)
1133 printf(" got inventory: %s %s\n", inv.ToString().c_str(), fAlreadyHave ? "have" : "new");
1134 printf(SINF SNET "received%s: %s\n",
1135 fAlreadyHave ? " already seen" : " new", inv.ToString().c_str());
1136
1137 if (!fAlreadyHave)
1138 pfrom->AskFor(inv);
(1857 . 14)(1892 . 14)
1140 if (vInv.size() > 50000)
1141 {
1142 pfrom->Misbehaving(20);
1143 return error("message getdata size() = %d", vInv.size());
1144 return error(SNET "getdata message size out of range. (%d)", vInv.size());
1145 }
1146
1147 BOOST_FOREACH(const CInv& inv, vInv)
1148 {
1149 if (fShutdown)
1150 return true;
1151 printf("received getdata for: %s\n", inv.ToString().c_str());
1152 printf(SINF SNET "received getdata %s\n", inv.ToString().c_str());
1153
1154 if (inv.type == MSG_BLOCK)
1155 {
(1902 . 7)(1937 . 8)
1157 else
1158 {
1159 pfrom->Misbehaving(100);
1160 return error("BANNED peer issuing unknown inv type.");
1161 return error(SNET "peer %s banned for issuing unknown inv message type",
1162 pfrom->addr.ToString().c_str());
1163 }
1164
1165 // Track requests for our stuff
(1925 . 12)(1961 . 14)
1167 pindex = pindex->pnext;
1168 int nLimit = 500 + locator.GetDistanceBack();
1169 unsigned int nBytes = 0;
1170 printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20).c_str(), nLimit);
1171 printf(SINF SNET "received getblocks height %d, block %s, limit %d\n",
1172 (pindex ? pindex->nHeight : -1), hashStop.ToString().c_str(), nLimit);
1173 for (; pindex; pindex = pindex->pnext)
1174 {
1175 if (pindex->GetBlockHash() == hashStop)
1176 {
1177 printf(" getblocks stopping at %d %s (%u bytes)\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str(), nBytes);
1178 printf(SINF SNET "getblocks response stopping on block %s at height %d. (%u bytes)\n",
1179 pindex->GetBlockHash().ToString().c_str(), pindex->nHeight, nBytes);
1180 break;
1181 }
1182 pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash()));
(1941 . 7)(1979 . 8)
1184 {
1185 // When this block is requested, we'll send an inv that'll make them
1186 // getblocks the next batch of inventory.
1187 printf(" getblocks stopping at limit %d %s (%u bytes)\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str(), nBytes);
1188 printf(SINF SNET "getblocks response stopping on block %s at height %d. (%u bytes)\n",
1189 pindex->nHeight, pindex->GetBlockHash().ToString().c_str(), nBytes);
1190 pfrom->hashContinue = pindex->GetBlockHash();
1191 break;
1192 }
(1974 . 7)(2013 . 8)
1194
1195 vector<CBlock> vHeaders;
1196 int nLimit = 2000 + locator.GetDistanceBack();
1197 printf("getheaders %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20).c_str(), nLimit);
1198 printf(SINF SNET "received getheaders height %d, block %s, limit %d\n",
1199 (pindex ? pindex->nHeight : -1), hashStop.ToString().c_str(), nLimit);
1200 for (; pindex; pindex = pindex->pnext)
1201 {
1202 vHeaders.push_back(pindex->GetBlockHeader());
(2005 . 7)(2045 . 7)
1204 }
1205 else if (fMissingInputs)
1206 {
1207 printf("REJECTED orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str());
1208 printf(SWAR SNET "tx %s rejected as orphan\n", inv.hash.ToString().c_str());
1209 }
1210 if (tx.nDoS) pfrom->Misbehaving(tx.nDoS);
1211 }
(2016 . 7)(2056 . 7)
1213 CBlock block;
1214 vRecv >> block;
1215
1216 printf("received block %s\n", block.GetHash().ToString().substr(0,20).c_str());
1217 printf(SINF SNET "received block %s\n", block.GetHash().ToString().c_str());
1218 // block.print();
1219
1220 CInv inv(MSG_BLOCK, block.GetHash());
(2108 . 7)(2148 . 8)
1222 {
1223 // He who comes to us with a turd, by the turd shall perish.
1224 pfrom->Misbehaving(100);
1225 return error("BANNED peer issuing heathen command.");
1226 return error(SNET "peer %s banned for issuing unknown message",
1227 pfrom->addr.ToString().c_str());
1228 }
1229
1230
(2147 . 13)(2188 . 13)
1232 {
1233 if (vRecv.size() > nHeaderSize)
1234 {
1235 printf("\n\nPROCESSMESSAGE MESSAGESTART NOT FOUND\n\n");
1236 printf(SWAR SNET "message start couldn't be found while processing message\n");
1237 vRecv.erase(vRecv.begin(), vRecv.end() - nHeaderSize);
1238 }
1239 break;
1240 }
1241 if (pstart - vRecv.begin() > 0)
1242 printf("\n\nPROCESSMESSAGE SKIPPED %d BYTES\n\n", pstart - vRecv.begin());
1243 printf(SWAR SNET "skipped %d bytes while processing message\n", pstart - vRecv.begin());
1244 vRecv.erase(vRecv.begin(), pstart);
1245
1246 // Read header
(2162 . 7)(2203 . 7)
1248 vRecv >> hdr;
1249 if (!hdr.IsValid())
1250 {
1251 printf("\n\nPROCESSMESSAGE: ERRORS IN HEADER %s\n\n\n", hdr.GetCommand().c_str());
1252 printf(SERR SNET "errors found in message %s header while processing message\n", hdr.GetCommand().c_str());
1253 continue;
1254 }
1255 string strCommand = hdr.GetCommand();
(2171 . 7)(2212 . 7)
1257 unsigned int nMessageSize = hdr.nMessageSize;
1258 if (nMessageSize > MAX_SIZE)
1259 {
1260 printf("ProcessMessage(%s, %u bytes) : nMessageSize > MAX_SIZE\n", strCommand.c_str(), nMessageSize);
1261 printf(SERR SNET "message %s size out of range. (%u bytes)\n", strCommand.c_str(), nMessageSize);
1262 continue;
1263 }
1264 if (nMessageSize > vRecv.size())
(2189 . 8)(2230 . 9)
1266 memcpy(&nChecksum, &hash, sizeof(nChecksum));
1267 if (nChecksum != hdr.nChecksum)
1268 {
1269 printf("ProcessMessage(%s, %u bytes) : CHECKSUM ERROR nChecksum=%08x hdr.nChecksum=%08x\n",
1270 strCommand.c_str(), nMessageSize, nChecksum, hdr.nChecksum);
1271 printf(SERR SNET "message %s checksum error while processing message"
1272 " (%u bytes, checksum %08x, header checksum %08x)\n",
1273 strCommand.c_str(), nMessageSize, nChecksum, hdr.nChecksum);
1274 continue;
1275 }
1276 }
(2213 . 12)(2255 . 15)
1278 if (strstr(e.what(), "end of data"))
1279 {
1280 // Allow exceptions from underlength message on vRecv
1281 printf("ProcessMessage(%s, %u bytes) : Exception '%s' caught, normally caused by a message being shorter than its stated length\n", strCommand.c_str(), nMessageSize, e.what());
1282 printf(SERR SNET "message %s caught exception '%s' while processing message,"
1283 " normally caused by a message being shorter than its stated length. (%u bytes)\n",
1284 strCommand.c_str(), e.what(), nMessageSize);
1285 }
1286 else if (strstr(e.what(), "size too large"))
1287 {
1288 // Allow exceptions from overlong size
1289 printf("ProcessMessage(%s, %u bytes) : Exception '%s' caught\n", strCommand.c_str(), nMessageSize, e.what());
1290 printf(SERR SNET "message %s caught exception '%s' while processing message. (%u bytes)\n",
1291 strCommand.c_str(), e.what(), nMessageSize);
1292 }
1293 else
1294 {
(2232 . 7)(2277 . 7)
1296 }
1297
1298 if (!fRet)
1299 printf("ProcessMessage(%s, %u bytes) FAILED\n", strCommand.c_str(), nMessageSize);
1300 printf(SWAR SNET "failed to process message %s. (%u bytes)\n", strCommand.c_str(), nMessageSize);
1301 }
1302
1303 vRecv.Compact();
(2403 . 7)(2448 . 7)
1305 const CInv& inv = (*pto->mapAskFor.begin()).second;
1306 if (!AlreadyHave(txdb, inv))
1307 {
1308 printf("sending getdata: %s\n", inv.ToString().c_str());
1309 printf(SINF SNET "sending getdata %s\n", inv.ToString().c_str());
1310 vGetData.push_back(inv);
1311 if (vGetData.size() >= 1000)
1312 {
(2595 . 7)(2640 . 8)
1314 dPriority += (double)nValueIn * nConf;
1315
1316 if (fDebug && GetBoolArg("-printpriority"))
1317 printf("priority nValueIn=%-12I64d nConf=%-5d dPriority=%-20.1f\n", nValueIn, nConf, dPriority);
1318 printf(SINF SMEM "priority: %-20.1f, tx inputs value: %-12I64d, confirmations: %-5d\n",
1319 dPriority, nValueIn, nConf);
1320 }
1321
1322 // Priority is sum(valuein * age) / txsize
(2608 . 10)(2654 . 9)
1324
1325 if (fDebug && GetBoolArg("-printpriority"))
1326 {
1327 printf("priority %-20.1f %s\n%s", dPriority, tx.GetHash().ToString().substr(0,10).c_str(), tx.ToString().c_str());
1328 printf(SINF SMEM "tx %s priority is %-20.1f\n", tx.GetHash().ToString().c_str(), dPriority);
1329 if (porphan)
1330 porphan->print();
1331 printf("\n");
1332 }
1333 }
1334
(2750 . 17)(2795 . 15)
1336 return false;
1337
1338 //// debug print
1339 printf("BitcoinMiner:\n");
1340 printf("proof-of-work found \n hash: %s \ntarget: %s\n", hash.GetHex().c_str(), hashTarget.GetHex().c_str());
1341 printf(SINF SMIN "miner found proof-of-work %s with target %s\n", hash.GetHex().c_str(), hashTarget.GetHex().c_str());
1342 pblock->print();
1343 printf("%s ", DateTimeStrFormat("%x %H:%M", GetTime()).c_str());
1344 printf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str());
1345 printf(SINF SMIN "miner generated %s bitcoin\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str());
1346
1347 // Found a solution
1348 CRITICAL_BLOCK(cs_main)
1349 {
1350 if (pblock->hashPrevBlock != hashBestChain)
1351 return error("BitcoinMiner : generated block is stale");
1352 return error(SMIN "miner generated a stale block %s", hash.ToString().c_str());
1353
1354 // Remove key from key pool
1355 reservekey.KeepKey();
(2771 . 7)(2814 . 7)
1357
1358 // Process this block the same as if we had received it from another node
1359 if (!ProcessBlock(NULL, pblock))
1360 return error("BitcoinMiner : ProcessBlock, block not accepted");
1361 return error(SMIN "miner rejected block %s", hash.ToString().c_str());
1362 }
1363
1364 return true;
(2781 . 7)(2824 . 7)
1366
1367 void static BitcoinMiner(CWallet *pwallet)
1368 {
1369 printf("BitcoinMiner started\n");
1370 printf(SINF SMIN "miner started\n");
1371 SetThreadPriority(THREAD_PRIORITY_LOWEST);
1372
1373 // Each thread has its own key and counter
(2815 . 7)(2858 . 7)
1375 return;
1376 IncrementExtraNonce(pblock.get(), pindexPrev, nExtraNonce);
1377
1378 printf("Running BitcoinMiner with %d transactions in block\n", pblock->vtx.size());
1379 printf(SINF SMIN "miner running with %d transactions in block\n", pblock->vtx.size());
1380
1381
1382 //
(2941 . 7)(2984 . 7)
1384 nHPSTimerStart = 0;
1385 if (vnThreadsRunning[3] == 0)
1386 dHashesPerSec = 0;
1387 printf("ThreadBitcoinMiner exiting, %d threads remaining\n", vnThreadsRunning[3]);
1388 printf(SINF SMIN "miner thread exiting, %d threads remaining\n", vnThreadsRunning[3]);
1389 }
1390
1391
(2956 . 17)(2999 . 17)
1393 if (fGenerateBitcoins)
1394 {
1395 int nProcessors = boost::thread::hardware_concurrency();
1396 printf("%d processors\n", nProcessors);
1397 printf(SINF SMIN "miner using %d processors\n", nProcessors);
1398 if (nProcessors < 1)
1399 nProcessors = 1;
1400 if (fLimitProcessors && nProcessors > nLimitProcessors)
1401 nProcessors = nLimitProcessors;
1402 int nAddThreads = nProcessors - vnThreadsRunning[3];
1403 printf("Starting %d BitcoinMiner threads\n", nAddThreads);
1404 printf(SINF SMIN "miner starting %d threads\n", nAddThreads);
1405 for (int i = 0; i < nAddThreads; i++)
1406 {
1407 if (!CreateThread(ThreadBitcoinMiner, pwallet))
1408 printf("Error: CreateThread(ThreadBitcoinMiner) failed\n");
1409 printf(SERR SMIN "miner can't create thread\n");
1410 Sleep(10);
1411 }
1412 }
(497 . 10)(497 . 10)- 31EB2CBDF4F83F10AE8A7CDD3A69312BA6EAFBECFAFBEDDF7546CE99847BD4F2A674037E2B89A0A7B91C37127D9770501C265A7977EDB0AE0B3A5964272692F9
1417 {
1418 BOOST_FOREACH(const CTxIn& txin, vin)
1419 if (!txin.scriptSig.IsPushOnly())
1420 return error("nonstandard txin: %s", txin.scriptSig.ToString().c_str());
1421 return error(SMEM "non-standard input %s", txin.scriptSig.ToString().c_str());
1422 BOOST_FOREACH(const CTxOut& txout, vout)
1423 if (!::IsStandard(txout.scriptPubKey))
1424 return error("nonstandard txout: %s", txout.scriptPubKey.ToString().c_str());
1425 return error(SMEM "non-standard output %s", txout.scriptPubKey.ToString().c_str());
1426 return true;
1427 }
1428
(573 . 18)(573 . 20)
1430 {
1431 CAutoFile filein = OpenBlockFile(pos.nFile, 0, pfileRet ? "rb+" : "rb");
1432 if (!filein)
1433 return error("CTransaction::ReadFromDisk() : OpenBlockFile failed");
1434 return error(SBLK "failure reading block file %d from disk", pos.nFile);
1435
1436 // Read transaction
1437 if (fseek(filein, pos.nTxPos, SEEK_SET) != 0)
1438 return error("CTransaction::ReadFromDisk() : fseek failed");
1439 return error(SBLK "failure reading block file %d from disk at position %d",
1440 pos.nFile, pos.nTxPos);
1441 filein >> *this;
1442
1443 // Return file pointer
1444 if (pfileRet)
1445 {
1446 if (fseek(filein, pos.nTxPos, SEEK_SET) != 0)
1447 return error("CTransaction::ReadFromDisk() : second fseek failed");
1448 return error(SBLK "second failure reading block file %d from disk at position %d",
1449 pos.nFile, pos.nTxPos);
1450 *pfileRet = filein.release();
1451 }
1452 return true;
(906 . 7)(908 . 7)
1454 // Open history file to append
1455 CAutoFile fileout = AppendBlockFile(nFileRet);
1456 if (!fileout)
1457 return error("CBlock::WriteToDisk() : AppendBlockFile failed");
1458 return error(SBLK "failure wrting block file %d to disk", nFileRet);
1459
1460 // Write index header
1461 unsigned int nSize = fileout.GetSerializeSize(*this);
(111 . 33)(111 . 33)- BB842420BCC67752EDF8E658524B135F499C5F8676557A6C12F47F204303E34BD73BEABDF6E9146BA452947C4E5CD298529969FAB90F16942F6BF0C1229F7043
1466 int nRet = select(hSocket + 1, NULL, &fdset, NULL, &timeout);
1467 if (nRet == 0)
1468 {
1469 printf("connection timeout\n");
1470 printf(SERR SNET "connection timeout\n");
1471 closesocket(hSocket);
1472 return false;
1473 }
1474 if (nRet == SOCKET_ERROR)
1475 {
1476 printf("select() for connection failed: %i\n",WSAGetLastError());
1477 printf(SERR SNET "select connection failed: %i\n", WSAGetLastError());
1478 closesocket(hSocket);
1479 return false;
1480 }
1481 socklen_t nRetSize = sizeof(nRet);
1482 if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) == SOCKET_ERROR)
1483 {
1484 printf("getsockopt() for connection failed: %i\n",WSAGetLastError());
1485 printf(SERR SNET "getsockopt for connection failed: %i\n", WSAGetLastError());
1486 closesocket(hSocket);
1487 return false;
1488 }
1489 if (nRet != 0)
1490 {
1491 printf("connect() failed after select(): %s\n",strerror(nRet));
1492 printf(SERR SNET "connect failed after select: %s\n", strerror(nRet));
1493 closesocket(hSocket);
1494 return false;
1495 }
1496 }
1497 else
1498 {
1499 printf("connect() failed: %i\n",WSAGetLastError());
1500 printf(SERR SNET "connect failed: %i\n", WSAGetLastError());
1501 closesocket(hSocket);
1502 return false;
1503 }
(157 . 7)(157 . 7)
1505
1506 if (fProxy)
1507 {
1508 printf("proxy connecting %s\n", addrConnect.ToString().c_str());
1509 printf(SWAR SNET "connecting through proxy to %s\n", addrConnect.ToString().c_str());
1510 char pszSocks4IP[] = "\4\1\0\0\0\0\0\0user";
1511 memcpy(pszSocks4IP + 2, &addrConnect.port, 2);
1512 memcpy(pszSocks4IP + 4, &addrConnect.ip, 4);
(168 . 22)(168 . 24)
1514 if (ret != nSize)
1515 {
1516 closesocket(hSocket);
1517 return error("Error sending to proxy");
1518 return error(SNET "couldn't send message over proxy address %s",
1519 addrConnect.ToString().c_str());
1520 }
1521 char pchRet[8];
1522 if (recv(hSocket, pchRet, 8, 0) != 8)
1523 {
1524 closesocket(hSocket);
1525 return error("Error reading proxy response");
1526 return error(SNET "couldn't read response over proxy address %s",
1527 addrConnect.ToString().c_str());
1528 }
1529 if (pchRet[1] != 0x5a)
1530 {
1531 closesocket(hSocket);
1532 if (pchRet[1] != 0x5b)
1533 printf("ERROR: Proxy returned error %d\n", pchRet[1]);
1534 printf(SERR SNET "proxy returned error %d\n", pchRet[1]);
1535 return false;
1536 }
1537 printf("proxy connected %s\n", addrConnect.ToString().c_str());
1538 printf(SWAR SNET "connected through proxy to %s\n", addrConnect.ToString().c_str());
1539 }
1540
1541 hSocketRet = hSocket;
(260 . 7)(262 . 7)
1543 if (it == mapAddresses.end())
1544 {
1545 // New address
1546 printf("AddAddress(%s)\n", addr.ToString().c_str());
1547 printf(SINF SADR "adding %s\n", addr.ToString().c_str());
1548 mapAddresses.insert(make_pair(addr.GetKey(), addr));
1549 fUpdated = true;
1550 fNew = true;
(469 . 7)(471 . 7)
1552 }
1553
1554 /// debug print
1555 printf("trying connection %s lastseen=%.1fhrs lasttry=%.1fhrs\n",
1556 printf(SINF SNET "trying to connect to %s\n",
1557 addrConnect.ToString().c_str(),
1558 (double)(addrConnect.nTime - GetAdjustedTime())/3600.0,
1559 (double)(addrConnect.nLastTry - GetAdjustedTime())/3600.0);
(482 . 11)(484 . 11)
1561 if (ConnectSocket(addrConnect, hSocket))
1562 {
1563 /// debug print
1564 printf("connected %s\n", addrConnect.ToString().c_str());
1565 printf(SINF SNET "connected to %s\n", addrConnect.ToString().c_str());
1566
1567 // Set to nonblocking
1568 if (fcntl(hSocket, F_SETFL, O_NONBLOCK) == SOCKET_ERROR)
1569 printf("ConnectSocket() : fcntl nonblocking setting failed, error %d\n", errno);
1570 printf(SERR SNET "socket fcntl nonblocking setting failed, error %d\n", errno);
1571
1572 // Add node
1573 CNode* pnode = new CNode(hSocket, addrConnect, false);
(511 . 9)(513 . 7)
1575 fDisconnect = true;
1576 if (hSocket != INVALID_SOCKET)
1577 {
1578 if (fDebug)
1579 printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
1580 printf("disconnecting node %s\n", addr.ToString().c_str());
1581 printf(SWAR SNET "disconnecting from node %s\n", addr.ToString().c_str());
1582 closesocket(hSocket);
1583 hSocket = INVALID_SOCKET;
1584 }
(559 . 7)(559 . 7)
1586 {
1587 if (addr.IsLocal())
1588 {
1589 printf("Warning: local node %s misbehaving\n", addr.ToString().c_str());
1590 printf(SWAR SNET "local node %s is misbehaving\n", addr.ToString().c_str());
1591 return false;
1592 }
1593
(604 . 12)(604 . 12)
1595 vnThreadsRunning[0]--;
1596 throw; // support pthread_cancel()
1597 }
1598 printf("ThreadSocketHandler exiting\n");
1599 printf(SWAR SNET "socket handling thread exiting\n");
1600 }
1601
1602 void ThreadSocketHandler2(void* parg)
1603 {
1604 printf("ThreadSocketHandler started\n");
1605 printf(SINF SNET "socket handling thread started\n");
1606 list<CNode*> vNodesDisconnected;
1607 int nPrevNodeCount = 0;
1608
(713 . 7)(713 . 7)
1610 int nErr = WSAGetLastError();
1611 if (hSocketMax > -1)
1612 {
1613 printf("socket select error %d\n", nErr);
1614 printf(SERR SNET "socket select error %d\n", nErr);
1615 for (int i = 0; i <= hSocketMax; i++)
1616 FD_SET(i, &fdsetRecv);
1617 }
(745 . 7)(745 . 7)
1619 if (hSocket == INVALID_SOCKET)
1620 {
1621 if (WSAGetLastError() != WSAEWOULDBLOCK)
1622 printf("socket error accept failed: %d\n", WSAGetLastError());
1623 printf(SERR SNET "socket error accept failed: %d\n", WSAGetLastError());
1624 }
1625 else if (nInbound >= GetArg("-maxconnections", 125) - MAX_OUTBOUND_CONNECTIONS)
1626 {
(753 . 12)(753 . 12)
1628 }
1629 else if (CNode::IsBanned(addr.ip))
1630 {
1631 printf("connection from %s dropped (banned)\n", addr.ToString().c_str());
1632 printf(SWAR SNET "connection from %s dropped. (banned)\n", addr.ToString().c_str());
1633 closesocket(hSocket);
1634 }
1635 else
1636 {
1637 printf("accepted connection %s\n", addr.ToString().c_str());
1638 printf(SINF SNET "accepted connection to %s\n", addr.ToString().c_str());
1639 CNode* pnode = new CNode(hSocket, addr, true);
1640 pnode->AddRef();
1641 CRITICAL_BLOCK(cs_vNodes)
(796 . 7)(796 . 7)
1643
1644 if (nPos > ReceiveBufferSize()) {
1645 if (!pnode->fDisconnect)
1646 printf("socket recv flood control disconnect (%d bytes)\n", vRecv.size());
1647 printf(SWAR SNET "socket received flood, disconnecting. (%d bytes)\n", vRecv.size());
1648 pnode->CloseSocketDisconnect();
1649 }
1650 else {
(813 . 7)(813 . 7)
1652 {
1653 // socket closed gracefully
1654 if (!pnode->fDisconnect)
1655 printf("socket closed\n");
1656 printf(SWAR SNET "socket closed\n");
1657 pnode->CloseSocketDisconnect();
1658 }
1659 else if (nBytes < 0)
(823 . 7)(823 . 7)
1661 if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
1662 {
1663 if (!pnode->fDisconnect)
1664 printf("socket recv error %d\n", nErr);
1665 printf(SERR SNET "socket received error %d\n", nErr);
1666 pnode->CloseSocketDisconnect();
1667 }
1668 }
(855 . 13)(855 . 13)
1670 int nErr = WSAGetLastError();
1671 if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
1672 {
1673 printf("socket send error %d\n", nErr);
1674 printf(SERR SNET "socket send error %d\n", nErr);
1675 pnode->CloseSocketDisconnect();
1676 }
1677 }
1678 if (vSend.size() > SendBufferSize()) {
1679 if (!pnode->fDisconnect)
1680 printf("socket send flood control disconnect (%d bytes)\n", vSend.size());
1681 printf(SWAR SNET "socket send flood, disconnecting. (%d bytes)\n", vSend.size());
1682 pnode->CloseSocketDisconnect();
1683 }
1684 }
(877 . 17)(877 . 17)
1686 {
1687 if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
1688 {
1689 printf("socket no message in first 60 seconds, %d %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0);
1690 printf(SWAR SNET "socket received no message in first 60 seconds, disconnecting\n");
1691 pnode->fDisconnect = true;
1692 }
1693 else if (GetTime() - pnode->nLastSend > 90*60 && GetTime() - pnode->nLastSendEmpty > 90*60)
1694 {
1695 printf("socket not sending\n");
1696 printf(SWAR SNET "socket not sending, disconnecting\n");
1697 pnode->fDisconnect = true;
1698 }
1699 else if (GetTime() - pnode->nLastRecv > 90*60)
1700 {
1701 printf("socket inactivity timeout\n");
1702 printf(SWAR SNET "socket inactivity timeout, disconnecting\n");
1703 pnode->fDisconnect = true;
1704 }
1705 }
(919 . 12)(919 . 12)
1707 vnThreadsRunning[1]--;
1708 PrintException(NULL, "ThreadOpenConnections()");
1709 }
1710 printf("ThreadOpenConnections exiting\n");
1711 printf(SWAR SNET "connection opening thread exiting\n");
1712 }
1713
1714 void ThreadOpenConnections2(void* parg)
1715 {
1716 printf("ThreadOpenConnections started\n");
1717 printf(SINF SNET "connection opening thread started\n");
1718
1719 // Connect to specific addresses
1720 if (mapArgs.count("-connect"))
(1107 . 12)(1107 . 12)
1722 vnThreadsRunning[2]--;
1723 PrintException(NULL, "ThreadMessageHandler()");
1724 }
1725 printf("ThreadMessageHandler exiting\n");
1726 printf(SWAR SNET "message handling thread exiting\n");
1727 }
1728
1729 void ThreadMessageHandler2(void* parg)
1730 {
1731 printf("ThreadMessageHandler started\n");
1732 printf(SINF SNET "message handling thread starting\n");
1733 SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL);
1734 while (!fShutdown)
1735 {
(1177 . 8)(1177 . 7)
1737 hListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
1738 if (hListenSocket == INVALID_SOCKET)
1739 {
1740 strError = strprintf("Error: Couldn't open socket for incoming connections (socket returned error %d)", WSAGetLastError());
1741 printf("%s\n", strError.c_str());
1742 printf(SERR SNET "couldn't open socket for incoming connections, error %d\n", WSAGetLastError());
1743 return false;
1744 }
1745
(1193 . 8)(1192 . 7)
1747
1748 if (fcntl(hListenSocket, F_SETFL, O_NONBLOCK) == SOCKET_ERROR)
1749 {
1750 strError = strprintf("Error: Couldn't set properties on socket for incoming connections (error %d)", WSAGetLastError());
1751 printf("%s\n", strError.c_str());
1752 printf(SERR SNET "couldn't set properties on socket for incoming connections, error %d\n", WSAGetLastError());
1753 return false;
1754 }
1755
(1209 . 19)(1207 . 17)
1757 {
1758 int nErr = WSAGetLastError();
1759 if (nErr == WSAEADDRINUSE)
1760 strError = strprintf(_("Unable to bind to port %d on this computer. Bitcoin is probably already running."), ntohs(sockaddr.sin_port));
1761 printf(SERR SNET "unable to bind to port %d, bitcoind is probably already running\n", ntohs(sockaddr.sin_port));
1762 else
1763 strError = strprintf("Error: Unable to bind to port %d on this computer (bind returned error %d)", ntohs(sockaddr.sin_port), nErr);
1764 printf("%s\n", strError.c_str());
1765 printf(SERR SNET "unable to bind to port %d, error %d\n", ntohs(sockaddr.sin_port), nErr);
1766 return false;
1767 }
1768 printf("Bound to port %d\n", ntohs(sockaddr.sin_port));
1769 printf(SINF SNET "bound to port %d\n", ntohs(sockaddr.sin_port));
1770
1771 // Listen for incoming connections
1772 if (listen(hListenSocket, SOMAXCONN) == SOCKET_ERROR)
1773 {
1774 strError = strprintf("Error: Listening for incoming connections failed (listen returned error %d)", WSAGetLastError());
1775 printf("%s\n", strError.c_str());
1776 printf(SERR SNET "listening for incoming connections failed, error %d", WSAGetLastError());
1777 return false;
1778 }
1779
(1248 . 7)(1244 . 7)
1781 {
1782 struct sockaddr_in* s4 = (struct sockaddr_in*)(ifa->ifa_addr);
1783 if (inet_ntop(ifa->ifa_addr->sa_family, (void*)&(s4->sin_addr), pszIP, sizeof(pszIP)) != NULL)
1784 printf("ipv4 %s: %s\n", ifa->ifa_name, pszIP);
1785 printf(SINF SNET "ipv4 address %s: %s\n", ifa->ifa_name, pszIP);
1786
1787 // Take the first IP that isn't loopback 127.x.x.x
1788 CAddress addr(*(unsigned int*)&s4->sin_addr, GetListenPort(), nLocalServices);
(1262 . 13)(1258 . 13)
1790 {
1791 struct sockaddr_in6* s6 = (struct sockaddr_in6*)(ifa->ifa_addr);
1792 if (inet_ntop(ifa->ifa_addr->sa_family, (void*)&(s6->sin6_addr), pszIP, sizeof(pszIP)) != NULL)
1793 printf("ipv6 %s: %s\n", ifa->ifa_name, pszIP);
1794 printf(SINF SNET "ipv6 address %s: %s\n", ifa->ifa_name, pszIP);
1795 }
1796 }
1797 freeifaddrs(myaddrs);
1798 }
1799
1800 printf("addrLocalHost = %s\n", addrLocalHost.ToString().c_str());
1801 printf(SINF SNET "local host address is %s\n", addrLocalHost.ToString().c_str());
1802
1803 if (fUseProxy || mapArgs.count("-connect") || fNoListen)
1804 {
(1284 . 7)(1280 . 7)
1806 GetConfigFile().c_str()));
1807 }
1808
1809 printf("addrLocalHost = %s\n", addrLocalHost.ToString().c_str());
1810 printf(SINF SNET "local host address is %s\n", addrLocalHost.ToString().c_str());
1811
1812 //
1813 // Start threads
(1292 . 15)(1288 . 15)
1815
1816 // Send and receive from sockets, accept connections
1817 if (!CreateThread(ThreadSocketHandler, NULL))
1818 printf("Error: CreateThread(ThreadSocketHandler) failed\n");
1819 printf(SERR SNET "can't create socket handling thread\n");
1820
1821 // Initiate outbound connections
1822 if (!CreateThread(ThreadOpenConnections, NULL))
1823 printf("Error: CreateThread(ThreadOpenConnections) failed\n");
1824 printf(SERR SNET "can't create connection opening thread\n");
1825
1826 // Process messages
1827 if (!CreateThread(ThreadMessageHandler, NULL))
1828 printf("Error: CreateThread(ThreadMessageHandler) failed\n");
1829 printf(SERR SNET "can't create message handling thread\n");
1830
1831 // Generate coins in the background
1832 GenerateBitcoins(fGenerateBitcoins, pwalletMain);
(1308 . 7)(1304 . 7)
1834
1835 bool StopNode()
1836 {
1837 printf("StopNode()\n");
1838 printf(SWAR SNET "stopping node\n");
1839 fShutdown = true;
1840 nTransactionsUpdated++;
1841 int64 nStart = GetTime();
(1319 . 11)(1315 . 11)
1843 break;
1844 Sleep(20);
1845 }
1846 if (vnThreadsRunning[0] > 0) printf("ThreadSocketHandler still running\n");
1847 if (vnThreadsRunning[1] > 0) printf("ThreadOpenConnections still running\n");
1848 if (vnThreadsRunning[2] > 0) printf("ThreadMessageHandler still running\n");
1849 if (vnThreadsRunning[3] > 0) printf("ThreadBitcoinMiner still running\n");
1850 if (vnThreadsRunning[4] > 0) printf("ThreadRPCServer still running\n");
1851 if (vnThreadsRunning[0] > 0) printf(SWAR SNET "socket handling thread still running\n");
1852 if (vnThreadsRunning[1] > 0) printf(SWAR SNET "connection opening thread still running\n");
1853 if (vnThreadsRunning[2] > 0) printf(SWAR SNET "message handling thread still running\n");
1854 if (vnThreadsRunning[3] > 0) printf(SWAR SMIN "miner thread still running\n");
1855 if (vnThreadsRunning[4] > 0) printf(SWAR SNET "rpc server thread still running\n");
1856 while (vnThreadsRunning[2] > 0 || vnThreadsRunning[4] > 0)
1857 Sleep(20);
1858 Sleep(50);
(1345 . 7)(1341 . 7)
1860 closesocket(pnode->hSocket);
1861 if (hListenSocket != INVALID_SOCKET)
1862 if (closesocket(hListenSocket) == SOCKET_ERROR)
1863 printf("closesocket(hListenSocket) failed with error %d\n", WSAGetLastError());
1864 printf(SERR SNET "closing socket failed with error %d\n", WSAGetLastError());
1865
1866 }
1867 }
(261 . 7)(261 . 7)- 35EFFBC7F73CDBDA92148BE58171B2337C090A7997EB3B02DAF9A88287B4315C80D7FA5EDF403BE9CF958969C0C7E0C1B578C10F146EE0EA9B2965A1F97971BF
1872 // We're using mapAskFor as a priority queue,
1873 // the key is the earliest time the request can be sent
1874 int64& nRequestTime = mapAlreadyAskedFor[inv];
1875 printf("askfor %s %"PRI64d"\n", inv.ToString().c_str(), nRequestTime);
1876 printf(SINF SNET "requesting inv %s\n", inv.ToString().c_str());
1877
1878 // Make sure not to reuse time indexes to keep things in the same order
1879 int64 nNow = (GetTime() - 1) * 1000000;
(286 . 8)(286 . 7)
1881 vSend << CMessageHeader(pszCommand, 0);
1882 nMessageStart = vSend.size();
1883 if (fDebug) {
1884 printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
1885 printf("sending: %s ", pszCommand);
1886 printf(SINF SNET "sending command %s\n", pszCommand);
1887 }
1888 }
1889
(301 . 14)(300 . 14)
1891 LEAVE_CRITICAL_SECTION(cs_vSend);
1892
1893 if (fDebug)
1894 printf("(aborted)\n");
1895 printf(SWAR SNET "aborted\n");
1896 }
1897
1898 void EndMessage()
1899 {
1900 if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
1901 {
1902 printf("dropmessages DROPPING SEND MESSAGE\n");
1903 printf(SWAR SNET "dropping send message\n");
1904 AbortMessage();
1905 return;
1906 }
(330 . 10)(329 . 6)
1908 memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nChecksum), &nChecksum, sizeof(nChecksum));
1909 }
1910
1911 if (fDebug) {
1912 printf("(%d bytes)\n", nSize);
1913 }
1914
1915 nHeaderStart = -1;
1916 nMessageStart = -1;
1917 LEAVE_CRITICAL_SECTION(cs_vSend);
(68 . 7)(68 . 7)
1922 // Message size
1923 if (nMessageSize > MAX_SIZE)
1924 {
1925 printf("CMessageHeader::IsValid() : (%s, %u bytes) nMessageSize > MAX_SIZE\n", GetCommand().c_str(), nMessageSize);
1926 printf(SERR SNET "message %s size out of range. (%u bytes)\n", GetCommand().c_str(), nMessageSize);
1927 return false;
1928 }
1929
- E618531AACEECEFE505689A76254DA2CAD45AF6DB44DE26138E130B166D1D26B6A78D0CCF352B8C9C11878E5549010CE48B2083089E14EE026D949F06CD310F6(877 . 7)(877 . 7)- 737F20496467F30D16567D63D809FE08641D524903AE5EB425A9D209DA2E9524195D7B3364BF723BCE428621344CC6C4861C58D601BFCD93B2AF50C537D5D038
1934 {
1935 if (nIn >= txTo.vin.size())
1936 {
1937 printf("ERROR: SignatureHash() : nIn=%d out of range\n", nIn);
1938 printf(SERR SMEM "signature hash for input number %d out of range\n", nIn);
1939 return 1;
1940 }
1941 CTransaction txTmp(txTo);
(908 . 7)(908 . 7)
1943 unsigned int nOut = nIn;
1944 if (nOut >= txTmp.vout.size())
1945 {
1946 printf("ERROR: SignatureHash() : nOut=%d out of range\n", nOut);
1947 printf(SERR SMEM "signature hash for output number %d out of range\n", nOut);
1948 return 1;
1949 }
1950 txTmp.vout.resize(nOut+1);
(142 . 11)(142 . 14)- E217371B4DA3B8F7B7FB1ACD0B281F361DE3854E91AF884BF70CB39267075A6BE1BB504DC9E4D3EEBEE60ECAF371AC8E83DAF88F69569A14C53FB189C4871A9F
1955 inline int OutputDebugStringF(const char* pszFormat, ...)
1956 {
1957 int ret = 0;
1958 const char* isodt = GetISODateTime().c_str();
1959
1960 if (fPrintToConsole)
1961 {
1962 // print to console
1963 va_list arg_ptr;
1964 va_start(arg_ptr, pszFormat);
1965 printf("%s ", isodt);
1966 ret = vprintf(pszFormat, arg_ptr);
1967 va_end(arg_ptr);
1968 }
(177 . 6)(180 . 7)
1970
1971 va_list arg_ptr;
1972 va_start(arg_ptr, pszFormat);
1973 fprintf(fileout, "%s ", isodt);
1974 ret = vfprintf(fileout, pszFormat, arg_ptr);
1975 va_end(arg_ptr);
1976 }
(246 . 7)(250 . 7)
1978 ret = limit - 1;
1979 buffer[limit-1] = 0;
1980 }
1981 printf("ERROR: %s\n", buffer);
1982 printf(SERR "%s\n", buffer);
1983 return false;
1984 }
1985
(806 . 7)(810 . 8)
1987 if (vTimeOffsets.empty())
1988 vTimeOffsets.push_back(0);
1989 vTimeOffsets.push_back(nOffsetSample);
1990 printf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), vTimeOffsets.back(), vTimeOffsets.back()/60);
1991 printf(SINF SPRC "added time data, samples %d, offset %+"PRI64d". (%+"PRI64d" minutes)\n",
1992 vTimeOffsets.size(), vTimeOffsets.back(), vTimeOffsets.back()/60);
1993 if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
1994 {
1995 sort(vTimeOffsets.begin(), vTimeOffsets.end());
(832 . 16)(837 . 10)
1997 if (!fMatch)
1998 {
1999 fDone = true;
2000 string strMessage = _("Warning: Please check that your computer's date and time are correct. If your clock is wrong Bitcoin will not work properly.");
2001 strMiscWarning = strMessage;
2002 printf("*** %s\n", strMessage.c_str());
2003 boost::thread(boost::bind(ThreadSafeMessageBox, strMessage+" ", string("Bitcoin"), wxOK | wxICON_EXCLAMATION, (wxWindow*)NULL, -1, -1));
2004 printf(SWAR SPRC "please check that your computer's date and time are correct\n");
2005 }
2006 }
2007 }
2008 BOOST_FOREACH(int64 n, vTimeOffsets)
2009 printf("%+"PRI64d" ", n);
2010 printf("| nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60);
2011 }
2012 }
2013
(18 . 6)(18 . 7)- BDC4FC472BE4A86FB91FA69368FAACE04414FDEEE5B8C82795E31D37E21581B973CAF7F3E9CCC27D487944A5782E3B59615180EAB87C8B3E81242901F3039E4D
2018 #include <boost/thread.hpp>
2019 #include <boost/interprocess/sync/interprocess_recursive_mutex.hpp>
2020 #include <boost/date_time/gregorian/gregorian_types.hpp>
2021 #include <boost/date_time/posix_time/posix_time.hpp>
2022 #include <boost/date_time/posix_time/posix_time_types.hpp>
2023
2024 #include <openssl/sha.h>
(37 . 6)(38 . 18)
2026 #define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0]))
2027 #define printf OutputDebugStringF
2028
2029 #define SERR "ERR "
2030 #define SWAR "WAR "
2031 #define SINF "INF "
2032
2033 #define SPRC "PRC "
2034 #define SMEM "MEM "
2035 #define SADR "ADR "
2036 #define SBLK "BLK "
2037 #define SNET "NET "
2038 #define SWAL "WAL "
2039 #define SMIN "MIN "
2040
2041 #ifdef snprintf
2042 #undef snprintf
2043 #endif
(373 . 6)(386 . 11)
2045 boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds();
2046 }
2047
2048 inline std::string GetISODateTime() {
2049 boost::posix_time::ptime ut = boost::posix_time::microsec_clock::universal_time();
2050 return boost::posix_time::to_iso_extended_string(ut);
2051 }
2052
2053 inline std::string DateTimeStrFormat(const char* pszFormat, int64 nTime)
2054 {
2055 time_t n = nTime;
(92 . 7)(92 . 7)
2060 if (pMasterKey.second.nDeriveIterations < 25000)
2061 pMasterKey.second.nDeriveIterations = 25000;
2062
2063 printf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations);
2064 printf(SINF SWAL "passphrase changed through %i deriving iterations\n", pMasterKey.second.nDeriveIterations);
2065
2066 if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
2067 return false;
(151 . 7)(151 . 7)
2069 if (kMasterKey.nDeriveIterations < 25000)
2070 kMasterKey.nDeriveIterations = 25000;
2071
2072 printf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations);
2073 printf(SINF SWAL "encrypting using %i deriving iterations\n", kMasterKey.nDeriveIterations);
2074
2075 if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod))
2076 return false;
(214 . 7)(214 . 7)
2078 CWalletTx& wtx = (*mi).second;
2079 if (!wtx.IsSpent(txin.prevout.n) && IsMine(wtx.vout[txin.prevout.n]))
2080 {
2081 printf("WalletUpdateSpent found spent coin %sbc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
2082 printf(SWAR SWAL "found spent %s bitcoin on tx %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
2083 wtx.MarkSpent(txin.prevout.n);
2084 wtx.WriteToDisk();
2085 vWalletUpdated.push_back(txin.prevout.hash);
(261 . 7)(261 . 7)
2087 }
2088
2089 //// debug print
2090 printf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString().substr(0,10).c_str(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : ""));
2091 printf(SINF SWAL "adding input from tx %s. (%s)\n", wtxIn.GetHash().ToString().c_str(), (fInsertedNew ? "new, " : (fUpdated ? "update" : "")));
2092
2093 // Write to disk
2094 if (fInsertedNew || fUpdated)
(440 . 7)(440 . 7)
2096 vector<unsigned char> vchPubKey;
2097 if (!ExtractAddress(txout.scriptPubKey, NULL, address))
2098 {
2099 printf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
2100 printf(SWAR SWAL "unknown transaction type found, tx %s\n",
2101 this->GetHash().ToString().c_str());
2102 address = " unknown ";
2103 }
(537 . 7)(537 . 7)
2105 }
2106 else
2107 {
2108 printf("ERROR: AddSupportingTransactions() : unsupported transaction\n");
2109 printf(SERR SWAL "unsupported tx\n");
2110 continue;
2111 }
2112
(605 . 7)(605 . 7)
2114 // Update fSpent if a tx got spent somewhere else by a copy of wallet.dat
2115 if (txindex.vSpent.size() != wtx.vout.size())
2116 {
2117 printf("ERROR: ReacceptWalletTransactions() : txindex.vSpent.size() %d != wtx.vout.size() %d\n", txindex.vSpent.size(), wtx.vout.size());
2118 printf(SERR SWAL "tx index spent count differs from output index length\n");
2119 continue;
2120 }
2121 for (int i = 0; i < txindex.vSpent.size(); i++)
(621 . 7)(621 . 8)
2123 }
2124 if (fUpdated)
2125 {
2126 printf("ReacceptWalletTransactions found spent coin %sbc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
2127 printf(SERR SWAL "found spent %s bitcoin on tx %s\n",
2128 FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
2129 wtx.MarkDirty();
2130 wtx.WriteToDisk();
2131 }
(658 . 7)(659 . 7)
2133 uint256 hash = GetHash();
2134 if (!txdb.ContainsTx(hash))
2135 {
2136 printf("Relaying wtx %s\n", hash.ToString().substr(0,10).c_str());
2137 printf(SINF SWAL "relaying wallet tx %s\n", hash.ToString().c_str());
2138 RelayMessage(CInv(MSG_TX, hash), (CTransaction)*this);
2139 }
2140 }
(689 . 7)(690 . 7)
2142 nLastTime = GetTime();
2143
2144 // Rebroadcast any of our txes that aren't in a block yet
2145 printf("ResendWalletTransactions()\n");
2146 printf(SWAR SWAL "resending wallet txs\n");
2147 CTxDB txdb("r");
2148 CRITICAL_BLOCK(cs_wallet)
2149 {
(890 . 11)(891 . 11)
2151 }
2152
2153 //// debug print
2154 printf("SelectCoins() best subset: ");
2155 std::string str;
2156 for (int i = 0; i < vValue.size(); i++)
2157 if (vfBest[i])
2158 printf("%s ", FormatMoney(vValue[i].first).c_str());
2159 printf("total %s\n", FormatMoney(nBest).c_str());
2160 str += FormatMoney(vValue[i].first) + (i == vValue.size() - 1 ? "" : " ");
2161 printf(SINF SWAL "selecting best output subset: %s\n", str.c_str());
2162 }
2163
2164 return true;
(1041 . 7)(1042 . 7)
2166 CRITICAL_BLOCK(cs_main)
2167 CRITICAL_BLOCK(cs_wallet)
2168 {
2169 printf("CommitTransaction:\n%s", wtxNew.ToString().c_str());
2170 printf(SINF SWAL "commit tx %s\n", wtxNew.ToString().c_str());
2171 {
2172 // This is only to keep the database open to defeat the auto-flush for the
2173 // duration of this scope. This is the only place where this optimization
(1077 . 7)(1078 . 7)
2175 if (!wtxNew.AcceptToMemoryPool())
2176 {
2177 // This must not fail. The transaction has already been signed and recorded.
2178 printf("CommitTransaction() : Error: Transaction not valid");
2179 printf(SERR SWAL "tx found non-valid while commiting");
2180 return false;
2181 }
2182 wtxNew.RelayWalletTransaction();
(1097 . 17)(1098 . 19)
2184 if (IsLocked())
2185 {
2186 string strError = _("Error: Wallet locked, unable to create transaction ");
2187 printf("SendMoney() : %s", strError.c_str());
2188 printf(SERR SWAL "send money failed with error %s\n", strError.c_str());
2189 return strError;
2190 }
2191 if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired))
2192 {
2193 string strError;
2194 if (nValue + nFeeRequired > GetBalance())
2195 strError = strprintf(_("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds "), FormatMoney(nFeeRequired).c_str());
2196 strError += strprintf("tx requires a tx fee of at"
2197 " least %s because of its amount, complexity, or use of recently"
2198 " received funds", FormatMoney(nFeeRequired).c_str());
2199 else
2200 strError = _("Error: Transaction creation failed ");
2201 printf("SendMoney() : %s", strError.c_str());
2202 strError += strprintf("tx creation failed");
2203 printf(SERR SWAL "send money failed with error: %s", strError.c_str());
2204 return strError;
2205 }
2206
(1205 . 10)(1208 . 10)
2208 if (mapWallet.count(block.vtx[0].GetHash()))
2209 {
2210 CWalletTx& wtx = mapWallet[block.vtx[0].GetHash()];
2211 printf(" mine: %d %d %d", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit());
2212 printf(SINF SWAL "depth is %d, blocks to maturity is %d and credit is %d\n",
2213 wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit());
2214 }
2215 }
2216 printf("\n");
2217 }
2218
2219 bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx)
(1267 . 7)(1270 . 7)
2221 walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey()));
2222 setKeyPool.insert(nIndex);
2223 }
2224 printf("CWallet::NewKeyPool wrote %"PRI64d" new keys\n", nKeys);
2225 printf(SINF SWAL "%"PRI64d" new keys written\n", nKeys);
2226 }
2227 return true;
2228 }
(1291 . 7)(1294 . 7)
2230 if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey())))
2231 throw runtime_error("TopUpKeyPool() : writing generated key failed");
2232 setKeyPool.insert(nEnd);
2233 printf("keypool added key %"PRI64d", size=%d\n", nEnd, setKeyPool.size());
2234 printf(SINF SWAL "added key %"PRI64d", current size is %d\n", nEnd, setKeyPool.size());
2235 }
2236 }
2237 return true;
(1319 . 7)(1322 . 7)
2239 if (!HaveKey(Hash160(keypool.vchPubKey)))
2240 throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool");
2241 assert(!keypool.vchPubKey.empty());
2242 printf("keypool reserve %"PRI64d"\n", nIndex);
2243 printf(SINF SWAL "keypool reserve %"PRI64d"\n", nIndex);
2244 }
2245 }
2246
(1331 . 7)(1334 . 7)
2248 CWalletDB walletdb(strWalletFile);
2249 walletdb.ErasePool(nIndex);
2250 }
2251 printf("keypool keep %"PRI64d"\n", nIndex);
2252 printf(SINF SWAL "keypool keep %"PRI64d"\n", nIndex);
2253 }
2254
2255 void CWallet::ReturnKey(int64 nIndex)
(1339 . 7)(1342 . 7)
2257 // Return to key pool
2258 CRITICAL_BLOCK(cs_wallet)
2259 setKeyPool.insert(nIndex);
2260 printf("keypool return %"PRI64d"\n", nIndex);
2261 printf(SINF SWAL "keypool return %"PRI64d"\n", nIndex);
2262 }
2263
2264 bool CWallet::GetKeyFromPool(vector<unsigned char>& result, bool fAllowReuse)
(1387 . 7)(1390 . 7)
2266 vchPubKey = keypool.vchPubKey;
2267 else
2268 {
2269 printf("CReserveKey::GetReservedKey(): Warning: using default key instead of a new key, top up your keypool.");
2270 printf(SWAR SWAL "using default key instead of a new key, top up your keypool\n");
2271 vchPubKey = pwallet->vchDefaultKey;
2272 }
2273 }