Skip to content
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

Fix Light Client validator set hash calculation #834

Merged
merged 17 commits into from
Mar 29, 2021

Conversation

thanethomson
Copy link
Contributor

@thanethomson thanethomson commented Mar 25, 2021

Closes #831

  • Referenced an issue explaining the need for the change
  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG.md

Signed-off-by: Thane Thomson <[email protected]>
This commit adds pagination to the `validators` method on the `Client`
trait (BREAKING).

Signed-off-by: Thane Thomson <[email protected]>
… string (like page numbers/per page counts)

Signed-off-by: Thane Thomson <[email protected]>
@thanethomson thanethomson changed the title Correctly compute validator set hash in Light Client Fix Light Client validator set hash calculation Mar 25, 2021
@thanethomson
Copy link
Contributor Author

thanethomson commented Mar 26, 2021

It's hard to know how to test this without doing (1) full integration testing or (2) mock testing with data captured from real nodes' RPC responses.

Both would be useful, but both would still require a significant amount of work. Depending on how urgent this solution is, we could possibly do these in follow-up PRs? (1) would be particularly useful as a job that regularly runs in CI (e.g. on a daily basis).

@thanethomson thanethomson marked this pull request as ready for review March 26, 2021 01:12
Signed-off-by: Thane Thomson <[email protected]>
@codecov-io
Copy link

codecov-io commented Mar 26, 2021

Codecov Report

Merging #834 (d9a03b7) into master (1cca3ac) will decrease coverage by 0.2%.
The diff coverage is 0.0%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #834     +/-   ##
========================================
- Coverage    29.1%   28.8%   -0.3%     
========================================
  Files         194     196      +2     
  Lines       10766   10865     +99     
  Branches     4443    4474     +31     
========================================
- Hits         3139    3137      -2     
- Misses       4653    4752     +99     
- Partials     2974    2976      +2     
Impacted Files Coverage Δ
light-client/src/components/io.rs 0.0% <0.0%> (ø)
proto/src/serializers/optional_from_str.rs 0.0% <0.0%> (ø)
rpc/src/client.rs 0.9% <0.0%> (-0.4%) ⬇️
rpc/src/client/bin/main.rs 0.3% <0.0%> (-0.1%) ⬇️
rpc/src/endpoint/consensus_state.rs 21.8% <ø> (ø)
rpc/src/endpoint/validators.rs 0.0% <0.0%> (ø)
rpc/src/error.rs 31.4% <ø> (ø)
rpc/src/lib.rs 100.0% <ø> (ø)
rpc/src/paging.rs 0.0% <0.0%> (ø)
proto/src/serializers/timestamp.rs 32.5% <0.0%> (-5.0%) ⬇️
... and 12 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 1cca3ac...d9a03b7. Read the comment docs.

Copy link
Member

@romac romac left a comment

Choose a reason for hiding this comment

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

Looks great! Left some minor suggestions and a couple questions.

rpc/src/client/bin/main.rs Outdated Show resolved Hide resolved
rpc/src/paging.rs Outdated Show resolved Hide resolved
rpc/src/paging.rs Outdated Show resolved Hide resolved
@@ -29,12 +66,28 @@ impl crate::SimpleRequest for Request {}

/// Validator responses
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why we need/what does this attribute brings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm in two minds about this right now.

On the one hand, I like the fact that it reduces the number of ways in which to construct a struct (this reduces the number of ways in which we can break downstream projects' code). If we restrict construction to the constructor, it also then, for certain structs, allows for parameter validation and additional guarantees that the resulting struct is most likely "correct".

On the other hand, we have some pretty massive structs where this doesn't work so well, where they have 9+ public fields. So the constructor-based approach becomes a little unwieldy. Usually I'd then use some builder pattern to construct such structs, but this will result in a significant amount more code (where I'm trying to avoid bloat, since if there's less code it's quicker to change).

I suppose, erring on the side of rapid development and less code (which is probably a good goal for the short- to medium-term), it's probably a better idea to go with the approach of direct struct construction?

Copy link
Member

Choose a reason for hiding this comment

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

a)

On the one hand, I like the fact that it reduces the number of ways in which to construct a struct (this reduces the number of ways in which we can break downstream projects' code). If we restrict construction to the constructor, it also then, for certain structs, allows for parameter validation and additional guarantees that the resulting struct is most likely "correct".

Agreed, I think this is the right approach for structs that are exposed publicly and which we expect our users to instantiate themselves manually. But, even if possible, it's not really the case here as we expect users to use the higher-level methods rather than use perform and construct the requests directly.

b)

On the other hand, we have some pretty massive structs where this doesn't work so well, where they have 9+ public fields. So the constructor-based approach becomes a little unwieldy. Usually I'd then use some builder pattern to construct such structs, but this will result in a significant amount more code (where I'm trying to avoid bloat, since if there's less code it's quicker to change).

If we ever want to use the builder pattern everywhere, this may help: https://lib.rs/crates/derive_builder :)

c)

I suppose, erring on the side of rapid development and less code (which is probably a good goal for the short- to medium-term), it's probably a better idea to go with the approach of direct struct construction?

Seems fine to me for now, given the reasoning I point a) above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

derive_builder looks amazing. We should definitely investigate using that approach for all the internal Tendermint domain types!

@thanethomson thanethomson requested a review from romac March 29, 2021 13:16
@thanethomson thanethomson merged commit 3c2d0d1 into master Mar 29, 2021
@thanethomson thanethomson deleted the thane/831-validators-hash branch March 29, 2021 15:07
thanethomson added a commit that referenced this pull request Mar 30, 2021
* Remove unused file

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

* Refactor validators RPC endpoint interface

This commit adds pagination to the `validators` method on the `Client`
trait (BREAKING).

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

* Ensure "total" response field is a string

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

* Add serializer for optional types that need to be converted to/from a string (like page numbers/per page counts)

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

* Refactor to ensure page numbers and per-page values are converted to/from strings first

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

* Convert tcp:// scheme to http:// for RPC addresses

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

* Add Light Client support for RPC URLs instead of net::Address

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

* Revert 14ad69f for now

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

* Revert f0c26f7

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

* Add CHANGELOG

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

* Convert infallible TryFroms to Froms

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

* Remove all non_exhaustive struct attributes

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

* Attempt to fix broken wasm_bindgen dependency

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

* Fixate syn dependency for light-client-js

Signed-off-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.

Incorrect validator set hash
3 participants