fix(retry): avoid truncating fractional retry_percent in TpsBudget#863
Open
SAY-5 wants to merge 2 commits into
Open
fix(retry): avoid truncating fractional retry_percent in TpsBudget#863SAY-5 wants to merge 2 commits into
SAY-5 wants to merge 2 commits into
Conversation
seanmonstar
reviewed
May 12, 2026
| // If there is no percent, then you gain nothing from deposits. | ||
| // Withdrawals can only be made against the reserve, over time. | ||
| (0, 1) | ||
| } else if retry_percent <= 1.0 { |
Collaborator
There was a problem hiding this comment.
I think most often the percent will be 10, 20, around there. So, to not need to deal with large numbers in the most common case, this could probably be edit to just <= 0.5. What do you think?
56de74d to
d769498
Compare
Author
|
Good call, switched to scaling only when retry_percent <= 0.5 so the common integer-ish percents keep the original arithmetic. Updated the test name to match. |
Collapses the fractional-percent and > 1 branches into one: scale deposits by 1000 and use (1000 / retry_percent) as the withdraw cost for every non-zero percent. This gives exact precision across the full [0, 1000] range without a special-case threshold. Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Author
|
Updated: applied the 1000x scaling uniformly for all non-zero retry_percent values (not just <= 0.5). This means the test case at 0.6 now actually verifies the fix: (1000, 1666) gives exactly 6 retries per 10 deposits. The > 1 case also simplifies to the same formula. |
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.
TpsBudget::newused(1, (1.0 / retry_percent) as isize)forretry_percent <= 1.0, which truncates the reciprocal so e.g.0.6authorizes a full retry per deposit instead of 0.6. This reuses the existing 1000x deposit scaling for all positive percentages and adds a regression test. Closes #857.