Skip to content

types: ConsensusParams test + document the ranges/limits - #748

Merged
ebuchman merged 2 commits into
developfrom
params-test
Oct 23, 2017
Merged

ebuchman merged 2 commits into
developfrom
params-test

Conversation

@odeke-em

Copy link
Copy Markdown
Contributor

Fixes #747
Updates #693

  • Document the unmentioned limits for ConsensusParams.Validate()
  • Make the limit for ConsensusParams.BlockSizeParams.MaxBytes
    clear at 100MiB

@odeke-em
odeke-em requested a review from ebuchman as a code owner October 15, 2017 21:35
@odeke-em
odeke-em requested a review from zramsay October 15, 2017 21:35
@codecov-io

codecov-io commented Oct 15, 2017 •

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (develop@fa56e8c). Click here to learn what that means.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             develop     #748   +/-   ##
==========================================
  Coverage           ?   57.24%           
==========================================
  Files              ?       82           
  Lines              ?     8436           
  Branches           ?        0           
==========================================
  Hits               ?     4829           
  Misses             ?     3191           
  Partials           ?      416

Comment thread types/params.go Outdated

const (
maxBlockSizeBytes = 104857600 // 100MB
_100MiB = 104857600

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎 we're losing meaning here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem though is that a plain maxBlockSizeBytes itself requires having to look it up and isn't documented anywhere, IMHO _100MiB is self documenting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but how about the following: what if somebody else starts using _100MiB and later you decide to change it to _120MiB. you accidentally change both usages and break the code (or worse).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having to look it up is fine. We shouldn't ruin the variable name :P

We do need to document this somewhere though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye aye, I'll revert the variable.

Comment thread types/params.go Outdated

// Validate validates the ConsensusParams to ensure all values
// are within their allowed limits, and returns an error if they are not.
// Expecting:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why duplicate the code? is this what we want from documentation? step by step duplication of the code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is duplicating the code, it saves folks from having to open the code and having to read each line, by line. That's what am trying to avoid. I had to go through the guts of it in order to write the tests themselves.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to go through the guts of it in order to write the tests themselves.

well, you are a developer, aren't you? you have to go through the guts sometimes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a better alternative is to include these conditions in the comments on the Params struct itself?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide a similar example from Golang source code?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, you are a developer, aren't you? you have to go through the guts sometimes

LOL I don't think this is fair in this case - these conditions are undocumented, so from the perspective of being able to test the functionality exposed to the user, it's fair to say this was to0 opaque - but for that reason we should put it on the Params struct rather than here on the Validate function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, you are a developer, aren't you? you have to go through the guts sometimes
I believe that the purpose of us making APIs is so make it easy for other people to build off our stuff easily. Imagine you had to read through all the source code of Go's APIs just to be able to use a function? My motivation here it is to try to improve developer experience/productivity and reduce the cognitive overload.

Could you provide a similar example from Golang source code?
I can find tonnes of examples:

and many more.

@ebuchman Perhaps a better alternative is to include these conditions in the comments on the Params struct itself?
Perhaps, but I think it is very easy for code to go stale that way as it is detached from the actual validation code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, wow. sorry for being so harsh. admit that I was wrong. great examples! Agree that good API and dev experience/productivity are very important.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a biggie @melekes :)

Comment thread types/params_test.go Outdated
)

func TestConsensusParamsValidation(t *testing.T) {
c1 := new(types.ConsensusParams)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not table tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed simpler, usually I'd use table tests but here they seemed simpler. However, I can add table tests since they aren't tightly coupled to the previous lines and don't require saving context of what previously happened. Thanks for pointing this out :)

Fixes #747
Updates #693

* Document the unmentioned limits for ConsensusParams.Validate()
* Make the limit for ConsensusParams.BlockSizeParams.MaxBytes
clear at 100MiB
@odeke-em

Copy link
Copy Markdown
Contributor Author

@melekes I've made them table tests, PTAL.

@ebuchman ebuchman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread types/params.go Outdated

// Validate validates the ConsensusParams to ensure all values
// are within their allowed limits, and returns an error if they are not.
// Expecting:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a better alternative is to include these conditions in the comments on the Params struct itself?

Comment thread types/params.go Outdated

// ensure blocks aren't too big
if params.BlockSizeParams.MaxBytes > maxBlockSizeBytes {
if params.BlockSizeParams.MaxBytes > _100MiB {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't good because if we change the limit we have to change the variable name. it really should just be maxBlockSizeBytes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point here, thanks.

@odeke-em

Copy link
Copy Markdown
Contributor Author

By the way, did you see this: https://github.com/tendermint/tendermint/blob/master/types/genesis_test.go#L72 ?
No I hadn't, perhaps we could update the test name, I grepped for Validate and no hits in the tests, otherwise I have to go through each file checking

Is there much new here?
Just the documentation, plus the actual new test cases testing the extreme ends of the ranges as opposed to 0, 1, but these can be adapted into that test. Thank you for pointing out that duplicate.

@ebuchman

Copy link
Copy Markdown
Contributor

perhaps we could update the test name

Yes, or just move that test to params_test.go, which is prob more appropriate. Thanks

@odeke-em

odeke-em commented Oct 20, 2017 •

Copy link
Copy Markdown
Contributor Author

Alright, thanks for the initial review folks. I've updated the PR with your feedback, PTAL at f24f039.

@ebuchman
ebuchman merged commit f97229f into develop Oct 23, 2017
@ebuchman
ebuchman deleted the params-test branch October 23, 2017 15:18
firelizzard18 pushed a commit to AccumulateNetwork/tendermint that referenced this pull request Nov 24, 2023
* Updated changelog with API changes in tendermint#286

* Cosmetic

* Update .changelog/unreleased/breaking-changes/286-p2p.md

Co-authored-by: Daniel <[email protected]>

* unclog build > CHANGELOG.md

---------

Co-authored-by: Daniel <[email protected]>
firelizzard18 pushed a commit to AccumulateNetwork/tendermint that referenced this pull request Nov 24, 2023
…#1120) (tendermint#1122)

* node: Revert removal of public reactor accessors (tendermint#1120)

* Revert "Remove unused code (tendermint#286)"

This reverts commit a2d9915.

Signed-off-by: Thane Thomson <[email protected]>

* node: Remove access to consensus state

Consensus state should only ever be accessible via the consensus
reactor.

Signed-off-by: Thane Thomson <[email protected]>

* Add changelog entry

Signed-off-by: Thane Thomson <[email protected]>

* Fix mistake in changelog entry

Signed-off-by: Thane Thomson <[email protected]>

---------

Signed-off-by: Thane Thomson <[email protected]>
(cherry picked from commit 577cbcb)

* Revert "Updated changelog with API changes in tendermint#286 (tendermint#748)"

This reverts commit 7a253f1.

Signed-off-by: Thane Thomson <[email protected]>

* Rebuild changelog with unreleased entries

Signed-off-by: Thane Thomson <[email protected]>

---------

Signed-off-by: Thane Thomson <[email protected]>
Co-authored-by: Thane Thomson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants