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.
502// Write records that span two blocks503Write(BigString("foo", kBlockSize));504Write(BigString("bar", kBlockSize));505Write("correct");507// Wipe the middle block508for (int offset = kBlockSize; offset < 2 * kBlockSize; offset++) {509SetByte(offset, 'x');510}512ASSERT_EQ("correct", Read());513ASSERT_EQ("EOF", Read());514const size_t dropped = DroppedBytes();515ASSERT_LE(dropped, 2 * kBlockSize + 100);516ASSERT_GE(dropped, 2 * kBlockSize);517}519TEST(LogTest, ReadStart) { CheckInitialOffsetRecord(0, 0); }521TEST(LogTest, ReadSecondOneOff) { CheckInitialOffsetRecord(1, 1); }523TEST(LogTest, ReadSecondTenThousand) { CheckInitialOffsetRecord(10000, 1); }525TEST(LogTest, ReadSecondStart) { CheckInitialOffsetRecord(10007, 1); }527TEST(LogTest, ReadThirdOneOff) { CheckInitialOffsetRecord(10008, 2); }529TEST(LogTest, ReadThirdStart) { CheckInitialOffsetRecord(20014, 2); }531TEST(LogTest, ReadFourthOneOff) { CheckInitialOffsetRecord(20015, 3); }533TEST(LogTest, ReadFourthFirstBlockTrailer) {534CheckInitialOffsetRecord(log::kBlockSize - 4, 3);535}537TEST(LogTest, ReadFourthMiddleBlock) {538CheckInitialOffsetRecord(log::kBlockSize + 1, 3);539}541TEST(LogTest, ReadFourthLastBlock) {542CheckInitialOffsetRecord(2 * log::kBlockSize + 1, 3);543}545TEST(LogTest, ReadFourthStart) {546CheckInitialOffsetRecord(5472 * (kHeaderSize + 1000) + (2 * log::kBlockSize - 1000) + 3 * kHeaderSize,5483);549}551TEST(LogTest, ReadInitialOffsetIntoBlockPadding) {552CheckInitialOffsetRecord(3 * log::kBlockSize - 3, 5);553}555TEST(LogTest, ReadEnd) { CheckOffsetPastEndReturnsNoRecords(0); }557TEST(LogTest, ReadPastEnd) { CheckOffsetPastEndReturnsNoRecords(5); }559} // namespace log560} // namespace leveldb562int main(int argc, char** argv) { return leveldb::test::RunAllTests(); }
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.