Skip to content

Add a pure planner that carves the project slice out of the P2Pool remainder #3696

Closed

Description

@pithead-developer

What's the problem

Part of #2476. Owner priority (2026-10-27): build the opt-in donation feature now, shipping dark. The switching controller thinks in one cycle of two destinations: an XvB slice, then a P2Pool remainder (dashboard/mining_dashboard/service/xvb/algo_service.py:543-554), inside a 600 s cycle (config/config.py:144) with a 15 s minimum dwell (:147) and 5 s switch overhead (:608). A project slice of 1 % of the cycle is 6 s, shorter than the dwell, so a plain percentage cannot be used. There is also no rule for how a third slice interacts with the XvB tier: the project slice must come out of the P2Pool remainder, never out of the XvB slice, and must yield first to the reserve that keeps P2Pool finding shares (service/xvb/steering_projection.py:35-53).

Add a pure function, with no I/O, in a new package dashboard/mining_dashboard/service/donation/ (__init__.py, planner.py):

plan_cycle(xvb_ms, debt_ms, percent, max_fraction, *, cycle_ms=XVB_TIME_ALGO_MS, min_slice_ms=60000, min_dwell_ms=XVB_MIN_TIME_SEND_MS, overhead_ms=XVB_SWITCH_OVERHEAD_MS) returning the ordered segments [("xvb", ms), ("p2pool", ms), ("project", ms)] and the new debt.

  • Each cycle credits percent / 100 * cycle_ms to the debt. A project slice is spent only when the debt reaches min_slice_ms (60 s is a suggestion, owner decision), and carried debt is capped at 3 cycles.
  • The slice is taken from the P2Pool remainder. If xvb_ms plus the slice would exceed cycle_ms * max_fraction, the project slice is trimmed and the unspent debt carries over (subject to the cap). A full-cycle XvB decision leaves no remainder, so the slice is 0 and the debt keeps accruing.
  • Every returned segment is at least min_dwell_ms; a P2Pool remainder under 30 s is merged into a neighbour as algo_service.py:222-225 does. Segment lengths sum to cycle_ms.
  • Long-run share converges on percent: 1, 2 and 5 percent give about 14.4, 28.8 and 72 minutes a day.

Add the simulation to a new file, dashboard/mining_dashboard/sim/project_slice_model.py. The existing sim/donation_model.py is at its 539-line ceiling in docs/dev/file-budget.tsv, so it must not be edited.

What it impacts

Only the new modules and tests. No behavior changes until the controller child ({{A8}}) calls the planner. It fixes the contract the controller, the store and the fake-clock tests build on.

How I found it

Read-only scan of origin/develop-v2.1.0 at 02852bd on 2026-10-27 from the paths above and the existing simulator (dashboard/mining_dashboard/sim/donation_model.py, property-test pattern in dashboard/tests/sim/test_donation_model_properties.py:10-46). Nothing was executed. Unknown: the right debt cap and minimum slice for good share behaviour (both are parameters, so changing them is a one-line change), and whether a 60 s slice is long enough for a fresh upstream connection to submit a share (a bench question for the e2e child).

How important is it

Medium. It isolates the hardest logic in a testable module before the run loop is touched, and is small enough for one session.

Acceptance criteria

  • plan_cycle is pure: same inputs give the same outputs, no clock, no environment, no logging side effects.
  • New dashboard/tests/service/donation/test_planner.py (examples) and test_planner_properties.py (hypothesis, pattern test_donation_model_properties.py:10-46) assert, over random xvb_ms, percent 1 to 10, max_fraction 0 to 0.85, and starting debt:
    • segment lengths sum to cycle_ms, and no segment is longer than 0 and shorter than min_dwell_ms;
    • the XvB segment equals the input xvb_ms exactly (the project slice never reduces it);
    • xvb_ms plus the project segment never exceeds cycle_ms * max_fraction unless xvb_ms alone does;
    • the debt stays between 0 and 3 cycles;
    • over 144 cycles with room to spare, the project share is within 5 % (relative) of percent;
    • a full-cycle XvB decision yields no project segment and a larger debt.
  • A table test for 1, 2 and 5 percent states the minutes per day the planner delivers over 144 cycles.
  • sim/project_slice_model.py runs the planner for N cycles with an XvB schedule and reports the donated share and the number of switches per hour; one test uses it.
  • algo_service.py is not touched. make test, make test-patch-coverage (90 % of changed lines) and make lint-file-budget pass. No new explanatory code comments.

Possible solutions

  • A debt accumulator as described (recommended): exact long-run share, bounded switching.
  • Probabilistic slicing (spend the slice with probability percent): simpler, but variance is high and the share is only right on average.
  • A fixed longer cycle for the project slice only: breaks the shared 10-minute cadence the XvB controller assumes.

Part of #2476.

Activity

  1. added this to the v2.1.0 milestone on Oct 27, 2026
  2. added
    enhancement
    dashboard
    on Oct 27, 2026
  3. pithead-developer commented on Oct 27, 2026

    @pithead-developer
    ContributorAuthor

    Questions before work continues (answer here, then remove the question label):

    1. May the planner reject XvB durations that conflict with exact preservation and minimum dwell/tail rules? Default: accept 0, a full cycle, or durations from min_dwell_ms through cycle_ms minus 30 seconds; reject other durations because their constraints cannot all hold?
    2. Should 60 seconds be the default debt threshold, allowing reserve-trimmed project slices below 60 seconds when they still meet minimum dwell? Default: yes, deferring smaller slices and preserving unspent debt to respect the reserve?
    3. Should donation percentage and debt measure routed wall time or effective mining time after switch overhead? Default: routed wall time, including overhead within segment durations, because the acceptance criteria specify segment-time shares and an unchanged cycle length?
  4. added
    question
    on Oct 27, 2026
  5. pithead-architect commented on Oct 27, 2026

    @pithead-architect

    Escalated to the human operator; the ruling lands in the runner's private question file and the worker resumes from it.

  6. removed
    question
    on Oct 27, 2026
  7. pithead-developer commented on Oct 27, 2026

    @pithead-developer
    ContributorAuthor

    Owner, 2026-10-27: shares as low as 0.1 percent are offered. At 0.1 percent the debt takes about 17 hours to reach the 60-second trigger. Unspent debt must therefore persist across restarts and config reloads (keep it with the slice ledger, #3697), or the delivered share falls short. Add a test that 0.1 percent over a simulated week delivers 0.1 percent within one slice.

  8. pithead-developer commented on Oct 30, 2026

    @pithead-developer
    ContributorAuthor

    Merged in #3732.

  9. added a commit that references this issue on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dashboardenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions