forest/
lib.rs

1// Copyright 2019-2025 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 documentation;
51mod eth;
52mod f3;
53mod fil_cns;
54mod genesis;
55mod health;
56mod interpreter;
57mod ipld;
58mod key_management;
59mod libp2p;
60mod libp2p_bitswap;
61mod lotus_json;
62mod message;
63mod message_pool;
64mod metrics;
65mod networks;
66mod rpc;
67mod shim;
68mod state_manager;
69mod state_migration;
70mod statediff;
71#[cfg(any(test, doc))]
72mod test_utils;
73mod tool;
74mod utils;
75mod wallet;
76
77/// These items are semver-exempt, and exist for forest author use only
78// We want to have doctests, but don't want our internals to be public because:
79// - We don't want to be concerned with library compat
80//   (We want our cargo semver to be _for the command line_).
81// - We don't want to mistakenly export items which we never actually use.
82//
83// So we re-export the relevant items and test with `cargo test --doc --features doctest-private`
84#[cfg(feature = "doctest-private")]
85#[doc(hidden)]
86pub mod doctest_private {
87    pub use crate::{
88        blocks::{CachingBlockHeader, Ticket, TipsetKey},
89        cli::humantoken::{TokenAmountPretty, parse},
90        shim::{
91            address::Address, crypto::Signature, econ::TokenAmount, error::ExitCode,
92            randomness::Randomness, sector::RegisteredSealProof, state_tree::ActorState,
93            version::NetworkVersion,
94        },
95        utils::io::progress_log::WithProgress,
96        utils::{encoding::blake2b_256, encoding::keccak_256, io::read_toml},
97    };
98}
99
100/// These items are semver-exempt, and exist for forest author use only
101// Allow benchmarks of forest internals
102#[cfg(feature = "benchmark-private")]
103#[doc(hidden)]
104pub mod benchmark_private;
105
106/// These items are semver-exempt, and exist for forest author use only
107// Allow interop tests of forest internals
108#[cfg(feature = "interop-tests-private")]
109#[doc(hidden)]
110pub mod interop_tests_private {
111    pub mod libp2p {
112        pub use crate::libp2p::*;
113    }
114    pub mod libp2p_bitswap {
115        pub use crate::libp2p_bitswap::*;
116    }
117    pub mod beacon {
118        pub use crate::beacon::BeaconEntry;
119    }
120}
121
122// These should be made private in https://github.com/ChainSafe/forest/issues/3013
123pub use auth::{JWT_IDENTIFIER, verify_token};
124pub use cli::main::main as forest_main;
125pub use cli_shared::cli::{Client, Config};
126pub use daemon::main::main as forestd_main;
127pub use key_management::{
128    ENCRYPTED_KEYSTORE_NAME, FOREST_KEYSTORE_PHRASE_ENV, KEYSTORE_NAME, KeyStore, KeyStoreConfig,
129};
130pub use tool::main::main as forest_tool_main;
131pub use wallet::main::main as forest_wallet_main;
132
133#[cfg(test)]
134fn block_on<T>(f: impl std::future::Future<Output = T>) -> T {
135    tokio::runtime::Builder::new_multi_thread()
136        .enable_all()
137        .build()
138        .unwrap()
139        .block_on(f)
140}