Skip to content

Conversation

@tolikzinovyev
Copy link
Contributor

@tolikzinovyev tolikzinovyev commented Jan 10, 2022

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.

@tolikzinovyev tolikzinovyev self-assigned this Jan 10, 2022
@tolikzinovyev tolikzinovyev requested a review from cce January 10, 2022 21:47
@tolikzinovyev tolikzinovyev changed the title NextRewardsState() tests Fix NextRewardsState() Jan 10, 2022

params, ok := config.Consensus[protocol.ConsensusCurrentVersion]
require.True(t, ok)
params.RewardsCalculationFix = true
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@tsachiherman tsachiherman marked this pull request as ready for review January 11, 2022 02:28
@codecov-commenter
Copy link

codecov-commenter commented Jan 11, 2022

Codecov Report

Merging #3403 (a84a702) into master (2346615) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
config/consensus.go 84.64% <100.00%> (+0.05%) ⬆️
data/bookkeeping/block.go 54.74% <100.00%> (+4.55%) ⬆️
ledger/internal/eval.go 70.36% <100.00%> (ø)
network/wsPeer.go 65.83% <0.00%> (-2.78%) ⬇️
crypto/merkletrie/trie.go 66.42% <0.00%> (-2.19%) ⬇️
crypto/merkletrie/node.go 91.62% <0.00%> (-1.87%) ⬇️
catchup/peerSelector.go 98.95% <0.00%> (-1.05%) ⬇️
catchup/service.go 69.90% <0.00%> (-0.75%) ⬇️
network/wsNetwork.go 62.72% <0.00%> (-0.20%) ⬇️
ledger/acctupdates.go 65.77% <0.00%> (+0.95%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2346615...a84a702. Read the comment docs.

@tsachiherman tsachiherman changed the title Fix NextRewardsState() ledger: fix NextRewardsState() Jan 11, 2022
require.Equal(t, uint64(2), state.RewardsLevel)
require.Equal(t, uint64(0), state.RewardsResidue)

assert.Zero(t, buf.Len())
Copy link
Contributor

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 )

Copy link
Contributor

@tsachiherman tsachiherman left a 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.

@tolikzinovyev
Copy link
Contributor Author

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?

@tolikzinovyev
Copy link
Contributor Author

There are some other overflow checks in the code, but they really shouldn't happen...

@tsachiherman
Copy link
Contributor

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.

@tolikzinovyev
Copy link
Contributor Author

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.

@tsachiherman
Copy link
Contributor

tsachiherman commented Jan 15, 2022 via email

@tsachiherman tsachiherman merged commit 2edd3de into algorand:master Jan 19, 2022
jannotti pushed a commit that referenced this pull request Jan 24, 2022
* 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>
jannotti pushed a commit that referenced this pull request Jan 25, 2022
* 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>
tsachiherman added a commit that referenced this pull request Feb 10, 2022
## Summary

Create an update path that would enable the following features:
1. Batch Verification (#3031)
2. State Proof Keys (#2990)
3. TEAL 6 (#3397)
4. Expired Participation Keys (#2924)
5. Fix rewards calculation bug (#3403)

## Test Plan

Unit tests added.
@tolikzinovyev tolikzinovyev deleted the rewards branch April 27, 2022 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants