#graph-traversal #epoch #algorithm #guard #bitcoin #codebase #guarded

bitcoin-epoch

RAII-style guard for using epoch-based graph traversal algorithms

2 releases

0.1.16-alpha.0 Apr 1, 2023
0.1.12-alpha.0 Jan 19, 2023

#26 in #graph-traversal

Download history 74/week @ 2024-07-22 86/week @ 2024-07-29 114/week @ 2024-08-05 73/week @ 2024-08-12 78/week @ 2024-08-19 109/week @ 2024-08-26 78/week @ 2024-09-02 52/week @ 2024-09-09 87/week @ 2024-09-16 91/week @ 2024-09-23 58/week @ 2024-09-30 81/week @ 2024-10-14 45/week @ 2024-10-21 41/week @ 2024-10-28 66/week @ 2024-11-04

233 downloads per month
Used in 46 crates (4 directly)

MIT license

265KB
685 lines

bitcoin-epoch

This crate is part of a direct translation of the Bitcoin Core C++ codebase to Rust.

It provides types and functions for managing epoch-based graph traversal algorithms, which are used extensively in the Bitcoin Core codebase to traverse transaction dependency graphs.

Epoch

Epoch is the main type of the crate. It is a RAII-style guard for using epoch-based graph traversal algorithms. It is used to avoid visiting the same transactions twice when walking ancestors or descendants.

The type contains a raw_epoch field that represents the current epoch, and a guarded field that indicates whether the epoch is currently being guarded by an EpochGuard. The default function creates an Epoch instance with a raw_epoch of 0 and guarded set to false.

The type provides a visited function, which takes a mutable reference to an EpochMarker and returns a boolean indicating whether the marker has already been visited during the current epoch. The guarded function returns a boolean indicating whether the epoch is currently being guarded by an EpochGuard.

EpochGuard

EpochGuard is a scoped lock guard that is used to guard an epoch for the duration of a block. It is responsible for incrementing the epoch when it goes out of scope, to ensure clear separation between epochs.

The type contains an epoch field that is an Rc<RefCell<Epoch>>, representing the epoch being guarded. The new function creates a new EpochGuard instance and guards the epoch, incrementing its raw_epoch field and setting its guarded field to true. The guard is released and the epoch's guarded field is set to false when the guard goes out of scope and the guard's drop function is called.

EpochMarker

EpochMarker is a simple struct that contains a marker field, which is used to keep track of whether a transaction has already been visited during the current epoch. The marker field is a u64 representing the epoch time.

The default function creates an EpochMarker instance with a marker field of 0.

Disclaimer

Note that some of the function bodies in this crate may still be in the process of translation from C++ to Rust.

Dependencies

~89MB
~833K SLoC