Conversation
terminate() has three callers (Close, Journal, Disable) but only Close represents the node actually restarting; Journal and Disable now pass persist=false so the address-biased cache save no longer runs redundantly or ahead of the trie journal write. Also: a reload is only considered warm once it reaches the same 2/3 fill target the preload itself targets (a snapshot saved mid-preload no longer permanently skips the top-up), the size-mismatch regression test now uses sizes that are actually rejected by fastcache instead of silently accepted ones, and a warm reload now logs.
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (82.45%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #2396 +/- ##
===========================================
- Coverage 55.57% 55.55% -0.02%
===========================================
Files 918 918
Lines 167133 167177 +44
===========================================
- Hits 92877 92870 -7
- Misses 68775 68830 +55
+ Partials 5481 5477 -4
... and 19 files with indirect coverage changes
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AddressBiasedCache(triedb/pathdb) warms dedicated in-RAM caches for a handful of large,rarely-mutated contracts on mainnet block producers via
cache.addresscachesizes, but doesa full rate-limited BFS walk from scratch on every startup and unconditionally wipes the
cache on every graceful shutdown. On the real BP config (4 addresses, up to 8196MB, at the
deployed 512KB/s preload rate limit) this costs up to ~3h of degraded-cache operation on
every planned restart.
This PR persists each address's cache to
<TrieJournalDirectory>/addresscache/<accountHash>.cacheon genuine graceful
Database.Close()(not onDisable()orJournal()— see below), andreloads it via
fastcache.LoadFromFileOrNewon startup, skipping the preload walk when thereload reaches the same 2/3-fill target the preload itself targets. Correctness does not
depend on freshness:
reader.Node()already hash-verifies every cache hit and evicts+refetcheson mismatch regardless of why an entry is stale, so a stale persisted snapshot can only cost
efficiency, never correctness.
commonCacheis untouched — only the configured per-addresscaches are persisted. Full design rationale:
agent-zerorepo,docs/superpowers/specs/2026-09-03-bor-preload-persist-repair-design.md.One correction made during implementation:
diskLayer.terminate()has 3 callers(
Database.Close,Database.Disable,Journal), not 1. Persisting on all 3 woulddouble-save on every real shutdown and add a redundant multi-GB write on
Disable()(snap-sync entry, not a restart). Fixed by threading a
persist boolthroughterminate()/AddressBiasedCache.Close(persist bool)— onlyDatabase.Close()passestrue.Executed tests
Full unit suite (
go test ./triedb/...): passing, race-clean.Live validation on a disposable GCP disk-clone of
posdevnodes-mainnet-bor-1(a syncedmainnet full node), configured with the real BP
addresscachesizes/preloadratelimitfrom
anonymous-91..94:pathdb_biased_address_{hit,miss})systemctl stop)Also validated: two consecutive persist→reload cycles (no staleness compounding); a
deliberately-deleted single-address snapshot correctly falls back to cold preload for
that address only, while the other 3 stay warm; zero panics/hash-mismatch/corruption
signals across the whole run.
Rollout notes
Not consensus-affecting — this is a read-cache optimization only, and correctness is
backstopped by the pre-existing, unmodified
reader.Node()hash-verify-and-evict path.No coordinated upgrade needed. Backwards-compatible: no new required config (the
persistence directory derives from the existing
JournalDirectory); a node with no priorsnapshot, a mismatched cache size, or a corrupted file all fall back to today's cold-walk
behavior unchanged. Operator-visible additions: a new
<datadir>/.../triedb/addresscache/directory on disk (sized to the configured
addresscachesizes, see table above) and a new"Reloaded address cache snapshot"info log line on warm startup. Orphaned snapshot filesfor an address later removed from config are not auto-cleaned (documented, deliberate v1
scope decision — not a leak, just a manual-cleanup wart).