Documentation
¶
Overview ¶
Package cache is Lantern's persistent, bounded, CID-keyed block cache.
The light node runs cache-first with an in-memory hamt.MemBlockStore: fast, but every process restart is cold, so a restarted node re-fetches its whole warm set (the PDP/payments/registry/USDFC contract subtrees) from the gateway/swarm on the first head advance. For a wallet that's fine. For a PDP node - which must prove/settle against warm contract state on a schedule and cannot afford a cold-start stall inside a proving window - it is not.
This package backs the block cache with Badger (pure-Go, already a Lantern dependency via the header store), so the warm set SURVIVES restart. It is CID-keyed exactly like MemBlockStore, so the content-addressed trust property is unchanged: bytes are stored under their CID and verified against it. A peer can never poison this cache because insertion goes through PutVerify on the network path.
Boundedness: a soft byte budget with sampled-LRU eviction plus a pin set (the warm contract subtrees a PDP node must never lose). This is the mid/PDP tier's 2-5 GB persistent footprint - deliberately bigger than the light node's memory cache, to cut the cold-fetch tail to zero in steady state.
It satisfies combined.Cache (hamt.BlockGetter + Put) so it is a drop-in replacement for MemBlockStore in the daemon fetcher.
Index ¶
- Constants
- type Options
- type Stats
- type Store
- func (s *Store) Close() error
- func (s *Store) Get(_ context.Context, c cid.Cid) ([]byte, error)
- func (s *Store) GetBlock(ctx context.Context, c cid.Cid) (block.Block, error)
- func (s *Store) Has(c cid.Cid) bool
- func (s *Store) Pin(c cid.Cid) error
- func (s *Store) Put(c cid.Cid, raw []byte) cid.Cid
- func (s *Store) PutVerify(c cid.Cid, raw []byte) error
- func (s *Store) Stats() Stats
- func (s *Store) Unpin(c cid.Cid) error
Constants ¶
const DefaultSoftCapBytes int64 = 3 << 30
DefaultSoftCapBytes is the default persistent-cache budget for the PDP tier: 3 GiB, the middle of the 2-5 GB target. Eviction keeps usage near this; pinned blocks are exempt.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// SoftCapBytes is the target on-disk block budget. 0 => default (3 GiB).
// Eviction fires when live block bytes exceed this. Pinned blocks are
// never evicted, so the effective floor is the pinned set size.
SoftCapBytes int64
}
Options configures the persistent cache.
type Stats ¶
type Stats struct {
LiveBytes int64
SoftCapBytes int64
Hits uint64
Misses uint64
Puts uint64
Evictions uint64
}
Stats is an observability snapshot of the cache.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a persistent, bounded, CID-keyed block cache.
func (*Store) Close ¶
Close flushes and closes the underlying Badger DB. Safe to call from any goroutine; concurrent Get/Put in flight when Close is entered are allowed to finish, and any background touch/eviction goroutines already spawned pre-Close are waited on before the DB is torn down.
func (*Store) Get ¶
Get returns the raw bytes for c, or an error if absent. Bumps the block's lastAccess for LRU. Implements hamt.BlockGetter.
func (*Store) Pin ¶
Pin marks c as un-evictable (the PDP warm set: contract subtrees a PDP node must never lose across restarts). Pinning a not-yet-present CID is a no-op that takes effect if/when the block is inserted.
func (*Store) Put ¶
Put stores raw bytes under c and returns c (for chaining). It does NOT re-hash; the combined fetcher only calls Put after a CID-verified fetch, matching MemBlockStore.Put semantics. Use PutVerify to insert untrusted bytes.