Documentation
¶
Overview ¶
Package beef provides storage and retrieval functionality for BEEF (Background Evaluation Extended Format) data in overlay services.
BEEF is a compact format for representing Bitcoin transactions along with their merkle proofs, enabling SPV (Simplified Payment Verification) without needing the full blockchain.
The package includes implementations for:
- Redis: Fast in-memory storage with optional persistence and TTL
- MongoDB: Document storage with replication support
- SQLite: Embedded database for local deployments
- Filesystem: Directory-based storage for simple file persistence
- LRU: In-memory cache with size limits and fallback support
- JungleBus: Network fetching from JungleBus service
Storage Interface:
The BeefStorage interface defines two core operations:
- SaveBeef: Store BEEF data associated with a transaction ID
- LoadBeef: Retrieve BEEF data by transaction ID
Example Usage:
// Create Redis BEEF storage with TTL and fallback
beefStore, err := beef.NewRedisBeefStorage("redis://localhost:6379?ttl=24h", fallbackStorage)
// Save BEEF data
err = beefStore.SaveBeef(ctx, &txid, beefBytes)
// Load BEEF data
beefData, err := beefStore.LoadBeef(ctx, &txid)
Storage Chaining:
Multiple storage backends can be chained for caching and fallback:
diskStorage := beef.NewFilesystemBeefStorage("/data/beef")
redisCache := beef.NewRedisBeefStorage("redis://localhost:6379?ttl=1h", diskStorage)
lruCache := beef.NewLRUBeefStorage(50*1024*1024, redisCache) // 50MB LRU -> Redis -> Disk
Implementation Notes:
- BEEF data is stored as binary data (base64 encoded in Redis)
- Transaction IDs are used as keys for efficient lookup
- Storage implementations should handle concurrent access safely
- LoadTx is now a standalone function, not a method on BeefStorage
Index ¶
- Variables
- func LoadTx(ctx context.Context, storage BeefStorage, txid *chainhash.Hash, ...) (*transaction.Transaction, error)
- func LoadTxFromBeef(ctx context.Context, beefBytes []byte, txid *chainhash.Hash, ...) (*transaction.Transaction, error)
- func ParseSize(sizeStr string) (int64, error)
- type BeefStorage
- type FilesystemBeefStorage
- type JunglebusBeefStorage
- type LRUBeefStorage
- type RedisBeefStorage
- type SQLiteBeefStorage
Constants ¶
This section is empty.
Variables ¶
var BeefKey = "beef"
var ErrNotFound = errors.New("not-found")
Functions ¶
func LoadTx ¶
func LoadTx(ctx context.Context, storage BeefStorage, txid *chainhash.Hash, chaintracker *headers_client.Client) (*transaction.Transaction, error)
LoadTx loads a transaction from any BeefStorage implementation with optional merkle path validation
func LoadTxFromBeef ¶
func LoadTxFromBeef(ctx context.Context, beefBytes []byte, txid *chainhash.Hash, chaintracker *headers_client.Client) (*transaction.Transaction, error)
LoadTxFromBeef is a helper function that loads a transaction from BEEF bytes and optionally validates its merkle path
Types ¶
type BeefStorage ¶
type BeefStorage interface {
LoadBeef(ctx context.Context, txid *chainhash.Hash) ([]byte, error)
SaveBeef(ctx context.Context, txid *chainhash.Hash, beefBytes []byte) error
}
func CreateBeefStorage ¶
func CreateBeefStorage(connectionStrings []string) (BeefStorage, error)
CreateBeefStorage creates a hierarchical stack of BeefStorage implementations from a slice of connection strings. Each storage layer uses the next as its fallback.
The first connection string creates the top-level storage (checked first), and the last creates the bottom-level fallback (checked last).
Supported formats:
- lru://?size=100mb or lru://?size=1gb (in-memory LRU cache with size limit)
- redis://localhost:6379?ttl=24h (Redis with optional TTL parameter)
- sqlite:///path/to/beef.db or sqlite://beef.db
- file:///path/to/storage/dir
- junglebus:// (fetches from JungleBus API)
- ./beef.db (inferred as SQLite)
- ./beef_storage/ (inferred as filesystem)
Example:
CreateBeefStorage([]string{"lru://?size=100mb", "redis://localhost:6379", "sqlite://beef.db", "junglebus://"})
Creates: LRU -> Redis -> SQLite -> JungleBus
type FilesystemBeefStorage ¶
type FilesystemBeefStorage struct {
// contains filtered or unexported fields
}
func NewFilesystemBeefStorage ¶
func NewFilesystemBeefStorage(basePath string, fallback BeefStorage) (*FilesystemBeefStorage, error)
type JunglebusBeefStorage ¶
type JunglebusBeefStorage struct {
// contains filtered or unexported fields
}
func NewJunglebusBeefStorage ¶
func NewJunglebusBeefStorage(junglebusURL string, fallback BeefStorage) *JunglebusBeefStorage
type LRUBeefStorage ¶
type LRUBeefStorage struct {
// contains filtered or unexported fields
}
func NewLRUBeefStorage ¶
func NewLRUBeefStorage(maxBytes int64, fallback BeefStorage) *LRUBeefStorage
NewLRUBeefStorage creates a new LRU cache with the specified maximum size in bytes
type RedisBeefStorage ¶
type RedisBeefStorage struct {
// contains filtered or unexported fields
}
func NewRedisBeefStorage ¶
func NewRedisBeefStorage(connString string, fallback BeefStorage) (*RedisBeefStorage, error)
type SQLiteBeefStorage ¶
type SQLiteBeefStorage struct {
// contains filtered or unexported fields
}
func NewSQLiteBeefStorage ¶
func NewSQLiteBeefStorage(dbPath string, fallback BeefStorage) (*SQLiteBeefStorage, error)
func (*SQLiteBeefStorage) Close ¶
func (t *SQLiteBeefStorage) Close() error