mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #19088: validation: use std::chrono throughout some validation functions
789e9dd3aa727176797529c35b2848f994630a82 validation: use std::chrono in IsCurrentForFeeEstimation() (fanquake) 47be28c8bc475eafeebd4fc58ea92f0d3df0d8c6 validation: use std::chrono in CChainState::FlushStateToDisk() (fanquake) Pull request description: Probably up for debate as to which type is used for the constants. Personally, swapping these to hours is more readable. ACKs for top commit: MarcoFalke: ACK 789e9dd3aa727176797529c35b2848f994630a82 jonatack: ACK 789e9dd3aa727176797529c35b2848f994630a82 Tree-SHA512: f4a25cbd00a49a54b7783a1f588be83706dd2a475cecb5c2e8b97b2d4b27c0955a7454d7486f2454e96351c44f233b300c4f4b9ca62fc7336277f10da34dd5c3
This commit is contained in:
parent
38a0fbee54
commit
bdb1a55c0b
@ -75,12 +75,12 @@ static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000;
|
|||||||
static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
|
static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
|
||||||
/** The pre-allocation chunk size for rev?????.dat files (since 0.8) */
|
/** The pre-allocation chunk size for rev?????.dat files (since 0.8) */
|
||||||
static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
|
static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
|
||||||
/** Time to wait (in seconds) between writing blocks/block index to disk. */
|
/** Time to wait between writing blocks/block index to disk. */
|
||||||
static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
|
static constexpr std::chrono::hours DATABASE_WRITE_INTERVAL{1};
|
||||||
/** Time to wait (in seconds) between flushing chainstate to disk. */
|
/** Time to wait between flushing chainstate to disk. */
|
||||||
static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
|
static constexpr std::chrono::hours DATABASE_FLUSH_INTERVAL{24};
|
||||||
/** Maximum age of our tip in seconds for us to be considered current for fee estimation */
|
/** Maximum age of our tip for us to be considered current for fee estimation */
|
||||||
static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
|
static constexpr std::chrono::hours MAX_FEE_ESTIMATION_TIP_AGE{3};
|
||||||
|
|
||||||
bool CBlockIndexWorkComparator::operator()(const CBlockIndex* pa, const CBlockIndex* pb) const
|
bool CBlockIndexWorkComparator::operator()(const CBlockIndex* pa, const CBlockIndex* pb) const
|
||||||
{
|
{
|
||||||
@ -419,7 +419,7 @@ static bool IsCurrentForFeeEstimation() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
|||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
if (::ChainstateActive().IsInitialBlockDownload())
|
if (::ChainstateActive().IsInitialBlockDownload())
|
||||||
return false;
|
return false;
|
||||||
if (::ChainActive().Tip()->GetBlockTime() < (GetTime() - MAX_FEE_ESTIMATION_TIP_AGE))
|
if (::ChainActive().Tip()->GetBlockTime() < count_seconds(GetTime<std::chrono::seconds>() - MAX_FEE_ESTIMATION_TIP_AGE))
|
||||||
return false;
|
return false;
|
||||||
if (::ChainActive().Height() < pindexBestHeader->nHeight - 1)
|
if (::ChainActive().Height() < pindexBestHeader->nHeight - 1)
|
||||||
return false;
|
return false;
|
||||||
@ -2432,8 +2432,8 @@ bool CChainState::FlushStateToDisk(
|
|||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
assert(this->CanFlushToDisk());
|
assert(this->CanFlushToDisk());
|
||||||
static int64_t nLastWrite = 0;
|
static std::chrono::microseconds nLastWrite{0};
|
||||||
static int64_t nLastFlush = 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;
|
||||||
|
|
||||||
@ -2465,12 +2465,12 @@ bool CChainState::FlushStateToDisk(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int64_t nNow = GetTimeMicros();
|
const auto nNow = GetTime<std::chrono::microseconds>();
|
||||||
// Avoid writing/flushing immediately after startup.
|
// Avoid writing/flushing immediately after startup.
|
||||||
if (nLastWrite == 0) {
|
if (nLastWrite.count() == 0) {
|
||||||
nLastWrite = nNow;
|
nLastWrite = nNow;
|
||||||
}
|
}
|
||||||
if (nLastFlush == 0) {
|
if (nLastFlush.count() == 0) {
|
||||||
nLastFlush = nNow;
|
nLastFlush = 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).
|
||||||
@ -2478,9 +2478,9 @@ bool CChainState::FlushStateToDisk(
|
|||||||
// 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 + (int64_t)DATABASE_WRITE_INTERVAL * 1000000;
|
bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && nNow > nLastWrite + 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 + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000;
|
bool fPeriodicFlush = mode == FlushStateMode::PERIODIC && nNow > nLastFlush + 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.
|
||||||
|
Loading…
Reference in New Issue
Block a user