Skip to main content

forest/
lib.rs

1// Copyright 2019-2026 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4#![recursion_limit = "1024"]
5#![cfg_attr(
6    not(test),
7    deny(
8        clippy::todo,
9        clippy::dbg_macro,
10        clippy::indexing_slicing,
11        clippy::get_unwrap,
12        clippy::unwrap_used,
13        clippy::unreachable,
14        clippy::unimplemented
15    )
16)]
17#![cfg_attr(
18    doc,
19    deny(rustdoc::all),
20    allow(
21        // We build with `--document-private-items` on both docs.rs and our
22        // vendored docs.
23        rustdoc::private_intra_doc_links,
24        // See module `doctest_private` below.
25        rustdoc::private_doc_tests,
26        rustdoc::missing_crate_level_docs
27    )
28)]
29
30// Forest handles chain state far larger than a 32-bit address space and relies on `usize == u64`
31// for lossless offset and length conversions in the CAR and index code. Enforce it at compile time.
32const _: () = assert!(
33    usize::BITS == 64,
34    "Forest only supports 64-bit targets (requires usize == u64)"
35);
36
37cfg_if::cfg_if! {
38    if #[cfg(feature = "rustalloc")] {
39    } else if #[cfg(feature = "jemalloc")] {
40        use crate::cli_shared::tikv_jemallocator::Jemalloc;
41        #[global_allocator]
42        static GLOBAL: Jemalloc = Jemalloc;
43    } else if #[cfg(feature = "system-alloc")] {
44        use std::alloc::System;
45        #[global_allocator]
46        static GLOBAL: System = System;
47    }
48}
49
50mod auth;
51mod beacon;
52mod blocks;
53mod chain;
54mod chain_sync;
55mod cid_collections;
56mod cli;
57mod cli_shared;
58mod daemon;
59mod db;
60mod dev;
61mod documentation;
62mod eth;
63mod f3;
64mod fil_cns;
65mod genesis;
66mod health;
67mod interpreter;
68mod ipld;
69mod key_management;
70mod libp2p;
71mod libp2p_bitswap;
72mod lotus_json;
73mod message;
74mod message_pool;
75mod metrics;
76mod networks;
77mod rpc;
78mod shim;
79mod state_manager;
80mod state_migration;
81mod statediff;
82#[cfg(any(test, doc))]
83mod test_utils;
84mod tool;
85mod utils;
86mod wallet;
87
88mod prelude {
89    pub use crate::{
90        db::Blockstore,
91        shim::clock::ChainEpoch,
92        utils::{ShallowClone, get_size::CidWrapper},
93    };
94    pub use ahash::{HashMapExt as _, HashSetExt as _};
95    pub use anyhow::Context as _;
96    pub use cid::Cid;
97    pub use futures::FutureExt as _;
98    pub use itertools::Itertools as _;
99    pub use std::{ops::Deref as _, sync::Arc};
100    pub use tracing::{debug, error, info, trace, warn};
101}
102
103/// These items are semver-exempt, and exist for forest author use only
104// We want to have doctests, but don't want our internals to be public because:
105// - We don't want to be concerned with library compat
106//   (We want our cargo semver to be _for the command line_).
107// - We don't want to mistakenly export items which we never actually use.
108//
109// So we re-export the relevant items and test with `cargo test --doc --features doctest-private`
110#[cfg(feature = "doctest-private")]
111#[doc(hidden)]
112pub mod doctest_private {
113    pub use crate::{
114        blocks::{CachingBlockHeader, Ticket, TipsetKey},
115        cli::humantoken::{TokenAmountPretty, parse},
116        shim::{
117            address::Address, crypto::Signature, econ::TokenAmount, error::ExitCode,
118            randomness::Randomness, sector::RegisteredSealProof, state_tree::ActorState,
119            version::NetworkVersion,
120        },
121        utils::io::progress_log::WithProgress,
122        utils::net::{DownloadFileOption, download_to},
123        utils::{encoding::blake2b_256, encoding::keccak_256, io::read_toml},
124    };
125}
126
127/// These items are semver-exempt, and exist for forest author use only
128// Allow benchmarks of forest internals
129#[cfg(feature = "benchmark-private")]
130#[doc(hidden)]
131pub mod benchmark_private;
132
133/// These items are semver-exempt, and exist for forest author use only
134// Allow interop tests of forest internals
135#[cfg(feature = "interop-tests-private")]
136#[doc(hidden)]
137pub mod interop_tests_private {
138    pub mod libp2p {
139        pub use crate::libp2p::*;
140    }
141    pub mod libp2p_bitswap {
142        pub use crate::libp2p_bitswap::*;
143    }
144    pub mod beacon {
145        pub use crate::beacon::BeaconEntry;
146    }
147}
148
149// These should be made private in https://github.com/ChainSafe/forest/issues/3013
150pub use auth::{JWT_IDENTIFIER, verify_token};
151pub use cli::main::main as forest_main;
152pub use cli_shared::cli::{Client, Config};
153pub use daemon::main::main as forestd_main;
154pub use dev::main::main as forest_dev_main;
155pub use key_management::{
156    ENCRYPTED_KEYSTORE_NAME, FOREST_KEYSTORE_PHRASE_ENV, KEYSTORE_NAME, KeyStore, KeyStoreConfig,
157};
158pub use tool::main::main as forest_tool_main;
159pub use wallet::main::main as forest_wallet_main;