// Package filterstore holds BIP158 filters keyed by the block they describe. // // The key is the block hash and nothing else, because the filter of a block is // a property of the block: two chains that carry the same block carry the same // filter, so one copy serves both. That is the reason the filter store is not // per chain and the header stores are. // // The bytes are the BlobStore's: one data file per 512 MB with a length-prefixed // record, a per-file index, and a tail record that names the newest append that // was durable, so a crash mid-append is repaired and nothing else is. The store // does not check a filter against the block: a filter's own hash is committed by // the chain's filter-header fold, and the builder checks it there before it // writes one. package filterstore import ( "path/filepath" "git.smesh.lol/nostrino/pkg/crypto/chainhash" "git.smesh.lol/btcd-lite/internal/store" ) // Dir is where a data directory keeps its filters. func Dir(data string) string { return filepath.Join(data, "filters", "by-block") } // Store is the filter store of one data directory. type Store struct { *store.BlobStore } // Open opens or creates the store in dir. func Open(dir string) (*Store, error) { b, err := store.NewBlobStore(dir, "flt", nil) if err != nil { return nil, err } return &Store{BlobStore: b}, nil } // Put files a filter under its block's hash. func (s *Store) Put(blockHash chainhash.Hash, filter []byte) error { return s.BlobStore.Put(blockHash, filter) } // Get returns the filter for a block. func (s *Store) Get(blockHash chainhash.Hash) ([]byte, error) { return s.BlobStore.Get(blockHash) }