MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / DumpMempool

Function DumpMempool

src/node/mempool_persist.cpp:153–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151}
152
153bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, FopenFn mockable_fopen_function, bool skip_file_commit)
154{
155 auto start = SteadyClock::now();
156
157 std::map<Txid, CAmount> mapDeltas;
158 std::vector<TxMempoolInfo> vinfo;
159 std::set<Txid> unbroadcast_txids;
160
161 static Mutex dump_mutex;
162 LOCK(dump_mutex);
163
164 {
165 LOCK(pool.cs);
166 for (const auto &i : pool.mapDeltas) {
167 mapDeltas[i.first] = i.second;
168 }
169 vinfo = pool.infoAll();
170 unbroadcast_txids = pool.GetUnbroadcastTxs();
171 }
172
173 auto mid = SteadyClock::now();
174
175 const fs::path file_fspath{dump_path + ".new"};
176 AutoFile file{mockable_fopen_function(file_fspath, "wb")};
177 if (file.IsNull()) {
178 return false;
179 }
180
181 try {
182 const uint64_t version{pool.m_opts.persist_v1_dat ? MEMPOOL_DUMP_VERSION_NO_XOR_KEY : MEMPOOL_DUMP_VERSION};
183 file << version;
184
185 if (!pool.m_opts.persist_v1_dat) {
186 const Obfuscation obfuscation{FastRandomContext{}.randbytes<Obfuscation::KEY_SIZE>()};
187 file << obfuscation;
188 file.SetObfuscation(obfuscation);
189 } else {
190 file.SetObfuscation({});
191 }
192
193 uint64_t mempool_transactions_to_write(vinfo.size());
194 file << mempool_transactions_to_write;
195 LogInfo("Writing %u mempool transactions to file...\n", mempool_transactions_to_write);
196 for (const auto& i : vinfo) {
197 file << TX_WITH_WITNESS(*(i.tx));
198 file << int64_t{count_seconds(i.m_time)};
199 file << int64_t{i.nFeeDelta};
200 mapDeltas.erase(i.tx->GetHash());
201 }
202
203 file << mapDeltas;
204
205 LogInfo("Writing %d unbroadcast transactions to file.\n", unbroadcast_txids.size());
206 file << unbroadcast_txids;
207
208 if (!skip_file_commit && !file.Commit()) {
209 (void)file.fclose();
210 throw std::runtime_error("Commit failed");

Callers 3

ShutdownFunction · 0.85
savemempoolFunction · 0.85

Calls 14

count_secondsFunction · 0.85
PathToStringFunction · 0.85
SysErrorStringFunction · 0.85
RenameOverFunction · 0.85
infoAllMethod · 0.80
GetUnbroadcastTxsMethod · 0.80
SetObfuscationMethod · 0.80
fcloseMethod · 0.80
IsNullMethod · 0.45
sizeMethod · 0.45
eraseMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected