Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 257 Lines • ▼ Show 20 Lines | |||||
uint256 hashAssumeValid; | uint256 hashAssumeValid; | ||||
arith_uint256 nMinimumChainWork; | arith_uint256 nMinimumChainWork; | ||||
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE_PER_KB); | CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE_PER_KB); | ||||
Amount maxTxFee = DEFAULT_TRANSACTION_MAXFEE; | Amount maxTxFee = DEFAULT_TRANSACTION_MAXFEE; | ||||
CTxMemPool g_mempool; | CTxMemPool g_mempool; | ||||
std::atomic_bool g_is_mempool_loaded{false}; | |||||
/** Constant stuff for coinbase transactions we create: */ | /** Constant stuff for coinbase transactions we create: */ | ||||
CScript COINBASE_FLAGS; | CScript COINBASE_FLAGS; | ||||
const std::string strMessageMagic = "Bitcoin Signed Message:\n"; | const std::string strMessageMagic = "Bitcoin Signed Message:\n"; | ||||
// Internal stuff | // Internal stuff | ||||
namespace { | namespace { | ||||
▲ Show 20 Lines • Show All 5,310 Lines • ▼ Show 20 Lines | |||||
CBlockFileInfo *GetBlockFileInfo(size_t n) { | CBlockFileInfo *GetBlockFileInfo(size_t n) { | ||||
LOCK(cs_LastBlockFile); | LOCK(cs_LastBlockFile); | ||||
return &vinfoBlockFile.at(n); | return &vinfoBlockFile.at(n); | ||||
} | } | ||||
static const uint64_t MEMPOOL_DUMP_VERSION = 1; | static const uint64_t MEMPOOL_DUMP_VERSION = 1; | ||||
bool LoadMempool(const Config &config) { | bool LoadMempool(const Config &config, CTxMemPool &pool) { | ||||
int64_t nExpiryTimeout = | int64_t nExpiryTimeout = | ||||
gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60; | gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60; | ||||
FILE *filestr = fsbridge::fopen(GetDataDir() / "mempool.dat", "rb"); | FILE *filestr = fsbridge::fopen(GetDataDir() / "mempool.dat", "rb"); | ||||
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); | CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); | ||||
if (file.IsNull()) { | if (file.IsNull()) { | ||||
LogPrintf( | LogPrintf( | ||||
"Failed to open mempool file from disk. Continuing anyway.\n"); | "Failed to open mempool file from disk. Continuing anyway.\n"); | ||||
return false; | return false; | ||||
Show All 19 Lines | try { | ||||
int64_t nTime; | int64_t nTime; | ||||
int64_t nFeeDelta; | int64_t nFeeDelta; | ||||
file >> tx; | file >> tx; | ||||
file >> nTime; | file >> nTime; | ||||
file >> nFeeDelta; | file >> nFeeDelta; | ||||
Amount amountdelta = nFeeDelta * SATOSHI; | Amount amountdelta = nFeeDelta * SATOSHI; | ||||
if (amountdelta != Amount::zero()) { | if (amountdelta != Amount::zero()) { | ||||
g_mempool.PrioritiseTransaction(tx->GetId(), prioritydummy, | pool.PrioritiseTransaction(tx->GetId(), prioritydummy, | ||||
amountdelta); | amountdelta); | ||||
} | } | ||||
CValidationState state; | CValidationState state; | ||||
if (nTime + nExpiryTimeout > nNow) { | if (nTime + nExpiryTimeout > nNow) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
AcceptToMemoryPoolWithTime( | AcceptToMemoryPoolWithTime( | ||||
config, g_mempool, state, tx, true /* fLimitFree */, | config, pool, state, tx, true /* fLimitFree */, | ||||
nullptr /* pfMissingInputs */, nTime, | nullptr /* pfMissingInputs */, nTime, | ||||
false /* fOverrideMempoolLimit */, | false /* fOverrideMempoolLimit */, | ||||
Amount::zero() /* nAbsurdFee */, false /* test_accept */); | Amount::zero() /* nAbsurdFee */, false /* test_accept */); | ||||
if (state.IsValid()) { | if (state.IsValid()) { | ||||
++count; | ++count; | ||||
} else { | } else { | ||||
++failed; | ++failed; | ||||
} | } | ||||
} else { | } else { | ||||
++skipped; | ++skipped; | ||||
} | } | ||||
if (ShutdownRequested()) { | if (ShutdownRequested()) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
std::map<uint256, Amount> mapDeltas; | std::map<uint256, Amount> mapDeltas; | ||||
file >> mapDeltas; | file >> mapDeltas; | ||||
for (const auto &i : mapDeltas) { | for (const auto &i : mapDeltas) { | ||||
g_mempool.PrioritiseTransaction(i.first, prioritydummy, i.second); | pool.PrioritiseTransaction(i.first, prioritydummy, i.second); | ||||
} | } | ||||
} 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 successes, %i " | LogPrintf("Imported mempool transactions from disk: %i successes, %i " | ||||
"failed, %i expired\n", | "failed, %i expired\n", | ||||
count, failed, skipped); | count, failed, skipped); | ||||
return true; | return true; | ||||
} | } | ||||
bool DumpMempool() { | 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; | ||||
static Mutex dump_mutex; | static Mutex dump_mutex; | ||||
LOCK(dump_mutex); | LOCK(dump_mutex); | ||||
{ | { | ||||
LOCK(g_mempool.cs); | LOCK(pool.cs); | ||||
for (const auto &i : g_mempool.mapDeltas) { | for (const auto &i : pool.mapDeltas) { | ||||
mapDeltas[i.first] = i.second.second; | mapDeltas[i.first] = i.second.second; | ||||
} | } | ||||
vinfo = g_mempool.infoAll(); | vinfo = pool.infoAll(); | ||||
} | } | ||||
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; | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |