Skip to content

Commit

Permalink
[mempool] Mark mempool import fails that were found in mempool as 'al…
Browse files Browse the repository at this point in the history
…ready there'

Summary:
I was investigating the reasons for failed imports in mempool and noticed that `LoadMempool()` and `pwallet->postInitProcess()` (for all wallets) are executed concurrently. The wallet will end up importing transactions that `LoadMempool()` later tries to import; the latter will fail due to the tx already being in the mempool.

Backport of Bitcoin Core PR11062
bitcoin/bitcoin#11062

Test Plan:
```
make check-all
```

Reviewers: Fabien, #bitcoin_abc, deadalnix

Reviewed By: Fabien, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4266
  • Loading branch information
kallewoof authored and jonspock committed Dec 29, 2019
1 parent 525c142 commit fa93f1b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/validation.cpp
Expand Up @@ -5507,8 +5507,9 @@ bool LoadMempool(const Config &config) {
}

int64_t count = 0;
int64_t skipped = 0;
int64_t expired = 0;
int64_t failed = 0;
int64_t already_there = 0;
int64_t nNow = GetTime();

try {
Expand Down Expand Up @@ -5546,10 +5547,18 @@ bool LoadMempool(const Config &config) {
if (state.IsValid()) {
++count;
} else {
++failed;
// mempool may contain the transaction already, e.g. from
// wallet(s) having loaded it while we were processing
// mempool transactions; consider these as valid, instead of
// failed, but mark them as 'already there'
if (g_mempool.exists(tx->GetHash())) {
++already_there;
} else {
++failed;
}
}
} else {
++skipped;
++expired;
}
}
std::map<uint256, Amount> mapDeltas;
Expand All @@ -5565,9 +5574,9 @@ bool LoadMempool(const Config &config) {
return false;
}

LogPrintf("Imported mempool transactions from disk: %i successes, %i "
"failed, %i expired\n",
count, failed, skipped);
LogPrintf("Imported mempool transactions from disk: %i succeeded, %i "
"failed, %i expired, %i already there\n",
count, failed, expired, already_there);
return true;
}

Expand Down

0 comments on commit fa93f1b

Please sign in to comment.