Skip to content

Remove cross-observer Ord implementation from BiasId #668

Description

@RyanKung

Problem

BiasId represents a DID relative to an observer/bias. In crates/core/src/dht/did.rs, BiasId::cmp converts the right operand to the left operand's bias when biases differ. Reversing the operands then uses a different reference point, so the result can violate the Ord contract.

For a ring of size (M = 2^160), for example:

a = BiasId::new(0, 1)
b = BiasId::new(M / 2, M - 1)

Comparing in a's reference frame yields a < b; comparing in b's reference frame can yield b < a. This makes mixed-bias values unsafe to sort or use in ordered collections.

Proposed direction

Do not provide a total Ord across different observers. Require a common observer at the comparison site, or expose an explicit comparator/ordered wrapper that carries that observer.

Acceptance criteria

  • Mixed-bias values cannot silently be ordered under different reference frames.
  • Same-bias Chord ordering remains available and is covered by tests.
  • Add a regression test demonstrating the former antisymmetry failure.
  • Audit ordered collection and sorting call sites and make their chosen observer explicit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions