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

Function LoadMempool

src/node/mempool_persist.cpp:43–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41static const uint64_t MEMPOOL_DUMP_VERSION{2};
42
43bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active_chainstate, ImportMempoolOptions&& opts)
44{
45 if (load_path.empty()) return false;
46
47 AutoFile file{opts.mockable_fopen_function(load_path, "rb")};
48 if (file.IsNull()) {
49 LogInfo("Failed to open mempool file. Continuing anyway.\n");
50 return false;
51 }
52
53 int64_t count = 0;
54 int64_t expired = 0;
55 int64_t failed = 0;
56 int64_t already_there = 0;
57 int64_t unbroadcast = 0;
58 const auto now{NodeClock::now()};
59
60 try {
61 uint64_t version;
62 file >> version;
63
64 if (version == MEMPOOL_DUMP_VERSION_NO_XOR_KEY) {
65 file.SetObfuscation({});
66 } else if (version == MEMPOOL_DUMP_VERSION) {
67 Obfuscation obfuscation;
68 file >> obfuscation;
69 file.SetObfuscation(obfuscation);
70 } else {
71 return false;
72 }
73
74 uint64_t total_txns_to_load;
75 file >> total_txns_to_load;
76 uint64_t txns_tried = 0;
77 LogInfo("Loading %u mempool transactions from file...\n", total_txns_to_load);
78 int next_tenth_to_report = 0;
79 while (txns_tried < total_txns_to_load) {
80 const int percentage_done(100.0 * txns_tried / total_txns_to_load);
81 if (next_tenth_to_report < percentage_done / 10) {
82 LogInfo("Progress loading mempool transactions from file: %d%% (tried %u, %u remaining)\n",
83 percentage_done, txns_tried, total_txns_to_load - txns_tried);
84 next_tenth_to_report = percentage_done / 10;
85 }
86 ++txns_tried;
87
88 CTransactionRef tx;
89 int64_t nTime;
90 int64_t nFeeDelta;
91 file >> TX_WITH_WITNESS(tx);
92 file >> nTime;
93 file >> nFeeDelta;
94
95 if (opts.use_current_time) {
96 nTime = TicksSinceEpoch<std::chrono::seconds>(now);
97 }
98
99 CAmount amountdelta = nFeeDelta;
100 if (amountdelta && opts.apply_fee_delta_priority) {

Callers 3

AppInitMainFunction · 0.85
importmempoolFunction · 0.85

Calls 11

AcceptToMemoryPoolFunction · 0.85
SetObfuscationMethod · 0.80
PrioritiseTransactionMethod · 0.80
AddUnbroadcastTxMethod · 0.80
emptyMethod · 0.45
IsNullMethod · 0.45
GetHashMethod · 0.45
existsMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected