Skip to content

fix(types): deduplicate validator addresses and align Validator Ord with PartialEq - #478

Closed
Yudis-bit wants to merge 1 commit into
circlefin:mainfrom
Yudis-bit:fix/validator-set-dedup-ord
Closed

Yudis-bit wants to merge 1 commit into
circlefin:mainfrom
Yudis-bit:fix/validator-set-dedup-ord

Conversation

@Yudis-bit

Copy link
Copy Markdown

Summary

Align Validator ordering with equality to uphold the standard library Ord contract, and enforce validator address uniqueness during ValidatorSet::sort_validators to prevent phantom voting power from inflating the consensus quorum threshold.

Details

Validator derived PartialEq comparing address, public key, and voting power, but manually implemented Ord comparing solely address. When two entries shared an address but had different voting power, cmp returned Equal while == evaluated to false, violating total order and corrupting sorting routines and standard collection lookups. Deriving PartialOrd and Ord ensures strict consistency across all fields.

In ValidatorSet::sort_validators, entries were sorted by descending voting power before calling vals.dedup(). Because dedup() only eliminates consecutive equal elements, non-adjacent entries for identical addresses remained in the set. Since get_by_address returns only the first match while total_voting_power sums every entry, duplicate entries contributed uncastable voting power to the 2/3 + 1 supermajority denominator. Retaining entries through a HashSet<Address> filter preserves the highest voting power entry for each address in linear time and eliminates duplicates. Additionally, aggregate power overflow is validated during construction in ValidatorSet::new to fail fast.

Testing

Verified with cargo test -p arc-consensus-types --target x86_64-pc-windows-gnu. All 181 unit tests and 31 integration tests passed, including regressions verifying that duplicates are deduplicated to the highest-power entry, Ord aligns with PartialEq, and total power overflow panics at construction.

Ran cargo clippy -p arc-consensus-types -- -D warnings and rustfmt --check crates/types/src/validator_set.rs with clean exits.


Closes: #477

…ith PartialEq

Validator derived PartialEq across address, public key, and voting power, but manually implemented Ord solely by address. This violated the std::cmp::Ord total order invariant when addresses matched but voting power differed.

sort_validators sorted primarily by descending voting power before calling vals.dedup(), leaving non-adjacent duplicate address entries intact. This inflated total_voting_power with uncastable phantom power and compromised the 2/3 + 1 supermajority calculation. Deduplication now filters duplicate addresses via HashSet retention, and aggregate voting power overflow is validated on construction.
Copilot AI balanced review requested due to automatic review settings October 4, 2026 05:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

⚠️ Unsigned Commits Detected

The following commits are missing a verified signature:

  • 6862642 by Yudistira Putra

How to fix: Sign your commits.

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Hi @Yudis-bit,

Thank you for your interest in contributing to Arc Node.

This PR has been automatically closed because you are not assigned to issue #477. We require contributors to be explicitly assigned to an issue before submitting a PR.

To contribute properly:

  1. Comment on issue ValidatorSet::sort_validators fails to deduplicate addresses and Validator violates Ord contract #477 requesting assignment
  2. Wait for maintainer approval
  3. Only submit a PR after you have been assigned

Please see our CONTRIBUTING.md for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValidatorSet::sort_validators fails to deduplicate addresses and Validator violates Ord contract

2 participants