mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02:00
Merge bitcoin/bitcoin#26513: Make static nLastFlush and nLastWrite Chainstate members
07dfbb5bb8Make static nLastFlush and nLastWrite Chainstate members (Aurèle Oulès) Pull request description: Fixes #22189. The `static std::multimap<uint256, FlatFilePos> mapBlocksUnknownParent; ` referenced in the issue was already fixed by #25571. I don't believe Chainstate references any other static variables. ACKs for top commit: jamesob: ACK07dfbb5bb8([`jamesob/ackr/26513.1.aureleoules.make_static_nlastflush_a`](https://github.com/jamesob/bitcoin/tree/ackr/26513.1.aureleoules.make_static_nlastflush_a)) theStack: Concept and code-review ACK07dfbb5bb8Tree-SHA512: 0f26463c079bbc5e0e62707d4ca4c8c9bbb99edfa3391d48d4915d24e2a1190873ecd4f9f11da25b44527671cdc82c41fd8234d56a4592a246989448d34406b0
This commit is contained in:
commit
07ac7a2dbf
2 changed files with 11 additions and 10 deletions
|
|
@ -2360,8 +2360,6 @@ bool Chainstate::FlushStateToDisk(
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
assert(this->CanFlushToDisk());
|
assert(this->CanFlushToDisk());
|
||||||
static std::chrono::microseconds nLastWrite{0};
|
|
||||||
static std::chrono::microseconds nLastFlush{0};
|
|
||||||
std::set<int> setFilesToPrune;
|
std::set<int> setFilesToPrune;
|
||||||
bool full_flush_completed = false;
|
bool full_flush_completed = false;
|
||||||
|
|
||||||
|
|
@ -2415,20 +2413,20 @@ bool Chainstate::FlushStateToDisk(
|
||||||
}
|
}
|
||||||
const auto nNow = GetTime<std::chrono::microseconds>();
|
const auto nNow = GetTime<std::chrono::microseconds>();
|
||||||
// Avoid writing/flushing immediately after startup.
|
// Avoid writing/flushing immediately after startup.
|
||||||
if (nLastWrite.count() == 0) {
|
if (m_last_write.count() == 0) {
|
||||||
nLastWrite = nNow;
|
m_last_write = nNow;
|
||||||
}
|
}
|
||||||
if (nLastFlush.count() == 0) {
|
if (m_last_flush.count() == 0) {
|
||||||
nLastFlush = nNow;
|
m_last_flush = nNow;
|
||||||
}
|
}
|
||||||
// The cache is large and we're within 10% and 10 MiB of the limit, but we have time now (not in the middle of a block processing).
|
// The cache is large and we're within 10% and 10 MiB of the limit, but we have time now (not in the middle of a block processing).
|
||||||
bool fCacheLarge = mode == FlushStateMode::PERIODIC && cache_state >= CoinsCacheSizeState::LARGE;
|
bool fCacheLarge = mode == FlushStateMode::PERIODIC && cache_state >= CoinsCacheSizeState::LARGE;
|
||||||
// The cache is over the limit, we have to write now.
|
// The cache is over the limit, we have to write now.
|
||||||
bool fCacheCritical = mode == FlushStateMode::IF_NEEDED && cache_state >= CoinsCacheSizeState::CRITICAL;
|
bool fCacheCritical = mode == FlushStateMode::IF_NEEDED && cache_state >= CoinsCacheSizeState::CRITICAL;
|
||||||
// It's been a while since we wrote the block index to disk. Do this frequently, so we don't need to redownload after a crash.
|
// It's been a while since we wrote the block index to disk. Do this frequently, so we don't need to redownload after a crash.
|
||||||
bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && nNow > nLastWrite + DATABASE_WRITE_INTERVAL;
|
bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && nNow > m_last_write + DATABASE_WRITE_INTERVAL;
|
||||||
// It's been very long since we flushed the cache. Do this infrequently, to optimize cache usage.
|
// It's been very long since we flushed the cache. Do this infrequently, to optimize cache usage.
|
||||||
bool fPeriodicFlush = mode == FlushStateMode::PERIODIC && nNow > nLastFlush + DATABASE_FLUSH_INTERVAL;
|
bool fPeriodicFlush = mode == FlushStateMode::PERIODIC && nNow > m_last_flush + DATABASE_FLUSH_INTERVAL;
|
||||||
// Combine all conditions that result in a full cache flush.
|
// Combine all conditions that result in a full cache flush.
|
||||||
fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune;
|
fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune;
|
||||||
// Write blocks and block index to disk.
|
// Write blocks and block index to disk.
|
||||||
|
|
@ -2458,7 +2456,7 @@ bool Chainstate::FlushStateToDisk(
|
||||||
|
|
||||||
UnlinkPrunedFiles(setFilesToPrune);
|
UnlinkPrunedFiles(setFilesToPrune);
|
||||||
}
|
}
|
||||||
nLastWrite = nNow;
|
m_last_write = nNow;
|
||||||
}
|
}
|
||||||
// Flush best chain related state. This can only be done if the blocks / block index write was also done.
|
// Flush best chain related state. This can only be done if the blocks / block index write was also done.
|
||||||
if (fDoFullFlush && !CoinsTip().GetBestBlock().IsNull()) {
|
if (fDoFullFlush && !CoinsTip().GetBestBlock().IsNull()) {
|
||||||
|
|
@ -2476,7 +2474,7 @@ bool Chainstate::FlushStateToDisk(
|
||||||
// Flush the chainstate (which may refer to block index entries).
|
// Flush the chainstate (which may refer to block index entries).
|
||||||
if (!CoinsTip().Flush())
|
if (!CoinsTip().Flush())
|
||||||
return AbortNode(state, "Failed to write to coin database");
|
return AbortNode(state, "Failed to write to coin database");
|
||||||
nLastFlush = nNow;
|
m_last_flush = nNow;
|
||||||
full_flush_completed = true;
|
full_flush_completed = true;
|
||||||
TRACE5(utxocache, flush,
|
TRACE5(utxocache, flush,
|
||||||
(int64_t)(GetTimeMicros() - nNow.count()), // in microseconds (µs)
|
(int64_t)(GetTimeMicros() - nNow.count()), // in microseconds (µs)
|
||||||
|
|
|
||||||
|
|
@ -743,6 +743,9 @@ private:
|
||||||
void UpdateTip(const CBlockIndex* pindexNew)
|
void UpdateTip(const CBlockIndex* pindexNew)
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
|
||||||
|
std::chrono::microseconds m_last_write{0};
|
||||||
|
std::chrono::microseconds m_last_flush{0};
|
||||||
|
|
||||||
friend ChainstateManager;
|
friend ChainstateManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue