-
Notifications
You must be signed in to change notification settings - Fork 523
ledger: fix NextRewardsState()
#3403
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
Conversation
35e42c4 to
805119b
Compare
data/bookkeeping/block_test.go
Outdated
|
|
||
| params, ok := config.Consensus[protocol.ConsensusCurrentVersion] | ||
| require.True(t, ok) | ||
| params.RewardsCalculationFix = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is "almost there". You'll need to confirm expected failure without the fix, and expected succeess with the fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also be a good idea to add expected failure after the fix, providing invalid input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (1). Why test on invalid input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testing it against invalid input ensures that the method does behave in the way we expect it to. I realize that there could be multitude of invalid inputs, and ideally, we need to analyze the codebase to ensure all the code-paths are taken and validated individually.
Codecov Report
@@ Coverage Diff @@
## master #3403 +/- ##
==========================================
- Coverage 47.65% 47.64% -0.01%
==========================================
Files 370 370
Lines 59804 59810 +6
==========================================
- Hits 28498 28495 -3
- Misses 28001 28010 +9
Partials 3305 3305
Continue to review full report at Codecov.
|
| require.Equal(t, uint64(2), state.RewardsLevel) | ||
| require.Equal(t, uint64(0), state.RewardsResidue) | ||
|
|
||
| assert.Zero(t, buf.Len()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in unit tests, you almost always want to use require and not assert. If the expression fails, there is no point in keep running the test. ( in fact, it could lead into some other test failures )
tsachiherman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For testing the expected empty log output, your change is fine.
However, you did not test the expected output in case of an error.
The last test does plus some long running tests check that log output is non-empty. What other errors are you referring to? |
|
There are some other overflow checks in the code, but they really shouldn't happen... |
Yes, I agree that it shouldn't happen under normal running conditions - but you're implementing a unit test; in this case, just explicitly check the output for the error string. |
Do you want me to cause those overflows to happen and check the logs? I'm not following. |
|
Yes, exactly. Pass artificial parameters that would reproduce the problem,
and confirm the implementation.
…On Fri, Jan 14, 2022, 19:41 Tolik Zinovyev ***@***.***> wrote:
There are some other overflow checks in the code, but they really
shouldn't happen...
Yes, I agree that it shouldn't happen under normal running conditions -
but you're implementing a unit test; in this case, just explicitly check
the output for the error string.
Do you want me to cause those overflows to happen and check the logs? I'm
not following.
—
Reply to this email directly, view it on GitHub
<#3403 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AF2OOHYZDG43MARDQ5HJJBTUWC7CXANCNFSM5LUP5VRQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
* ledger: fix `NextRewardsState()` (#3403) ## Summary A modification of #3336. Added a new test where the rewards pool overspends and proposed a fix in `NextRewardsState()` requiring a consensus upgrade. ## Test Plan This is mostly tests. * Fix a potential problem of committing non-uniform consensus versions (#3453) If accountdb accumulates a large backlog, it is possible catchpoint tracker would attempt to commit a wider range than account updates tracker expects. * avoid generating log error on EnsureValidatedBlock / EnsureBlock (#3424) In EnsureBlock,, do not log as error message if the error is ledgercore.ErrNonSequentialBlockEval and the block round is in the past (i.e. already in the ledger). * Fix typo Fulll to Full (#3456) Fix typo * Fix worng message on restore crash db. (#3455) When crash state is found but could not be restored, noCrashState variable is used to report a warning. However, this variable was set to false in a case where there was no crash state, and the wrong warning was reported. * Adding new scenario for feature networks (#3451) Co-authored-by: Tolik Zinovyev <tolik@algorand.com> Co-authored-by: Pavel Zbitskiy <65323360+algorandskiy@users.noreply.github.com> Co-authored-by: Shant Karakashian <55754073+algonautshant@users.noreply.github.com>
* ledger: fix `NextRewardsState()` (#3403) ## Summary A modification of #3336. Added a new test where the rewards pool overspends and proposed a fix in `NextRewardsState()` requiring a consensus upgrade. ## Test Plan This is mostly tests. * Fix a potential problem of committing non-uniform consensus versions (#3453) If accountdb accumulates a large backlog, it is possible catchpoint tracker would attempt to commit a wider range than account updates tracker expects. * avoid generating log error on EnsureValidatedBlock / EnsureBlock (#3424) In EnsureBlock,, do not log as error message if the error is ledgercore.ErrNonSequentialBlockEval and the block round is in the past (i.e. already in the ledger). * Fix typo Fulll to Full (#3456) Fix typo * Fix worng message on restore crash db. (#3455) When crash state is found but could not be restored, noCrashState variable is used to report a warning. However, this variable was set to false in a case where there was no crash state, and the wrong warning was reported. * Adding new scenario for feature networks (#3451) * Fixing telemetry ports (#3497) Co-authored-by: Tolik Zinovyev <tolik@algorand.com> Co-authored-by: Pavel Zbitskiy <65323360+algorandskiy@users.noreply.github.com> Co-authored-by: Shant Karakashian <55754073+algonautshant@users.noreply.github.com> Co-authored-by: Jack <87339414+algojack@users.noreply.github.com>
Summary
A modification of #3336. Added a new test where the rewards pool overspends and proposed a fix in
NextRewardsState()requiring a consensus upgrade.Test Plan
This is mostly tests.