//! GHOSTDAG consensus implementation for Synor blockchain.
//!
//! This crate implements the GHOSTDAG (Greedy Heaviest-Observed Sub-Tree Directed Acyclic Graph)
//! protocol, based on Kaspa's design with modifications for Synor.
//!
//! # GHOSTDAG Overview
//!
//! GHOSTDAG allows multiple blocks to be created in parallel while maintaining
//! a consistent ordering through a "blue set" selection algorithm.
//!
//! Key concepts:
//! - **DAG**: Directed Acyclic Graph where blocks can have multiple parents
//! - **Blue Set**: The "honest" chain of blocks, selected using k-cluster
//! - **Blue Score**: Cumulative count of blue blocks in ancestry
//! - **k parameter**: Controls how many parallel blocks are allowed (antichain width)
//!
//! # Performance Targets
//!
//! - Block time: ~100ms (10 blocks/second)
//! - Max parents per block: 64
//! - k parameter: 18 (allows ~18 parallel miners)

#![allow(dead_code)]

pub mod dag;
pub mod ghostdag;
pub mod ordering;
pub mod pruning;
pub mod reachability;

pub use dag::{BlockDag, BlockRelations, DagError};
pub use ghostdag::{GhostdagData, GhostdagError, GhostdagManager};
pub use ordering::{BlockOrdering, OrderedBlock};
pub use pruning::{PruningConfig, PruningManager};
pub use reachability::{ReachabilityError, ReachabilityStore};

use synor_types::Hash256;

/// Block ID type (hash of block header).
pub type BlockId = Hash256;

/// Blue score - cumulative count of blue ancestors.
pub type BlueScore = u64;

/// DAA score - difficulty adjustment algorithm score.
pub type DaaScore = u64;

/// GHOSTDAG k parameter - controls antichain width.
/// Higher k = more parallel blocks allowed = higher throughput
/// but also more complex blue set calculation.
pub const GHOSTDAG_K: u8 = 18;

/// Maximum number of parents a block can have.
pub const MAX_BLOCK_PARENTS: usize = 64;

/// Merge depth - how many blocks back we consider for merging.
pub const MERGE_DEPTH: u64 = 3600; // ~6 minutes at 10 bps

/// Finality depth - after this many confirmations, blocks are final.
pub const FINALITY_DEPTH: u64 = 86400; // ~2.4 hours at 10 bps

/// Pruning depth - how many blocks to keep in memory.
pub const PRUNING_DEPTH: u64 = 288_000; // ~8 hours at 10 bps

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    #[allow(clippy::assertions_on_constants)]
    fn test_constants() {
        assert!(GHOSTDAG_K > 0);
        assert!(MAX_BLOCK_PARENTS >= GHOSTDAG_K as usize);
        assert!(FINALITY_DEPTH > MERGE_DEPTH);
    }
}
