test: chainstate write test for periodic chainstate flush
This commit is contained in:
4 files changed
+50
-4
No files matched your search
@@ -47,6 +47,7 @@ add_executable(test_bitcoin
|
|||||||
blockmanager_tests.cpp
|
blockmanager_tests.cpp
|
||||||
bloom_tests.cpp
|
bloom_tests.cpp
|
||||||
bswap_tests.cpp
|
bswap_tests.cpp
|
||||||
|
chainstate_write_tests.cpp
|
||||||
checkqueue_tests.cpp
|
checkqueue_tests.cpp
|
||||||
cluster_linearize_tests.cpp
|
cluster_linearize_tests.cpp
|
||||||
coins_tests.cpp
|
coins_tests.cpp
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
// Copyright (c) The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <test/util/setup_common.h>
|
||||||
|
#include <validation.h>
|
||||||
|
#include <validationinterface.h>
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(chainstate_write_tests)
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(chainstate_write_interval, TestingSetup)
|
||||||
|
{
|
||||||
|
struct TestSubscriber final : CValidationInterface {
|
||||||
|
bool m_did_flush{false};
|
||||||
|
void ChainStateFlushed(ChainstateRole, const CBlockLocator&) override
|
||||||
|
{
|
||||||
|
m_did_flush = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto sub{std::make_shared<TestSubscriber>()};
|
||||||
|
m_node.validation_signals->RegisterSharedValidationInterface(sub);
|
||||||
|
auto& chainstate{Assert(m_node.chainman)->ActiveChainstate()};
|
||||||
|
BlockValidationState state_dummy{};
|
||||||
|
|
||||||
|
// The first periodic flush sets m_last_flush and does not flush
|
||||||
|
chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC);
|
||||||
|
m_node.validation_signals->SyncWithValidationInterfaceQueue();
|
||||||
|
BOOST_CHECK(!sub->m_did_flush);
|
||||||
|
|
||||||
|
SetMockTime(GetTime<std::chrono::minutes>() + 23h + 59min);
|
||||||
|
chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC);
|
||||||
|
m_node.validation_signals->SyncWithValidationInterfaceQueue();
|
||||||
|
BOOST_CHECK(!sub->m_did_flush);
|
||||||
|
|
||||||
|
SetMockTime(GetTime<std::chrono::minutes>() + 24h);
|
||||||
|
chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC);
|
||||||
|
m_node.validation_signals->SyncWithValidationInterfaceQueue();
|
||||||
|
BOOST_CHECK(sub->m_did_flush);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
+2
-2
@@ -2878,7 +2878,7 @@ bool Chainstate::FlushStateToDisk(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const auto nNow{SteadyClock::now()};
|
const auto nNow{NodeClock::now()};
|
||||||
// Avoid writing/flushing immediately after startup.
|
// Avoid writing/flushing immediately after startup.
|
||||||
if (m_last_write == decltype(m_last_write){}) {
|
if (m_last_write == decltype(m_last_write){}) {
|
||||||
m_last_write = nNow;
|
m_last_write = nNow;
|
||||||
@@ -2951,7 +2951,7 @@ bool Chainstate::FlushStateToDisk(
|
|||||||
m_last_flush = nNow;
|
m_last_flush = nNow;
|
||||||
full_flush_completed = true;
|
full_flush_completed = true;
|
||||||
TRACEPOINT(utxocache, flush,
|
TRACEPOINT(utxocache, flush,
|
||||||
int64_t{Ticks<std::chrono::microseconds>(SteadyClock::now() - nNow)},
|
int64_t{Ticks<std::chrono::microseconds>(NodeClock::now() - nNow)},
|
||||||
(uint32_t)mode,
|
(uint32_t)mode,
|
||||||
(uint64_t)coins_count,
|
(uint64_t)coins_count,
|
||||||
(uint64_t)coins_mem_usage,
|
(uint64_t)coins_mem_usage,
|
||||||
|
|||||||
+3
-2
@@ -31,6 +31,7 @@
|
|||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
#include <util/hasher.h>
|
#include <util/hasher.h>
|
||||||
#include <util/result.h>
|
#include <util/result.h>
|
||||||
|
#include <util/time.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <versionbits.h>
|
#include <versionbits.h>
|
||||||
|
|
||||||
@@ -802,8 +803,8 @@ private:
|
|||||||
void UpdateTip(const CBlockIndex* pindexNew)
|
void UpdateTip(const CBlockIndex* pindexNew)
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
|
||||||
SteadyClock::time_point m_last_write{};
|
NodeClock::time_point m_last_write{};
|
||||||
SteadyClock::time_point m_last_flush{};
|
NodeClock::time_point m_last_flush{};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In case of an invalid snapshot, rename the coins leveldb directory so
|
* In case of an invalid snapshot, rename the coins leveldb directory so
|
||||||
|
|||||||
Reference in new issue
Block a user