consensus: context cache for cumulative RCT outputs#638
Open
redsh4de wants to merge 2 commits into
Open
Conversation
2a2a691 to
b4dea58
Compare
7319680 to
601ae34
Compare
87025e4 to
5dc24c1
Compare
5dc24c1 to
db714b5
Compare
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.
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_infosevery time. Also curbs a potential DoS vectorWhere
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- newOutputDistributionrequest/response.numb_rct_outputsfield onNewBlockData.src/task.rs- build the cache at startup, push on update, truncate on pop, serve the request.types:src/types.rs- newOutputAmount.OutputDistributionInputis now generic over it, and itsrct_start_heightfield is gone.src/blockchain.rs- renamed theOutputDistributionread request toPreRctOutputDistribution(now pre-RCT only), addedCumulativeRctOutsInRange.storage/blockchain:src/service/read.rs- renamed theoutput_distributionhandler topre_rct_output_distributionand narrowed it to pre-RCT amounts, addedcumulative_rct_outs_in_range.binaries/cuprated:src/rpc/handlers/shared.rs- decode the amounts intoOutputAmount, route to the context.src/rpc/service/blockchain.rs- removed the old DBoutput_distributionwrapper.src/rpc/service/blockchain_context.rs- newoutput_distributionwrapper (routes to the context).src/blockchain/manager/handler.rs- setnumb_rct_outputson 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.