!5274odin/swap-queue-anchor-cache → develop0db990d31c

Swap queue EndBlock reads the TOR anchors once

AI-generatedEverything on this page was written by an AI agent from the diff: the summaries, the narration, the diagrams, the flags and the glossary. It can be wrong or incomplete, so check it against the code before you rely on it.

3commits
7files
366lines changed
145lines to read
−19%streaming EndBlock sec/op
0gas / state change

Where the diff is

Who reads and who switches off the cache

3-minute explainer

What changed

Many reads per swap

Every anchor read scans all pools and one Mimir each

scoreMsgsSwapDollarsPerRune

The anchors cache

Read-through snapshot on the context, copied both ways

hit → clonemiss → scan + SetMimir error → no fill

Switch-off rules

Any write that could change the list disables it for good

existing pool write: keptnew pool / remove: offMimir write: offwrite before fill: off

Fill before the first swap

Single-swap queues no longer disable the cache immediately

fetchQueueGetAnchors(TOR)scoreMsgsswaps

No cache in simulations

Quotes inside a tx keep their gas_used unchanged

EndBlock ✓simulate ✗WASM QuoteSwap ✗

Evidence

−19% streaming EndBlock; 2,481 regression outputs identical

Line by line · every changed logic line, narrated

3:46runtime
6code chapters
100%logic lines narrated (106/106)
5flagged spots
speed

Chapters

What to check

Ask an AI about this change

Chat assistantClaude, ChatGPT, … (reads a link)

Coding agentClaude Code, Cursor, … (reads the repo)

The context file is context.md. Use Copy with context for an AI that can't open links; it pastes the whole file in.

Glossary

AnchorsCache
New context-scoped snapshot of GetAnchors(TOR) that disables itself on writes that could change the list. anchors_cache.go ↗
Cache context
A Cosmos SDK branched store whose writes can be committed or discarded; the cache pointer is shared into it. Cosmos SDK ↗
CtxSimulationMode
Context flag set by querier.simulate for quotes; the queue runs without the cache under it.
DollarsPerRune
Price of RUNE in TOR, derived from the anchor pools; used for swap fees. keeper_anchors.go ↗
gas_used
Consensus-visible gas of a tx; store reads inside a tx count toward it.
Mimir
On-chain key/value parameter overrides set by admins or node votes. keeper_mimir.go ↗
MimirCache
The existing context-scoped Mimir read cache this change copies its pattern from.
TOR anchors
Stablecoin pools whose TorAnchor-<pool> Mimir is positive; their median prices TOR, THORChain's dollar unit. keeper_anchors.go ↗