types: ConsensusParams test + document the ranges/limits#748
types: ConsensusParams test + document the ranges/limits#748
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #748 +/- ##
==========================================
Coverage ? 57.24%
==========================================
Files ? 82
Lines ? 8436
Branches ? 0
==========================================
Hits ? 4829
Misses ? 3191
Partials ? 416 |
types/params.go
Outdated
|
|
||
| const ( | ||
| maxBlockSizeBytes = 104857600 // 100MB | ||
| _100MiB = 104857600 |
There was a problem hiding this comment.
👎 we're losing meaning here
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Aye aye, I'll revert the variable.
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: |
There was a problem hiding this comment.
why duplicate the code? is this what we want from documentation? step by step duplication of the code
There was a problem hiding this comment.
we should probably document maxBlockSizeBytes somewhere here https://tendermint.readthedocs.io/en/master/specification/block-structure.html
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Perhaps a better alternative is to include these conditions in the comments on the Params struct itself?
There was a problem hiding this comment.
Could you provide a similar example from Golang source code?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
- https://github.com/golang/go/blob/a6ae01a64a6a5ef17a4825cd486aa31f62481100/src/net/http/request.go#L1146-L1147
- https://github.com/golang/go/blob/a9afa4e933f3eff131f12e24bb0f5b9f3168ca14/src/os/dir.go#L7-L46
https://github.com/golang/go/blob/a9afa4e933f3eff131f12e24bb0f5b9f3168ca14/src/os/env.go#L46 - https://github.com/golang/go/blob/a9afa4e933f3eff131f12e24bb0f5b9f3168ca14/src/os/exec/exec.go#L127-L139
- https://github.com/golang/go/blob/a6ae01a64a6a5ef17a4825cd486aa31f62481100/src/runtime/mksizeclasses.go#L171-L174
- https://github.com/golang/go/blob/a6ae01a64a6a5ef17a4825cd486aa31f62481100/src/io/io.go#L286-L294
- https://github.com/golang/go/blob/a6ae01a64a6a5ef17a4825cd486aa31f62481100/src/io/io.go#L296-L302
- https://github.com/golang/go/blob/a6ae01a64a6a5ef17a4825cd486aa31f62481100/src/io/io.go#L330-L336
- https://github.com/golang/go/blob/a6ae01a64a6a5ef17a4825cd486aa31f62481100/src/bytes/bytes.go#L115-L119
- https://github.com/golang/go/blob/a6ae01a64a6a5ef17a4825cd486aa31f62481100/src/math/big/rat.go#L463-L468
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.
There was a problem hiding this comment.
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.
types/params_test.go
Outdated
| ) | ||
|
|
||
| func TestConsensusParamsValidation(t *testing.T) { | ||
| c1 := new(types.ConsensusParams) |
There was a problem hiding this comment.
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 :)
|
@melekes I've made them table tests, PTAL. |
ebuchman
left a comment
There was a problem hiding this comment.
By the way, did you see this: https://github.com/tendermint/tendermint/blob/master/types/genesis_test.go#L72 ?
Is there much new here?
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: |
There was a problem hiding this comment.
Perhaps a better alternative is to include these conditions in the comments on the Params struct itself?
types/params.go
Outdated
|
|
||
| // ensure blocks aren't too big | ||
| if params.BlockSizeParams.MaxBytes > maxBlockSizeBytes { | ||
| if params.BlockSizeParams.MaxBytes > _100MiB { |
There was a problem hiding this comment.
this isn't good because if we change the limit we have to change the variable name. it really should just be maxBlockSizeBytes
There was a problem hiding this comment.
Great point here, thanks.
|
|
Yes, or just move that test to params_test.go, which is prob more appropriate. Thanks |
|
Alright, thanks for the initial review folks. I've updated the PR with your feedback, PTAL at f24f039. |
* Updated changelog with API changes in tendermint#286 * Cosmetic * Update .changelog/unreleased/breaking-changes/286-p2p.md Co-authored-by: Daniel <daniel.cason@informal.systems> * unclog build > CHANGELOG.md --------- Co-authored-by: Daniel <daniel.cason@informal.systems>
…#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 <connect@thanethomson.com> * node: Remove access to consensus state Consensus state should only ever be accessible via the consensus reactor. Signed-off-by: Thane Thomson <connect@thanethomson.com> * Add changelog entry Signed-off-by: Thane Thomson <connect@thanethomson.com> * Fix mistake in changelog entry Signed-off-by: Thane Thomson <connect@thanethomson.com> --------- Signed-off-by: Thane Thomson <connect@thanethomson.com> (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 <connect@thanethomson.com> * Rebuild changelog with unreleased entries Signed-off-by: Thane Thomson <connect@thanethomson.com> --------- Signed-off-by: Thane Thomson <connect@thanethomson.com> Co-authored-by: Thane Thomson <connect@thanethomson.com>
Fixes #747
Updates #693
clear at 100MiB