Problem
WarmupCache is currently wired directly into HexPatriciaHashed via hph.cache field and hph.enableWarmupCache flag. The trie accesses the cache directly, bypassing the PatriciaContext abstraction:
hph.cache = warmuper.Cache() // direct coupling
Proposed Solution
Introduce CachingPatriciaContext — a wrapper over PatriciaContext that transparently caches Branch(), Account(), and Storage() reads:
type CachingPatriciaContext struct {
inner PatriciaContext
cache *WarmupCache
}
func (c *CachingPatriciaContext) Branch(prefix []byte) ([]byte, kv.Step, error) {
if data, ok := c.cache.GetBranch(prefix); ok {
return data, 0, nil
}
data, step, err := c.inner.Branch(prefix)
if err == nil && len(data) > 0 {
c.cache.PutBranch(prefix, data)
}
return data, step, err
}
Result
- Remove
hph.cache *WarmupCache and hph.enableWarmupCache bool fields
- Trie uses only
PatriciaContext — single interface for all external data
CachingPatriciaContext reusable without Warmuper (simple LRU cache)
- Easier to test in isolation
Problem
WarmupCacheis currently wired directly intoHexPatriciaHashedviahph.cachefield andhph.enableWarmupCacheflag. The trie accesses the cache directly, bypassing thePatriciaContextabstraction:Proposed Solution
Introduce
CachingPatriciaContext— a wrapper overPatriciaContextthat transparently cachesBranch(),Account(), andStorage()reads:Result
hph.cache *WarmupCacheandhph.enableWarmupCache boolfieldsPatriciaContext— single interface for all external dataCachingPatriciaContextreusable withoutWarmuper(simple LRU cache)