mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Trim headers when flushing to disk, and reduce flush interval from 1h to 5min.
This commit is contained in:
parent
eff6be337f
commit
4f0da3ce3d
1 changed files with 28 additions and 1 deletions
|
|
@ -76,7 +76,7 @@ static const unsigned int EXTRA_DESCENDANT_TX_SIZE_LIMIT = 10000;
|
|||
/** Maximum kilobytes for transactions to store for processing during reorg */
|
||||
static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000;
|
||||
/** Time to wait between writing blocks/block index to disk. */
|
||||
static constexpr std::chrono::hours DATABASE_WRITE_INTERVAL{1};
|
||||
static constexpr std::chrono::minutes DATABASE_WRITE_INTERVAL{5};
|
||||
/** Time to wait between flushing chainstate to disk. */
|
||||
static constexpr std::chrono::hours DATABASE_FLUSH_INTERVAL{24};
|
||||
/** Maximum age of our tip for us to be considered current for fee estimation */
|
||||
|
|
@ -2346,6 +2346,7 @@ bool CChainState::FlushStateToDisk(
|
|||
}
|
||||
std::vector<const CBlockIndex*> vBlocks;
|
||||
vBlocks.reserve(setDirtyBlockIndex.size());
|
||||
std::set<CBlockIndex*> setTrimmableBlockIndex(setDirtyBlockIndex);
|
||||
for (std::set<CBlockIndex*>::iterator it = setDirtyBlockIndex.begin(); it != setDirtyBlockIndex.end(); ) {
|
||||
vBlocks.push_back(*it);
|
||||
setDirtyBlockIndex.erase(it++);
|
||||
|
|
@ -2353,6 +2354,32 @@ bool CChainState::FlushStateToDisk(
|
|||
if (!pblocktree->WriteBatchSync(vFiles, nLastBlockFile, vBlocks)) {
|
||||
return AbortNode(state, "Failed to write to block index database");
|
||||
}
|
||||
|
||||
if (fTrimHeaders) {
|
||||
LogPrintf("Flushing block index, trimming headers, setTrimmableBlockIndex.size(): %d\n", setTrimmableBlockIndex.size());
|
||||
int trim_height = m_chain.Height() - nMustKeepFullHeaders;
|
||||
int min_height = std::numeric_limits<int>::max();
|
||||
CBlockIndex* min_index = nullptr;
|
||||
for (std::set<CBlockIndex*>::iterator it = setTrimmableBlockIndex.begin(); it != setTrimmableBlockIndex.end(); it++) {
|
||||
(*it)->assert_untrimmed();
|
||||
if ((*it)->nHeight < trim_height) {
|
||||
(*it)->trim();
|
||||
if ((*it)->nHeight < min_height) {
|
||||
min_height = (*it)->nHeight;
|
||||
min_index = *it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle any remaining untrimmed blocks that were too recent for trimming last time we flushed.
|
||||
if (min_index) {
|
||||
min_index = min_index->pprev;
|
||||
while (min_index && !min_index->trimmed()) {
|
||||
min_index->trim();
|
||||
min_index = min_index->pprev;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Finally remove any pruned files
|
||||
if (fFlushForPrune) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue