| 4953 | static const uint64_t MEMPOOL_DUMP_VERSION = 1; |
| 4954 | |
| 4955 | bool LoadMempool(void) |
| 4956 | { |
| 4957 | const CChainParams& chainparams = Params(); |
| 4958 | int64_t nExpiryTimeout = gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60; |
| 4959 | FILE* filestr = fsbridge::fopen(GetDataDir() / "mempool.dat", "rb"); |
| 4960 | CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); |
| 4961 | if (file.IsNull()) { |
| 4962 | LogPrintf("Failed to open mempool file from disk. Continuing anyway.\n"); |
| 4963 | return false; |
| 4964 | } |
| 4965 | |
| 4966 | int64_t count = 0; |
| 4967 | int64_t expired = 0; |
| 4968 | int64_t failed = 0; |
| 4969 | int64_t already_there = 0; |
| 4970 | int64_t nNow = GetTime(); |
| 4971 | |
| 4972 | try { |
| 4973 | uint64_t version; |
| 4974 | file >> version; |
| 4975 | if (version != MEMPOOL_DUMP_VERSION) { |
| 4976 | return false; |
| 4977 | } |
| 4978 | uint64_t num; |
| 4979 | file >> num; |
| 4980 | while (num--) { |
| 4981 | CTransactionRef tx; |
| 4982 | int64_t nTime; |
| 4983 | int64_t nFeeDelta; |
| 4984 | file >> tx; |
| 4985 | file >> nTime; |
| 4986 | file >> nFeeDelta; |
| 4987 | |
| 4988 | CAmount amountdelta = nFeeDelta; |
| 4989 | if (amountdelta) { |
| 4990 | mempool.PrioritiseTransaction(tx->GetHash(), amountdelta); |
| 4991 | } |
| 4992 | CValidationState state; |
| 4993 | if (nTime + nExpiryTimeout > nNow) { |
| 4994 | LOCK(cs_main); |
| 4995 | AcceptToMemoryPoolWithTime(chainparams, mempool, state, tx, nullptr /* pfMissingInputs */, nTime, |
| 4996 | nullptr /* plTxnReplaced */, false /* bypass_limits */, 0 /* nAbsurdFee */, |
| 4997 | false /* test_accept */); |
| 4998 | if (state.IsValid()) { |
| 4999 | ++count; |
| 5000 | } else { |
| 5001 | // mempool may contain the transaction already, e.g. from |
| 5002 | // wallet(s) having loaded it while we were processing |
| 5003 | // mempool transactions; consider these as valid, instead of |
| 5004 | // failed, but mark them as 'already there' |
| 5005 | if (mempool.exists(tx->GetHash())) { |
| 5006 | ++already_there; |
| 5007 | } else { |
| 5008 | ++failed; |
| 5009 | } |
| 5010 | } |
| 5011 | } else { |
| 5012 | ++expired; |
no test coverage detected