Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 5,786 Lines • ▼ Show 20 Lines | if (file.IsNull()) { | ||||
"Failed to open mempool file from disk. Continuing anyway.\n"); | "Failed to open mempool file from disk. Continuing anyway.\n"); | ||||
return false; | return false; | ||||
} | } | ||||
int64_t count = 0; | int64_t count = 0; | ||||
int64_t expired = 0; | int64_t expired = 0; | ||||
int64_t failed = 0; | int64_t failed = 0; | ||||
int64_t already_there = 0; | int64_t already_there = 0; | ||||
int64_t unbroadcast = 0; | |||||
int64_t nNow = GetTime(); | int64_t nNow = GetTime(); | ||||
try { | try { | ||||
uint64_t version; | uint64_t version; | ||||
file >> version; | file >> version; | ||||
if (version != MEMPOOL_DUMP_VERSION) { | if (version != MEMPOOL_DUMP_VERSION) { | ||||
return false; | return false; | ||||
} | } | ||||
Show All 40 Lines | try { | ||||
} | } | ||||
} | } | ||||
std::map<TxId, Amount> mapDeltas; | std::map<TxId, Amount> mapDeltas; | ||||
file >> mapDeltas; | file >> mapDeltas; | ||||
for (const auto &i : mapDeltas) { | for (const auto &i : mapDeltas) { | ||||
pool.PrioritiseTransaction(i.first, i.second); | pool.PrioritiseTransaction(i.first, i.second); | ||||
} | } | ||||
std::set<TxId> unbroadcast_txids; | |||||
file >> unbroadcast_txids; | |||||
unbroadcast = unbroadcast_txids.size(); | |||||
for (const auto &txid : unbroadcast_txids) { | |||||
pool.AddUnbroadcastTx(txid); | |||||
} | |||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
LogPrintf("Failed to deserialize mempool data on disk: %s. Continuing " | LogPrintf("Failed to deserialize mempool data on disk: %s. Continuing " | ||||
"anyway.\n", | "anyway.\n", | ||||
e.what()); | e.what()); | ||||
return false; | return false; | ||||
} | } | ||||
LogPrintf("Imported mempool transactions from disk: %i succeeded, %i " | LogPrintf("Imported mempool transactions from disk: %i succeeded, %i " | ||||
"failed, %i expired, %i already there\n", | "failed, %i expired, %i already there, %i waiting for initial " | ||||
count, failed, expired, already_there); | "broadcast\n", | ||||
count, failed, expired, already_there, unbroadcast); | |||||
return true; | return true; | ||||
} | } | ||||
bool DumpMempool(const CTxMemPool &pool) { | bool DumpMempool(const CTxMemPool &pool) { | ||||
int64_t start = GetTimeMicros(); | int64_t start = GetTimeMicros(); | ||||
std::map<uint256, Amount> mapDeltas; | std::map<uint256, Amount> mapDeltas; | ||||
std::vector<TxMempoolInfo> vinfo; | std::vector<TxMempoolInfo> vinfo; | ||||
std::set<TxId> unbroadcast_txids; | |||||
static Mutex dump_mutex; | static Mutex dump_mutex; | ||||
LOCK(dump_mutex); | LOCK(dump_mutex); | ||||
{ | { | ||||
LOCK(pool.cs); | LOCK(pool.cs); | ||||
for (const auto &i : pool.mapDeltas) { | for (const auto &i : pool.mapDeltas) { | ||||
mapDeltas[i.first] = i.second; | mapDeltas[i.first] = i.second; | ||||
} | } | ||||
vinfo = pool.infoAll(); | vinfo = pool.infoAll(); | ||||
unbroadcast_txids = pool.GetUnbroadcastTxs(); | |||||
} | } | ||||
int64_t mid = GetTimeMicros(); | int64_t mid = GetTimeMicros(); | ||||
try { | try { | ||||
FILE *filestr = fsbridge::fopen(GetDataDir() / "mempool.dat.new", "wb"); | FILE *filestr = fsbridge::fopen(GetDataDir() / "mempool.dat.new", "wb"); | ||||
if (!filestr) { | if (!filestr) { | ||||
return false; | return false; | ||||
} | } | ||||
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); | CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); | ||||
uint64_t version = MEMPOOL_DUMP_VERSION; | uint64_t version = MEMPOOL_DUMP_VERSION; | ||||
file << version; | file << version; | ||||
file << uint64_t(vinfo.size()); | file << uint64_t(vinfo.size()); | ||||
for (const auto &i : vinfo) { | for (const auto &i : vinfo) { | ||||
file << *(i.tx); | file << *(i.tx); | ||||
file << int64_t(count_seconds(i.m_time)); | file << int64_t(count_seconds(i.m_time)); | ||||
file << i.nFeeDelta; | file << i.nFeeDelta; | ||||
mapDeltas.erase(i.tx->GetId()); | mapDeltas.erase(i.tx->GetId()); | ||||
} | } | ||||
file << mapDeltas; | file << mapDeltas; | ||||
LogPrintf("Writing %d unbroadcast transactions to disk.\n", | |||||
unbroadcast_txids.size()); | |||||
file << unbroadcast_txids; | |||||
if (!FileCommit(file.Get())) { | if (!FileCommit(file.Get())) { | ||||
throw std::runtime_error("FileCommit failed"); | throw std::runtime_error("FileCommit failed"); | ||||
} | } | ||||
file.fclose(); | file.fclose(); | ||||
RenameOver(GetDataDir() / "mempool.dat.new", | RenameOver(GetDataDir() / "mempool.dat.new", | ||||
GetDataDir() / "mempool.dat"); | GetDataDir() / "mempool.dat"); | ||||
int64_t last = GetTimeMicros(); | int64_t last = GetTimeMicros(); | ||||
LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", | LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |