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.
1// Copyright (c) 2011 The LevelDB Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file. See the AUTHORS file for names of contributors.5#ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_6#define STORAGE_LEVELDB_DB_SNAPSHOT_H_8#include "db/dbformat.h"9#include "leveldb/db.h"11namespace leveldb {13class SnapshotList;15// Snapshots are kept in a doubly-linked list in the DB.16// Each SnapshotImpl corresponds to a particular sequence number.17class SnapshotImpl : public Snapshot {18public:19SnapshotImpl(SequenceNumber sequence_number)20: sequence_number_(sequence_number) {}22SequenceNumber sequence_number() const { return sequence_number_; }24private:25friend class SnapshotList;27// SnapshotImpl is kept in a doubly-linked circular list. The SnapshotList28// implementation operates on the next/previous fields directly.29SnapshotImpl* prev_;30SnapshotImpl* next_;32const SequenceNumber sequence_number_;34#if !defined(NDEBUG)35SnapshotList* list_ = nullptr;36#endif // !defined(NDEBUG)37};39class SnapshotList {40public:41SnapshotList() : head_(0) {42head_.prev_ = &head_;43head_.next_ = &head_;44}46bool empty() const { return head_.next_ == &head_; }47SnapshotImpl* oldest() const {48assert(!empty());49return head_.next_;50}51SnapshotImpl* newest() const {52assert(!empty());53return head_.prev_;54}56// Creates a SnapshotImpl and appends it to the end of the list.57SnapshotImpl* New(SequenceNumber sequence_number) {58assert(empty() || newest()->sequence_number_ <= sequence_number);60SnapshotImpl* snapshot = new SnapshotImpl(sequence_number);62#if !defined(NDEBUG)63snapshot->list_ = this;64#endif // !defined(NDEBUG)65snapshot->next_ = &head_;66snapshot->prev_ = head_.prev_;67snapshot->prev_->next_ = snapshot;68snapshot->next_->prev_ = snapshot;69return snapshot;70}72// Removes a SnapshotImpl from this list.73//74// The snapshot must have been created by calling New() on this list.75//76// The snapshot pointer should not be const, because its memory is77// deallocated. However, that would force us to change DB::ReleaseSnapshot(),78// which is in the API, and currently takes a const Snapshot.79void Delete(const SnapshotImpl* snapshot) {80#if !defined(NDEBUG)81assert(snapshot->list_ == this);82#endif // !defined(NDEBUG)83snapshot->prev_->next_ = snapshot->next_;84snapshot->next_->prev_ = snapshot->prev_;85delete snapshot;86}88private:89// Dummy head of doubly-linked list of snapshots90SnapshotImpl head_;91};93} // namespace leveldb95#endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_
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.