Skip to content

commitment: move BranchCache behind PatriciaContext interface #20218

Description

@mh0lt

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:

  1. Concurrent trie subtries can each have their own context with seamless cache access — one PatriciaContext per subtrie, cache shared or partitioned as needed.
  2. The commitment package public API stays lean — no additional accessor surface on Trie or HexPatriciaHashed.
  3. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions