Skip to content

fix: don't let cache rebuild publish read before invalidation - #1159

Merged
Klakurka merged 2 commits into
masterfrom
fix/cache-rebuild-race
Nov 26, 2026
Merged

Klakurka merged 2 commits into
masterfrom
fix/cache-rebuild-race

Conversation

@Klakurka

Copy link
Copy Markdown
Member

A rebuild (CacheSet.addressCreation, or the balance fallback in getBalanceForAddress) reads an address's txs from the DB and then writes the caches unconditionally. If the address was invalidated in between, e.g. because prices were linked for one of its txs, the rebuild wrote what it read before that change and the cache stayed wrong until the next invalidation.

Each address now has a cache generation counter that invalidations (and tx creation) bump. A rebuild reads it before reading the DB and writes through a Lua script that checks it and sets all keys atomically; if it changed, the result is discarded and the next read rebuilds.

A rebuild (CacheSet.addressCreation, or the balance fallback in
getBalanceForAddress) reads an address's txs from the DB and then writes the
caches unconditionally. If the address was invalidated in between, e.g.
because prices were linked for one of its txs, the rebuild wrote what it read
before that change and the cache stayed wrong until the next invalidation.

Each address now has a cache generation counter that invalidations (and tx
creation) bump. A rebuild reads it before reading the DB and writes through a
Lua script that checks it and sets all keys atomically; if it changed, the
result is discarded and the next read rebuilds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Klakurka Klakurka self-assigned this Nov 26, 2026
@Klakurka Klakurka added the bug Something isn't working label Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d2cd87c2-0534-485b-a136-a8471abf90f8
Commits

Reviewing files that changed from the base of the PR and between b551c14 and d91162b.

Files selected for processing: 6

  • redis/balanceCache.ts
  • redis/cacheGeneration.ts
  • redis/clientInstance.ts
  • redis/index.ts
  • redis/paymentCache.ts
  • tests/unittests/cacheGeneration.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@Klakurka
Klakurka merged commit 41b5b83 into master Nov 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant