Skip to content

Improve node cache#921

Open
AlCutter wants to merge 7 commits intotransparency-dev:mainfrom
AlCutter:better_nodecache
Open

Improve node cache#921
AlCutter wants to merge 7 commits intotransparency-dev:mainfrom
AlCutter:better_nodecache

Conversation

@AlCutter
Copy link
Copy Markdown
Collaborator

@AlCutter AlCutter commented Mar 27, 2026

This PR improves the implementation of the node cache under client.

With these changes, nodeCache is now thread-safe, and supports concurrent fetching of arbitrary nodes, potentially speeding up the process of building trees and proofs if the underlying storage has high latency.

Towards #892

@AlCutter AlCutter force-pushed the better_nodecache branch 5 times, most recently from fa70582 to abcc0ce Compare March 27, 2026 16:06
@AlCutter AlCutter force-pushed the better_nodecache branch 3 times, most recently from 1b04ec4 to dda2351 Compare March 27, 2026 17:14
@AlCutter AlCutter marked this pull request as ready for review March 27, 2026 17:17
@AlCutter AlCutter requested a review from a team as a code owner March 27, 2026 17:17
@AlCutter AlCutter requested review from phbnf and roger2hk March 27, 2026 17:17
// the tile containing the requested node will be fetched and cached, and the
// node hash returned.
// The tile containing the node will be fetched if necessary.
func (n *nodeCache) GetNode(ctx context.Context, id compact.NodeID) ([]byte, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a race condition in GetNode() when the LRU cache is full.

Scenario:

  1. The first goroutine calls GetNode(). It's a cache miss, then the goroutine fetches the tile and add the node to the LRU cache.
  2. Meanwhile, there are many other goroutines fetching other tiles and adding the nodes into the LRU cache.
  3. The LRU cache is full and evicts the node from the first goroutine.
  4. The first goroutine tries to call n.nodes.Get(id); and couldn't find the node.
  5. The unexpected error internal error: missing node %+v is returned.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants