Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251std::string key2 = "key2";252std::unique_ptr<SQLiteBatch> batch2 = std::make_unique<SQLiteBatch>(*database);253BOOST_CHECK(batch2->Write(key2, value));254// The first key must not exist255BOOST_CHECK(!batch2->Exists(key));256}258BOOST_AUTO_TEST_CASE(concurrent_txn_dont_interfere)259{260std::string key = "key";261std::string value = "value";262std::string value2 = "value_2";264DatabaseOptions options;265DatabaseStatus status;266bilingual_str error;267const auto& database = MakeSQLiteDatabase(m_path_root / "sqlite", options, status, error);269std::unique_ptr<DatabaseBatch> handler = Assert(database)->MakeBatch();271// Verify concurrent db transactions does not interfere between each other.272// Start db txn, write key and check the key does exist within the db txn.273BOOST_CHECK(handler->TxnBegin());274BOOST_CHECK(handler->Write(key, value));275BOOST_CHECK(handler->Exists(key));277// But, the same key, does not exist in another handler278std::unique_ptr<DatabaseBatch> handler2 = Assert(database)->MakeBatch();279BOOST_CHECK(handler2->Exists(key));281// Attempt to commit the handler txn calling the handler2 methods.282// Which, must not be possible.283BOOST_CHECK(!handler2->TxnCommit());284BOOST_CHECK(!handler2->TxnAbort());286// Only the first handler can commit the changes.287BOOST_CHECK(handler->TxnCommit());288// And, once commit is completed, handler2 can read the record289std::string read_value;290BOOST_CHECK(handler2->Read(key, read_value));291BOOST_CHECK_EQUAL(read_value, value);293// Also, once txn is committed, single write statements are re-enabled.294// Which means that handler2 can read the record changes directly.295BOOST_CHECK(handler->Write(key, value2, /*fOverwrite=*/true));296BOOST_CHECK(handler2->Read(key, read_value));297BOOST_CHECK_EQUAL(read_value, value2);298}300BOOST_AUTO_TEST_CASE(in_memory_database_cannot_reopen)301{302// Reopening an in-memory database would create a fresh empty connection,303// silently losing all data. Open() must throw instead.304InMemoryWalletDatabase database;305database.Close();306BOOST_CHECK_THROW(database.Open(), std::runtime_error);307}309BOOST_AUTO_TEST_SUITE_END()310} // namespace wallet
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.