Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Fix PartialOrd implementation for prune candidate #2463

Conversation

suchapalaver
Copy link
Contributor

@suchapalaver suchapalaver commented Oct 12, 2023

In the previous code, the line Some(Ordering::reverse(self.0.cmp(&other.0))) was incorrect because it would return the opposite of what you intended, potentially leading to incorrect ordering of elements.

Signed-off-by: Joseph Livesey jlivesey@gmail.com

@vaporos
Copy link
Contributor

vaporos commented Oct 25, 2023

Can you elaborate in the commit message on the reasoning on why this is correct vs. the previous code?

@suchapalaver suchapalaver force-pushed the fix/partial-ord-implementation-for-prune-candidate branch from e44e4db to 6a5827b Compare October 25, 2023 21:44
@suchapalaver
Copy link
Contributor Author

Can you elaborate in the commit message on the reasoning on why this is correct vs. the previous code?

@vaporos, thanks. I've updated the commit message to read:

Fix 'PruneCandidate' 'PartialOrd' impl to return result of 'self.cmp(other)', not its reverse

@suchapalaver suchapalaver force-pushed the fix/partial-ord-implementation-for-prune-candidate branch from 6a5827b to 2ff4ca2 Compare October 25, 2023 21:48
@peterschwarz
Copy link
Contributor

Can you elaborate in the commit message on the reasoning on why this is correct vs. the previous code?

@vaporos, thanks. I've updated the commit message to read:

Fix 'PruneCandidate' 'PartialOrd' impl to return result of 'self.cmp(other)', not its reverse

I would still think of that comment as the “what” and not the “why”

@suchapalaver
Copy link
Contributor Author

suchapalaver commented Oct 25, 2023

Can you elaborate in the commit message on the reasoning on why this is correct vs. the previous code?

@vaporos, thanks. I've updated the commit message to read:

Fix 'PruneCandidate' 'PartialOrd' impl to return result of 'self.cmp(other)', not its reverse

I would still think of that comment as the “what” and not the “why”

Any suggestions? I think for people working in Rust it's clear why the "what" is correcting something wrong. You have a custom implementation of Ord. So you don't want your implementation of PartialOrd to reverse that.

@suchapalaver suchapalaver force-pushed the fix/partial-ord-implementation-for-prune-candidate branch 2 times, most recently from d4c1ae4 to 7a1647a Compare October 26, 2023 14:26
@suchapalaver
Copy link
Contributor Author

suchapalaver commented Oct 26, 2023

This, btw,fixes the build issues on PR 2458.

The previous implementation used 'Ordering::reverse' incorrectly, potentially leading to incorrect element ordering. The corrected code now properly returns the result of 'self.cmp(other)', aligning with the 'PartialOrd' trait's requirements for element comparisons.

Signed-off-by: Joseph Livesey <jlivesey@gmail.com>
@suchapalaver suchapalaver force-pushed the fix/partial-ord-implementation-for-prune-candidate branch from 7a1647a to 24714b7 Compare November 1, 2023 20:13
@vaporos vaporos merged commit 4f6994e into hyperledger-archives:1-3 Nov 20, 2023
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants