-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bonus Token by adjustavailableTokens #30
Comments
Thanks for this; it does indeed look like a bug. I'll add a fix for it soon. |
Once adjustavailableTokens() is called, the number of tokens should be updated in accordance with the tick even if the buket is full. Semantically, extra tokens are discarded though we, in fact, simply returns from the function.
I proposed a PR to fix this, and your review comments are welcome. I also added a test case for this issue in case future changes might need a regression test. FYI: I noticed there are some test-cases failures, they might need some careful examination and fix. |
Fix bonus tokens by function adjustavailableTokens (#30)
Resolved via #31. |
I noticed that inside the function
adjustavailableTokens()
the
tb.latestTick
is not updated iftb.availableTokens >= tb.capacity
。That makes the description of the variable latestTick holds the latest tick for which we know the number of tokens in the bucket. not so accurate, IMO.
And I wrote a snippet of code which can produce surprising results:
Output
That is, after taken all tokens out of the bucket, the bucket is still full.
Is this by design or just an implementation bug?
The text was updated successfully, but these errors were encountered: