Summary
The persistent BranchCache (added in PR #19954) is currently a direct field on HexPatriciaHashed. It should be moved behind the PatriciaContext interface so that:
- Concurrent trie subtries can each have their own context with seamless cache access — one
PatriciaContext per subtrie, cache shared or partitioned as needed.
- The commitment package public API stays lean — no additional accessor surface on
Trie or HexPatriciaHashed.
- Cache lifecycle is tied to context lifecycle — creation, invalidation, and cleanup follow the context rather than the trie struct.
Current state (PR #19954)
BranchCache is a field on HexPatriciaHashed
GetBranchCache() / SetBranchCache() are on the Trie interface
- Cache is cleared on
Reset() (fork safety)
- Cache is invalidated on fold write paths (delete, propagate, branch)
Proposed refactoring
- Move
BranchCache ownership to PatriciaContext implementations (e.g. TrieContext)
PatriciaContext interface gets GetBranchCache() / SetBranchCache() methods
- Remove
BranchCache field and accessors from HexPatriciaHashed / Trie interface
branchFromCacheOrDB reads cache via hph.ctx.GetBranchCache() instead of hph.branchCache
- Fold write invalidation calls through context
Context
Review feedback from @awskii on PR #19954:
"this cache can be implementation behind PatriciaContext because concurrent trie requires multiple contexts (one per subtrie) and behind this iface it can be seamlessly integrated"
"better keep cache behind patriciaContext and not bloating commitment"
🤖 Generated with Claude Code
Summary
The persistent
BranchCache(added in PR #19954) is currently a direct field onHexPatriciaHashed. It should be moved behind thePatriciaContextinterface so that:PatriciaContextper subtrie, cache shared or partitioned as needed.TrieorHexPatriciaHashed.Current state (PR #19954)
BranchCacheis a field onHexPatriciaHashedGetBranchCache()/SetBranchCache()are on theTrieinterfaceReset()(fork safety)Proposed refactoring
BranchCacheownership toPatriciaContextimplementations (e.g.TrieContext)PatriciaContextinterface getsGetBranchCache()/SetBranchCache()methodsBranchCachefield and accessors fromHexPatriciaHashed/TrieinterfacebranchFromCacheOrDBreads cache viahph.ctx.GetBranchCache()instead ofhph.branchCacheContext
Review feedback from @awskii on PR #19954:
🤖 Generated with Claude Code