brk_computer
Advanced Bitcoin analytics engine that transforms indexed blockchain data into comprehensive metrics and financial analytics.
Overview
This crate provides a sophisticated analytics engine that processes indexed Bitcoin blockchain data to compute comprehensive metrics, financial analytics, and statistical aggregations. Built on top of brk_indexer, it transforms raw blockchain data into actionable insights through state tracking, cohort analysis, market metrics, and advanced Bitcoin-specific calculations.
Key Features:
- Comprehensive Bitcoin analytics pipeline with 6 major computation modules
- UTXO and address cohort analysis with lifecycle tracking
- Market metrics integration with price data and financial calculations
- Cointime economics and realized/unrealized profit/loss analysis
- Supply dynamics and monetary policy metrics
- Pool analysis for centralization and mining statistics
- Memory allocation tracking and performance optimization
- Parallel computation with multi-threaded processing
Target Use Cases:
- Bitcoin market analysis and research platforms
- On-chain analytics for investment and trading decisions
- Academic research requiring comprehensive blockchain metrics
- Financial applications needing Bitcoin exposure and risk metrics
Installation
Quick Start
use Computer;
use Indexer;
use Fetcher;
use Exit;
use Path;
// Initialize dependencies
let outputs_path = new;
let indexer = forced_import?;
let fetcher = Some;
// Create computer with price data support
let mut computer = forced_import?;
// Compute analytics from indexer state
let exit = default;
let starting_indexes = default;
computer.compute?;
println!;
API Overview
Core Structure
The Computer is organized into 7 specialized computation modules:
indexes: Fundamental blockchain index computationsconstants: Network constants and protocol parametersmarket: Price-based financial metrics and market analysispools: Mining pool analysis and centralization metricschain: Core blockchain metrics (difficulty, hashrate, fees)stateful: Advanced state tracking (UTXO lifecycles, address behaviors)cointime: Cointime economics and value-time calculations
Key Methods
Computer::forced_import(outputs_path, indexer, fetcher) -> Result<Self>
Creates computer instance with optional price data integration.
compute(&mut self, indexer: &Indexer, starting_indexes: Indexes, exit: &Exit) -> Result<()>
Main computation pipeline processing all analytics modules.
Analytics Categories
Market Analytics:
- Price-based metrics (market cap, realized cap, MVRV)
- Trading volume analysis and liquidity metrics
- Return calculations and volatility measurements
- Dollar-cost averaging and investment strategy metrics
On-Chain Analytics:
- Transaction count and size statistics
- Fee analysis and block space utilization
- Address activity and entity clustering
- UTXO age distributions and spending patterns
Monetary Analytics:
- Circulating supply and issuance tracking
- Realized vs. unrealized gains/losses
- Cointime destruction and accumulation
- Velocity and economic activity indicators
Examples
Basic Analytics Computation
use Computer;
// Initialize with indexer and optional price data
let computer = forced_import?;
// Compute all analytics modules
let exit = default;
computer.compute?;
// Access computed metrics
println!;
println!;
println!;
Market Analysis
use Computer;
use ;
let computer = forced_import?;
// Access market metrics after computation
if let Some = &computer.market
// Chain-level metrics
let height = new;
if let Some = computer.chain.height_to_difficulty.get?
Cohort Analysis
use Computer;
use ;
let computer = forced_import?;
// Address cohort analysis
let cohort_date = from_days_since_genesis;
// Analyze address behavior patterns
if let Some = &computer.stateful.address_cohorts
// UTXO cohort lifecycle analysis
if let Some = &computer.stateful.utxo_cohorts
Supply and Monetary Analysis
use Computer;
use ;
let computer = forced_import?;
// Supply dynamics
let height = new;
if let Some = computer.chain.height_to_circulating_supply.get?
// Realized vs unrealized analysis
let date = from_days_since_genesis;
if let Some = computer.market.dateindex_to_realized_cap.get?
Architecture
Computation Pipeline
The computer implements a sophisticated multi-stage pipeline:
- Index Computation: Fundamental blockchain metrics and time-based indexes
- Constants Computation: Network parameters and protocol constants
- Price Integration: Optional price data fetching and processing
- Parallel Computation: Chain, market, pools, stateful, and cointime analytics
- Cross-Dependencies: Advanced metrics requiring multiple data sources
Memory Management
Allocation Tracking:
allocativeintegration for memory usage analysis- Efficient vector storage with compression options
- Strategic lazy vs. eager evaluation for memory optimization
Performance Optimization:
rayonparallel processing for CPU-intensive calculations- Vectorized operations for time-series computations
- Memory-mapped storage for large datasets
State Management
Stateful Analytics:
- UTXO lifecycle tracking with creation/destruction events
- Address cohort analysis with behavioral clustering
- Transaction pattern recognition and anomaly detection
- Economic cycle analysis with market phase detection
Cointime Economics:
- Bitcoin days destroyed and accumulated calculations
- Velocity measurements and economic activity indicators
- Age-weighted value transfer analysis
- Long-term holder vs. active trader segmentation
Modular Design
Each computation module operates independently:
- Chain Module: Basic blockchain metrics (fees, difficulty, hashrate)
- Market Module: Price-dependent financial calculations
- Pools Module: Mining centralization and pool analysis
- Stateful Module: Advanced lifecycle and behavior tracking
- Cointime Module: Economic time-value calculations
Data Dependencies
Required Dependencies:
brk_indexer: Raw blockchain data accessbrk_structs: Type definitions and conversions
Optional Dependencies:
brk_fetcher: Price data for financial metrics- Market analysis requires price integration
Computation Orchestration
Sequential Stages:
- Indexes → Constants (foundational metrics)
- Fetched → Price (price data processing)
- Parallel: Chain, Market, Pools, Stateful, Cointime
Exit Handling:
- Graceful shutdown with consistent state preservation
- Checkpoint-based recovery for long-running computations
- Multi-threaded coordination with exit signaling
Code Analysis Summary
Main Structure: Computer struct coordinating 7 specialized analytics modules (indexes, constants, market, pools, chain, stateful, cointime)
Computation Pipeline: Multi-stage analytics processing with parallel execution and dependency management
State Tracking: Advanced UTXO and address lifecycle analysis with cohort-based behavioral clustering
Financial Analytics: Comprehensive market metrics including realized/unrealized analysis and cointime economics
Memory Optimization: allocative tracking with lazy/eager evaluation strategies and compressed vector storage
Parallel Processing: rayon integration for CPU-intensive calculations with coordinated exit handling
Architecture: Modular analytics engine transforming indexed blockchain data into actionable financial and economic insights
This README was generated by Claude Code