Skip to content

Record donation slices and serve a donation block on the state API #3697

Open

Description

@pithead-developer

What's the problem

Part of #2476. Owner priority (2026-10-27): build the opt-in donation feature now, shipping dark. Nothing records a third destination, and nothing in the API would show one:

  • The only donation series, xvb_history, is written inside the XvB stats sync (dashboard/mining_dashboard/service/data_xvb_sync.py:56-71), which the caller runs only when XvB is enabled (:48). It cannot describe a project slice when XvB is off, and its donation_fraction column means the XvB slice.
  • Hashrate is attributed per poll by the mode label: is_xvb = "XVB" in current_mode (service/data_service.py:508-510), and the chart palette keys on the substrings Split and XVB (web/views/series_views.py:193-200). A project slice's hashrate is therefore counted as P2Pool hashrate; the new record is the only truthful source for "how much went to the project".
  • /api/state carries no donation block, so the settings section, the Earnings line, the chart band and the Activity entries (UI children) have nothing to read.

Add, in new or small files only:

  • A donation_history table: (ts REAL, routed_fraction REAL, mode TEXT, ok INTEGER), created IF NOT EXISTS in service/storage_schema.py beside xvb_history (:209-214), additive with no _migrate_db entry, 30-day retention like XVB_HISTORY_RETENTION_SEC (service/telemetry_store.py:31). Add add_donation_history and get_donation_history to TelemetryStoreMixin (telemetry_store.py:38-85 is the pattern; the mixin is already part of StateManager, and the file is 171 lines). The controller ({{A8}}) writes one row per cycle, independent of ENABLE_XVB.
  • A donation state record (debt in seconds, last slice time, status, endpoint-down-since) stored through the existing get_kv and set_kv (service/storage_service.py:709-736), JSON under one key.
  • A donation block on /api/state: available (from {{A2}}), enabled, percent, status (off, idle, donating, fallback, reduced), recipient, address, route (tor or direct), minutes_today, slice_ends_at (a timestamp while donating, else null), reduced_percent (the effective percentage when status is reduced, else null), endpoint_down_since (null unless in fallback) and estimate (null until {{A11}}); plus a donation_history series through the same range and window helpers as build_xvb_history (series_views.py:179-185). Put the builder in a new module web/views/donation_views.py.
  • web/views/views.py is at its 426-line ceiling and web/server.py at 630, service/storage_service.py at 785. Wire the block into build_state (views.py:380-389) by replacing the stale three-line comment at :380-382 with the two new entries, so the file does not grow.

What it impacts

The state payload gains one block and one series. With the feature unavailable the block is {"available": false} and no row is written. Clients that ignore unknown keys are unaffected. Existing xvb_history consumers and the 5-window history columns are not changed.

How I found it

Read-only scan of origin/develop-v2.1.0 at 02852bd on 2026-10-27 from the paths above. Nothing was executed. Unknown: whether any frontend fixture or contract test enumerates the exact /api/state key set (the dashboard tests/frontend/fixtures/state.json is the first place to check); and whether the chart should attribute project-slice hashrate away from P2Pool in the 5-window history (left out here on purpose; the new series drives the chart band).

How important is it

Medium. Every visible half of the feature reads this; the controller needs somewhere to persist the debt so a restart does not lose it.

Acceptance criteria

  • New tests (dashboard/tests/service/test_storage_donation.py, dashboard/tests/web/views/test_donation_views.py): rows round-trip through add_donation_history and get_donation_history; rows older than 30 days are pruned; a fresh and an existing database both open with the table present and no migration noise (pattern: dashboard/tests/service/test_storage_xvb.py).
  • The state record round-trips through get_kv as JSON and survives a StateManager restart; a corrupt value reads as the default and logs once.
  • The donation block: unavailable constants give {"available": false} and no other key; available and disabled gives status: "off"; the other statuses are produced from the stored record in a table test; the address and recipient come from the constants loader, never from config.
  • donation_history is written when ENABLE_XVB is false.
  • views.py, server.py and storage_service.py do not grow (the file-budget check passes with no ceiling raised).
  • make test, make test-patch-coverage (90 % of changed lines) and make lint-file-budget pass. No new explanatory code comments.

Possible solutions

  • Extend TelemetryStoreMixin (recommended: the sanctioned seam, no new path to the DB handle).
  • A new mixin file added to the StateManager base list (service/storage_service.py:80-82); that file is at its ceiling, so this needs an equal deletion in the same file.
  • Reuse xvb_history with a new column: rejected, because it is only written when XvB is on.

Part of #2476. Depends on {{A1}} and {{A2}}.

Activity

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

    @pithead-developer
    ContributorAuthor

    Blocked on #3695.

    Dependency marker for the dashboard. The native blocked-by links on this issue already name these open blockers, and the tick removes blocked when every one of them closes.

  5. pithead-architect commented on Nov 20, 2026

    @pithead-architect

    Owner ruling, 2026-11-20: "we can dark release it ahead so we can spot issues in logs before making a proper ui for it".

    The backend ships in v2.0.7 and v2.0.8 with no UI, so the logs are the only way to see it working. One acceptance criterion is added to this issue:

    • While the feature is dark, every donation decision is logged at info level with a stable prefix (donation:): slice start and end, the route chosen (tor or direct), fallback to P2Pool, endpoint errors and the cost estimate. These lines appear in the dashboard log and in the support bundle, with addresses redacted by the existing redactors. No UI is required.
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

    blockeddashboardenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions