Calculate topic rewards in a more precise way - #967
Draft
fstecker wants to merge 2 commits into
Draft
Conversation
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.
This is a proposed fix for an inaccuracy in how the rewards allocated to a topic are calculated at the end of a topic.
This would be correct if all quantities involved were constant throughout the epoch. But in reality, because the epochs of other topics end in the meantime, the normalized topic weight of our topic constantly updates throughout its epoch. A correct implementation would keep track of the normalized topic weight in each block of the epoch, and sum these up, instead of just multiplying the last one of them with
epochLength. But naively, this would come with a signification computational cost.This PR is an optimized version of this, which sidesteps the computational. We keep a history of the topic-independent quantity
over every block. We hold this in a "Fenwick tree", a type of list which allows to summing over ranges in logarithmic time. Then, at the end of every epoch, we can just compute
The details are described in RES-919.
This PR is not intended to be merged as-is, I haven't even tested it. I just wanted to put this suggestion into code, hoping that it can serve as a starting point for a proper fix.
Summary by cubic
Compute topic rewards block-by-block using a Fenwick tree to fix inaccuracies when topic weights change mid-epoch. This implements the approach described in RES-919 and keeps reward calculations precise without heavy compute.
New Features
rewardCurrentBlockEmission / totalSumPreviousTopicWeights, stored in a Fenwick tree for O(log N) range sums.Bug Fixes
Written for commit 88eaab1. Summary will update on new commits.