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

Implement verify_light() and verify_light_trusting() #1226

Merged
merged 17 commits into from
Nov 24, 2022

Conversation

hu55a1n1
Copy link
Member

@hu55a1n1 hu55a1n1 commented Nov 10, 2022

Closes: #1222

  • 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/

Copy link
Contributor

@mzabaluev mzabaluev left a comment

Choose a reason for hiding this comment

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

The changes look good so far. It would be nice if the names matched so that the code compiles.
We may also need some more tests for the newly added functionality.

light-client-verifier/src/operations/voting_power.rs Outdated Show resolved Hide resolved
light-client-verifier/src/predicates.rs Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2022

Codecov Report

Merging #1226 (90bdd30) into main (d102af4) will increase coverage by 0.0%.
The diff coverage is 100.0%.

@@          Coverage Diff           @@
##            main   #1226    +/-   ##
======================================
  Coverage   64.2%   64.3%            
======================================
  Files        244     245     +1     
  Lines      21364   21485   +121     
======================================
+ Hits       13734   13821    +87     
- Misses      7630    7664    +34     
Impacted Files Coverage Δ
...ght-client-verifier/src/operations/voting_power.rs 98.0% <ø> (ø)
light-client/src/tests.rs 93.5% <ø> (-0.1%) ⬇️
light-client-verifier/src/verifier.rs 91.0% <100.0%> (+3.1%) ⬆️
abci/src/codec.rs 88.8% <0.0%> (-1.3%) ⬇️
testgen/src/commit.rs 90.6% <0.0%> (-0.7%) ⬇️
testgen/src/header.rs 83.5% <0.0%> (-0.6%) ⬇️
tendermint/src/hash.rs 63.0% <0.0%> (-0.6%) ⬇️
abci/src/server.rs 8.8% <0.0%> (-0.4%) ⬇️
rpc/src/endpoint/tx.rs 25.0% <0.0%> (ø)
tendermint/src/error.rs 0.0% <0.0%> (ø)
... and 9 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@hu55a1n1 hu55a1n1 marked this pull request as ready for review November 15, 2022 18:49
Copy link
Contributor

@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.

This seems good to me, thanks @hu55a1n1! Could you please add a changelog entry for this?

Copy link
Contributor

@mzabaluev mzabaluev left a comment

Choose a reason for hiding this comment

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

Looks good!

Comment on lines 155 to 166
trait IntoResult<T, E> {
fn into_result(self, ok: T) -> Result<T, E>;
}

impl<T> IntoResult<T, Verdict> for Verdict {
fn into_result(self, ok: T) -> Result<T, Verdict> {
match self {
Verdict::Success => Ok(ok),
error => Err(error),
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the purpose of this could look more obvious if this were just a helper function. Then again, method chaining is neat.

Copy link
Contributor

Choose a reason for hiding this comment

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

As an aside, not related to this PR: why did there have to be a non-idiomatic Verdict, rather than a Result<(), VerificationError> where VerificationError would be an enum or otherwise easily matchable to that variant?
Basically, what the existing impl From<Result<(), VerificationError>> for Verdict does could be just how the Result returned value is supposed to be used if you care about the NotEnoughTrust case. Cc @romac

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, let's do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, let's do that.

I didn't mean this to be done in scope for this PR, which so far has not introduced breaking changes, but if you think it would be good and easy thing to do in the next release, I'm all for it.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, let's target this for 0.27.

@hu55a1n1 hu55a1n1 marked this pull request as draft November 18, 2022 19:29
@hu55a1n1
Copy link
Member Author

Thanks, @mzabaluev, @thanethomson and @romac for reviewing this. @ancazamfir pointed out that the misbehaviour handling in IBC used the same logic as the update handling (i.e. ProdVerifier::verify), but it was done in a way that required us to separate the expensive checks from the inexpensive ones and call them alternatively for each header in the misbehaviour evidence/msg. I ended up extracting 4 functions from the verify() method, making them publicly visible and implementing verify() itself using these component methods.

@hu55a1n1 hu55a1n1 requested a review from ancazamfir November 18, 2022 19:47
@hu55a1n1 hu55a1n1 marked this pull request as ready for review November 18, 2022 19:54
Copy link
Contributor

@ancazamfir ancazamfir left a comment

Choose a reason for hiding this comment

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

Thanks @hu55a1n1! Left a few comments but in general it looks good. Could we see cosmos/ibc-rs#215 updates before we merge this?

light-client-verifier/src/verifier.rs Outdated Show resolved Hide resolved
light-client-verifier/src/verifier.rs Outdated Show resolved Hide resolved
light-client-verifier/src/verifier.rs Outdated Show resolved Hide resolved
light-client-verifier/src/verifier.rs Outdated Show resolved Hide resolved
light-client-verifier/src/verifier.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ancazamfir ancazamfir left a comment

Choose a reason for hiding this comment

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

I will approve as it looks great, thanks @hu55a1n1
If you can make the API name in this discussion it's great. I also added two very minor comments.

…hub.com:informalsystems/tendermint-rs into hu55a1n1/1222-impl-verify-commit-light-trusting
@hu55a1n1
Copy link
Member Author

hu55a1n1 commented Nov 24, 2022

If you can make the API name cosmos/ibc-rs#215 (comment) it's great.

Done -> c0f2469

@thanethomson thanethomson merged commit e1468e2 into main Nov 24, 2022
@thanethomson thanethomson deleted the hu55a1n1/1222-impl-verify-commit-light-trusting branch November 24, 2022 21:12
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.

Request for tendermint go like APIs (VerifyCommitLight() and VerifyCommitLightTrusting())
6 participants