diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c31bd08dd..ea6263e961 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,9 +28,9 @@ get_directory_property(precious_variables CACHE_VARIABLES) #============================= set(CLIENT_NAME "Bitcoin Core") set(CLIENT_VERSION_MAJOR 29) -set(CLIENT_VERSION_MINOR 3) +set(CLIENT_VERSION_MINOR 4) set(CLIENT_VERSION_BUILD 0) -set(CLIENT_VERSION_RC 0) +set(CLIENT_VERSION_RC 1) set(CLIENT_VERSION_IS_RELEASE "true") set(COPYRIGHT_YEAR "2025") diff --git a/doc/man/bitcoin-cli.1 b/doc/man/bitcoin-cli.1 index 6146224cdd..33f28d1ac0 100644 --- a/doc/man/bitcoin-cli.1 +++ b/doc/man/bitcoin-cli.1 @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIN-CLI "1" "February 2026" "bitcoin-cli v29.3.0" "User Commands" +.TH BITCOIN-CLI "1" "June 2026" "bitcoin-cli v29.4.0rc1" "User Commands" .SH NAME -bitcoin-cli \- manual page for bitcoin-cli v29.3.0 +bitcoin-cli \- manual page for bitcoin-cli v29.4.0rc1 .SH SYNOPSIS .B bitcoin-cli [\fI\,options\/\fR] \fI\, \/\fR[\fI\,params\/\fR] @@ -15,7 +15,7 @@ bitcoin-cli \- manual page for bitcoin-cli v29.3.0 .B bitcoin-cli [\fI\,options\/\fR] \fI\,help \/\fR .SH DESCRIPTION -Bitcoin Core RPC client version v29.3.0 +Bitcoin Core RPC client version v29.4.0rc1 .PP The bitcoin\-cli utility provides a command line interface to interact with a Bitcoin Core RPC server. .PP diff --git a/doc/man/bitcoin-qt.1 b/doc/man/bitcoin-qt.1 index a4fec08c7a..ab57dd61d7 100644 --- a/doc/man/bitcoin-qt.1 +++ b/doc/man/bitcoin-qt.1 @@ -1,12 +1,12 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIN-QT "1" "February 2026" "bitcoin-qt v29.3.0" "User Commands" +.TH BITCOIN-QT "1" "June 2026" "bitcoin-qt v29.4.0rc1" "User Commands" .SH NAME -bitcoin-qt \- manual page for bitcoin-qt v29.3.0 +bitcoin-qt \- manual page for bitcoin-qt v29.4.0rc1 .SH SYNOPSIS .B bitcoin-qt [\fI\,options\/\fR] [\fI\,URI\/\fR] .SH DESCRIPTION -Bitcoin Core version v29.3.0 +Bitcoin Core version v29.4.0rc1 .PP The bitcoin\-qt application provides a graphical interface for interacting with Bitcoin Core. .PP diff --git a/doc/man/bitcoin-tx.1 b/doc/man/bitcoin-tx.1 index a58bfea152..de043b7142 100644 --- a/doc/man/bitcoin-tx.1 +++ b/doc/man/bitcoin-tx.1 @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIN-TX "1" "February 2026" "bitcoin-tx v29.3.0" "User Commands" +.TH BITCOIN-TX "1" "June 2026" "bitcoin-tx v29.4.0rc1" "User Commands" .SH NAME -bitcoin-tx \- manual page for bitcoin-tx v29.3.0 +bitcoin-tx \- manual page for bitcoin-tx v29.4.0rc1 .SH SYNOPSIS .B bitcoin-tx [\fI\,options\/\fR] \fI\, \/\fR[\fI\,commands\/\fR] @@ -9,7 +9,7 @@ bitcoin-tx \- manual page for bitcoin-tx v29.3.0 .B bitcoin-tx [\fI\,options\/\fR] \fI\,-create \/\fR[\fI\,commands\/\fR] .SH DESCRIPTION -Bitcoin Core bitcoin\-tx utility version v29.3.0 +Bitcoin Core bitcoin\-tx utility version v29.4.0rc1 .PP The bitcoin\-tx tool is used for creating and modifying bitcoin transactions. .PP diff --git a/doc/man/bitcoin-util.1 b/doc/man/bitcoin-util.1 index b7e0127ae1..063e05883a 100644 --- a/doc/man/bitcoin-util.1 +++ b/doc/man/bitcoin-util.1 @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIN-UTIL "1" "February 2026" "bitcoin-util v29.3.0" "User Commands" +.TH BITCOIN-UTIL "1" "June 2026" "bitcoin-util v29.4.0rc1" "User Commands" .SH NAME -bitcoin-util \- manual page for bitcoin-util v29.3.0 +bitcoin-util \- manual page for bitcoin-util v29.4.0rc1 .SH SYNOPSIS .B bitcoin-util [\fI\,options\/\fR] [\fI\,command\/\fR] @@ -9,7 +9,7 @@ bitcoin-util \- manual page for bitcoin-util v29.3.0 .B bitcoin-util [\fI\,options\/\fR] \fI\,grind \/\fR .SH DESCRIPTION -Bitcoin Core bitcoin\-util utility version v29.3.0 +Bitcoin Core bitcoin\-util utility version v29.4.0rc1 .PP The bitcoin\-util tool provides bitcoin related functionality that does not rely on the ability to access a running node. Available [commands] are listed below. .SH OPTIONS diff --git a/doc/man/bitcoin-wallet.1 b/doc/man/bitcoin-wallet.1 index 96c2f4e1c9..8f7f721406 100644 --- a/doc/man/bitcoin-wallet.1 +++ b/doc/man/bitcoin-wallet.1 @@ -1,12 +1,12 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIN-WALLET "1" "February 2026" "bitcoin-wallet v29.3.0" "User Commands" +.TH BITCOIN-WALLET "1" "June 2026" "bitcoin-wallet v29.4.0rc1" "User Commands" .SH NAME -bitcoin-wallet \- manual page for bitcoin-wallet v29.3.0 +bitcoin-wallet \- manual page for bitcoin-wallet v29.4.0rc1 .SH SYNOPSIS .B bitcoin-wallet [\fI\,options\/\fR] \fI\,\/\fR .SH DESCRIPTION -Bitcoin Core bitcoin\-wallet utility version v29.3.0 +Bitcoin Core bitcoin\-wallet utility version v29.4.0rc1 .PP bitcoin\-wallet is an offline tool for creating and interacting with Bitcoin Core wallet files. .PP diff --git a/doc/man/bitcoind.1 b/doc/man/bitcoind.1 index 10ec23f695..7a8c4c3e1b 100644 --- a/doc/man/bitcoind.1 +++ b/doc/man/bitcoind.1 @@ -1,12 +1,12 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIND "1" "February 2026" "bitcoind v29.3.0" "User Commands" +.TH BITCOIND "1" "June 2026" "bitcoind v29.4.0rc1" "User Commands" .SH NAME -bitcoind \- manual page for bitcoind v29.3.0 +bitcoind \- manual page for bitcoind v29.4.0rc1 .SH SYNOPSIS .B bitcoind [\fI\,options\/\fR] .SH DESCRIPTION -Bitcoin Core daemon version v29.3.0 +Bitcoin Core daemon version v29.4.0rc1 .PP The Bitcoin Core daemon (bitcoind) is a headless program that connects to the Bitcoin network to validate and relay transactions and blocks, as well as relaying addresses. .PP diff --git a/doc/release-notes.md b/doc/release-notes.md index bd6db525f5..c59434e8c4 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -1,6 +1,6 @@ -Bitcoin Core version 29.x is now available from: +Bitcoin Core version 29.4rc1 is now available from: - + This release includes various bug fixes and performance improvements, as well as updated translations. @@ -37,9 +37,14 @@ unsupported systems. Notable changes =============== +This release fixes an issue where the chainstate database would repeatedly +rewrite large portions of itself, causing excessive disk reads and writes +during normal operation. + ### Validation - #35209 validation: correct lifetime of precomputed tx data +- #35465 coins: compact chainstate regularly ### Leveldb @@ -58,6 +63,10 @@ Notable changes - #34228 depends: Unset SOURCE_DATE_EPOCH in gen_id script - #34848 cmake: Migrate away from deprecated SQLite3 target +### Test + +- #34918 fuzz: [refactor] Remove unused g_setup pointers + ### Doc - #34510 doc: fix broken bpftrace installation link diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index 8fb366515a..2341545b63 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -251,7 +251,7 @@ CDBWrapper::CDBWrapper(const DBParams& params) if (params.options.force_compact) { LogPrintf("Starting database compaction of %s\n", fs::PathToString(params.path)); - DBContext().pdb->CompactRange(nullptr, nullptr); + CompactFull(); LogPrintf("Finished database compaction of %s\n", fs::PathToString(params.path)); } @@ -306,11 +306,18 @@ bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync) return true; } +std::optional CDBWrapper::GetProperty(const std::string& property) const +{ + if (std::string value; DBContext().pdb->GetProperty(property, &value)) return value; + return std::nullopt; +} + +void CDBWrapper::CompactFull() { DBContext().pdb->CompactRange(nullptr, nullptr); } + size_t CDBWrapper::DynamicMemoryUsage() const { - std::string memory; std::optional parsed; - if (!DBContext().pdb->GetProperty("leveldb.approximate-memory-usage", &memory) || !(parsed = ToIntegral(memory))) { + if (auto memory{GetProperty("leveldb.approximate-memory-usage")}; !memory || !(parsed = ToIntegral(*memory))) { LogDebug(BCLog::LEVELDB, "Failed to get approximate-memory-usage property\n"); return 0; } diff --git a/src/dbwrapper.h b/src/dbwrapper.h index dd5daa7a1f..08081c1a0d 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -273,6 +273,12 @@ public: bool WriteBatch(CDBBatch& batch, bool fSync = false); + //! Perform a blocking full compaction of the underlying LevelDB. + void CompactFull(); + + //! Return a LevelDB property value, if available. + std::optional GetProperty(const std::string& property) const; + // Get an estimate of LevelDB memory usage (in bytes). size_t DynamicMemoryUsage() const; diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index c46144b34b..1780e97e65 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -1049,6 +1050,30 @@ BOOST_FIXTURE_TEST_CASE(ccoins_flush_behavior, FlushTest) } } +BOOST_FIXTURE_TEST_CASE(coins_db_leveldb_layout, FlushTest) +{ + auto level2_files{[](CCoinsViewDB& base) { + return *Assert(ToIntegral(*Assert(base.GetDBProperty("leveldb.num-files-at-level2")))); + }}; + const COutPoint outpoint{Txid::FromUint256(m_rng.rand256()), 0}; + const Coin coin{MakeCoin()}; + const uint256 block_hash{m_rng.rand256()}; + + CCoinsViewDB base{{.path = m_args.GetDataDirBase() / "coins_db_leveldb_layout", .cache_bytes = 1_MiB, .wipe_data = true}, {}}; + CCoinsViewCache cache{&base}; + + cache.EmplaceCoinInternalDANGER(COutPoint{outpoint}, Coin{coin}); + cache.SetBestBlock(block_hash); + cache.Sync(); + + BOOST_CHECK_EQUAL(level2_files(base), 0); + WITH_LOCK(::cs_main, return base.CompactFull()).wait(); + BOOST_CHECK_EQUAL(level2_files(base), 1); + + BOOST_CHECK(*Assert(base.GetCoin(outpoint)) == coin); + BOOST_CHECK_EQUAL(base.GetBestBlock(), block_hash); +} + BOOST_AUTO_TEST_CASE(coins_resource_is_used) { CCoinsMapMemoryResource resource; diff --git a/src/test/fuzz/deserialize.cpp b/src/test/fuzz/deserialize.cpp index 270d546c39..e34690ea6e 100644 --- a/src/test/fuzz/deserialize.cpp +++ b/src/test/fuzz/deserialize.cpp @@ -36,18 +36,13 @@ using node::SnapshotMetadata; -namespace { -const BasicTestingSetup* g_setup; -} // namespace - void initialize_deserialize() { static const auto testing_setup = MakeNoLogFileContext<>(); - g_setup = testing_setup.get(); } #define FUZZ_TARGET_DESERIALIZE(name, code) \ - FUZZ_TARGET(name, .init = initialize_deserialize) \ + FUZZ_TARGET(name, .init = initialize_deserialize) \ { \ try { \ code \ diff --git a/src/txdb.cpp b/src/txdb.cpp index 1622039d63..11b0724a9a 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -12,10 +12,14 @@ #include #include #include +#include #include #include +#include #include +#include +#include #include #include @@ -51,11 +55,22 @@ CCoinsViewDB::CCoinsViewDB(DBParams db_params, CoinsViewOptions options) : m_options{std::move(options)}, m_db{std::make_unique(m_db_params)} { } +CCoinsViewDB::~CCoinsViewDB() +{ + if (m_compaction.valid()) { + if (m_compaction.wait_for(std::chrono::seconds{0}) != std::future_status::ready) { + LogInfo("Waiting for background chainstate compaction of %s", fs::PathToString(m_db_params.path)); + } + m_compaction.wait(); + } +} + void CCoinsViewDB::ResizeCache(size_t new_cache_size) { // We can't do this operation with an in-memory DB since we'll lose all the coins upon // reset. if (!m_db_params.memory_only) { + LOCK(m_db_mutex); // Have to do a reset first to get the original `m_db` state to release its // filesystem lock. m_db.reset(); @@ -156,6 +171,30 @@ size_t CCoinsViewDB::EstimateSize() const return m_db->EstimateSize(DB_COIN, uint8_t(DB_COIN + 1)); } +std::optional CCoinsViewDB::GetDBProperty(const std::string& property) +{ + return m_db->GetProperty(property); +} + +std::shared_future CCoinsViewDB::CompactFull() +{ + AssertLockHeld(::cs_main); + if (m_compaction.valid() && m_compaction.wait_for(std::chrono::seconds{0}) != std::future_status::ready) return m_compaction; + m_compaction = std::async(std::launch::async, [this] { + try { + util::ThreadRename("utxocompact"); + LOCK(m_db_mutex); + + LogDebug(BCLog::COINDB, "Starting chainstate compaction of %s", fs::PathToString(m_db_params.path)); + m_db->CompactFull(); + LogDebug(BCLog::COINDB, "Finished chainstate compaction of %s", fs::PathToString(m_db_params.path)); + } catch (const std::exception& e) { + LogWarning("Failed chainstate compaction (%s)", e.what()); + } + }).share(); + return m_compaction; +} + /** Specialization of CCoinsViewCursor to iterate over a CCoinsViewDB */ class CCoinsViewDBCursor: public CCoinsViewCursor { diff --git a/src/txdb.h b/src/txdb.h index 968b7c2781..8944fbc1ac 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -14,8 +14,10 @@ #include #include +#include #include #include +#include #include class COutPoint; @@ -39,9 +41,13 @@ class CCoinsViewDB final : public CCoinsView protected: DBParams m_db_params; CoinsViewOptions m_options; + //! Prevents CompactFull() from using m_db while ResizeCache() replaces it. + Mutex m_db_mutex; std::unique_ptr m_db; + std::shared_future m_compaction; public: explicit CCoinsViewDB(DBParams db_params, CoinsViewOptions options); + ~CCoinsViewDB() override; std::optional GetCoin(const COutPoint& outpoint) const override; bool HaveCoin(const COutPoint &outpoint) const override; @@ -55,10 +61,16 @@ public: size_t EstimateSize() const override; //! Dynamically alter the underlying leveldb cache size. - void ResizeCache(size_t new_cache_size) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + void ResizeCache(size_t new_cache_size) EXCLUSIVE_LOCKS_REQUIRED(cs_main, !m_db_mutex); //! @returns filesystem path to on-disk storage or std::nullopt if in memory. std::optional StoragePath() { return m_db->StoragePath(); } + + //! Perform a full compaction of the underlying LevelDB on a one-shot background thread. + std::shared_future CompactFull() EXCLUSIVE_LOCKS_REQUIRED(cs_main, !m_db_mutex); + + //! Return an underlying LevelDB property value, if available. + std::optional GetDBProperty(const std::string& property); }; #endif // BITCOIN_TXDB_H diff --git a/src/validation.cpp b/src/validation.cpp index 90711c2089..ff281bc1a6 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -111,6 +111,13 @@ const std::vector CHECKLEVEL_DOC { * */ static constexpr int PRUNE_LOCK_BUFFER{10}; +// Return whether the completed full flush should compact chainstate +static bool ShouldCompactChainstate(bool in_ibd) +{ + static constexpr uint32_t flush_ratio{320}; // Roughly every 2 weeks with hourly flushes + return !in_ibd && FastRandomContext().randrange(flush_ratio) == 0; +} + TRACEPOINT_SEMAPHORE(validation, block_connected); TRACEPOINT_SEMAPHORE(utxocache, flush); TRACEPOINT_SEMAPHORE(mempool, replaced); @@ -2938,9 +2945,20 @@ bool Chainstate::FlushStateToDisk( (bool)fFlushForPrune); } } - if (full_flush_completed && m_chainman.m_options.signals) { - // Update best block in wallet (so we can detect restored wallets). - m_chainman.m_options.signals->ChainStateFlushed(this->GetRole(), m_chain.GetLocator()); + + if (full_flush_completed) { + if (m_chainman.m_options.signals) { + // Update best block in wallet (so we can detect restored wallets). + m_chainman.m_options.signals->ChainStateFlushed(this->GetRole(), m_chain.GetLocator()); + } + + if (!m_chainman.m_interrupt && ShouldCompactChainstate(m_chainman.IsInitialBlockDownload())) { + try { + CoinsDB().CompactFull(); + } catch (const std::exception& e) { + LogWarning("Failed to start chainstate compaction (%s)", e.what()); + } + } } } catch (const std::runtime_error& e) { return FatalError(m_chainman.GetNotifications(), state, strprintf(_("System error while flushing: %s"), e.what())); diff --git a/src/wallet/test/fuzz/crypter.cpp b/src/wallet/test/fuzz/crypter.cpp index 7869f5f39c..733a5cd32f 100644 --- a/src/wallet/test/fuzz/crypter.cpp +++ b/src/wallet/test/fuzz/crypter.cpp @@ -11,11 +11,9 @@ namespace wallet { namespace { -const TestingSetup* g_setup; void initialize_crypter() { static const auto testing_setup = MakeNoLogFileContext(); - g_setup = testing_setup.get(); } FUZZ_TARGET(crypter, .init = initialize_crypter) diff --git a/test/lint/test_runner/src/main.rs b/test/lint/test_runner/src/main.rs index 0d785682bb..26ed455042 100644 --- a/test/lint/test_runner/src/main.rs +++ b/test/lint/test_runner/src/main.rs @@ -203,7 +203,7 @@ fn get_subtrees() -> Vec<&'static str> { vec![ "src/crc32c", "src/crypto/ctaes", - "src/leveldb", + //"src/leveldb", No longer a subtree in this release branch, due to direct cherry-picks "src/minisketch", "src/secp256k1", ]