From ec3a2f29f0c47824356ad134f2acbc717434c880 Mon Sep 17 00:00:00 2001 From: deadmanoz Date: Thu, 26 Jun 2025 15:35:04 +0800 Subject: [PATCH 1/8] Docker functionality, change location of 'blk_index_to_blk_recap.json' --- .dockerignore | 68 ++++++++ .env.example | 42 +++++ .gitignore | 3 + Cargo.toml | 1 + DOCKER.md | 152 ++++++++++++++++++ Dockerfile | 55 +++++++ crates/brk_cli/src/run.rs | 2 +- .../brk_parser/src/blk_index_to_blk_recap.rs | 4 +- crates/brk_parser/src/lib.rs | 14 +- docker-build.sh | 60 +++++++ docker-compose.yml | 57 +++++++ 11 files changed, 453 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 DOCKER.md create mode 100644 Dockerfile create mode 100755 docker-build.sh create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..494e86bb3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,68 @@ +# Git +.git +.gitignore + +# Build artifacts +target/ + +# Development files +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS files +.DS_Store +Thumbs.db + +# Docker files +Dockerfile +docker-compose.yml +.dockerignore +docker-build.sh + +# Documentation +docs/ +LICENSE +# Keep README.md for build process +!README.md + +# CI/CD +.github/ + +# Logs and temporary files +*.log +tmp/ +temp/ + +# BRK runtime data (should be in volumes) +.brk/ + +# Example and test data +examples/ +tests/ +*.test +*.example + +# Node modules (if any frontend deps) +node_modules/ + +# Python cache (if any) +__pycache__/ +*.pyc +*.pyo + +# Rust workspace cache +**/*.rs.bk + +# macOS +.AppleDouble +.LSOverride + +# Windows +Desktop.ini +ehthumbs.db + +# Linux +.directory \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..8454693c4 --- /dev/null +++ b/.env.example @@ -0,0 +1,42 @@ +# Bitcoin Core data directory +# This should point to your Bitcoin Core data directory +BITCOIN_DATA_DIR=/path/to/bitcoin + +# Bitcoin Core RPC configuration +# If running Bitcoin Core on the same host (not in Docker), use host.docker.internal on macOS/Windows +# or the host's IP address on Linux +BTC_RPC_HOST=localhost +BTC_RPC_PORT=8332 + +# Use either cookie file authentication (recommended) or username/password +# Cookie file is automatically created by Bitcoin Core +# If using username/password, comment out RPCCOOKIEFILE in docker-compose.yml +# BTC_RPC_USER=your_rpc_username +# BTC_RPC_PASSWORD=your_rpc_password + +# BRK configuration +# Services to run: all, processor, or server +BRK_SERVICES=all + +# Computation mode: lazy (compute on demand) or eager (precompute and save) +BRK_COMPUTATION=lazy + +# Data format: raw (faster) or compressed (saves disk space) +BRK_FORMAT=raw + +# Enable price fetching from exchanges +BRK_FETCH=true + +# Enable Model Context Protocol (MCP) for AI/LLM integration +BRK_MCP=true + +# BRK data storage options +# Option 1: Use a Docker named volume (default, recommended) +# This is the default configuration - no changes needed. +# Leave this commented to use the default named volume +# BRK_DATA_VOLUME=brk-data + +# Option 2: Use a bind mount to a local directory +# Uncomment and set this to use a specific directory on your host +# Also uncomment the corresponding line in docker-compose.yml +# BRK_DATA_DIR=/path/to/brk/data \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8e8834d1e..e18eea715 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ _* # Logs .log + +# Environment variables/configs +.env diff --git a/Cargo.toml b/Cargo.toml index cdc0ec231..da2139dcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ package.edition = "2024" package.version = "0.0.71" package.homepage = "https://bitcoinresearchkit.org" package.repository = "https://github.com/bitcoinresearchkit/brk" +package.readme = "README.md" [profile.release] lto = "fat" diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 000000000..404c44ead --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,152 @@ +# Docker Setup for BRK + +This guide explains how to run BRK using Docker and Docker Compose. + +## Prerequisites + +- Docker Engine (with buildx support) +- Docker Compose v2 +- A running Bitcoin Core node with RPC enabled +- Access to Bitcoin Core's blocks directory + +## Quick Start + +1. **Create environment file** + ```bash + cp .env.example .env + ``` + Edit `.env` and set `BITCOIN_DATA_DIR` to your Bitcoin Core data directory. + +2. **Run with Docker Compose** + ```bash + docker compose up -d + ``` + +3. **Access BRK** + - Web interface: http://localhost:7070 + - API: http://localhost:7070/api + +## Configuration + +### Environment Variables + +| Variable | Description | Default | +|----------|-------------|---------| +| `BITCOIN_DATA_DIR` | Path to Bitcoin Core data directory | Required | +| `BTC_RPC_HOST` | Bitcoin Core RPC host | `localhost` | +| `BTC_RPC_PORT` | Bitcoin Core RPC port | `8332` | +| `BRK_SERVICES` | Services to run (`all`, `processor`, `server`) | `all` | +| `BRK_COMPUTATION` | Computation mode (`lazy`, `eager`) | `lazy` | +| `BRK_FORMAT` | Data format (`raw`, `compressed`) | `raw` | +| `BRK_FETCH` | Enable price fetching | `true` | +| `BRK_MCP` | Enable MCP for AI/LLM | `true` | + +### Service Modes + +- **`all`**: Run both processor and server (default) +- **`processor`**: Only process blockchain data +- **`server`**: Only serve API/web interface + +### Connecting to Bitcoin Core + +#### Option 1: Cookie File Authentication (Recommended) +BRK will automatically use the `.cookie` file from your Bitcoin Core directory. + +#### Option 2: Username/Password +1. Uncomment the RPC user/password lines in `docker-compose.yml` +2. Set `BTC_RPC_USER` and `BTC_RPC_PASSWORD` in your `.env` file + +#### Network Connectivity +- **Same host**: + - If Bitcoin Core is running natively (not in Docker): Use `host.docker.internal` on macOS/Windows or `172.17.0.1` on Linux + - If Bitcoin Core is also in Docker: Use the service name or container IP +- **Remote host**: Use the actual IP address or hostname + +## Building the Image + +### Using Docker Compose (Simple) +```bash +docker compose build +``` + +### Using Docker Build Script +```bash +# Build with default settings +./docker-build.sh + +# Build with custom tag +./docker-build.sh --tag v1.0.0 +``` + +## Volumes and Data Storage + +BRK supports two options for storing its data: + +### Option 1: Docker Named Volume (Default) +Uses a Docker-managed named volume called `brk-data`. This is the recommended approach for most users. + +**Advantages:** +- Managed by Docker +- Easy backup/restore +- Platform-independent + +**Usage:** This is the default configuration - no changes needed. + +### Option 2: Bind Mount +Maps a specific directory on your host to the container's data directory. + +**Advantages:** +- Direct access to files from host +- Easy to locate and manage +- Can be on specific storage devices + +**Usage:** +1. Set `BRK_DATA_DIR` in your `.env` file to your desired host directory +2. In `docker-compose.yml`, comment out the named volume line and uncomment the bind mount line + +**Example:** +```bash +# In .env file +BRK_DATA_DIR=/home/user/brk-data +``` + +```yaml +# In docker-compose.yml, uncomment and change as necessary: + # - ${BRK_DATA_VOLUME:-brk-data}:/home/brk/.brk + - ${BRK_DATA_DIR:-./brk-data}:/home/brk/.brk +``` + +### Volume Details +- **BRK data**: Stores computed datasets, indexes, and application state +- **Bitcoin data**: Mounted read-only from host (always a bind mount) + +## Monitoring + +View logs: +```bash +docker compose logs -f brk +``` + +Check status: +```bash +docker compose ps +``` + +## Troubleshooting + +### Cannot connect to Bitcoin Core +1. Ensure Bitcoin Core is running with `-server=1` +2. Check RPC credentials are correct +3. Verify network connectivity from container + +### Permission denied errors +Ensure the Bitcoin data directory is readable by the container user (UID 1000). + +### Out of memory +Increase Docker's memory limit or use `BRK_COMPUTATION=lazy` to reduce memory usage. + +## Security Considerations + +- Bitcoin data is mounted read-only for safety +- BRK runs as non-root user inside container +- Only necessary ports are exposed diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..f5795c75a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +# Build stage +FROM rust:nightly AS builder + +# Install build dependencies +RUN apt-get update && apt-get install -y \ + pkg-config \ + libssl-dev \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Copy all source files +COPY . . + +# Build the application +RUN cargo build --release --locked + +# Runtime stage +FROM debian:bookworm-slim + +# Install runtime dependencies +RUN apt-get update && apt-get install -y \ + ca-certificates \ + openssl \ + && rm -rf /var/lib/apt/lists/* + +# Create non-root user +RUN useradd -m -s /bin/bash brk + +# Copy binary from builder +COPY --from=builder /app/target/release/brk /usr/local/bin/brk + +# Copy websites directory +COPY --from=builder /app/websites /app/websites + +# Set ownership +RUN chown -R brk:brk /app + +# Switch to non-root user +USER brk + +# Create directories for BRK data +RUN mkdir -p /home/brk/.brk + +# Expose API port +EXPOSE 3110 + +# Set working directory +WORKDIR /home/brk + +# Default entrypoint +ENTRYPOINT ["brk"] + +# Default command (can be overridden) +CMD ["--services", "all"] \ No newline at end of file diff --git a/crates/brk_cli/src/run.rs b/crates/brk_cli/src/run.rs index 398153356..9d42afadf 100644 --- a/crates/brk_cli/src/run.rs +++ b/crates/brk_cli/src/run.rs @@ -16,7 +16,7 @@ pub fn run() -> color_eyre::Result<()> { let exit = Exit::new(); - let parser = brk_parser::Parser::new(config.blocksdir(), rpc); + let parser = brk_parser::Parser::new_with_outputs_dir(config.blocksdir(), config.outputsdir(), rpc); let format = config.format(); diff --git a/crates/brk_parser/src/blk_index_to_blk_recap.rs b/crates/brk_parser/src/blk_index_to_blk_recap.rs index e4e619467..4f8b07862 100644 --- a/crates/brk_parser/src/blk_index_to_blk_recap.rs +++ b/crates/brk_parser/src/blk_index_to_blk_recap.rs @@ -15,11 +15,11 @@ pub struct BlkIndexToBlkRecap { impl BlkIndexToBlkRecap { pub fn import( - bitcoin_dir: &Path, + outputs_dir: &Path, blk_index_to_blk_path: &BlkIndexToBlkPath, start: Option, ) -> (Self, u16) { - let path = bitcoin_dir.join("blk_index_to_blk_recap.json"); + let path = outputs_dir.join("blk_index_to_blk_recap.json"); let tree = { if let Ok(file) = File::open(&path) { diff --git a/crates/brk_parser/src/lib.rs b/crates/brk_parser/src/lib.rs index 59b80bdb7..b5222e212 100644 --- a/crates/brk_parser/src/lib.rs +++ b/crates/brk_parser/src/lib.rs @@ -38,12 +38,22 @@ const BOUND_CAP: usize = 50; pub struct Parser { blocks_dir: PathBuf, + outputs_dir: PathBuf, rpc: &'static bitcoincore_rpc::Client, } impl Parser { pub fn new(blocks_dir: PathBuf, rpc: &'static bitcoincore_rpc::Client) -> Self { - Self { blocks_dir, rpc } + // For backward compatibility, use blocks_dir as outputs_dir + Self { + outputs_dir: blocks_dir.clone(), + blocks_dir, + rpc + } + } + + pub fn new_with_outputs_dir(blocks_dir: PathBuf, outputs_dir: PathBuf, rpc: &'static bitcoincore_rpc::Client) -> Self { + Self { blocks_dir, outputs_dir, rpc } } pub fn get(&self, height: Height) -> Block { @@ -74,7 +84,7 @@ impl Parser { let blk_index_to_blk_path = BlkIndexToBlkPath::scan(blocks_dir); let (mut blk_index_to_blk_recap, blk_index) = - BlkIndexToBlkRecap::import(blocks_dir, &blk_index_to_blk_path, start); + BlkIndexToBlkRecap::import(&self.outputs_dir, &blk_index_to_blk_path, start); let xor_bytes = XORBytes::from(blocks_dir); diff --git a/docker-build.sh b/docker-build.sh new file mode 100755 index 000000000..359c8a72b --- /dev/null +++ b/docker-build.sh @@ -0,0 +1,60 @@ +#!/bin/bash +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Default values +IMAGE_NAME="brk" +TAG="latest" + +# Function to print colored output +print_info() { + echo -e "${GREEN}[INFO]${NC} $1" +} + +print_warn() { + echo -e "${YELLOW}[WARN]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + -t|--tag) + TAG="$2" + shift 2 + ;; + -h|--help) + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " -t, --tag TAG Tag for the image (default: latest)" + echo " -h, --help Show this help message" + exit 0 + ;; + *) + print_error "Unknown option: $1" + exit 1 + ;; + esac +done + +# Build the image +print_info "Building BRK Docker image..." +print_info "Image: ${IMAGE_NAME}:${TAG}" + +# Execute the build +if docker build -t "${IMAGE_NAME}:${TAG}" .; then + print_info "Build completed successfully!" + print_info "Image built as ${IMAGE_NAME}:${TAG}" +else + print_error "Build failed!" + exit 1 +fi \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..b74f8357c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,57 @@ +services: + brk: + build: + context: . + dockerfile: Dockerfile + image: brk:latest + container_name: brk + restart: unless-stopped + ports: + - 7070:3110 # Map host port 7070 to container port 3110 + volumes: + # Bitcoin Core data directory (read-only) + # For access to raw block data + - ${BITCOIN_DATA_DIR:-/path/to/bitcoin}:/bitcoin:ro + # BRK data directory for outputs and state + # Option 1: Use a named volume (default) + - ${BRK_DATA_VOLUME:-brk-data}:/home/brk/.brk + # Option 2: Use a bind mount (uncomment and set BRK_DATA_DIR in .env) + # - ${BRK_DATA_DIR:-./brk-data}:/home/brk/.brk + environment: + # Bitcoin Core configuration + - BITCOINDIR=/bitcoin + - BLOCKSDIR=/bitcoin/blocks + + # RPC configuration + # RPC node access is for chain validation, chain sync status etc. + - RPCCONNECT=${BTC_RPC_HOST:-localhost} + - RPCPORT=${BTC_RPC_PORT:-8332} + # - RPCCOOKIEFILE=/bitcoin/.cookie + + # Username/password authentication + - RPCUSER=${BTC_RPC_USER} + - RPCPASSWORD=${BTC_RPC_PASSWORD} + + # BRK configuration + - BRKDIR=/home/brk/.brk + - COMPUTATION=${BRK_COMPUTATION:-lazy} + - FORMAT=${BRK_FORMAT:-raw} + - FETCH=${BRK_FETCH:-true} + - MCP=${BRK_MCP:-true} + command: + - --bitcoindir + - /bitcoin + - --brkdir + - /home/brk/.brk + - --rpcconnect + - "${BTC_RPC_HOST:-localhost}" + - --rpcuser + - "${BTC_RPC_USER:-bitcoin}" + - --rpcpassword + - "${BTC_RPC_PASSWORD:-bitcoin}" + - --services + - "${BRK_SERVICES:-all}" # Can be: all, processor, server + +volumes: + brk-data: + driver: local \ No newline at end of file From d83a833b4d1202dc4da5a0a6d91c1357ec8c0ef9 Mon Sep 17 00:00:00 2001 From: deadmanoz Date: Fri, 27 Jun 2025 11:45:04 +0800 Subject: [PATCH 2/8] Switch to multiple container setup --- Cargo.lock | 1 + DOCKER.md | 229 ++++++++++++++++++++++++------- Dockerfile | 11 +- crates/brk_cli/src/config.rs | 42 +++--- crates/brk_cli/src/run.rs | 56 +++++--- crates/brk_server/Cargo.toml | 1 + crates/brk_server/src/api/mod.rs | 10 ++ docker-compose.yml | 54 ++++++-- 8 files changed, 305 insertions(+), 99 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e3eac41a..68c48520e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1003,6 +1003,7 @@ dependencies = [ "log", "minreq", "serde", + "serde_json", "tokio", "tower-http", "tracing", diff --git a/DOCKER.md b/DOCKER.md index 404c44ead..e1c43c2ab 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -19,33 +19,88 @@ This guide explains how to run BRK using Docker and Docker Compose. 2. **Run with Docker Compose** ```bash - docker compose up -d + # Multi-container mode (recommended) + docker compose up -d brk-processor brk-server ``` 3. **Access BRK** - Web interface: http://localhost:7070 - API: http://localhost:7070/api + - Health check: http://localhost:7070/health + +## Deployment Modes + +BRK supports flexible deployment modes to suit different use cases: + +### 1. Multi-Container Mode (Recommended) + +Deploy indexer and server as separate containers. This means the following: +- Better resource isolation +- Independent scaling of components +- Server doesn't need Bitcoin Core or RPC access +- Cleaner failure isolation +- Server can start independently (will serve empty data until processor indexes blocks) + +```bash +# Start both processor and server +docker compose up brk-processor brk-server + +# Or run in background +docker compose up -d brk-processor brk-server +``` + +### 2. Processor-Only Mode + +For indexing without web interface: + +```bash +docker compose up brk-processor +``` + +### 3. Server-Only Mode + +For serving pre-indexed data: + +```bash +docker compose up brk-server +``` ## Configuration ### Environment Variables -| Variable | Description | Default | -|----------|-------------|---------| -| `BITCOIN_DATA_DIR` | Path to Bitcoin Core data directory | Required | -| `BTC_RPC_HOST` | Bitcoin Core RPC host | `localhost` | -| `BTC_RPC_PORT` | Bitcoin Core RPC port | `8332` | -| `BRK_SERVICES` | Services to run (`all`, `processor`, `server`) | `all` | -| `BRK_COMPUTATION` | Computation mode (`lazy`, `eager`) | `lazy` | -| `BRK_FORMAT` | Data format (`raw`, `compressed`) | `raw` | -| `BRK_FETCH` | Enable price fetching | `true` | -| `BRK_MCP` | Enable MCP for AI/LLM | `true` | +| Variable | Description | Default | Required For | +|----------|-------------|---------|-------------| +| `BITCOIN_DATA_DIR` | Path to Bitcoin Core data directory | Required | Processor | +| `BTC_RPC_HOST` | Bitcoin Core RPC host | `localhost` | Processor | +| `BTC_RPC_PORT` | Bitcoin Core RPC port | `8332` | Processor | +| `BTC_RPC_USER` | Bitcoin RPC username | - | Processor | +| `BTC_RPC_PASSWORD` | Bitcoin RPC password | - | Processor | +| `BRK_DATA_VOLUME` | Docker volume name for BRK data | `brk-data` | Both | +| `BRK_COMPUTATION` | Computation mode (`lazy`, `eager`) | `lazy` | Processor | +| `BRK_FORMAT` | Data format (`raw`, `compressed`) | `raw` | Processor | +| `BRK_FETCH` | Enable price fetching | `true` | Processor | +| `BRK_MCP` | Enable MCP for AI/LLM | `true` | Server | -### Service Modes +### Example .env File -- **`all`**: Run both processor and server (default) -- **`processor`**: Only process blockchain data -- **`server`**: Only serve API/web interface +```env +# Bitcoin Core paths +BITCOIN_DATA_DIR=/path/to/bitcoin/data +BRK_DATA_VOLUME=brk-data + +# Bitcoin RPC (required for processor) +BTC_RPC_HOST=localhost +BTC_RPC_PORT=8332 +BTC_RPC_USER=your_username +BTC_RPC_PASSWORD=your_password + +# BRK settings +BRK_COMPUTATION=lazy +BRK_FORMAT=raw +BRK_FETCH=true +BRK_MCP=true +``` ### Connecting to Bitcoin Core @@ -53,8 +108,7 @@ This guide explains how to run BRK using Docker and Docker Compose. BRK will automatically use the `.cookie` file from your Bitcoin Core directory. #### Option 2: Username/Password -1. Uncomment the RPC user/password lines in `docker-compose.yml` -2. Set `BTC_RPC_USER` and `BTC_RPC_PASSWORD` in your `.env` file +Set `BTC_RPC_USER` and `BTC_RPC_PASSWORD` in your `.env` file. #### Network Connectivity - **Same host**: @@ -64,12 +118,12 @@ BRK will automatically use the `.cookie` file from your Bitcoin Core directory. ## Building the Image -### Using Docker Compose (Simple) +### Using Docker Compose... ```bash docker compose build ``` -### Using Docker Build Script +### or ... Using Docker Build Script ```bash # Build with default settings ./docker-build.sh @@ -85,68 +139,145 @@ BRK supports two options for storing its data: ### Option 1: Docker Named Volume (Default) Uses a Docker-managed named volume called `brk-data`. This is the recommended approach for most users. -**Advantages:** -- Managed by Docker -- Easy backup/restore -- Platform-independent - -**Usage:** This is the default configuration - no changes needed. - ### Option 2: Bind Mount Maps a specific directory on your host to the container's data directory. +This may be desirable if you want to use a specific storage location for BRK data (e.g. a different disk). -**Advantages:** -- Direct access to files from host -- Easy to locate and manage -- Can be on specific storage devices - -**Usage:** 1. Set `BRK_DATA_DIR` in your `.env` file to your desired host directory 2. In `docker-compose.yml`, comment out the named volume line and uncomment the bind mount line -**Example:** ```bash # In .env file BRK_DATA_DIR=/home/user/brk-data ``` -```yaml -# In docker-compose.yml, uncomment and change as necessary: - # - ${BRK_DATA_VOLUME:-brk-data}:/home/brk/.brk - - ${BRK_DATA_DIR:-./brk-data}:/home/brk/.brk +```bash +# In docker-compose.yml, for BOTH the processor and server services. +# Comment out: + - ${BRK_DATA_VOLUME:-brk-data}:/home/brk/.brk + +# Uncomment: + # - ${BRK_DATA_DIR:-./brk-data}:/home/brk/.brk ``` -### Volume Details -- **BRK data**: Stores computed datasets, indexes, and application state -- **Bitcoin data**: Mounted read-only from host (always a bind mount) +Can also remove or comment out the `volumes` section from the docker-compose.yml file (right at the bottom): +```bash +# Comment out: +volumes: + brk-data: + driver: local +``` + +## Health Checks + +Both containers include health checks: + +- `brk-processor`: checks that the BRK process is running +- `brk-server`: tests network connectivity on port 3110 ## Monitoring -View logs: +### Check Container Status ```bash -docker compose logs -f brk +# View running containers +docker compose ps + +# Check health status +docker compose ps --format \"table {{.Service}}\\t{{.Status}}\\t{{.Health}}\" ``` -Check status: +### View Logs ```bash -docker compose ps +# View logs from both containers +docker compose logs brk-processor brk-server + +# Follow logs in real-time +docker compose logs -f brk-processor brk-server + +# View logs from specific container +docker compose logs -f brk-server ``` ## Troubleshooting -### Cannot connect to Bitcoin Core +### Server Issues + +#### Server returns empty data +- This is normal if processor hasn't indexed any blocks yet +- Server can start before processor and will serve data as it becomes available +- Check that BRK data volume is properly shared between containers + +#### Server won't start +- Check Docker Compose logs: `docker compose logs brk-server` +- Verify health endpoint: `curl http://localhost:7070/health` +- Ensure no port conflicts on 7070 + +### Processor Issues + +#### Cannot connect to Bitcoin Core 1. Ensure Bitcoin Core is running with `-server=1` 2. Check RPC credentials are correct 3. Verify network connectivity from container +4. Test RPC connection: `docker compose exec brk-processor brk --help` -### Permission denied errors -Ensure the Bitcoin data directory is readable by the container user (UID 1000). +#### Processor fails to start +- Verify Bitcoin RPC credentials in `.env` +- Ensure Bitcoin Core is running and accessible +- Check Bitcoin data directory permissions (should be readable by UID 1000) -### Out of memory -Increase Docker's memory limit or use `BRK_COMPUTATION=lazy` to reduce memory usage. +### Performance Issues + +#### Slow indexing +- Ensure adequate disk space for indexed data +- Monitor memory usage during initial indexing +- Use `BRK_COMPUTATION=lazy` to reduce memory usage + +#### Out of memory +- Increase Docker's memory limit +- Use `BRK_COMPUTATION=lazy` mode +- Monitor container resource usage: `docker stats` + +### Permission Issues + +#### Permission denied errors +- Ensure the Bitcoin data directory is readable by the container user (UID 1000) +- Check that volumes are properly mounted +- Verify file ownership: `ls -la $BITCOIN_DATA_DIR` + +### Network Issues + +#### Cannot access web interface +- Verify port mapping: `docker compose ps` +- Check firewall settings +- Ensure no other services are using port 7070 ## Security Considerations - Bitcoin data is mounted read-only for safety - BRK runs as non-root user inside container - Only necessary ports are exposed + +## Backup and Recovery + +### Backing Up BRK Data + +```bash +# Create backup of named volume +docker run --rm -v brk_brk-data:/source -v \"$(pwd)\":/backup alpine tar czf /backup/brk-backup.tar.gz -C /source . + +# Or if using bind mount +tar czf brk-backup.tar.gz -C \"$BRK_DATA_DIR\" . +``` + +### Restoring BRK Data + +```bash +# Stop containers +docker compose down + +# Restore from backup (named volume) +docker run --rm -v brk_brk-data:/target -v \"$(pwd)\":/backup alpine tar xzf /backup/brk-backup.tar.gz -C /target + +# Start containers +docker compose up -d +``` \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f5795c75a..ca1d387f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,13 @@ -# Build stage -FROM rust:nightly AS builder +# ************* +# Builder +# ************* +FROM rustlang/rust:nightly AS builder # Install build dependencies RUN apt-get update && apt-get install -y \ pkg-config \ libssl-dev \ + build-essential \ && rm -rf /var/lib/apt/lists/* WORKDIR /app @@ -15,7 +18,9 @@ COPY . . # Build the application RUN cargo build --release --locked -# Runtime stage +# ************* +# Runtime +# ************* FROM debian:bookworm-slim # Install runtime dependencies diff --git a/crates/brk_cli/src/config.rs b/crates/brk_cli/src/config.rs index a0851c456..f67ca0850 100644 --- a/crates/brk_cli/src/config.rs +++ b/crates/brk_cli/src/config.rs @@ -201,33 +201,37 @@ impl Config { } fn check(&self) { - if !self.bitcoindir().is_dir() { - println!("{:?} isn't a valid directory", self.bitcoindir()); - println!("Please use the --bitcoindir parameter to set a valid path."); - println!("Run the program with '-h' for help."); - std::process::exit(1); - } - - if !self.blocksdir().is_dir() { - println!("{:?} isn't a valid directory", self.blocksdir()); - println!("Please use the --blocksdir parameter to set a valid path."); - println!("Run the program with '-h' for help."); - std::process::exit(1); + // Only check Bitcoin directories and RPC if we're running the processor + if self.process() { + if !self.bitcoindir().is_dir() { + println!("{:?} isn't a valid directory", self.bitcoindir()); + println!("Please use the --bitcoindir parameter to set a valid path."); + println!("Run the program with '-h' for help."); + std::process::exit(1); + } + + if !self.blocksdir().is_dir() { + println!("{:?} isn't a valid directory", self.blocksdir()); + println!("Please use the --blocksdir parameter to set a valid path."); + println!("Run the program with '-h' for help."); + std::process::exit(1); + } + + if self.rpc_auth().is_err() { + println!( + "No way found to authenticate the RPC client, please either set --rpccookiefile or --rpcuser and --rpcpassword.\nRun the program with '-h' for help." + ); + std::process::exit(1); + } } + // Always check BRK directory (needed by both processor and server) if !self.brkdir().is_dir() { println!("{:?} isn't a valid directory", self.brkdir()); println!("Please use the --brkdir parameter to set a valid path."); println!("Run the program with '-h' for help."); std::process::exit(1); } - - if self.rpc_auth().is_err() { - println!( - "No way found to authenticate the RPC client, please either set --rpccookiefile or --rpcuser and --rpcpassword.\nRun the program with '-h' for help." - ); - std::process::exit(1); - } } fn read(path: &Path) -> Self { diff --git a/crates/brk_cli/src/run.rs b/crates/brk_cli/src/run.rs index 9d42afadf..1f7ea0db3 100644 --- a/crates/brk_cli/src/run.rs +++ b/crates/brk_cli/src/run.rs @@ -12,19 +12,31 @@ use crate::config::Config; pub fn run() -> color_eyre::Result<()> { let config = Config::import()?; - let rpc = config.rpc()?; + let rpc = if config.process() { + Some(config.rpc()?) + } else { + None + }; let exit = Exit::new(); - let parser = brk_parser::Parser::new_with_outputs_dir(config.blocksdir(), config.outputsdir(), rpc); + let parser = if config.process() && rpc.is_some() { + Some(brk_parser::Parser::new_with_outputs_dir( + config.blocksdir(), + config.outputsdir(), + rpc.unwrap(), + )) + } else { + None + }; let format = config.format(); let mut indexer = Indexer::forced_import(&config.outputsdir())?; - let wait_for_synced_node = || -> color_eyre::Result<()> { + let wait_for_synced_node = |rpc_client: &bitcoincore_rpc::Client| -> color_eyre::Result<()> { let is_synced = || -> color_eyre::Result { - let info = rpc.get_blockchain_info()?; + let info = rpc_client.get_blockchain_info()?; Ok(info.headers == info.blocks) }; @@ -70,27 +82,33 @@ pub fn run() -> color_eyre::Result<()> { }; if config.process() { - loop { - wait_for_synced_node()?; + if let (Some(rpc_client), Some(parser)) = (rpc, parser) { + loop { + wait_for_synced_node(rpc_client)?; - let block_count = rpc.get_block_count()?; + let block_count = rpc_client.get_block_count()?; - info!("{} blocks found.", block_count + 1); + info!("{} blocks found.", block_count + 1); - let starting_indexes = - indexer.index(&parser, rpc, &exit, config.check_collisions())?; + let starting_indexes = + indexer.index(&parser, rpc_client, &exit, config.check_collisions())?; - computer.compute(&mut indexer, starting_indexes, &exit)?; + computer.compute(&mut indexer, starting_indexes, &exit)?; - if let Some(delay) = config.delay() { - sleep(Duration::from_secs(delay)) - } - - info!("Waiting for new blocks..."); - - while block_count == rpc.get_block_count()? { - sleep(Duration::from_secs(1)) + if let Some(delay) = config.delay() { + sleep(Duration::from_secs(delay)) + } + + info!("Waiting for new blocks..."); + + while block_count == rpc_client.get_block_count()? { + sleep(Duration::from_secs(1)) + } } + } else { + return Err(color_eyre::eyre::eyre!( + "RPC client and parser required for processing mode" + ))?; } } diff --git a/crates/brk_server/Cargo.toml b/crates/brk_server/Cargo.toml index 1e1cc3643..099f50d3a 100644 --- a/crates/brk_server/Cargo.toml +++ b/crates/brk_server/Cargo.toml @@ -28,6 +28,7 @@ jiff = { workspace = true } log = { workspace = true } minreq = { workspace = true } serde = { workspace = true } +serde_json = { workspace = true } tokio = { workspace = true } tower-http = { version = "0.6.6", features = ["compression-full", "trace"] } tracing = "0.1.41" diff --git a/crates/brk_server/src/api/mod.rs b/crates/brk_server/src/api/mod.rs index 99631973c..78c54e522 100644 --- a/crates/brk_server/src/api/mod.rs +++ b/crates/brk_server/src/api/mod.rs @@ -107,6 +107,16 @@ impl ApiRoutes for Router { }, ), ) + .route( + "/health", + get(|| async { + Json(serde_json::json!({ + "status": "healthy", + "service": "brk-server", + "timestamp": jiff::Timestamp::now().to_string() + })) + }), + ) .route( "/api", get(|| async { diff --git a/docker-compose.yml b/docker-compose.yml index b74f8357c..59edf59fd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,18 +1,18 @@ +# BRK multi-container Docker Compose configuration + services: - brk: + brk-processor: build: context: . dockerfile: Dockerfile image: brk:latest - container_name: brk + container_name: brk-processor restart: unless-stopped - ports: - - 7070:3110 # Map host port 7070 to container port 3110 volumes: # Bitcoin Core data directory (read-only) # For access to raw block data - ${BITCOIN_DATA_DIR:-/path/to/bitcoin}:/bitcoin:ro - # BRK data directory for outputs and state + # BRK data directory for outputs and state (shared with server) # Option 1: Use a named volume (default) - ${BRK_DATA_VOLUME:-brk-data}:/home/brk/.brk # Option 2: Use a bind mount (uncomment and set BRK_DATA_DIR in .env) @@ -22,8 +22,7 @@ services: - BITCOINDIR=/bitcoin - BLOCKSDIR=/bitcoin/blocks - # RPC configuration - # RPC node access is for chain validation, chain sync status etc. + # RPC configuration (required for processor) - RPCCONNECT=${BTC_RPC_HOST:-localhost} - RPCPORT=${BTC_RPC_PORT:-8332} # - RPCCOOKIEFILE=/bitcoin/.cookie @@ -37,7 +36,6 @@ services: - COMPUTATION=${BRK_COMPUTATION:-lazy} - FORMAT=${BRK_FORMAT:-raw} - FETCH=${BRK_FETCH:-true} - - MCP=${BRK_MCP:-true} command: - --bitcoindir - /bitcoin @@ -50,7 +48,45 @@ services: - --rpcpassword - "${BTC_RPC_PASSWORD:-bitcoin}" - --services - - "${BRK_SERVICES:-all}" # Can be: all, processor, server + - processor + healthcheck: + test: ["CMD", "pgrep", "-f", "brk"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 60s + + brk-server: + build: + context: . + dockerfile: Dockerfile + image: brk:latest + container_name: brk-server + restart: unless-stopped + ports: + - 7070:3110 # Map host port 7070 to container port 3110 + volumes: + # BRK data directory (shared with processor) + # Option 1: Use a named volume (default) + - ${BRK_DATA_VOLUME:-brk-data}:/home/brk/.brk + # Option 2: Use a bind mount (uncomment and set BRK_DATA_DIR in .env) + # - ${BRK_DATA_DIR:-./brk-data}:/home/brk/.brk + environment: + # BRK configuration (server doesn't need Bitcoin RPC) + - BRKDIR=/home/brk/.brk + - MCP=${BRK_MCP:-true} + command: + - --brkdir + - /home/brk/.brk + - --services + - server + # Note: Server can start without processor, will serve empty data until processor indexes blocks + healthcheck: + test: ["CMD", "sh", "-c", "nc -z localhost 3110 || exit 1"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 30s volumes: brk-data: From 870c70180fa1a166d2e9f35ce8e0435d821c4cd8 Mon Sep 17 00:00:00 2001 From: deadmanoz Date: Fri, 4 Jul 2025 11:40:37 +0800 Subject: [PATCH 3/8] Back to a single image/container setup --- DOCKER.md | 102 +++++++++++++++++---------------------------- docker-compose.yml | 47 ++++----------------- 2 files changed, 47 insertions(+), 102 deletions(-) diff --git a/DOCKER.md b/DOCKER.md index e1c43c2ab..a0b5945f6 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -19,8 +19,7 @@ This guide explains how to run BRK using Docker and Docker Compose. 2. **Run with Docker Compose** ```bash - # Multi-container mode (recommended) - docker compose up -d brk-processor brk-server + docker compose up -d ``` 3. **Access BRK** @@ -28,59 +27,39 @@ This guide explains how to run BRK using Docker and Docker Compose. - API: http://localhost:7070/api - Health check: http://localhost:7070/health -## Deployment Modes +## Architecture -BRK supports flexible deployment modes to suit different use cases: +BRK runs as a single container that includes both the blockchain processor and API server. This simplified architecture: +- Ensures processor and server are always in sync +- Simplifies deployment and monitoring +- Uses a single shared data directory -### 1. Multi-Container Mode (Recommended) - -Deploy indexer and server as separate containers. This means the following: -- Better resource isolation -- Independent scaling of components -- Server doesn't need Bitcoin Core or RPC access -- Cleaner failure isolation -- Server can start independently (will serve empty data until processor indexes blocks) +The container runs the BRK binary with `--services all` to enable both processor and server functionality. ```bash -# Start both processor and server -docker compose up brk-processor brk-server +# Start BRK +docker compose up # Or run in background -docker compose up -d brk-processor brk-server -``` - -### 2. Processor-Only Mode - -For indexing without web interface: - -```bash -docker compose up brk-processor -``` - -### 3. Server-Only Mode - -For serving pre-indexed data: - -```bash -docker compose up brk-server +docker compose up -d ``` ## Configuration ### Environment Variables -| Variable | Description | Default | Required For | -|----------|-------------|---------|-------------| -| `BITCOIN_DATA_DIR` | Path to Bitcoin Core data directory | Required | Processor | -| `BTC_RPC_HOST` | Bitcoin Core RPC host | `localhost` | Processor | -| `BTC_RPC_PORT` | Bitcoin Core RPC port | `8332` | Processor | -| `BTC_RPC_USER` | Bitcoin RPC username | - | Processor | -| `BTC_RPC_PASSWORD` | Bitcoin RPC password | - | Processor | -| `BRK_DATA_VOLUME` | Docker volume name for BRK data | `brk-data` | Both | -| `BRK_COMPUTATION` | Computation mode (`lazy`, `eager`) | `lazy` | Processor | -| `BRK_FORMAT` | Data format (`raw`, `compressed`) | `raw` | Processor | -| `BRK_FETCH` | Enable price fetching | `true` | Processor | -| `BRK_MCP` | Enable MCP for AI/LLM | `true` | Server | +| Variable | Description | Default | +|----------|-------------|---------| +| `BITCOIN_DATA_DIR` | Path to Bitcoin Core data directory | - | +| `BTC_RPC_HOST` | Bitcoin Core RPC host | `localhost` | +| `BTC_RPC_PORT` | Bitcoin Core RPC port | `8332` | +| `BTC_RPC_USER` | Bitcoin RPC username | - | +| `BTC_RPC_PASSWORD` | Bitcoin RPC password | - | +| `BRK_DATA_VOLUME` | Docker volume name for BRK data | `brk-data` | +| `BRK_COMPUTATION` | Computation mode (`lazy`, `eager`) | `lazy` | +| `BRK_FORMAT` | Data format (`raw`, `compressed`) | `raw` | +| `BRK_FETCH` | Enable price fetching | `true` | +| `BRK_MCP` | Enable MCP for AI/LLM | `true` | ### Example .env File @@ -89,7 +68,7 @@ docker compose up brk-server BITCOIN_DATA_DIR=/path/to/bitcoin/data BRK_DATA_VOLUME=brk-data -# Bitcoin RPC (required for processor) +# Bitcoin RPC configuration BTC_RPC_HOST=localhost BTC_RPC_PORT=8332 BTC_RPC_USER=your_username @@ -118,7 +97,7 @@ Set `BTC_RPC_USER` and `BTC_RPC_PASSWORD` in your `.env` file. ## Building the Image -### Using Docker Compose... +### Using Docker Compose ```bash docker compose build ``` @@ -152,7 +131,7 @@ BRK_DATA_DIR=/home/user/brk-data ``` ```bash -# In docker-compose.yml, for BOTH the processor and server services. +# In docker-compose.yml # Comment out: - ${BRK_DATA_VOLUME:-brk-data}:/home/brk/.brk @@ -170,16 +149,15 @@ volumes: ## Health Checks -Both containers include health checks: - -- `brk-processor`: checks that the BRK process is running -- `brk-server`: tests network connectivity on port 3110 +The container includes a combined health check that verifies: +- The BRK process is running +- The API server is responding on port 3110 ## Monitoring ### Check Container Status ```bash -# View running containers +# View running container docker compose ps # Check health status @@ -188,14 +166,11 @@ docker compose ps --format \"table {{.Service}}\\t{{.Status}}\\t{{.Health}}\" ### View Logs ```bash -# View logs from both containers -docker compose logs brk-processor brk-server +# View logs +docker compose logs # Follow logs in real-time -docker compose logs -f brk-processor brk-server - -# View logs from specific container -docker compose logs -f brk-server +docker compose logs -f ``` ## Troubleshooting @@ -203,12 +178,11 @@ docker compose logs -f brk-server ### Server Issues #### Server returns empty data -- This is normal if processor hasn't indexed any blocks yet -- Server can start before processor and will serve data as it becomes available -- Check that BRK data volume is properly shared between containers +- This is normal if the processor hasn't indexed any blocks yet +- The server component will serve data as the processor indexes blocks #### Server won't start -- Check Docker Compose logs: `docker compose logs brk-server` +- Check Docker Compose logs: `docker compose logs` - Verify health endpoint: `curl http://localhost:7070/health` - Ensure no port conflicts on 7070 @@ -218,7 +192,7 @@ docker compose logs -f brk-server 1. Ensure Bitcoin Core is running with `-server=1` 2. Check RPC credentials are correct 3. Verify network connectivity from container -4. Test RPC connection: `docker compose exec brk-processor brk --help` +4. Test RPC connection: `docker compose exec brk brk --help` #### Processor fails to start - Verify Bitcoin RPC credentials in `.env` @@ -272,12 +246,12 @@ tar czf brk-backup.tar.gz -C \"$BRK_DATA_DIR\" . ### Restoring BRK Data ```bash -# Stop containers +# Stop container docker compose down # Restore from backup (named volume) docker run --rm -v brk_brk-data:/target -v \"$(pwd)\":/backup alpine tar xzf /backup/brk-backup.tar.gz -C /target -# Start containers +# Start container docker compose up -d ``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 59edf59fd..fc9e7bf95 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,18 +1,20 @@ -# BRK multi-container Docker Compose configuration +# BRK single-container Docker Compose configuration services: - brk-processor: + brk: build: context: . dockerfile: Dockerfile image: brk:latest - container_name: brk-processor + container_name: brk restart: unless-stopped + ports: + - 7070:3110 # Map host port 7070 to container port 3110 volumes: # Bitcoin Core data directory (read-only) # For access to raw block data - ${BITCOIN_DATA_DIR:-/path/to/bitcoin}:/bitcoin:ro - # BRK data directory for outputs and state (shared with server) + # BRK data directory for outputs and state # Option 1: Use a named volume (default) - ${BRK_DATA_VOLUME:-brk-data}:/home/brk/.brk # Option 2: Use a bind mount (uncomment and set BRK_DATA_DIR in .env) @@ -36,6 +38,7 @@ services: - COMPUTATION=${BRK_COMPUTATION:-lazy} - FORMAT=${BRK_FORMAT:-raw} - FETCH=${BRK_FETCH:-true} + - MCP=${BRK_MCP:-true} command: - --bitcoindir - /bitcoin @@ -48,46 +51,14 @@ services: - --rpcpassword - "${BTC_RPC_PASSWORD:-bitcoin}" - --services - - processor + - all healthcheck: - test: ["CMD", "pgrep", "-f", "brk"] + test: ["CMD", "sh", "-c", "pgrep -f brk && nc -z localhost 3110"] interval: 30s timeout: 10s retries: 3 start_period: 60s - brk-server: - build: - context: . - dockerfile: Dockerfile - image: brk:latest - container_name: brk-server - restart: unless-stopped - ports: - - 7070:3110 # Map host port 7070 to container port 3110 - volumes: - # BRK data directory (shared with processor) - # Option 1: Use a named volume (default) - - ${BRK_DATA_VOLUME:-brk-data}:/home/brk/.brk - # Option 2: Use a bind mount (uncomment and set BRK_DATA_DIR in .env) - # - ${BRK_DATA_DIR:-./brk-data}:/home/brk/.brk - environment: - # BRK configuration (server doesn't need Bitcoin RPC) - - BRKDIR=/home/brk/.brk - - MCP=${BRK_MCP:-true} - command: - - --brkdir - - /home/brk/.brk - - --services - - server - # Note: Server can start without processor, will serve empty data until processor indexes blocks - healthcheck: - test: ["CMD", "sh", "-c", "nc -z localhost 3110 || exit 1"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 30s - volumes: brk-data: driver: local \ No newline at end of file From fa1e5aaa7f4e9f61b67ebae721af75cc67852267 Mon Sep 17 00:00:00 2001 From: deadmanoz Date: Fri, 4 Jul 2025 12:15:32 +0800 Subject: [PATCH 4/8] Make Parser::new the only entrypoint --- crates/brk_cli/src/run.rs | 2 +- crates/brk_computer/examples/main.rs | 2 +- crates/brk_indexer/examples/main.rs | 5 +++-- crates/brk_parser/examples/main.rs | 5 +++-- crates/brk_parser/examples/p2a.rs | 5 +++-- crates/brk_parser/src/blk_index_to_blk_recap.rs | 2 +- crates/brk_parser/src/lib.rs | 11 +++-------- crates/brk_server/examples/main.rs | 5 +++-- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/crates/brk_cli/src/run.rs b/crates/brk_cli/src/run.rs index 1f7ea0db3..59b9001be 100644 --- a/crates/brk_cli/src/run.rs +++ b/crates/brk_cli/src/run.rs @@ -21,7 +21,7 @@ pub fn run() -> color_eyre::Result<()> { let exit = Exit::new(); let parser = if config.process() && rpc.is_some() { - Some(brk_parser::Parser::new_with_outputs_dir( + Some(brk_parser::Parser::new( config.blocksdir(), config.outputsdir(), rpc.unwrap(), diff --git a/crates/brk_computer/examples/main.rs b/crates/brk_computer/examples/main.rs index 9de2efeb3..d7520f530 100644 --- a/crates/brk_computer/examples/main.rs +++ b/crates/brk_computer/examples/main.rs @@ -25,7 +25,7 @@ pub fn main() -> color_eyre::Result<()> { thread::Builder::new() .stack_size(32 * 1024 * 1024) .spawn(move || -> color_eyre::Result<()> { - let parser = Parser::new(bitcoin_dir.join("blocks"), rpc); + let parser = Parser::new(bitcoin_dir.join("blocks"), default_brk_path(), rpc); let _outputs_dir = default_brk_path().join("outputs"); let outputs_dir = _outputs_dir.as_path(); diff --git a/crates/brk_indexer/examples/main.rs b/crates/brk_indexer/examples/main.rs index 5fa9c2a40..f4b18234f 100644 --- a/crates/brk_indexer/examples/main.rs +++ b/crates/brk_indexer/examples/main.rs @@ -1,6 +1,6 @@ use std::{path::Path, time::Instant}; -use brk_core::default_bitcoin_path; +use brk_core::{default_bitcoin_path, default_brk_path}; use brk_exit::Exit; use brk_indexer::Indexer; use brk_parser::Parser; @@ -13,6 +13,7 @@ fn main() -> color_eyre::Result<()> { brk_logger::init(Some(Path::new(".log"))); let bitcoin_dir = default_bitcoin_path(); + let brk_dir = default_brk_path(); let rpc = Box::leak(Box::new(bitcoincore_rpc::Client::new( "http://localhost:8332", @@ -20,7 +21,7 @@ fn main() -> color_eyre::Result<()> { )?)); let exit = Exit::new(); - let parser = Parser::new(bitcoin_dir.join("blocks"), rpc); + let parser = Parser::new(bitcoin_dir.join("blocks"), brk_dir, rpc); let outputs = Path::new("../../_outputs"); diff --git a/crates/brk_parser/examples/main.rs b/crates/brk_parser/examples/main.rs index 0a56f9a2d..019807203 100644 --- a/crates/brk_parser/examples/main.rs +++ b/crates/brk_parser/examples/main.rs @@ -1,11 +1,12 @@ use bitcoincore_rpc::{Auth, Client}; -use brk_core::{Height, default_bitcoin_path}; +use brk_core::{Height, default_bitcoin_path, default_brk_path}; use brk_parser::Parser; fn main() { let i = std::time::Instant::now(); let bitcoin_dir = default_bitcoin_path(); + let brk_dir = default_brk_path(); let rpc = Box::leak(Box::new( Client::new( @@ -18,7 +19,7 @@ fn main() { let start = None; let end = None; - let parser = Parser::new(bitcoin_dir.join("blocks"), rpc); + let parser = Parser::new(bitcoin_dir.join("blocks"), brk_dir, rpc); parser .parse(start, end) diff --git a/crates/brk_parser/examples/p2a.rs b/crates/brk_parser/examples/p2a.rs index c858c7800..5fc6d89a7 100644 --- a/crates/brk_parser/examples/p2a.rs +++ b/crates/brk_parser/examples/p2a.rs @@ -1,11 +1,12 @@ use bitcoincore_rpc::{Auth, Client}; -use brk_core::{Height, OutputType, default_bitcoin_path}; +use brk_core::{Height, OutputType, default_bitcoin_path, default_brk_path}; use brk_parser::Parser; fn main() { let i = std::time::Instant::now(); let bitcoin_dir = default_bitcoin_path(); + let brk_dir = default_brk_path(); let rpc = Box::leak(Box::new( Client::new( @@ -18,7 +19,7 @@ fn main() { // let start = None; // let end = None; - let parser = Parser::new(bitcoin_dir.join("blocks"), rpc); + let parser = Parser::new(bitcoin_dir.join("blocks"), brk_dir, rpc); // parser // .parse(start, end) diff --git a/crates/brk_parser/src/blk_index_to_blk_recap.rs b/crates/brk_parser/src/blk_index_to_blk_recap.rs index 4f8b07862..95e6c6db7 100644 --- a/crates/brk_parser/src/blk_index_to_blk_recap.rs +++ b/crates/brk_parser/src/blk_index_to_blk_recap.rs @@ -5,7 +5,7 @@ use std::{ path::{Path, PathBuf}, }; -use crate::{BlkIndexToBlkPath, Height, blk_recap::BlkRecap}; +use crate::{blk_recap::BlkRecap, BlkIndexToBlkPath, Height}; #[derive(Debug)] pub struct BlkIndexToBlkRecap { diff --git a/crates/brk_parser/src/lib.rs b/crates/brk_parser/src/lib.rs index b5222e212..e0dca6f7b 100644 --- a/crates/brk_parser/src/lib.rs +++ b/crates/brk_parser/src/lib.rs @@ -43,18 +43,13 @@ pub struct Parser { } impl Parser { - pub fn new(blocks_dir: PathBuf, rpc: &'static bitcoincore_rpc::Client) -> Self { - // For backward compatibility, use blocks_dir as outputs_dir + pub fn new(blocks_dir: PathBuf, brk_dir: PathBuf, rpc: &'static bitcoincore_rpc::Client) -> Self { Self { - outputs_dir: blocks_dir.clone(), - blocks_dir, + blocks_dir, + outputs_dir: brk_dir, rpc } } - - pub fn new_with_outputs_dir(blocks_dir: PathBuf, outputs_dir: PathBuf, rpc: &'static bitcoincore_rpc::Client) -> Self { - Self { blocks_dir, outputs_dir, rpc } - } pub fn get(&self, height: Height) -> Block { self.parse(Some(height), Some(height)) diff --git a/crates/brk_server/examples/main.rs b/crates/brk_server/examples/main.rs index c92854022..fd7c6e710 100644 --- a/crates/brk_server/examples/main.rs +++ b/crates/brk_server/examples/main.rs @@ -2,7 +2,7 @@ use std::{path::Path, thread::sleep, time::Duration}; use bitcoincore_rpc::RpcApi; use brk_computer::Computer; -use brk_core::default_bitcoin_path; +use brk_core::{default_bitcoin_path, default_brk_path}; use brk_exit::Exit; use brk_fetcher::Fetcher; use brk_indexer::Indexer; @@ -18,6 +18,7 @@ pub fn main() -> color_eyre::Result<()> { let process = true; let bitcoin_dir = default_bitcoin_path(); + let brk_dir = default_brk_path(); let rpc = Box::leak(Box::new(bitcoincore_rpc::Client::new( "http://localhost:8332", @@ -25,7 +26,7 @@ pub fn main() -> color_eyre::Result<()> { )?)); let exit = Exit::new(); - let parser = Parser::new(bitcoin_dir.join("blocks"), rpc); + let parser = Parser::new(bitcoin_dir.join("blocks"), brk_dir, rpc); let outputs_dir = Path::new("../../_outputs"); From 30ba0342066eb9ffba04e65c1a8e239380b106c0 Mon Sep 17 00:00:00 2001 From: deadmanoz Date: Fri, 4 Jul 2025 12:52:20 +0800 Subject: [PATCH 5/8] Move docker artefacts into /docker directory --- .dockerignore => docker/.dockerignore | 0 .env.example => docker/.env.example | 0 DOCKER.md => docker/DOCKER.md | 56 +++++++++++-------- Dockerfile => docker/Dockerfile | 0 docker-build.sh => docker/docker-build.sh | 19 ++++++- .../docker-compose.yml | 6 +- 6 files changed, 54 insertions(+), 27 deletions(-) rename .dockerignore => docker/.dockerignore (100%) rename .env.example => docker/.env.example (100%) rename DOCKER.md => docker/DOCKER.md (78%) rename Dockerfile => docker/Dockerfile (100%) rename docker-build.sh => docker/docker-build.sh (64%) rename docker-compose.yml => docker/docker-compose.yml (96%) diff --git a/.dockerignore b/docker/.dockerignore similarity index 100% rename from .dockerignore rename to docker/.dockerignore diff --git a/.env.example b/docker/.env.example similarity index 100% rename from .env.example rename to docker/.env.example diff --git a/DOCKER.md b/docker/DOCKER.md similarity index 78% rename from DOCKER.md rename to docker/DOCKER.md index a0b5945f6..7c53d00de 100644 --- a/DOCKER.md +++ b/docker/DOCKER.md @@ -13,13 +13,18 @@ This guide explains how to run BRK using Docker and Docker Compose. 1. **Create environment file** ```bash - cp .env.example .env + cp docker/.env.example docker/.env ``` - Edit `.env` and set `BITCOIN_DATA_DIR` to your Bitcoin Core data directory. + Edit `docker/.env` and set `BITCOIN_DATA_DIR` to your Bitcoin Core data directory. 2. **Run with Docker Compose** ```bash - docker compose up -d + docker compose -f docker/docker-compose.yml up -d + ``` + + Or from the docker directory: + ```bash + cd docker && docker compose up -d ``` 3. **Access BRK** @@ -38,10 +43,13 @@ The container runs the BRK binary with `--services all` to enable both processor ```bash # Start BRK -docker compose up +docker compose -f docker/docker-compose.yml up # Or run in background -docker compose up -d +docker compose -f docker/docker-compose.yml up -d + +# Alternative: from docker directory +cd docker && docker compose up -d ``` ## Configuration @@ -87,7 +95,7 @@ BRK_MCP=true BRK will automatically use the `.cookie` file from your Bitcoin Core directory. #### Option 2: Username/Password -Set `BTC_RPC_USER` and `BTC_RPC_PASSWORD` in your `.env` file. +Set `BTC_RPC_USER` and `BTC_RPC_PASSWORD` in your `docker/.env` file. #### Network Connectivity - **Same host**: @@ -99,16 +107,16 @@ Set `BTC_RPC_USER` and `BTC_RPC_PASSWORD` in your `.env` file. ### Using Docker Compose ```bash -docker compose build +docker compose -f docker/docker-compose.yml build ``` ### or ... Using Docker Build Script ```bash # Build with default settings -./docker-build.sh +./docker/docker-build.sh # Build with custom tag -./docker-build.sh --tag v1.0.0 +./docker/docker-build.sh --tag v1.0.0 ``` ## Volumes and Data Storage @@ -122,16 +130,16 @@ Uses a Docker-managed named volume called `brk-data`. This is the recommended ap Maps a specific directory on your host to the container's data directory. This may be desirable if you want to use a specific storage location for BRK data (e.g. a different disk). -1. Set `BRK_DATA_DIR` in your `.env` file to your desired host directory -2. In `docker-compose.yml`, comment out the named volume line and uncomment the bind mount line +1. Set `BRK_DATA_DIR` in your `docker/.env` file to your desired host directory +2. In `docker/docker-compose.yml`, comment out the named volume line and uncomment the bind mount line ```bash -# In .env file +# In docker/.env file BRK_DATA_DIR=/home/user/brk-data ``` ```bash -# In docker-compose.yml +# In docker/docker-compose.yml # Comment out: - ${BRK_DATA_VOLUME:-brk-data}:/home/brk/.brk @@ -139,7 +147,7 @@ BRK_DATA_DIR=/home/user/brk-data # - ${BRK_DATA_DIR:-./brk-data}:/home/brk/.brk ``` -Can also remove or comment out the `volumes` section from the docker-compose.yml file (right at the bottom): +Can also remove or comment out the `volumes` section from the docker/docker-compose.yml file (right at the bottom): ```bash # Comment out: volumes: @@ -158,19 +166,19 @@ The container includes a combined health check that verifies: ### Check Container Status ```bash # View running container -docker compose ps +docker compose -f docker/docker-compose.yml ps # Check health status -docker compose ps --format \"table {{.Service}}\\t{{.Status}}\\t{{.Health}}\" +docker compose -f docker/docker-compose.yml ps --format \"table {{.Service}}\\t{{.Status}}\\t{{.Health}}\" ``` ### View Logs ```bash # View logs -docker compose logs +docker compose -f docker/docker-compose.yml logs # Follow logs in real-time -docker compose logs -f +docker compose -f docker/docker-compose.yml logs -f ``` ## Troubleshooting @@ -182,7 +190,7 @@ docker compose logs -f - The server component will serve data as the processor indexes blocks #### Server won't start -- Check Docker Compose logs: `docker compose logs` +- Check Docker Compose logs: `docker compose -f docker/docker-compose.yml logs` - Verify health endpoint: `curl http://localhost:7070/health` - Ensure no port conflicts on 7070 @@ -192,10 +200,10 @@ docker compose logs -f 1. Ensure Bitcoin Core is running with `-server=1` 2. Check RPC credentials are correct 3. Verify network connectivity from container -4. Test RPC connection: `docker compose exec brk brk --help` +4. Test RPC connection: `docker compose -f docker/docker-compose.yml exec brk brk --help` #### Processor fails to start -- Verify Bitcoin RPC credentials in `.env` +- Verify Bitcoin RPC credentials in `docker/.env` - Ensure Bitcoin Core is running and accessible - Check Bitcoin data directory permissions (should be readable by UID 1000) @@ -221,7 +229,7 @@ docker compose logs -f ### Network Issues #### Cannot access web interface -- Verify port mapping: `docker compose ps` +- Verify port mapping: `docker compose -f docker/docker-compose.yml ps` - Check firewall settings - Ensure no other services are using port 7070 @@ -247,11 +255,11 @@ tar czf brk-backup.tar.gz -C \"$BRK_DATA_DIR\" . ```bash # Stop container -docker compose down +docker compose -f docker/docker-compose.yml down # Restore from backup (named volume) docker run --rm -v brk_brk-data:/target -v \"$(pwd)\":/backup alpine tar xzf /backup/brk-backup.tar.gz -C /target # Start container -docker compose up -d +docker compose -f docker/docker-compose.yml up -d ``` \ No newline at end of file diff --git a/Dockerfile b/docker/Dockerfile similarity index 100% rename from Dockerfile rename to docker/Dockerfile diff --git a/docker-build.sh b/docker/docker-build.sh similarity index 64% rename from docker-build.sh rename to docker/docker-build.sh index 359c8a72b..f64f279a6 100755 --- a/docker-build.sh +++ b/docker/docker-build.sh @@ -50,8 +50,25 @@ done print_info "Building BRK Docker image..." print_info "Image: ${IMAGE_NAME}:${TAG}" +# Detect script location and set paths accordingly +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" + +# Determine if we're running from project root or docker directory +if [[ "$(basename "$PWD")" == "docker" ]]; then + # Running from docker directory + DOCKERFILE_PATH="./Dockerfile" + BUILD_CONTEXT=".." + print_info "Running from docker directory" +else + # Running from project root or elsewhere + DOCKERFILE_PATH="docker/Dockerfile" + BUILD_CONTEXT="." + print_info "Running from project root" +fi + # Execute the build -if docker build -t "${IMAGE_NAME}:${TAG}" .; then +if docker build -f "$DOCKERFILE_PATH" -t "${IMAGE_NAME}:${TAG}" "$BUILD_CONTEXT"; then print_info "Build completed successfully!" print_info "Image built as ${IMAGE_NAME}:${TAG}" else diff --git a/docker-compose.yml b/docker/docker-compose.yml similarity index 96% rename from docker-compose.yml rename to docker/docker-compose.yml index fc9e7bf95..6fa3b79af 100644 --- a/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,10 +1,12 @@ # BRK single-container Docker Compose configuration +name: brk + services: brk: build: - context: . - dockerfile: Dockerfile + context: .. + dockerfile: docker/Dockerfile image: brk:latest container_name: brk restart: unless-stopped From f89276d7b8f2d2500ec9d69c828deaaf2e62274f Mon Sep 17 00:00:00 2001 From: deadmanoz Date: Fri, 4 Jul 2025 15:51:28 +0800 Subject: [PATCH 6/8] Remove redundant services --- crates/brk_cli/src/config.rs | 59 ++++++++--------------- crates/brk_cli/src/lib.rs | 1 - crates/brk_cli/src/run.rs | 88 ++++++++++++---------------------- crates/brk_cli/src/services.rs | 23 --------- 4 files changed, 49 insertions(+), 122 deletions(-) delete mode 100644 crates/brk_cli/src/services.rs diff --git a/crates/brk_cli/src/config.rs b/crates/brk_cli/src/config.rs index f67ca0850..d6190d2e9 100644 --- a/crates/brk_cli/src/config.rs +++ b/crates/brk_cli/src/config.rs @@ -13,7 +13,6 @@ use clap_derive::Parser; use color_eyre::eyre::eyre; use serde::{Deserialize, Serialize}; -use crate::services::Services; #[derive(Parser, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] #[command(version, about)] @@ -33,10 +32,6 @@ pub struct Config { #[arg(long, value_name = "PATH")] brkdir: Option, - /// Activated services, default: all, saved - #[serde(default, deserialize_with = "default_on_error")] - #[arg(short, long)] - services: Option, /// Computation of computed datasets, `lazy` computes data whenever requested without saving it, `eager` computes the data once and saves it to disk, default: `lazy`, saved #[serde(default, deserialize_with = "default_on_error")] @@ -129,9 +124,6 @@ impl Config { config_saved.brkdir = Some(brkdir); } - if let Some(services) = config_args.services.take() { - config_saved.services = Some(services); - } if let Some(computation) = config_args.computation.take() { config_saved.computation = Some(computation); @@ -201,37 +193,33 @@ impl Config { } fn check(&self) { - // Only check Bitcoin directories and RPC if we're running the processor - if self.process() { - if !self.bitcoindir().is_dir() { - println!("{:?} isn't a valid directory", self.bitcoindir()); - println!("Please use the --bitcoindir parameter to set a valid path."); - println!("Run the program with '-h' for help."); - std::process::exit(1); - } - - if !self.blocksdir().is_dir() { - println!("{:?} isn't a valid directory", self.blocksdir()); - println!("Please use the --blocksdir parameter to set a valid path."); - println!("Run the program with '-h' for help."); - std::process::exit(1); - } - - if self.rpc_auth().is_err() { - println!( - "No way found to authenticate the RPC client, please either set --rpccookiefile or --rpcuser and --rpcpassword.\nRun the program with '-h' for help." - ); - std::process::exit(1); - } + if !self.bitcoindir().is_dir() { + println!("{:?} isn't a valid directory", self.bitcoindir()); + println!("Please use the --bitcoindir parameter to set a valid path."); + println!("Run the program with '-h' for help."); + std::process::exit(1); + } + + if !self.blocksdir().is_dir() { + println!("{:?} isn't a valid directory", self.blocksdir()); + println!("Please use the --blocksdir parameter to set a valid path."); + println!("Run the program with '-h' for help."); + std::process::exit(1); } - // Always check BRK directory (needed by both processor and server) if !self.brkdir().is_dir() { println!("{:?} isn't a valid directory", self.brkdir()); println!("Please use the --brkdir parameter to set a valid path."); println!("Run the program with '-h' for help."); std::process::exit(1); } + + if self.rpc_auth().is_err() { + println!( + "No way found to authenticate the RPC client, please either set --rpccookiefile or --rpcuser and --rpcpassword.\nRun the program with '-h' for help." + ); + std::process::exit(1); + } } fn read(path: &Path) -> Self { @@ -310,15 +298,6 @@ impl Config { self.outputsdir().join("hars") } - pub fn process(&self) -> bool { - self.services - .is_none_or(|m| m == Services::All || m == Services::Processor) - } - - pub fn serve(&self) -> bool { - self.services - .is_none_or(|m| m == Services::All || m == Services::Server) - } fn path_cookiefile(&self) -> PathBuf { self.rpccookiefile.as_ref().map_or_else( diff --git a/crates/brk_cli/src/lib.rs b/crates/brk_cli/src/lib.rs index ed14a5406..2b5ce02ea 100644 --- a/crates/brk_cli/src/lib.rs +++ b/crates/brk_cli/src/lib.rs @@ -4,7 +4,6 @@ use brk_core::{dot_brk_log_path, dot_brk_path}; mod config; mod run; -mod services; use run::*; diff --git a/crates/brk_cli/src/run.rs b/crates/brk_cli/src/run.rs index 59b9001be..49b231a9a 100644 --- a/crates/brk_cli/src/run.rs +++ b/crates/brk_cli/src/run.rs @@ -12,23 +12,13 @@ use crate::config::Config; pub fn run() -> color_eyre::Result<()> { let config = Config::import()?; - let rpc = if config.process() { - Some(config.rpc()?) - } else { - None - }; - + let rpc = config.rpc()?; let exit = Exit::new(); - - let parser = if config.process() && rpc.is_some() { - Some(brk_parser::Parser::new( - config.blocksdir(), - config.outputsdir(), - rpc.unwrap(), - )) - } else { - None - }; + let parser = brk_parser::Parser::new( + config.blocksdir(), + config.brkdir(), + rpc, + ); let format = config.format(); @@ -62,60 +52,42 @@ pub fn run() -> color_eyre::Result<()> { .enable_all() .build()? .block_on(async { - let server = if config.serve() { - let served_indexer = indexer.clone(); - let served_computer = computer.clone(); + // Always start the server + let served_indexer = indexer.clone(); + let served_computer = computer.clone(); - let server = Server::new(served_indexer, served_computer, config.website())?; + let server = Server::new(served_indexer, served_computer, config.website())?; - let watch = config.watch(); - let mcp = config.mcp(); - let opt = Some(tokio::spawn(async move { - server.serve(watch, mcp).await.unwrap(); - })); + let watch = config.watch(); + let mcp = config.mcp(); + let server_handle = tokio::spawn(async move { + server.serve(watch, mcp).await.unwrap(); + }); - sleep(Duration::from_secs(1)); + sleep(Duration::from_secs(1)); - opt - } else { - None - }; + // Always run the processor + loop { + wait_for_synced_node(rpc)?; - if config.process() { - if let (Some(rpc_client), Some(parser)) = (rpc, parser) { - loop { - wait_for_synced_node(rpc_client)?; + let block_count = rpc.get_block_count()?; - let block_count = rpc_client.get_block_count()?; + info!("{} blocks found.", block_count + 1); - info!("{} blocks found.", block_count + 1); + let starting_indexes = + indexer.index(&parser, rpc, &exit, config.check_collisions())?; - let starting_indexes = - indexer.index(&parser, rpc_client, &exit, config.check_collisions())?; + computer.compute(&mut indexer, starting_indexes, &exit)?; - computer.compute(&mut indexer, starting_indexes, &exit)?; + if let Some(delay) = config.delay() { + sleep(Duration::from_secs(delay)) + } - if let Some(delay) = config.delay() { - sleep(Duration::from_secs(delay)) - } + info!("Waiting for new blocks..."); - info!("Waiting for new blocks..."); - - while block_count == rpc_client.get_block_count()? { - sleep(Duration::from_secs(1)) - } - } - } else { - return Err(color_eyre::eyre::eyre!( - "RPC client and parser required for processing mode" - ))?; + while block_count == rpc.get_block_count()? { + sleep(Duration::from_secs(1)) } } - - if let Some(handle) = server { - handle.await.unwrap(); - } - - Ok(()) }) } diff --git a/crates/brk_cli/src/services.rs b/crates/brk_cli/src/services.rs deleted file mode 100644 index d06597a4b..000000000 --- a/crates/brk_cli/src/services.rs +++ /dev/null @@ -1,23 +0,0 @@ -use clap_derive::{Parser, ValueEnum}; -use serde::{Deserialize, Serialize}; - -#[derive( - Default, - Debug, - Clone, - Copy, - Parser, - ValueEnum, - Serialize, - Deserialize, - PartialEq, - Eq, - PartialOrd, - Ord, -)] -pub enum Services { - #[default] - All, - Processor, - Server, -} From 5de9757d46263f6729e9b60528812f85dc4ecf43 Mon Sep 17 00:00:00 2001 From: deadmanoz Date: Fri, 4 Jul 2025 16:37:39 +0800 Subject: [PATCH 7/8] Remove services from docker --- docker/DOCKER.md | 2 +- docker/docker-compose.yml | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/docker/DOCKER.md b/docker/DOCKER.md index 7c53d00de..dcf642501 100644 --- a/docker/DOCKER.md +++ b/docker/DOCKER.md @@ -39,7 +39,7 @@ BRK runs as a single container that includes both the blockchain processor and A - Simplifies deployment and monitoring - Uses a single shared data directory -The container runs the BRK binary with `--services all` to enable both processor and server functionality. +The container runs the BRK binary which provides both processor and server functionality. ```bash # Start BRK diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 6fa3b79af..aa2b01633 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -52,8 +52,6 @@ services: - "${BTC_RPC_USER:-bitcoin}" - --rpcpassword - "${BTC_RPC_PASSWORD:-bitcoin}" - - --services - - all healthcheck: test: ["CMD", "sh", "-c", "pgrep -f brk && nc -z localhost 3110"] interval: 30s From 94d4b05c296a1a382ac4d6fbde62488bfea13ff4 Mon Sep 17 00:00:00 2001 From: deadmanoz Date: Tue, 15 Jul 2025 08:48:39 -0700 Subject: [PATCH 8/8] Address review feedback --- .gitignore | 5 +++++ crates/brk_cli/src/run.rs | 2 -- crates/brk_parser/src/lib.rs | 4 ++-- docker/DOCKER.md | 4 +--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index e18eea715..32c7474d9 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,8 @@ _* # Environment variables/configs .env + +# Profiling +profile.json.gz +flamegraph.svg +*.trace diff --git a/crates/brk_cli/src/run.rs b/crates/brk_cli/src/run.rs index 49b231a9a..bdd90f512 100644 --- a/crates/brk_cli/src/run.rs +++ b/crates/brk_cli/src/run.rs @@ -52,7 +52,6 @@ pub fn run() -> color_eyre::Result<()> { .enable_all() .build()? .block_on(async { - // Always start the server let served_indexer = indexer.clone(); let served_computer = computer.clone(); @@ -66,7 +65,6 @@ pub fn run() -> color_eyre::Result<()> { sleep(Duration::from_secs(1)); - // Always run the processor loop { wait_for_synced_node(rpc)?; diff --git a/crates/brk_parser/src/lib.rs b/crates/brk_parser/src/lib.rs index e0dca6f7b..ff2247067 100644 --- a/crates/brk_parser/src/lib.rs +++ b/crates/brk_parser/src/lib.rs @@ -43,10 +43,10 @@ pub struct Parser { } impl Parser { - pub fn new(blocks_dir: PathBuf, brk_dir: PathBuf, rpc: &'static bitcoincore_rpc::Client) -> Self { + pub fn new(blocks_dir: PathBuf, outputs_dir: PathBuf, rpc: &'static bitcoincore_rpc::Client) -> Self { Self { blocks_dir, - outputs_dir: brk_dir, + outputs_dir: outputs_dir, rpc } } diff --git a/docker/DOCKER.md b/docker/DOCKER.md index dcf642501..68259fdbd 100644 --- a/docker/DOCKER.md +++ b/docker/DOCKER.md @@ -39,8 +39,6 @@ BRK runs as a single container that includes both the blockchain processor and A - Simplifies deployment and monitoring - Uses a single shared data directory -The container runs the BRK binary which provides both processor and server functionality. - ```bash # Start BRK docker compose -f docker/docker-compose.yml up @@ -210,7 +208,7 @@ docker compose -f docker/docker-compose.yml logs -f ### Performance Issues #### Slow indexing -- Ensure adequate disk space for indexed data +- Ensure adequate disk space for indexed data - a minimum of 3GB/s is recommended - Monitor memory usage during initial indexing - Use `BRK_COMPUTATION=lazy` to reduce memory usage