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

Msg processors for ICS03 Ack and Confirm messages #228

Merged
merged 8 commits into from
Sep 17, 2020

Conversation

adizere
Copy link
Member

@adizere adizere commented Sep 10, 2020

Closes: #223

ready for review!


For contributor use:

  • Unit tests written
  • Added test to CI if applicable
  • Updated CHANGELOG_PENDING.md
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Updated relevant documentation (docs/) and code comments
  • Re-reviewed Files changed in the Github PR explorer

@codecov-commenter
Copy link

codecov-commenter commented Sep 10, 2020

Codecov Report

Merging #228 into master will increase coverage by 27.1%.
The diff coverage is 59.2%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #228      +/-   ##
=========================================
+ Coverage    13.6%   40.8%   +27.1%     
=========================================
  Files          69      81      +12     
  Lines        3752    5778    +2026     
  Branches     1374    1986     +612     
=========================================
+ Hits          513    2359    +1846     
- Misses       2618    3227     +609     
+ Partials      621     192     -429     
Impacted Files Coverage Δ
modules/src/events.rs 0.0% <ø> (ø)
modules/src/ics02_client/events.rs 0.0% <ø> (ø)
modules/src/ics02_client/raw.rs 0.0% <0.0%> (ø)
modules/src/ics03_connection/error.rs 9.3% <0.0%> (-24.0%) ⬇️
modules/src/ics04_channel/error.rs 23.0% <0.0%> (-2.0%) ⬇️
modules/src/ics04_channel/packet.rs 0.0% <0.0%> (ø)
modules/src/ics07_tendermint/client_def.rs 0.0% <0.0%> (ø)
modules/src/ics07_tendermint/error.rs 33.3% <0.0%> (+33.3%) ⬆️
modules/src/ics07_tendermint/msgs/update_client.rs 0.0% <0.0%> (ø)
modules/src/mock_client/header.rs 0.0% <0.0%> (ø)
... and 136 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 16ba954...546e4ee. Read the comment docs.

@adizere adizere marked this pull request as ready for review September 10, 2020 16:55
Comment on lines 168 to +178
if claimed_height > ctx.chain_current_height() {
return Err(Kind::InvalidConsensusHeight
.context(claimed_height.to_string())
.into());
}

// Fail if the consensus height is too old (outside of trusting period).
if claimed_height.value()
// Fail if the consensus height is too advanced.
Err(Kind::InvalidConsensusHeight(claimed_height).into())
} else if claimed_height.value()
< (ctx.chain_current_height().value() - ctx.chain_consensus_states_history_size() as u64)
{
return Err(Kind::StaleConsensusHeight
.context(claimed_height.to_string())
.into());
// Fail if the consensus height is too old (outside of trusting period).
Err(Kind::StaleConsensusHeight(claimed_height).into())
} else {
// Height check is within normal bounds, check passes.
Ok(())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious on the Rust idiomatic way for this. In other languages this is frowned upon:

if <expr1> {
    return <err1>
} else if <expr2> {
    return <err2>
...
} else  {
    return <err99>
}

And instead:

if <expr1> {
    return <err1>
}
if <expr2> {
    return <err2>
}
...
return <err99>

I also prefer the latter.

Copy link
Member

Choose a reason for hiding this comment

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

I would say that in Rust the former is more idiomatic since in Rust if statements are expressions of their own, but both are fine by me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

But if this were happening in the middle of the function (for eg. an early return with explicit return statements, then yeah I would also prefer the latter.

Copy link
Collaborator

Choose a reason for hiding this comment

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

https://doc.rust-lang.org/rust-by-example/flow_control/if_else.html but I have no preference.

yes but there is no return in the if arms

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am asking because it is very typical that we start a function body with a number of checks where we return errors if they fail. If we have a lot of checks we end up with a long if-then-elseif-... and I find that harder to read.

Copy link
Collaborator

Choose a reason for hiding this comment

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

More importantly though I would like to have consistency in our code base. So I will follow whatever we decide :)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah for such checks I agree that the version with return is better.

Copy link
Collaborator

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

Looks good! Thanks Adi!

@adizere adizere merged commit d0f8aa1 into master Sep 17, 2020
@adizere adizere deleted the adi/ics03_processors branch September 17, 2020 15:41
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.

ICS03 Ack and Confirm message processors
4 participants