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

Use flex-error for tendermint-rs errors #923

Merged
merged 30 commits into from
Aug 7, 2021
Merged

Conversation

soareschen
Copy link
Contributor

@soareschen soareschen commented Jul 1, 2021

Closes #669

This is the second part for informalsystems/hermes#988

  • Referenced an issue explaining the need for the change
  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Added entry in .changelog/

@codecov-commenter
Copy link

codecov-commenter commented Jul 14, 2021

Codecov Report

Merging #923 (afd7185) into master (e824bfc) will increase coverage by 1.2%.
The diff coverage is 54.9%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #923     +/-   ##
========================================
+ Coverage    70.6%   71.9%   +1.2%     
========================================
  Files         205     202      -3     
  Lines       16439   16183    -256     
========================================
+ Hits        11620   11643     +23     
+ Misses       4819    4540    -279     
Impacted Files Coverage Δ
abci/src/lib.rs 100.0% <ø> (ø)
light-client/examples/light_client.rs 0.0% <0.0%> (ø)
light-client/src/builder/error.rs 0.0% <0.0%> (ø)
light-client/src/builder/light_client.rs 0.0% <0.0%> (ø)
light-client/src/builder/supervisor.rs 0.0% <0.0%> (ø)
light-client/src/components/io.rs 0.0% <0.0%> (-1.4%) ⬇️
light-client/src/evidence.rs 50.0% <ø> (ø)
light-client/src/fork_detector.rs 78.6% <0.0%> (-1.4%) ⬇️
light-client/src/lib.rs 100.0% <ø> (ø)
light-client/src/utils/block_on.rs 0.0% <0.0%> (ø)
... and 113 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 e824bfc...afd7185. Read the comment docs.

@thanethomson
Copy link
Member

This all looks pretty great so far! Is it ready for review yet?

@soareschen
Copy link
Contributor Author

It should be reviewable soon. Currently I am refactoring the coding convention from error::constructor_error() to Error::constructor() in informalsystems/hermes#988. I will also do the same here and also update the documentation of flex-error to reflect the changes.

@soareschen soareschen marked this pull request as ready for review July 27, 2021 08:19
Signed-off-by: Thane Thomson <connect@thanethomson.com>
thanethomson and others added 2 commits August 7, 2021 15:13
* Implement full-duplex secret connection (#938)

* Implement thread-safe cloning of a secret connection

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Expand documentation for SecretConnection on threading considerations

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Extract peer construction into its own method

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add test for cloned SecretConnection

This adds a `TcpStream`-based test for parallelizing operations on a
`SecretConnection`. I used `TcpStream` instead of the buffered reader in
the other tests because it wasn't feasible to implement the `TryClone`
trait for that buffered pipe implementation.

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add more messages to test

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Expand comment for clarity

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add .changelog entry

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Restore half-duplex operations

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Extract encrypt/decrypt fns as independent methods

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove unnecessary trait bounds

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Extract send/receive state

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Extract read/write functionality as standalone methods

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add logic to facilitate splitting SecretConnection into its sending and receiving halves

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Restore split SecretConnection test using new semantics

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Update changelog entry

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Update docs for `SecretConnection`

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Condense error reporting

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Extract TryClone trait into its own crate

As per the discussion at
#938 (comment),
this extracts the `TryClone` trait into a new crate called
`tendermint-std-ext` in the `std-ext` directory.

This new crate is intended to contain any code that we need that extends
the Rust standard library.

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Reorder imports

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Assert validation regardless of debug build

This introduces the internal encryption assertions at runtime regardless
of build type. This may introduce a small performance hit, but it's
probably worth it to ensure correctness.

Effectively this is keeping an eye on the code in the
`encrypt_and_write` fn to ensure its correctness.

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove remote_pubkey optionality from sender/receiver halves

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Update SecretConnection docs with comment content

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix doc link to TryClone trait

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix doc link to TryClone trait

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add docs on SecretConnection failures and connection integrity

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Synchronize sending/receiving failures to comply with crypto algorithm constraints

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Rename try_split method to split for SecretConnection

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove redundant field name prefixes

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix broken link in docs

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix recent clippy errors on `master` (#941)

* Fix needless borrows in codebase

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Ignore needless collect warning (we do actually seem to need it)

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove trailing semicolon in macro to fix docs compiling

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Copy link
Member

@thanethomson thanethomson left a comment

Choose a reason for hiding this comment

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

Thanks for all this work @soareschen! It's really excellent.

I fixed a couple of minor things (e.g. some error messages during Light Client testing) and I've fixed the merge conflicts with master, so I'm going to go ahead and merge this now. Everything compiles, clippy's happy and all tests pass.

If we encounter any issues we can always fix them in follow-up PRs.

Comment on lines +73 to 77
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::io(e)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This is an example of what I'm talking about in #946.

}
}

impl Clone for Error {
Copy link
Member

Choose a reason for hiding this comment

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

Is this not perhaps something that flex-error should do automatically in the define_error macro?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't use #[derive(Clone)] here because eyre::Report doesn't implement Clone. This is a general problem for deriving on the main error type, because error tracers like eyre::Report do not implement many common traits, not even std::error::Error. So I made flex-error leave that to the user to decide how to deal with the tracer part.

use std::fmt::Display;

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct ResponseError {
Copy link
Member

Choose a reason for hiding this comment

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

Nice refactor! Thanks 🙏

@thanethomson thanethomson merged commit 877e408 into master Aug 7, 2021
@thanethomson thanethomson deleted the soares/flex-error branch August 7, 2021 21:11
@thanethomson thanethomson added this to the Q3 2021 milestone Aug 7, 2021
@hdevalence hdevalence mentioned this pull request Sep 9, 2021
5 tasks
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.

Retiring anomaly
3 participants