$ show lightninglabs/neutrino
This repository is a production-grade Go library implementing a Bitcoin light client based on BIP 157/158 compact block filters (Neutrino). It is designed for mobile Lightning Network wallets and provides SPV (Simplified Payment Verification) without requiring a full node. The core architecture revolves around a ChainService that orchestrates peer connections, block header sync, filter header sync, UTXO queries, transaction broadcasting, and chain rescanning. The library stores headers in flat files with bbolt-backed indices, and filters in a boltdb database. It includes a sophisticated peer query management system with retry, timeout, and banning logic, as well as caching layers for blocks and filters. The codebase is well-structured into subpackages with clear responsibilities, many of which are reusable in other Go projects. It is actively maintained by Lightning Labs and used in production by lnd (Lightning Network Daemon).
The LLM identified 6 files worth highlighting for reuse:
A generic, concurrency-safe LRU cache with configurable capacity, size tracking via a Size() method, and optional eviction callbacks. It is self-contained and can be extracted as a standalone library for caching any type of items with memory-aware eviction.
A typed concurrent FIFO queue with a bounded channel and an overflow list for burst handling. It provides non-blocking push and pop operations with context support, and is safe for use across multiple goroutines. This is a clean, reusable implementation of a classic producer-consumer pattern.
A batch writer that accumulates items until a configurable threshold (number of items or time interval) is reached, then flushes them as a batch to a write function. It is designed to batch database writes for efficiency, with graceful shutdown and error handling. The pattern is generic and applicable to any sink that benefits from batching.
A bounded, in-memory chain of headers with O(log n) ancestor lookup via skip pointers. It maintains a fixed-size window of headers and provides efficient ancestry queries for reorg handling. The skip-list implementation is non-obvious and demonstrates advanced data structure design, and the component is self-contained enough to be reused in any blockchain-related project.
A heap-based priority queue for scheduling work items with configurable ordering, used by the query work manager. It supports push, pop, and removal of items, and is designed to be goroutine-safe. The pattern is a clean separation of scheduling logic and can be extracted for any task queue requiring priority-based execution.
A persistent ban store that records banned IP networks with reasons and expiration times. It serializes bans to a simple file format and provides methods to add, remove, check, and expire bans. The implementation is self-contained and demonstrates a robust pattern for managing peer bans in a P2P network, suitable for extraction into other networking projects.