diff --git a/crates/floresta-chain/src/lib.rs b/crates/floresta-chain/src/lib.rs index 24c67315..ba05ae1a 100644 --- a/crates/floresta-chain/src/lib.rs +++ b/crates/floresta-chain/src/lib.rs @@ -21,6 +21,9 @@ pub use pruned_utreexo::error::*; pub use pruned_utreexo::udata::*; pub use pruned_utreexo::Notification; +/// Simple enum representing the network type. +/// +/// Possible values are Bitcoin, Testnet, Regtest, and Signet. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Network { Bitcoin, diff --git a/crates/floresta-chain/src/pruned_utreexo/chain_state.rs b/crates/floresta-chain/src/pruned_utreexo/chain_state.rs index 535215a2..2044f1fd 100644 --- a/crates/floresta-chain/src/pruned_utreexo/chain_state.rs +++ b/crates/floresta-chain/src/pruned_utreexo/chain_state.rs @@ -1,3 +1,19 @@ +//! The chain state contains both the blocks and blockchain validation logic +//! +//! This module provides the implementation of Bitcoin's consensus rules and chain validation, +//! enabling verification of transactions and blocks. It maintains: +//! +//! - Block headers and chain organization +//! - Chain selection based on proof-of-work +//! - Block validation and transaction verification +//! - UTXO set tracking via a Utreexo accumulator +//! - Support for Initial Block Download (IBD) +//! +//! Key types: +//! - [ChainState]: Main type implementing chain consensus and block validation +//! - [ChainStateInner]: Internal state storage and validation data +//! - [BlockConsumer]: Trait for receiving new block notifications +//! - [BestChain]: Tracks the current best chain and alternative forks extern crate alloc; use alloc::borrow::ToOwned; diff --git a/crates/floresta-chain/src/pruned_utreexo/chain_state_builder.rs b/crates/floresta-chain/src/pruned_utreexo/chain_state_builder.rs index 41040bda..fc6a8a2c 100644 --- a/crates/floresta-chain/src/pruned_utreexo/chain_state_builder.rs +++ b/crates/floresta-chain/src/pruned_utreexo/chain_state_builder.rs @@ -1,3 +1,13 @@ +//! This module provides a builder pattern for constructing ChainState instances with various +//! optional configurations. +//! +//! It includes: +//! - Chain parameters +//! - Chainstore backend +//! - Initial block download status +//! - Assumed valid blocks for validation optimization +//! - UTREEXO accumulator state +//! - Current chain tip and header use bitcoin::block::Header as BlockHeader; use bitcoin::hashes::Hash; use bitcoin::BlockHash; diff --git a/crates/floresta-chain/src/pruned_utreexo/chainparams.rs b/crates/floresta-chain/src/pruned_utreexo/chainparams.rs index 6de49af1..8937d890 100644 --- a/crates/floresta-chain/src/pruned_utreexo/chainparams.rs +++ b/crates/floresta-chain/src/pruned_utreexo/chainparams.rs @@ -1,3 +1,14 @@ +//! This module provides configuration and parameters for different Bitcoin networks (mainnet, +//! testnet, signet, and regtest). +//! +//! It includes: +//! - Network-specific parameters like block reward halving intervals and maturity periods +//! - DNS seeds for peer discovery +//! - Assumable validation states for Utreexo +//! - Block verification flag exceptions +//! +//! The main struct [`ChainParams`] encapsulates all chain-specific parameters while +//! [`DnsSeed`] handles peer discovery through DNS. extern crate alloc; use alloc::vec::Vec; use core::ffi::c_uint; diff --git a/crates/floresta-chain/src/pruned_utreexo/error.rs b/crates/floresta-chain/src/pruned_utreexo/error.rs index 62a98723..1081ad73 100644 --- a/crates/floresta-chain/src/pruned_utreexo/error.rs +++ b/crates/floresta-chain/src/pruned_utreexo/error.rs @@ -1,3 +1,12 @@ +//! This module defines error types specific to the blockchain validation and database operations, along with conversion between types. +//! +//! The main error types are: +//! - [BlockchainError]: High-level error type that encapsulates all the error kinds from our node chain backend operation. +//! - [TransactionError]: Represents errors in transaction validation +//! - [BlockValidationErrors]: Errors encountered during block validation that are not tied to any specific transaction +//! +//! Each error type implements `Display` and `Debug` for error reporting. + use core::fmt::Debug; use bitcoin::blockdata::script; diff --git a/crates/floresta-chain/src/pruned_utreexo/mod.rs b/crates/floresta-chain/src/pruned_utreexo/mod.rs index 1a6c19d4..5b93fefd 100644 --- a/crates/floresta-chain/src/pruned_utreexo/mod.rs +++ b/crates/floresta-chain/src/pruned_utreexo/mod.rs @@ -1,3 +1,21 @@ +//! This module is centered around the `ChainState` type, defining it and providing +//! implementations for the [BlockchainInterface] and [UpdatableChainstate] traits. +//! +//! Consequently, `ChainState` serves as the blockchain backend for our node and is +//! the highest-level type in `floresta-chain`. It is responsible for: +//! +//! - Keeping track of the chain state, and using a [ChainStore] for persisted storage +//! - Correctly updating the state with the help of the `consensus.rs` functions +//! - Interfacing with other components, and providing data about the current view of the chain +//! +//! The primary methods for updating our state are [ChainState::accept_header], which constructs +//! a chain of headers, and [ChainState::connect_block], which verifies the corresponding blocks. +//! +//! Key types: +//! - [ChainState]: The high-level chain backend +//! - [ChainStateInner]: Inner `ChainState` type that is guarded by a lock +//! - [BlockConsumer]: Trait for receiving new block notifications +//! - [BestChain]: Tracks the current best chain and alternative forks extern crate alloc; pub mod chain_state; @@ -158,10 +176,10 @@ pub trait UpdatableChainstate { fn mark_chain_as_assumed(&self, acc: Stump, tip: BlockHash) -> Result; } -/// [ChainStore] is a trait defining how we interact with our chain database. This definitions -/// will be used by the [ChainState] to save and retrieve data about the blockchain, likely +/// This trait is defining how we interact with our chain database. This definitions +/// will be used by the [ChainState](chain_state::ChainState) to save and retrieve data about the blockchain, likely /// on disk. -/// Right now, you can use the [KvChainStore] in your code, it implements this trait and +/// Right now, you can use the [KvChainStore](chainstore::KvChainStore) in your code, it implements this trait and /// uses a key-value store to save data. /// The [DatabaseError] is a simple trait that can be implemented by any error type that /// implements [std::error::Error] and [std::fmt::Display]. This is useful to abstract