Skip to content

Commit

Permalink
Merge bitcoin#29227: log mempool loading progress
Browse files Browse the repository at this point in the history
eb78ea4 [log] mempool loading (glozow)

Pull request description:

  Motivated by bitcoin#29193. Currently, we only log something (non-debug) when we fail to load the file and at the end of importing all the transactions. That means it's hard to tell what's happening if it's taking a long time to load.

  This PR adds a maximum of 10 new unconditional log lines:
  - When we start to load transactions.
  - Our progress percentage when it advances by at least 10% from the last time we logged. Percentage is based on the number of transactions.

  If there are lots of transactions in the mempool, the logs will look like this:
  ```
  2024-01-11T11:36:30.410726Z Loading 401 mempool transactions from disk...
  2024-01-11T11:36:30.423374Z Progress loading mempool transactions from disk: 10% (tried 41, 360 remaining)
  2024-01-11T11:36:30.435539Z Progress loading mempool transactions from disk: 20% (tried 81, 320 remaining)
  2024-01-11T11:36:30.447874Z Progress loading mempool transactions from disk: 30% (tried 121, 280 remaining)
  2024-01-11T11:36:30.460474Z Progress loading mempool transactions from disk: 40% (tried 161, 240 remaining)
  2024-01-11T11:36:30.473731Z Progress loading mempool transactions from disk: 50% (tried 201, 200 remaining)
  2024-01-11T11:36:30.487806Z Progress loading mempool transactions from disk: 60% (tried 241, 160 remaining)
  2024-01-11T11:36:30.501739Z Progress loading mempool transactions from disk: 70% (tried 281, 120 remaining)
  2024-01-11T11:36:30.516334Z Progress loading mempool transactions from disk: 80% (tried 321, 80 remaining)
  2024-01-11T11:36:30.531309Z Progress loading mempool transactions from disk: 90% (tried 361, 40 remaining)
  2024-01-11T11:36:30.549019Z  Imported mempool transactions from disk: 401 succeeded, 0 failed, 0 expired, 0 already there, 400 waiting for initial broadcast
  ```
  If there are 0 or 1 transactions, progress logs aren't printed.

ACKs for top commit:
  kevkevinpal:
    Concept ACK [eb78ea4](bitcoin@eb78ea4)
  ismaelsadeeq:
    ACK eb78ea4
  dergoegge:
    Code review ACK eb78ea4
  theStack:
    re-ACK eb78ea4
  mzumsande:
    tested ACK eb78ea4

Tree-SHA512: ae4420986dc7bd5cb675a7ebc76b24c8ee60007f0296ed37e272f1c3415764d44963bea84c51948da319a65661dca8a95eac2a59bf7e745519b6fcafa09812cf
  • Loading branch information
fanquake committed Jan 15, 2024
2 parents 17e33fb + eb78ea4 commit 05c4c5a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/kernel/mempool_persist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,20 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
return false;
}
file.SetXor(xor_key);
uint64_t num;
file >> num;
while (num) {
--num;
uint64_t total_txns_to_load;
file >> total_txns_to_load;
uint64_t txns_tried = 0;
LogInfo("Loading %u mempool transactions from disk...\n", total_txns_to_load);
int next_tenth_to_report = 0;
while (txns_tried < total_txns_to_load) {
const int percentage_done(100.0 * txns_tried / total_txns_to_load);
if (next_tenth_to_report < percentage_done / 10) {
LogInfo("Progress loading mempool transactions from disk: %d%% (tried %u, %u remaining)\n",
percentage_done, txns_tried, total_txns_to_load - txns_tried);
next_tenth_to_report = percentage_done / 10;
}
++txns_tried;

CTransactionRef tx;
int64_t nTime;
int64_t nFeeDelta;
Expand Down

0 comments on commit 05c4c5a

Please sign in to comment.