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

preliminaries for bumping nightly to 2023-08-25 #33047

Merged
merged 16 commits into from
Aug 29, 2023
Merged

Conversation

t-nelson
Copy link
Contributor

Problem

four months worth of nightly lints

Summary of Changes

fix them shits

@@ -192,7 +192,7 @@ impl PartialEq for HeaviestSubtreeForkChoice {
impl PartialOrd for HeaviestSubtreeForkChoice {
// Sort by root
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.tree_root.partial_cmp(&other.tree_root)
Some(self.tree_root.cmp(&other.tree_root))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@ilya-bobyr ilya-bobyr Aug 29, 2023

Choose a reason for hiding this comment

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

Considering, Ord is implemented for HeaviestSubtreeForkChoice, this can also be

Suggested change
Some(self.tree_root.cmp(&other.tree_root))
Some(self.cmp(other))

It is actually what the standard library documentation suggests: https://doc.rust-lang.org/nightly/std/cmp/trait.PartialOrd.html#how-can-i-implement-partialord

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but comparing the other fields would change semantics, which i'm not trying to do here

Copy link
Contributor

Choose a reason for hiding this comment

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

PartialOrd and Ord implementations must be consistent.
It is part of the trait description:

If Ord is also implemented for Self and Rhs, it must also be consistent with partial_cmp (see the documentation of that trait for the exact requirements).

From https://doc.rust-lang.org/nightly/std/cmp/trait.PartialOrd.html

So, it is actually better to define one in terms of another. Reducing the chance they diverge.
Currently, they are consistent:

#[cfg(test)]
impl Ord for HeaviestSubtreeForkChoice {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.tree_root.cmp(&other.tree_root)
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that's an ashwin question. don't want to break consensus for the sake of following someone else's rules 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

Either approach is fine, they both only compare tree roots. Furthermore this impl is only used for tests, we never compare HeaviestSubtreeForkChoice in consensus.

ilya-bobyr
ilya-bobyr previously approved these changes Aug 29, 2023
Copy link
Contributor

@ilya-bobyr ilya-bobyr left a comment

Choose a reason for hiding this comment

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

Clippy is really good at finding all these redundancies and unnecessary complications!

@@ -192,7 +192,7 @@ impl PartialEq for HeaviestSubtreeForkChoice {
impl PartialOrd for HeaviestSubtreeForkChoice {
// Sort by root
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.tree_root.partial_cmp(&other.tree_root)
Some(self.tree_root.cmp(&other.tree_root))
Copy link
Contributor

@ilya-bobyr ilya-bobyr Aug 29, 2023

Choose a reason for hiding this comment

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

Considering, Ord is implemented for HeaviestSubtreeForkChoice, this can also be

Suggested change
Some(self.tree_root.cmp(&other.tree_root))
Some(self.cmp(other))

It is actually what the standard library documentation suggests: https://doc.rust-lang.org/nightly/std/cmp/trait.PartialOrd.html#how-can-i-implement-partialord

@t-nelson
Copy link
Contributor Author

Clippy is really good at finding all these redundancies and unnecessary complications!

can't wait to not have to nag about some of these thing in review! 😅

@t-nelson t-nelson added the automerge Merge this Pull Request automatically once CI passes label Aug 29, 2023
@mergify mergify bot merged commit b8dc5da into solana-labs:master Aug 29, 2023
16 checks passed
Copy link
Contributor

@AshwinSekar AshwinSekar 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, i checked the following:

immutable_deseriaized_packet.rs
unprocessed_transaction_storage.rs
cluster_info_vote_listener.rs
commitment_service.rs
consensus.rs
heaviest_subtree_fork_choice.rs
latest_validator_votes_for_frozen_banks.rs
optimistic_confirmation_verifier.rs
cluster_slot_state_verifier.rs
replay_stage.rs
verified_vote_packets.rs

@@ -192,7 +192,7 @@ impl PartialEq for HeaviestSubtreeForkChoice {
impl PartialOrd for HeaviestSubtreeForkChoice {
// Sort by root
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.tree_root.partial_cmp(&other.tree_root)
Some(self.tree_root.cmp(&other.tree_root))
Copy link
Contributor

Choose a reason for hiding this comment

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

Either approach is fine, they both only compare tree roots. Furthermore this impl is only used for tests, we never compare HeaviestSubtreeForkChoice in consensus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this Pull Request automatically once CI passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants