Skip to content

commitment: move warmup cache behind PatriciaContext #20277

Description

@awskii

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

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions