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

Abstract components to query connection end #167

Merged
merged 7 commits into from
Feb 15, 2024

Conversation

ljoss17
Copy link
Contributor

@ljoss17 ljoss17 commented Feb 14, 2024

Closes: #153

Description


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests: integration (for Hermes) or unit/mock tests (for modules).
  • 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).

async fn query_connection_end(
chain: &Chain,
connection_id: &Chain::ConnectionId,
height: Option<&Chain::Height>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's always require a height, and have the caller retrieve the latest height via CanQueryChainHeight if necessary.

IMO making the height optional complicates the implementation without much benefit.

Copy link
Member

@romac romac Feb 15, 2024

Choose a reason for hiding this comment

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

Isn't this the simplest way to get the connection end at the latest height without incurring another redundant query at the call site when the user is only interested in the latest height?

I would vote for either keeping the optional height parameter or define our own enum QueryHeight<Height> { Latest, Specific(Height) } type and take a QueryHeight<Chain::Height> as an argument.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The chain height can easily be cached every few hundred milliseconds, so that the query do not become costly.

If we really want to make it optional, perhaps we can add an abstract HeightParam as follows:

pub trait HasHeightParamType: HasHeightType {
    type HeightParam: Async + From<Self::Height>;
}

We would also add WithLatestHeight variants of the trait, and allow implementations to choose different strategies to handle the latest height parameter. For example:

impl<Chain> ClientStateWithLatestHeightQuerier<Chain>
    for QueryLatestClientStateWithDefaultHeightParam
where
    Chain::HeightParam: Default,

and

impl<Chain> ClientStateWithLatestHeightQuerier<Chain>
    for QueryLatestHeightAndClientState
where
    Chain: CanQueryChainHeight,

Anyway, it is not too important for the current case of querying connection end, as it is only used once in the CLI. Let's keep this for now, and continue our discussion somewhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened #172

let query_height = if let Some(height) = height {
let specified_height = Height::new(chain_handle.id().version(), height)
.map_err(|e| RelayerError::generic(eyre!("Failed to create Height with revision number `{}` and revision height `{height}`. Error: {e}", chain_handle.id().version())))?;
let height = self.height.map(|h| Height::new(chain.chain_id().version(), h).map_err(|e| RelayerError::generic(eyre!("Failed to create Height with revision number `{}` and revision height `{h}`. Error: {e}", chain.chain_id().version()))).unwrap());
Copy link
Member

Choose a reason for hiding this comment

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

There's something weird going on with the formatting here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I've had odd behaviour with cargo fmt and the CI doesn't seem to complain either. I don't know what's going on

Copy link
Member

Choose a reason for hiding this comment

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

As last resort you can mark the block with #[rustfmt::skip] and format it manually.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a .map_err() followed by an .unwrap(), which doesn't really make sense. And if you want to do map_err(), perhaps it is better to do it right after Height::new().

Copy link
Contributor Author

@ljoss17 ljoss17 Feb 15, 2024

Choose a reason for hiding this comment

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

As last resort you can mark the block with #[rustfmt::skip] and format it manually.

The lines inside the .map don't seem to be impacted by cargo fmt, I can format it manually without disabling rustfmt

There is a .map_err() followed by an .unwrap(), which doesn't really make sense. And if you want to do map_err(), perhaps it is better to do it right after Height::new().

Oh good catch. I will update this using transpose() and ? instead of the unwrap, see a1878ee

@ljoss17 ljoss17 mentioned this pull request Feb 15, 2024
5 tasks
@soareschen soareschen merged commit 7b3720c into main Feb 15, 2024
10 checks passed
@soareschen soareschen deleted the luca_joss/abstract-query-connection-end branch February 15, 2024 13:05
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.

Abstract query connection end CLI
3 participants