| 5030 | } |
| 5031 | |
| 5032 | bool DumpMempool(void) |
| 5033 | { |
| 5034 | int64_t start = GetTimeMicros(); |
| 5035 | |
| 5036 | std::map<uint256, CAmount> mapDeltas; |
| 5037 | std::vector<TxMempoolInfo> vinfo; |
| 5038 | |
| 5039 | { |
| 5040 | LOCK(mempool.cs); |
| 5041 | for (const auto &i : mempool.mapDeltas) { |
| 5042 | mapDeltas[i.first] = i.second; |
| 5043 | } |
| 5044 | vinfo = mempool.infoAll(); |
| 5045 | } |
| 5046 | |
| 5047 | int64_t mid = GetTimeMicros(); |
| 5048 | |
| 5049 | try { |
| 5050 | FILE* filestr = fsbridge::fopen(GetDataDir() / "mempool.dat.new", "wb"); |
| 5051 | if (!filestr) { |
| 5052 | return false; |
| 5053 | } |
| 5054 | |
| 5055 | CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); |
| 5056 | |
| 5057 | uint64_t version = MEMPOOL_DUMP_VERSION; |
| 5058 | file << version; |
| 5059 | |
| 5060 | file << (uint64_t)vinfo.size(); |
| 5061 | for (const auto& i : vinfo) { |
| 5062 | file << *(i.tx); |
| 5063 | file << (int64_t)i.nTime; |
| 5064 | file << (int64_t)i.nFeeDelta; |
| 5065 | mapDeltas.erase(i.tx->GetHash()); |
| 5066 | } |
| 5067 | |
| 5068 | file << mapDeltas; |
| 5069 | if (!FileCommit(file.Get())) |
| 5070 | throw std::runtime_error("FileCommit failed"); |
| 5071 | file.fclose(); |
| 5072 | RenameOver(GetDataDir() / "mempool.dat.new", GetDataDir() / "mempool.dat"); |
| 5073 | int64_t last = GetTimeMicros(); |
| 5074 | LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", (mid-start)*MICRO, (last-mid)*MICRO); |
| 5075 | } catch (const std::exception& e) { |
| 5076 | LogPrintf("Failed to dump mempool: %s. Continuing anyway.\n", e.what()); |
| 5077 | return false; |
| 5078 | } |
| 5079 | return true; |
| 5080 | } |
| 5081 | |
| 5082 | //! Guess how far we are in the verification process at the given block index |
| 5083 | //! require cs_main if pindex has not been validated yet (because nChainTx might be unset) |
no test coverage detected