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

Organize host chain methods under a new HostChainContext trait #386

Closed
wants to merge 8 commits into from

Conversation

Farhad-Shabani
Copy link
Member

@Farhad-Shabani Farhad-Shabani commented Jan 27, 2023

Closes: #384 , #418


Description

Following the discussion around client state validation methods that check parameters (fields) of the client state implementation. After a bit of thought, I came up with an idea (around validate_self_client) of combining all host-related methods under a single chain called "HostChainContext" and separating related host errors under the "HostError" enum, plus added some docstrings.
These methods do not have chain-specific arguments and returns, so ideally, any chain should be able to provide them.
There just remains one small cavity. Having the "unbonding_period" method in it, which looks more of Tendermint chains. Couldn't find a better way at the moment, and I addressed it by changing the return type into the Option<Duration>

Note: The change in this PR is also connected to #418. That should have been handled here, hopefully.


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests.
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

@Farhad-Shabani Farhad-Shabani self-assigned this Jan 27, 2023
@Farhad-Shabani Farhad-Shabani changed the title Expose validate method for client state interface Expose validate method on client state interface Jan 27, 2023
@codecov
Copy link

codecov bot commented Jan 27, 2023

Codecov Report

Base: 55.63% // Head: 55.94% // Increases project coverage by +0.31% 🎉

Coverage data is based on head (037e069) compared to base (649e7bd).
Patch coverage: 12.93% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #386      +/-   ##
==========================================
+ Coverage   55.63%   55.94%   +0.31%     
==========================================
  Files         122      122              
  Lines       16996    17103     +107     
==========================================
+ Hits         9455     9568     +113     
+ Misses       7541     7535       -6     
Impacted Files Coverage Δ
...s/ibc/src/clients/ics07_tendermint/host_helpers.rs 0.00% <0.00%> (ø)
crates/ibc/src/core/context.rs 3.91% <0.00%> (+0.02%) ⬆️
crates/ibc/src/core/ics02_client/error.rs 4.76% <ø> (ø)
crates/ibc/src/core/ics03_connection/error.rs 7.69% <ø> (ø)
crates/ibc/src/core/ics04_channel/context.rs 81.41% <ø> (+2.62%) ⬆️
crates/ibc/src/core/ics24_host/error.rs 0.00% <0.00%> (ø)
crates/ibc/src/mock/context.rs 61.85% <53.57%> (-0.11%) ⬇️
crates/ibc/src/test_utils.rs 53.72% <0.00%> (-0.45%) ⬇️
...bc/src/core/ics02_client/handler/upgrade_client.rs 63.74% <0.00%> (-0.44%) ⬇️
...ibc/src/core/ics02_client/handler/update_client.rs 38.46% <0.00%> (-0.21%) ⬇️
... and 25 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Farhad-Shabani Farhad-Shabani changed the title Expose validate method on client state interface Organize host chain methods under a new HostChainContext trait Feb 14, 2023
@Farhad-Shabani Farhad-Shabani marked this pull request as ready for review February 14, 2023 14:49
@plafer
Copy link
Contributor

plafer commented Feb 14, 2023

I came up with an idea (around validate_self_client) of combining all host-related methods under a single chain called "HostChainContext"

ValidationContext and ExecutionContext are all the host-related methods; in the previous API, Client/Connection/Channel{Keeper,Reader} contained the host methods. What criterion did you use to determine whether a method should be moved to the HostChainContext? For example, isn't consensus_state() a host method too? Or connection_end()? Or any other method?

These methods do not have chain-specific arguments and returns, so ideally, any chain should be able to provide them.

What do you mean by "chain-specific arguments and returns"? As designed, ValidationContext & ExecutionContext are implementable by any chain. To better understand where you're coming from, could you give an example of a method in ValidationContext/ExecutionContext that a hypothetical chain would not be able to implement?

counterparty_client_state: Any,
) -> Result<(), HostError>
where
Ctx: HostChainContext,
Copy link
Contributor

Choose a reason for hiding this comment

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

ValidateSelfClientContext is designed to ask for an implementation of all the methods that it needs in its implementation; some only implementable by Tendermint hosts (such as unbonding_period()). I believe this is the root cause for why you had to change the signature to Option<Duration>; not all hosts can implement it.

This is why I don't think it is appropriate for ValidationContext to have HostChainContext as a supertrait. Hypothetically, say we also provided the implementation of validate_self_client() for NEAR hosts; would we need to have that Context be a supertrait of ValidationContext as well, requiring all hosts to implement NEAR-specific methods (and have the signature return an Option for those too)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I understand your concern, but rather than the unbonding_period() method, which I also found it there to be a wart, other methods should be available by any chain

Comment on lines +130 to +132
let host_height = self.host_height()?;
let host_consensus_state = self.host_consensus_state(&host_height)?;
Ok(host_consensus_state.timestamp())
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we can assume that this will work for all hosts. Basecoin-rs is an example: we added pending_host_consensus_state() because host_consensus_state() was not quite right. I think it should simply be made abstract; each host can implement it however they see fit. We should do it in a separate PR though to keep PRs as self-contained as possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, moving the host_timestamp() methods brought a need to handle them here. but, sure alright.

Copy link
Contributor

Choose a reason for hiding this comment

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

what do you mean by "moving the host_timestamp() methods brought a need to handle them here"?

@Farhad-Shabani
Copy link
Member Author

ValidationContext and ExecutionContext are all the host-related methods; in the previous API, Client/Connection/Channel{Keeper,Reader} contained the host methods. What criterion did you use to determine whether a method should be moved to the HostChainContext? For example, isn't consensus_state() a host method too? Or connection_end()? Or any other method?

For a clearer picture of where it's instantiated, consider the below grouping:

  • Group 1: Methods that retrieve state from the consensus engine (or we shall say from non-module parts) and validate a state against them
  • Group 2: Methods that call the value of a state from paths (module-related parts) and validate them
  • Group 3: Methods that set a new state by storing in the paths (module-related parts)

@Farhad-Shabani
Copy link
Member Author

The idea had the aim of demonstrating how it could make implementation smoother, but looking at your comment, if it's not going to make it easier for us, then it wouldn't work for that purpose.

@plafer
Copy link
Contributor

plafer commented Feb 15, 2023

Closing as discussed in sync meeting.

@plafer plafer closed this Feb 15, 2023
@Farhad-Shabani Farhad-Shabani deleted the farhad/separate-validate-from-new branch February 21, 2023 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Extract validation step inside new client state creation and expose it as a separate method
2 participants