Bug Fix: fix unsigned underflow in per-block net calculation#2033
Open
ukane-philemon wants to merge 1 commit intodecred:masterfrom
Open
Bug Fix: fix unsigned underflow in per-block net calculation#2033ukane-philemon wants to merge 1 commit intodecred:masterfrom
ukane-philemon wants to merge 1 commit intodecred:masterfrom
Conversation
The per-block net value was previously computed using uint64, which caused underflow when sent > received within a block. This resulted in incorrect large positive values due to unsigned wraparound. Net flow per-block can legitimately be negative, the calculation now uses int64 which correctly represents block level balance changes and prevents overflow. Signed-off-by: Philemon Ukane <ukanephilemon@gmail.com>
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.
The per-block net value was previously computed using uint64, which caused underflow when sent > received within a block.
This resulted in incorrect large positive values due to unsigned wraparound.
Net flow per-block can legitimately be negative, the calculation now uses int64 which correctly represents block level balance changes and prevents overflow.
Closes #2031
Checkout the balances on the Treasury page to confirm issue and also address balances like this one: https://dcrdata.decred.org/address/DsSCPWJX871jTQ8CmN1ZaCQw4pW27YW2wDa?chart=amountflow&zoom=mm6vmelc-mm6x0uy8&bin=all&flow=7
Before:

After
