bitcoind now compiles without wxWidgets or wxBase
[novacoin.git] / db.cpp
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
4
5 #include "headers.h"
6
7 void ThreadFlushWalletDB(void* parg);
8
9
10 unsigned int nWalletDBUpdated;
11
12
13
14
15 //
16 // CDB
17 //
18
19 static CCriticalSection cs_db;
20 static bool fDbEnvInit = false;
21 DbEnv dbenv(0);
22 static map<string, int> mapFileUseCount;
23 static map<string, Db*> mapDb;
24
25 class CDBInit
26 {
27 public:
28     CDBInit()
29     {
30     }
31     ~CDBInit()
32     {
33         if (fDbEnvInit)
34         {
35             dbenv.close(0);
36             fDbEnvInit = false;
37         }
38     }
39 }
40 instance_of_cdbinit;
41
42
43 CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL)
44 {
45     int ret;
46     if (pszFile == NULL)
47         return;
48
49     fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
50     bool fCreate = strchr(pszMode, 'c');
51     unsigned int nFlags = DB_THREAD;
52     if (fCreate)
53         nFlags |= DB_CREATE;
54
55     CRITICAL_BLOCK(cs_db)
56     {
57         if (!fDbEnvInit)
58         {
59             if (fShutdown)
60                 return;
61             string strDataDir = GetDataDir();
62             string strLogDir = strDataDir + "/database";
63             filesystem::create_directory(strLogDir.c_str());
64             string strErrorFile = strDataDir + "/db.log";
65             printf("dbenv.open strLogDir=%s strErrorFile=%s\n", strLogDir.c_str(), strErrorFile.c_str());
66
67             dbenv.set_lg_dir(strLogDir.c_str());
68             dbenv.set_lg_max(10000000);
69             dbenv.set_lk_max_locks(10000);
70             dbenv.set_lk_max_objects(10000);
71             dbenv.set_errfile(fopen(strErrorFile.c_str(), "a")); /// debug
72             dbenv.set_flags(DB_AUTO_COMMIT, 1);
73             ret = dbenv.open(strDataDir.c_str(),
74                              DB_CREATE     |
75                              DB_INIT_LOCK  |
76                              DB_INIT_LOG   |
77                              DB_INIT_MPOOL |
78                              DB_INIT_TXN   |
79                              DB_THREAD     |
80                              DB_PRIVATE    |
81                              DB_RECOVER,
82                              S_IRUSR | S_IWUSR);
83             if (ret > 0)
84                 throw runtime_error(strprintf("CDB() : error %d opening database environment\n", ret));
85             fDbEnvInit = true;
86         }
87
88         strFile = pszFile;
89         ++mapFileUseCount[strFile];
90         pdb = mapDb[strFile];
91         if (pdb == NULL)
92         {
93             pdb = new Db(&dbenv, 0);
94
95             ret = pdb->open(NULL,      // Txn pointer
96                             pszFile,   // Filename
97                             "main",    // Logical db name
98                             DB_BTREE,  // Database type
99                             nFlags,    // Flags
100                             0);
101
102             if (ret > 0)
103             {
104                 delete pdb;
105                 pdb = NULL;
106                 CRITICAL_BLOCK(cs_db)
107                     --mapFileUseCount[strFile];
108                 strFile = "";
109                 throw runtime_error(strprintf("CDB() : can't open database file %s, error %d\n", pszFile, ret));
110             }
111
112             if (fCreate && !Exists(string("version")))
113             {
114                 bool fTmp = fReadOnly;
115                 fReadOnly = false;
116                 WriteVersion(VERSION);
117                 fReadOnly = fTmp;
118             }
119
120             mapDb[strFile] = pdb;
121         }
122     }
123 }
124
125 void CDB::Close()
126 {
127     if (!pdb)
128         return;
129     if (!vTxn.empty())
130         vTxn.front()->abort();
131     vTxn.clear();
132     pdb = NULL;
133
134     // Flush database activity from memory pool to disk log
135     unsigned int nMinutes = 0;
136     if (strFile == "addr.dat")
137         nMinutes = 2;
138     if (strFile == "blkindex.dat" && IsInitialBlockDownload() && nBestHeight % 500 != 0)
139         nMinutes = 1;
140     dbenv.txn_checkpoint(0, nMinutes, 0);
141
142     CRITICAL_BLOCK(cs_db)
143         --mapFileUseCount[strFile];
144 }
145
146 void CloseDb(const string& strFile)
147 {
148     CRITICAL_BLOCK(cs_db)
149     {
150         if (mapDb[strFile] != NULL)
151         {
152             // Close the database handle
153             Db* pdb = mapDb[strFile];
154             pdb->close(0);
155             delete pdb;
156             mapDb[strFile] = NULL;
157         }
158     }
159 }
160
161 void DBFlush(bool fShutdown)
162 {
163     // Flush log data to the actual data file
164     //  on all files that are not in use
165     printf("DBFlush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started");
166     if (!fDbEnvInit)
167         return;
168     CRITICAL_BLOCK(cs_db)
169     {
170         map<string, int>::iterator mi = mapFileUseCount.begin();
171         while (mi != mapFileUseCount.end())
172         {
173             string strFile = (*mi).first;
174             int nRefCount = (*mi).second;
175             printf("%s refcount=%d\n", strFile.c_str(), nRefCount);
176             if (nRefCount == 0)
177             {
178                 // Move log data to the dat file
179                 CloseDb(strFile);
180                 dbenv.txn_checkpoint(0, 0, 0);
181                 printf("%s flush\n", strFile.c_str());
182                 dbenv.lsn_reset(strFile.c_str(), 0);
183                 mapFileUseCount.erase(mi++);
184             }
185             else
186                 mi++;
187         }
188         if (fShutdown)
189         {
190             char** listp;
191             if (mapFileUseCount.empty())
192                 dbenv.log_archive(&listp, DB_ARCH_REMOVE);
193             dbenv.close(0);
194             fDbEnvInit = false;
195         }
196     }
197 }
198
199
200
201
202
203
204 //
205 // CTxDB
206 //
207
208 bool CTxDB::ReadTxIndex(uint256 hash, CTxIndex& txindex)
209 {
210     assert(!fClient);
211     txindex.SetNull();
212     return Read(make_pair(string("tx"), hash), txindex);
213 }
214
215 bool CTxDB::UpdateTxIndex(uint256 hash, const CTxIndex& txindex)
216 {
217     assert(!fClient);
218     return Write(make_pair(string("tx"), hash), txindex);
219 }
220
221 bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight)
222 {
223     assert(!fClient);
224
225     // Add to tx index
226     uint256 hash = tx.GetHash();
227     CTxIndex txindex(pos, tx.vout.size());
228     return Write(make_pair(string("tx"), hash), txindex);
229 }
230
231 bool CTxDB::EraseTxIndex(const CTransaction& tx)
232 {
233     assert(!fClient);
234     uint256 hash = tx.GetHash();
235
236     return Erase(make_pair(string("tx"), hash));
237 }
238
239 bool CTxDB::ContainsTx(uint256 hash)
240 {
241     assert(!fClient);
242     return Exists(make_pair(string("tx"), hash));
243 }
244
245 bool CTxDB::ReadOwnerTxes(uint160 hash160, int nMinHeight, vector<CTransaction>& vtx)
246 {
247     assert(!fClient);
248     vtx.clear();
249
250     // Get cursor
251     Dbc* pcursor = GetCursor();
252     if (!pcursor)
253         return false;
254
255     unsigned int fFlags = DB_SET_RANGE;
256     loop
257     {
258         // Read next record
259         CDataStream ssKey;
260         if (fFlags == DB_SET_RANGE)
261             ssKey << string("owner") << hash160 << CDiskTxPos(0, 0, 0);
262         CDataStream ssValue;
263         int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
264         fFlags = DB_NEXT;
265         if (ret == DB_NOTFOUND)
266             break;
267         else if (ret != 0)
268         {
269             pcursor->close();
270             return false;
271         }
272
273         // Unserialize
274         string strType;
275         uint160 hashItem;
276         CDiskTxPos pos;
277         ssKey >> strType >> hashItem >> pos;
278         int nItemHeight;
279         ssValue >> nItemHeight;
280
281         // Read transaction
282         if (strType != "owner" || hashItem != hash160)
283             break;
284         if (nItemHeight >= nMinHeight)
285         {
286             vtx.resize(vtx.size()+1);
287             if (!vtx.back().ReadFromDisk(pos))
288             {
289                 pcursor->close();
290                 return false;
291             }
292         }
293     }
294
295     pcursor->close();
296     return true;
297 }
298
299 bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex)
300 {
301     assert(!fClient);
302     tx.SetNull();
303     if (!ReadTxIndex(hash, txindex))
304         return false;
305     return (tx.ReadFromDisk(txindex.pos));
306 }
307
308 bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx)
309 {
310     CTxIndex txindex;
311     return ReadDiskTx(hash, tx, txindex);
312 }
313
314 bool CTxDB::ReadDiskTx(COutPoint outpoint, CTransaction& tx, CTxIndex& txindex)
315 {
316     return ReadDiskTx(outpoint.hash, tx, txindex);
317 }
318
319 bool CTxDB::ReadDiskTx(COutPoint outpoint, CTransaction& tx)
320 {
321     CTxIndex txindex;
322     return ReadDiskTx(outpoint.hash, tx, txindex);
323 }
324
325 bool CTxDB::WriteBlockIndex(const CDiskBlockIndex& blockindex)
326 {
327     return Write(make_pair(string("blockindex"), blockindex.GetBlockHash()), blockindex);
328 }
329
330 bool CTxDB::EraseBlockIndex(uint256 hash)
331 {
332     return Erase(make_pair(string("blockindex"), hash));
333 }
334
335 bool CTxDB::ReadHashBestChain(uint256& hashBestChain)
336 {
337     return Read(string("hashBestChain"), hashBestChain);
338 }
339
340 bool CTxDB::WriteHashBestChain(uint256 hashBestChain)
341 {
342     return Write(string("hashBestChain"), hashBestChain);
343 }
344
345 CBlockIndex* InsertBlockIndex(uint256 hash)
346 {
347     if (hash == 0)
348         return NULL;
349
350     // Return existing
351     map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
352     if (mi != mapBlockIndex.end())
353         return (*mi).second;
354
355     // Create new
356     CBlockIndex* pindexNew = new CBlockIndex();
357     if (!pindexNew)
358         throw runtime_error("LoadBlockIndex() : new CBlockIndex failed");
359     mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
360     pindexNew->phashBlock = &((*mi).first);
361
362     return pindexNew;
363 }
364
365 bool CTxDB::LoadBlockIndex()
366 {
367     // Get database cursor
368     Dbc* pcursor = GetCursor();
369     if (!pcursor)
370         return false;
371
372     // Load mapBlockIndex
373     unsigned int fFlags = DB_SET_RANGE;
374     loop
375     {
376         // Read next record
377         CDataStream ssKey;
378         if (fFlags == DB_SET_RANGE)
379             ssKey << make_pair(string("blockindex"), uint256(0));
380         CDataStream ssValue;
381         int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
382         fFlags = DB_NEXT;
383         if (ret == DB_NOTFOUND)
384             break;
385         else if (ret != 0)
386             return false;
387
388         // Unserialize
389         string strType;
390         ssKey >> strType;
391         if (strType == "blockindex")
392         {
393             CDiskBlockIndex diskindex;
394             ssValue >> diskindex;
395
396             // Construct block index object
397             CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
398             pindexNew->pprev          = InsertBlockIndex(diskindex.hashPrev);
399             pindexNew->pnext          = InsertBlockIndex(diskindex.hashNext);
400             pindexNew->nFile          = diskindex.nFile;
401             pindexNew->nBlockPos      = diskindex.nBlockPos;
402             pindexNew->nHeight        = diskindex.nHeight;
403             pindexNew->nVersion       = diskindex.nVersion;
404             pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
405             pindexNew->nTime          = diskindex.nTime;
406             pindexNew->nBits          = diskindex.nBits;
407             pindexNew->nNonce         = diskindex.nNonce;
408
409             // Watch for genesis block
410             if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == hashGenesisBlock)
411                 pindexGenesisBlock = pindexNew;
412         }
413         else
414         {
415             break;
416         }
417     }
418     pcursor->close();
419
420     // Calculate bnChainWork
421     vector<pair<int, CBlockIndex*> > vSortedByHeight;
422     vSortedByHeight.reserve(mapBlockIndex.size());
423     foreach(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
424     {
425         CBlockIndex* pindex = item.second;
426         vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex));
427     }
428     sort(vSortedByHeight.begin(), vSortedByHeight.end());
429     foreach(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
430     {
431         CBlockIndex* pindex = item.second;
432         pindex->bnChainWork = (pindex->pprev ? pindex->pprev->bnChainWork : 0) + pindex->GetBlockWork();
433     }
434
435     // Load hashBestChain pointer to end of best chain
436     if (!ReadHashBestChain(hashBestChain))
437     {
438         if (pindexGenesisBlock == NULL)
439             return true;
440         return error("CTxDB::LoadBlockIndex() : hashBestChain not loaded");
441     }
442     if (!mapBlockIndex.count(hashBestChain))
443         return error("CTxDB::LoadBlockIndex() : hashBestChain not found in the block index");
444     pindexBest = mapBlockIndex[hashBestChain];
445     nBestHeight = pindexBest->nHeight;
446     bnBestChainWork = pindexBest->bnChainWork;
447     printf("LoadBlockIndex(): hashBestChain=%s  height=%d\n", hashBestChain.ToString().substr(0,16).c_str(), nBestHeight);
448
449     return true;
450 }
451
452
453
454
455
456 //
457 // CAddrDB
458 //
459
460 bool CAddrDB::WriteAddress(const CAddress& addr)
461 {
462     return Write(make_pair(string("addr"), addr.GetKey()), addr);
463 }
464
465 bool CAddrDB::LoadAddresses()
466 {
467     CRITICAL_BLOCK(cs_mapAddresses)
468     {
469         // Load user provided addresses
470         CAutoFile filein = fopen((GetDataDir() + "/addr.txt").c_str(), "rt");
471         if (filein)
472         {
473             try
474             {
475                 char psz[1000];
476                 while (fgets(psz, sizeof(psz), filein))
477                 {
478                     CAddress addr(psz, NODE_NETWORK);
479                     addr.nTime = 0; // so it won't relay unless successfully connected
480                     if (addr.IsValid())
481                         AddAddress(addr);
482                 }
483             }
484             catch (...) { }
485         }
486
487         // Get cursor
488         Dbc* pcursor = GetCursor();
489         if (!pcursor)
490             return false;
491
492         loop
493         {
494             // Read next record
495             CDataStream ssKey;
496             CDataStream ssValue;
497             int ret = ReadAtCursor(pcursor, ssKey, ssValue);
498             if (ret == DB_NOTFOUND)
499                 break;
500             else if (ret != 0)
501                 return false;
502
503             // Unserialize
504             string strType;
505             ssKey >> strType;
506             if (strType == "addr")
507             {
508                 CAddress addr;
509                 ssValue >> addr;
510                 mapAddresses.insert(make_pair(addr.GetKey(), addr));
511             }
512         }
513         pcursor->close();
514
515         printf("Loaded %d addresses\n", mapAddresses.size());
516
517         // Fix for possible bug that manifests in mapAddresses.count in irc.cpp,
518         // just need to call count here and it doesn't happen there.  The bug was the
519         // pack pragma in irc.cpp and has been fixed, but I'm not in a hurry to delete this.
520         mapAddresses.count(vector<unsigned char>(18));
521     }
522
523     return true;
524 }
525
526 bool LoadAddresses()
527 {
528     return CAddrDB("cr+").LoadAddresses();
529 }
530
531
532
533
534 //
535 // CWalletDB
536 //
537
538 bool CWalletDB::LoadWallet()
539 {
540     vchDefaultKey.clear();
541     int nFileVersion = 0;
542
543     // Modify defaults
544 #ifndef __WXMSW__
545     // Tray icon sometimes disappears on 9.10 karmic koala 64-bit, leaving no way to access the program
546     fMinimizeToTray = false;
547     fMinimizeOnClose = false;
548 #endif
549
550     //// todo: shouldn't we catch exceptions and try to recover and continue?
551     CRITICAL_BLOCK(cs_mapKeys)
552     CRITICAL_BLOCK(cs_mapWallet)
553     {
554         // Get cursor
555         Dbc* pcursor = GetCursor();
556         if (!pcursor)
557             return false;
558
559         loop
560         {
561             // Read next record
562             CDataStream ssKey;
563             CDataStream ssValue;
564             int ret = ReadAtCursor(pcursor, ssKey, ssValue);
565             if (ret == DB_NOTFOUND)
566                 break;
567             else if (ret != 0)
568                 return false;
569
570             // Unserialize
571             // Taking advantage of the fact that pair serialization
572             // is just the two items serialized one after the other
573             string strType;
574             ssKey >> strType;
575             if (strType == "name")
576             {
577                 string strAddress;
578                 ssKey >> strAddress;
579                 ssValue >> mapAddressBook[strAddress];
580             }
581             else if (strType == "tx")
582             {
583                 uint256 hash;
584                 ssKey >> hash;
585                 CWalletTx& wtx = mapWallet[hash];
586                 ssValue >> wtx;
587
588                 if (wtx.GetHash() != hash)
589                     printf("Error in wallet.dat, hash mismatch\n");
590
591                 //// debug print
592                 //printf("LoadWallet  %s\n", wtx.GetHash().ToString().c_str());
593                 //printf(" %12I64d  %s  %s  %s\n",
594                 //    wtx.vout[0].nValue,
595                 //    DateTimeStrFormat("%x %H:%M:%S", wtx.nTime).c_str(),
596                 //    wtx.hashBlock.ToString().substr(0,16).c_str(),
597                 //    wtx.mapValue["message"].c_str());
598             }
599             else if (strType == "key" || strType == "wkey")
600             {
601                 vector<unsigned char> vchPubKey;
602                 ssKey >> vchPubKey;
603                 CWalletKey wkey;
604                 if (strType == "key")
605                     ssValue >> wkey.vchPrivKey;
606                 else
607                     ssValue >> wkey;
608
609                 mapKeys[vchPubKey] = wkey.vchPrivKey;
610                 mapPubKeys[Hash160(vchPubKey)] = vchPubKey;
611             }
612             else if (strType == "defaultkey")
613             {
614                 ssValue >> vchDefaultKey;
615             }
616             else if (strType == "version")
617             {
618                 ssValue >> nFileVersion;
619                 if (nFileVersion == 10300)
620                     nFileVersion = 300;
621             }
622             else if (strType == "setting")
623             {
624                 string strKey;
625                 ssKey >> strKey;
626
627                 // Menu state
628                 if (strKey == "fGenerateBitcoins")  ssValue >> fGenerateBitcoins;
629
630                 // Options
631                 if (strKey == "nTransactionFee")    ssValue >> nTransactionFee;
632                 if (strKey == "addrIncoming")       ssValue >> addrIncoming;
633                 if (strKey == "fLimitProcessors")   ssValue >> fLimitProcessors;
634                 if (strKey == "nLimitProcessors")   ssValue >> nLimitProcessors;
635                 if (strKey == "fMinimizeToTray")    ssValue >> fMinimizeToTray;
636                 if (strKey == "fMinimizeOnClose")   ssValue >> fMinimizeOnClose;
637                 if (strKey == "fUseProxy")          ssValue >> fUseProxy;
638                 if (strKey == "addrProxy")          ssValue >> addrProxy;
639
640             }
641         }
642         pcursor->close();
643     }
644
645     printf("nFileVersion = %d\n", nFileVersion);
646     printf("fGenerateBitcoins = %d\n", fGenerateBitcoins);
647     printf("nTransactionFee = %"PRI64d"\n", nTransactionFee);
648     printf("addrIncoming = %s\n", addrIncoming.ToString().c_str());
649     printf("fMinimizeToTray = %d\n", fMinimizeToTray);
650     printf("fMinimizeOnClose = %d\n", fMinimizeOnClose);
651     printf("fUseProxy = %d\n", fUseProxy);
652     printf("addrProxy = %s\n", addrProxy.ToString().c_str());
653
654
655     // The transaction fee setting won't be needed for many years to come.
656     // Setting it to zero here in case they set it to something in an earlier version.
657     if (nTransactionFee != 0)
658     {
659         nTransactionFee = 0;
660         WriteSetting("nTransactionFee", nTransactionFee);
661     }
662
663     // Upgrade
664     if (nFileVersion < VERSION)
665     {
666         // Get rid of old debug.log file in current directory
667         if (nFileVersion <= 105 && !pszSetDataDir[0])
668             unlink("debug.log");
669
670         WriteVersion(VERSION);
671     }
672
673     return true;
674 }
675
676 bool LoadWallet(bool& fFirstRunRet)
677 {
678     fFirstRunRet = false;
679     if (!CWalletDB("cr+").LoadWallet())
680         return false;
681     fFirstRunRet = vchDefaultKey.empty();
682
683     if (mapKeys.count(vchDefaultKey))
684     {
685         // Set keyUser
686         keyUser.SetPubKey(vchDefaultKey);
687         keyUser.SetPrivKey(mapKeys[vchDefaultKey]);
688     }
689     else
690     {
691         // Create new keyUser and set as default key
692         RandAddSeedPerfmon();
693         keyUser.MakeNewKey();
694         if (!AddKey(keyUser))
695             return false;
696         if (!SetAddressBookName(PubKeyToAddress(keyUser.GetPubKey()), "Your Address"))
697             return false;
698         CWalletDB().WriteDefaultKey(keyUser.GetPubKey());
699     }
700
701     CreateThread(ThreadFlushWalletDB, NULL);
702     return true;
703 }
704
705 void ThreadFlushWalletDB(void* parg)
706 {
707     static bool fOneThread;
708     if (fOneThread)
709         return;
710     fOneThread = true;
711     if (mapArgs.count("-noflushwallet"))
712         return;
713
714     unsigned int nLastSeen = nWalletDBUpdated;
715     unsigned int nLastFlushed = nWalletDBUpdated;
716     int64 nLastWalletUpdate = GetTime();
717     while (!fShutdown)
718     {
719         Sleep(500);
720
721         if (nLastSeen != nWalletDBUpdated)
722         {
723             nLastSeen = nWalletDBUpdated;
724             nLastWalletUpdate = GetTime();
725         }
726
727         if (nLastFlushed != nWalletDBUpdated && GetTime() - nLastWalletUpdate >= 2)
728         {
729             TRY_CRITICAL_BLOCK(cs_db)
730             {
731                 // Don't do this if any databases are in use
732                 int nRefCount = 0;
733                 map<string, int>::iterator mi = mapFileUseCount.begin();
734                 while (mi != mapFileUseCount.end())
735                 {
736                     nRefCount += (*mi).second;
737                     mi++;
738                 }
739
740                 if (nRefCount == 0 && !fShutdown)
741                 {
742                     string strFile = "wallet.dat";
743                     map<string, int>::iterator mi = mapFileUseCount.find(strFile);
744                     if (mi != mapFileUseCount.end())
745                     {
746                         printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
747                         printf("Flushing wallet.dat\n");
748                         nLastFlushed = nWalletDBUpdated;
749                         int64 nStart = GetTimeMillis();
750
751                         // Flush wallet.dat so it's self contained
752                         CloseDb(strFile);
753                         dbenv.txn_checkpoint(0, 0, 0);
754                         dbenv.lsn_reset(strFile.c_str(), 0);
755
756                         mapFileUseCount.erase(mi++);
757                         printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart);
758                     }
759                 }
760             }
761         }
762     }
763 }