Skip to content

doc, refactor(apps/hermes/server): add code guidelines, enable extra clippy lints #2777

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

Merged
merged 2 commits into from
Jun 12, 2025

Conversation

Riateche
Copy link
Contributor

Summary

We want to add better linting throughout our codebase. I also put together this guide to help deal with these new lints.

Rationale

To improve code quality: avoid panics, overflows and other suspicious code patterns.

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

Copy link

vercel bot commented Jun 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 10:17am
component-library ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 10:17am
developer-hub ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 10:17am
entropy-debugger ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 10:17am
entropy-explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 10:17am
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 10:17am
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 10:17am
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 10:17am

Copy link
Collaborator

@ali-behjati ali-behjati left a comment

Choose a reason for hiding this comment

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

Very nice!

Comment on lines +681 to +682
.publish_time()
- i64::try_from(window_seconds).context("window size overflow")?
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we ban unchecked math operations?

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 should do it but I think it's better to do it a bit later because it requires more work to do it properly.

@keyvankhademi keyvankhademi requested a review from Copilot June 11, 2025 16:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors various parts of the Hermes server code to improve linting, enforce stricter error context handling, and update integer types for consistency. Key changes include:

  • Updating error handling by adding context to error messages using anyhow’s Context.
  • Changing cache size types from u64 to usize and modifying related arithmetic.
  • Adding extensive clippy lint configurations in Cargo.toml and updating allow attributes with explicit reasons.

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
apps/hermes/server/src/state/wormhole.rs Enhanced error context for VAA timestamp parsing and address slicing.
apps/hermes/server/src/state/metrics.rs Replaced unwrap with error logging when encoding metrics.
apps/hermes/server/src/state/cache.rs Updated cache size type and simplified while loops.
apps/hermes/server/src/state/benchmarks.rs Added error context during URL construction.
apps/hermes/server/src/state/aggregate/wormhole_merkle.rs Added clippy allow attributes for tests.
apps/hermes/server/src/state/aggregate/metrics.rs Improved error handling in slot clearing with explicit expect.
apps/hermes/server/src/state/aggregate.rs Updated integer conversion and error contexts during message state construction.
apps/hermes/server/src/state.rs Changed parameter type from u64 to usize for cache size.
apps/hermes/server/src/serde.rs Refactored hex deserialization to use strip_prefix for clarity.
apps/hermes/server/src/network/wormhole.rs Enriched allow attributes with explicit reasons for unused code.
apps/hermes/server/src/main.rs Updated shutdown signal and default argument handling with context.
apps/hermes/server/src/config/cache.rs Changed cache size type to usize.
apps/hermes/server/src/config.rs Added explicit reasons to clippy allow attributes.
apps/hermes/server/src/api/types.rs Applied clippy test allow attributes.
apps/hermes/server/src/api/rest/get_vaa_ccip.rs Simplified slicing by storing params.data in a temporary variable.
apps/hermes/server/src/api/rest.rs Added clippy allow attributes to tests.
apps/hermes/server/src/api.rs Allowed deprecated endpoints with explicit rationale.
apps/hermes/server/src/build.rs Added allow for expect usage with the provided rationale.
apps/hermes/server/Cargo.toml Introduced extensive clippy lint configuration.
Comments suppressed due to low confidence (1)

apps/hermes/server/src/state/aggregate.rs:496

  • Using unwrap_or_else to silently convert a retrieval error into an empty vector may hide underlying issues. Consider propagating the error instead of suppressing it to improve error traceability.
.await.unwrap_or_else(|err| {

Copy link
Contributor

@tejasbadadare tejasbadadare left a comment

Choose a reason for hiding this comment

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

thank you!

unsafe_code = "deny"

[lints.clippy]
# See https://www.notion.so/pyth-network/Rust-code-guidelines-20a2eecaaac98060b6b2d9a52c9f9141
Copy link
Contributor

Choose a reason for hiding this comment

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

should we have a link to our private notion in this public repo? maybe you can publish the notion doc as a webpage and link that if you want to include it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added guides directly to the crosschain repo for better visibility.

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.

3 participants