Skip to content

consensus: context cache for cumulative RCT outputs#638

Open
redsh4de wants to merge 2 commits into
Cuprate:mainfrom
redsh4de:feat/output-distrib-cache
Open

consensus: context cache for cumulative RCT outputs#638
redsh4de wants to merge 2 commits into
Cuprate:mainfrom
redsh4de:feat/output-distrib-cache

Conversation

@redsh4de

@redsh4de redsh4de commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What

Adds a in-memory rolling cache for cumulative RCT outputs, used by OutputDistribution.

Closes #635

Why

Public nodes that get frequent transaction requests benefit from this, as they don't have to rescan block_infos every time. Also curbs a potential DoS vector

Where

consensus/context:

  • src/distribution.rs - new module: the cache, the request handler, the slicing/delta math, and the per-block RCT count.
  • src/lib.rs - new OutputDistribution request/response. numb_rct_outputs field on NewBlockData.
  • src/task.rs - build the cache at startup, push on update, truncate on pop, serve the request.

types:

  • src/types.rs - new OutputAmount. OutputDistributionInput is now generic over it, and its rct_start_height field is gone.
  • src/blockchain.rs - renamed the OutputDistribution read request to PreRctOutputDistribution (now pre-RCT only), added CumulativeRctOutsInRange.

storage/blockchain:

  • src/service/read.rs - renamed the output_distribution handler to pre_rct_output_distribution and narrowed it to pre-RCT amounts, added cumulative_rct_outs_in_range.

binaries/cuprated:

  • src/rpc/handlers/shared.rs - decode the amounts into OutputAmount, route to the context.
  • src/rpc/service/blockchain.rs - removed the old DB output_distribution wrapper.
  • src/rpc/service/blockchain_context.rs - new output_distribution wrapper (routes to the context).
  • src/blockchain/manager/handler.rs - set numb_rct_outputs on the new block.

How

The cache keeps the cumulative RCT output counts per block, built once at startup from the database and kept up to date by the context task - each new block pushes its total, a pop truncates from the end (same as the difficulty and weight caches).

Requests are answered by slicing the cached prefix: the amount 0 (RCT) distribution comes straight from the cache for any (from, to) range. Pre-RCT amounts are forwarded to the database and merged back in request order.

@github-actions github-actions Bot added the A-storage Area: Related to storage. label Jun 11, 2026
@redsh4de redsh4de force-pushed the feat/output-distrib-cache branch from 2a2a691 to b4dea58 Compare June 11, 2026 13:55
@github-actions github-actions Bot added A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-workspace Area: Changes to a root workspace file or general repo file. labels Jun 11, 2026
@redsh4de redsh4de force-pushed the feat/output-distrib-cache branch 2 times, most recently from 7319680 to 601ae34 Compare June 11, 2026 20:06
@redsh4de redsh4de marked this pull request as ready for review June 11, 2026 20:21
@redsh4de redsh4de force-pushed the feat/output-distrib-cache branch 2 times, most recently from 87025e4 to 5dc24c1 Compare June 12, 2026 11:38
@redsh4de redsh4de force-pushed the feat/output-distrib-cache branch from 5dc24c1 to db714b5 Compare June 12, 2026 19:00
@github-actions github-actions Bot added A-consensus Area: Related to consensus. A-types Area: Related to types. A-binaries Area: Related to binaries. and removed A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-workspace Area: Changes to a root workspace file or general repo file. labels Jun 12, 2026
@redsh4de redsh4de changed the title storage: runtime cache for cumulative RCT outputs storage: context cache for cumulative RCT outputs Jun 12, 2026
@redsh4de redsh4de changed the title storage: context cache for cumulative RCT outputs consensus: context cache for cumulative RCT outputs Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-binaries Area: Related to binaries. A-consensus Area: Related to consensus. A-storage Area: Related to storage. A-types Area: Related to types.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache cumulative_rct_outs for OutputDistribution

1 participant