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