Skip to content

maker.mixdepth_selection

maker.mixdepth_selection

Source mixdepth candidate ordering for maker CoinJoins.

Classes

MixdepthSelectionPolicy

Bases: StrEnum

Policies for choosing a source mixdepth among eligible balances.

Source code in maker/src/maker/mixdepth_selection.py
 9
10
11
12
13
class MixdepthSelectionPolicy(StrEnum):
    """Policies for choosing a source mixdepth among eligible balances."""

    BALANCED = "balanced"
    CONCENTRATED = "concentrated"
Attributes
BALANCED = 'balanced' class-attribute instance-attribute
CONCENTRATED = 'concentrated' class-attribute instance-attribute

Functions:

mixdepth_attempt_order(eligible_mixdepths: Mapping[int, int], mixdepth_count: int, policy: MixdepthSelectionPolicy) -> list[int]

Return eligible source mixdepths in the order they should be attempted.

concentrated follows the legacy yg-privacyenhanced cyclic-gap selector. After each choice, it removes that depth and recomputes the next gap so reservation conflicts retain the same policy semantics.

Source code in maker/src/maker/mixdepth_selection.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def mixdepth_attempt_order(
    eligible_mixdepths: Mapping[int, int],
    mixdepth_count: int,
    policy: MixdepthSelectionPolicy,
) -> list[int]:
    """Return eligible source mixdepths in the order they should be attempted.

    ``concentrated`` follows the legacy yg-privacyenhanced cyclic-gap selector.
    After each choice, it removes that depth and recomputes the next gap so
    reservation conflicts retain the same policy semantics.
    """
    _validate_inputs(eligible_mixdepths, mixdepth_count, policy)

    if policy is MixdepthSelectionPolicy.BALANCED:
        return sorted(
            eligible_mixdepths,
            key=lambda mixdepth: (-eligible_mixdepths[mixdepth], mixdepth),
        )

    remaining = set(eligible_mixdepths)
    candidates: list[int] = []
    while remaining:
        candidate = _select_largest_cyclic_gap_end(remaining, mixdepth_count)
        candidates.append(candidate)
        remaining.remove(candidate)
    return candidates