A high-performance, multi-chain blockchain indexing and querying system built in Rust with FoundationDB as the primary storage backend.
Almanac is a distributed blockchain data indexing platform designed to efficiently track, store, and query events across multiple blockchain networks. It provides real-time indexing capabilities with strong consistency guarantees through FoundationDB's ACID transactions.
The system is built around several core components organized in a modular crate structure:
almanac-core- Core types, traits, and abstractions for events, storage, and filteringalmanac-storage- Storage layer with FoundationDB backend and memory implementationsalmanac-indexing- Event ingestion pipeline with batch processing and validationalmanac-api- REST API server with authentication and rate limitingalmanac-chains- Chain adapters for different blockchain protocolsalmanac-consensus- Consensus and finality handling logicalmanac-eventbus- Event bus system for internal communicationalmanac-config- Configuration managementalmanac-testing- Testing utilities and fixtures
Almanac supports multiple blockchain networks through dedicated node services:
almanac-nodes/ethereum- Ethereum indexing nodealmanac-nodes/cosmos- Cosmos indexing nodealmanac-nodes/solana- Solana indexing node (WIP)
Each chain adapter implements the ChainAdapter trait, providing a unified interface for blockchain integration.
- Multi-chain Support - Index events from Ethereum, Cosmos, and Solana networks
- FoundationDB Storage - ACID transactions with strong consistency guarantees
- Real-time Indexing - Low-latency event processing with configurable batch sizes
- REST API - Comprehensive API for querying indexed data
- Anchor IDL Indexing - Automatic detection and storage of Solana Anchor program IDLs
- Authentication - API key-based authentication with configurable permissions
- Rate Limiting - Built-in rate limiting to protect against abuse
- Reorg Handling - Automatic blockchain reorganization detection and handling
- Distributed Architecture - Designed for horizontal scaling across multiple nodes
- Nix Integration - Complete Nix flake for reproducible builds and deployments
- Health Monitoring - Built-in health checks and Prometheus metrics
Almanac uses FoundationDB as its primary storage backend, providing:
- ACID Transactions - Strong consistency across all operations
- Horizontal Scaling - Automatic sharding and replication
- Tuple Space Model - Efficient key-value storage with complex queries
- Change Tracking - Built-in change streams for real-time updates
- Storage Proofs - Cryptographic proofs for data integrity
The storage layer also includes a memory backend for testing and development.
Configuration is managed through TOML files with environment-specific overrides:
config/dev.toml- Development configurationconfig/prod.toml- Production configurationconfig/test.toml- Test configurationconfig/cosmos.toml- Cosmos-specific settingsconfig/ethereum.toml- Ethereum-specific settingsconfig/solana.toml- Solana-specific settings
- Rust 1.75+
- FoundationDB 7.1+
- Nix
# Enter development shell
nix develop
# Build all crates
nix build
# Run tests
nix flake check# Development - run API with Swagger UI
nix run .#swagger-ui
# Alternative - run via development shell
nix develop
cargo run --bin almanac-apiThe API server supports both memory and FoundationDB storage backends, configured via environment variables:
export STORAGE_BACKEND=foundationdb # or memory
export FDB_CLUSTER_FILE=/path/to/fdb.cluster
export FDB_NAMESPACE=almanac
export API_HOST=127.0.0.1
export API_PORT=8080# Use simulation cluster for multi-chain indexing
nix run .#sim-cluster -- init ethereum,cosmos,fdb
nix run .#sim-cluster -- start
# Or run individual indexers via development shell
nix develop
cargo run --bin almanac-node-ethereum -- --config config/ethereum.toml
cargo run --bin almanac-node-cosmos -- --config config/cosmos.tomlThe project includes several helper scripts in the scripts/ directory:
# Setup development environment
./scripts/dev/setup-dev-env.sh
# Run all tests
./scripts/testing/run-all-tests.sh
# Test API functionality
./scripts/testing/api-tests.sh
# Monitor API health
./scripts/services/monitor-api-health.sh
# Manage API service
./scripts/services/manage-api-service.shThe REST API provides endpoints for querying indexed blockchain data:
# Set API key (if authentication is enabled)
export API_KEY="your-api-key"# Get events for a specific contract
curl -X GET "http://localhost:8080/api/v1/events?address=0x..." \
-H "X-API-Key: $API_KEY"
# Query events with filters
curl -X GET "http://localhost:8080/api/v1/events?from_block=1000000&to_block=1000100" \
-H "X-API-Key: $API_KEY"
# Get events by chain
curl -X GET "http://localhost:8080/api/v1/chains/ethereum/events" \
-H "X-API-Key: $API_KEY"# Get semantic interpretations
curl -X GET "http://localhost:8080/api/v1/chains/ethereum/contracts/0x.../semantics/field_name"
-H "X-API-Key: $API_KEY"
# Submit semantic interpretation
curl -X POST "http://localhost:8080/api/v1/chains/ethereum/contracts/0x.../semantics/field_name"
-H "X-API-Key: $API_KEY"
-H "Content-Type: application/json"
-d '{"interpretation": {"semantic_tags": ["balance"], "confidence": "high"}}'
# Generate traverse request (storage proof)
curl -X POST "http://localhost:8080/api/v1/traverse/request/ethereum/0x..."
-H "X-API-Key: $API_KEY"# API health check
curl http://localhost:8080/health
# Node health (varies by port)
curl http://localhost:9092/health # Ethereum node
curl http://localhost:9093/health # Cosmos node# Build production image
nix build .#almanac-api
# Use NixOS modules
# See nix/modules/almanac-api.nix for configuration options-
Build release binaries:
# Build API and tools nix build .#swagger-ui nix build .#generate-openapi-spec # Build via development shell nix develop cargo build --release --bin almanac-api cargo build --release --bin almanac-node-ethereum cargo build --release --bin almanac-node-cosmos
-
Set up FoundationDB cluster
-
Configure environment variables
-
Run services with appropriate configurations
The project includes comprehensive testing at multiple levels:
# Run all unit tests
nix develop -c cargo test
# Test specific crates
nix develop -c cargo test --package almanac-storage
nix develop -c cargo test --package almanac-api# Run integration tests
nix develop -c cargo test --package almanac-chains --features ethereum,cosmos -- --ignored
# E2E tests
nix develop -c cargo test --package e2e# Run benchmarks (when available)
nix develop -c cargo benchAlmanac includes built-in monitoring and observability:
- Health Checks - Service health endpoints at
/healthand/ready - Metrics - Prometheus-compatible metrics on port 9090
- Logging - Structured logging with configurable levels
Key environment variables for configuration:
# Storage
STORAGE_BACKEND=foundationdb|memory
FDB_CLUSTER_FILE=/path/to/fdb.cluster
FDB_NAMESPACE=almanac
# API
API_HOST=127.0.0.1
API_PORT=8080
ADMIN_API_KEY=your-admin-key
RATE_LIMIT_PER_MINUTE=100
# Logging
RUST_LOG=info
RUST_BACKTRACE=1Each chain requires specific configuration in its TOML file:
[chain]
id = "ethereum-mainnet"
confirmations = 6
[rpc]
url = "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY"
timeout_secs = 30
max_retries = 3
[indexing]
start_block = 18000000
batch_size = 100
max_concurrent_batches = 5
[storage.fdb]
cluster_file = "/etc/foundationdb/fdb.cluster"- Architecture Overview
- FoundationDB Implementation
- Chain Adapter Guide
- Integration Guide
- Running Guide
- Testing Guide
Cover image from Gaine's New-York pocket almanack for the year 1789
