#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

#17 in #graph-traversal

Download history 112/week @ 2023-12-13 132/week @ 2023-12-20 64/week @ 2023-12-27 77/week @ 2024-01-03 104/week @ 2024-01-10 105/week @ 2024-01-17 41/week @ 2024-01-24 41/week @ 2024-01-31 66/week @ 2024-02-07 121/week @ 2024-02-14 91/week @ 2024-02-21 121/week @ 2024-02-28 88/week @ 2024-03-06 92/week @ 2024-03-13 156/week @ 2024-03-20 195/week @ 2024-03-27

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

MIT license

265KB
684 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

~87MB
~800K SLoC