-
Notifications
You must be signed in to change notification settings - Fork 302
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| use anyhow::Context; | ||
| use log::warn; | ||
| #[cfg(test)] | ||
| use mock_instant::{SystemTime, UNIX_EPOCH}; | ||
|
|
@@ -164,8 +165,9 @@ pub struct AccumulatorMessages { | |
| } | ||
|
|
||
| impl AccumulatorMessages { | ||
| #[allow(clippy::cast_possible_truncation, reason = "intended truncation")] | ||
| pub fn ring_index(&self) -> u32 { | ||
| (self.slot % self.ring_size as u64) as u32 | ||
| (self.slot % u64::from(self.ring_size)) as u32 | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -492,7 +494,12 @@ where | |
| let state_data = self.into().data.read().await; | ||
| let price_feeds_metadata = PriceFeedMeta::retrieve_price_feeds_metadata(self) | ||
| .await | ||
| .unwrap(); | ||
| .unwrap_or_else(|err| { | ||
| tracing::error!( | ||
| "unexpected failure of PriceFeedMeta::retrieve_price_feeds_metadata(self): {err}" | ||
| ); | ||
| Vec::new() | ||
| }); | ||
|
|
||
| let current_time = SystemTime::now(); | ||
|
|
||
|
|
@@ -529,8 +536,8 @@ where | |
| latest_completed_unix_timestamp: state_data.latest_completed_update_time.and_then( | ||
| |t| { | ||
| t.duration_since(UNIX_EPOCH) | ||
| .map(|d| d.as_secs() as i64) | ||
| .ok() | ||
| .and_then(|d| d.as_secs().try_into().ok()) | ||
| }, | ||
| ), | ||
| price_feeds_metadata_len: price_feeds_metadata.len(), | ||
|
|
@@ -547,7 +554,11 @@ fn build_message_states( | |
| let wormhole_merkle_message_states_proofs = | ||
| construct_message_states_proofs(&accumulator_messages, &wormhole_merkle_state)?; | ||
|
|
||
| let current_time: UnixTimestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() as _; | ||
| let current_time: UnixTimestamp = SystemTime::now() | ||
| .duration_since(UNIX_EPOCH)? | ||
| .as_secs() | ||
| .try_into() | ||
| .context("timestamp overflow")?; | ||
|
|
||
| accumulator_messages | ||
| .raw_messages | ||
|
|
@@ -663,7 +674,12 @@ where | |
| )); | ||
| } else { | ||
| // Use the publish time from the first end message | ||
| end_messages[0].message.publish_time() - window_seconds as i64 | ||
| end_messages | ||
| .first() | ||
| .context("no messages found")? | ||
| .message | ||
| .publish_time() | ||
| - i64::try_from(window_seconds).context("window size overflow")? | ||
|
Comment on lines
+681
to
+682
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we ban unchecked math operations? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| }; | ||
| let start_time = RequestTime::FirstAfter(start_timestamp); | ||
|
|
||
|
|
@@ -807,6 +823,12 @@ fn calculate_twap(start_message: &TwapMessage, end_message: &TwapMessage) -> Res | |
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[allow( | ||
| clippy::unwrap_used, | ||
| clippy::indexing_slicing, | ||
| clippy::cast_possible_wrap, | ||
| reason = "tests" | ||
| )] | ||
| mod test { | ||
| use { | ||
| super::*, | ||
|
|
@@ -892,11 +914,11 @@ mod test { | |
| ) -> PriceFeedMessage { | ||
| PriceFeedMessage { | ||
| feed_id: [seed; 32], | ||
| price: seed as _, | ||
| conf: seed as _, | ||
| price: seed.into(), | ||
| conf: seed.into(), | ||
| exponent: 0, | ||
| ema_conf: seed as _, | ||
| ema_price: seed as _, | ||
| ema_conf: seed.into(), | ||
| ema_price: seed.into(), | ||
| publish_time, | ||
| prev_publish_time, | ||
| } | ||
|
|
@@ -1239,7 +1261,7 @@ mod test { | |
| PriceIdentifier::new([100; 32]), | ||
| PriceIdentifier::new([200; 32]) | ||
| ], | ||
| RequestTime::FirstAfter(slot as i64), | ||
| RequestTime::FirstAfter(slot.into()), | ||
| ) | ||
| .await | ||
| .is_err()); | ||
|
|
@@ -1631,6 +1653,7 @@ mod test { | |
| } | ||
| } | ||
| #[cfg(test)] | ||
| #[allow(clippy::unwrap_used, reason = "tests")] | ||
| /// Unit tests for the core TWAP calculation logic in `calculate_twap` | ||
| mod calculate_twap_unit_tests { | ||
| use super::*; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.