Skip to content

fix: keep DRep vote percentages when the SPO stake total is missing - #4322

Merged
kusssal merged 18 commits into
developfrom
fix/4321-drep-vote-percentages
Dec 4, 2026
Merged

kusssal merged 18 commits into
developfrom
fix/4321-drep-vote-percentages

Conversation

@kusssal

@kusssal kusssal commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

List of changes

  • Fix the db-sync and Koios providers dropping the SPO stake total when one pool has no voting power. db-sync leaves voting_power NULL for a pool outside the SPO voting distribution, such as one that retired during the epoch (mainnet epoch 671 has one), and Koios mirrors it. Both now count it as 0.
  • Fix /network/total-stake failing with 501 when one figure is missing: each missing figure is now null, so the DRep figures still arrive (D179).
  • Fix the live-action votes panel computing from missing totals. With no DRep, SPO or committee total it shows the amounts and says why the percentages are not available (the totals could not be loaded, or the DRep total is no larger than the abstaining stake), and says nothing while they load, instead of negative shares, a negative "not voted" at 100% or a 0% threshold. The committee block is gated on dashboard.metrics, and the totals and metrics load in parallel. The DRep abstain figure shows "—" when the always-abstain stake is unknown.
  • Fix /ada-holder/get-voting-power answering 0 for any failure. It answers 0 only for an account with no record, 503 for a failed read and 501 for a provider without account voting power (the fixture). The frontend shows an unread or missing voting power as "₳ —" on the dashboard, its voting power chip, the DRep directory and cards and a DRep's page, and none of them wait for it forever; DrepDataDTO.votingPower is number | null. /drep/voting-power-list answers null rather than 0 for a predefined option without a figure.
  • Fix lists and pages that showed a failed read as "nothing exists" ("You haven't voted", "No results", "No DReps found", "No governance actions found", an action that "does not exist") and the DRep directory's endless loader. They now say the data could not be loaded.
  • Fix the DRep directory's Abstain and No Confidence options, which were blank, and the Storybook play test that asserted the old figures.
  • Fix /drep/get-voting-power and /drep/voting-power-list answering 0 for a DRep with no figure in the newest snapshot: they answer null, and the chip, the directory card and the DRep page show "—".
  • Fix deposits the backend does not know showing as 0 ada in the registration, create-action, insufficient-balance and retirement texts.
  • Fix /network/metrics reporting counters it does not have as 0: they are null.
  • Stop retrying a 501, and stop the dashboard and DRep directory waiting forever when the delegation or voter info read fails.

Checked on preview db-sync: epochs 1385 and 1327 each have one NULL row; the providers now return the exact voting_power sum, and /misc/network/metrics answers 200 for them instead of 501.

Checklist

  • related issue
  • My changes generate no new warnings
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the changelog
  • I have added tests that prove my fix is effective or that my feature works

@mesudip mesudip left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lets also review other places so that when backend returns 501, frontend doesn't collapses it to 0 or null

@mesudip mesudip left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Following up on my earlier request with specifics. The provider change looks right to me: a NULL pool_stat.voting_power counts as 0, and the SPO total is omitted only when no pool has one (Koios reads every page). The per-figure null on /network/total-stake and the guard on the DRep denominator also look right. Checks pass: provider-dbsync (154 tests), provider-koios (100), backend verify (464), and the frontend's tsc, lint and vitest. What's left is the same class of bug in the file this PR touches, and two comments.

Must fix

  1. The DRep Abstain row still turns a missing figure into 0.

    • src/components/molecules/VotesSubmitted.tsx:111-112 does dRepAbstainVotes + (networkTotalStake?.alwaysAbstainVotingPower ?? 0).
    • This PR makes alwaysAbstainVotingPower nullable. When it is null, or still loading, the row shows only the action's own abstain stake, with no sign it is partial.
    • D153's convention adds the DRep always-abstain stake to the DRep abstain, and D179 says "null, never 0". Show the abstain figure as unavailable, or mark it as partial, when the figure is null.
  2. Comments contradict this PR's provider change. src/network/network.service.ts:120-121 and test/legacy-shape.spec.ts:349-350 say db-sync and Koios leave the SPO total out "until every pool's voting power for the epoch is recorded". That is the rule this PR removes.

  3. D179's note "(D178 is taken by the open delegation-history pull request.)" should go. D148 says an entry never points elsewhere. #4318 also adds a D178, so the reservation doesn't hold anyway; renumber at merge instead.

Same file, older, same class of bug

  1. The committee block shows a negative "Not voted" and a 0% threshold.
    • noOfCommitteeMembers falls back to ?? 0 (VotesSubmitted.tsx:91), and the threshold falls back to 0 (:92-96).
    • /network/metrics is fetched only after /network/total-stake (enabled: false, sequential awaits). So while it loads, or if it fails, "Not voted" = 0 − yes − no − abstain (:168), which is negative, and the threshold reads 0%.
    • The gate that should hide the block, isFeatureAvailable("dashboard.committeeThreshold"), never fires: that id isn't in the FeatureId union, and isAvailable treats unknown ids as available.

Other places that show ₳ 0 for a missing figure (a follow-up issue is fine)

  1. The formatters return "0" for missing values.
    • correctVoteAdaFormat and correctDRepDirectoryFormat (src/utils/adaFormat.ts) return "0" for null or undefined, and every caller shows it as "₳ 0": DRepCard.tsx:310, DRepDetailsCard.tsx:198, DRepDetailsCardHeader.tsx:71, VotingPowerChips.tsx:71, StakeRadio.tsx:91, DelegateDashboardCard.tsx:88, DirectVoterDashboardCard.tsx:27.
    • The DRep row's voting power is ApiInteger | null in the backend but votingPower?: number in the frontend's DrepDataDTO, so the compiler can't flag these.
    • The backend's /ada-holder/get-voting-power deliberately answers 0 on any failure, a 501 and a database outage included (AdaHolderService.getVotingPower). That needs an error path in the frontend before it can change.

Minor

  1. The "Percentages are not available: the total stake could not be loaded." note is misleading in two cases. It also shows while the request is still loading, and when the total did load but isn't above the abstain stake.

  2. Conflict with #4316. #4316 rewrites VotesSubmitted's render (VotesGroup), models/api.ts and en.json. Whichever lands second has to carry sharesUnavailable and the nullable types across.

@mesudip mesudip mentioned this pull request Dec 2, 2026
5 tasks done
@kusssal

kusssal commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Some of this was already fixed by the commits pushed just before your follow-up (it still quotes the committee size's ?? 0, /ada-holder/get-voting-power answering 0 and backend verify at 464), so here is where each point stands on the new head, ebbb7d0:

  1. DRep Abstain row: fixed in 4a9dce6. With alwaysAbstainVotingPower null or still loading, the row shows "—" instead of the action's own abstain stake.
  2. Comments: fixed in 9a2280f. network.service.ts and legacy-shape.spec.ts now say the providers leave the SPO total out only when no pool has a voting power for the epoch.
  3. D179's D178 note: removed in 9a2280f; numbers get settled at merge.
  4. Committee block: the negative "Not voted" and the 0% threshold were fixed in 4a9dce6 (size and threshold stay unknown until /network/metrics answers). 8bbf9a2 gates the block on dashboard.metrics, the feature /network/metrics belongs to, instead of dashboard.committeeThreshold, and requests the totals and the metrics in parallel. govtool/AGENTS.md no longer cites the dead id.
  5. ₳ 0 for missing figures: done here rather than in a follow-up. 4401c3b and 360bbb2 covered the dashboard, the directory, the DRep page header and /ada-holder/get-voting-power (503 or 501 on failure; 0 only for an account with no record). 3a98d45 covers the rest you listed: DRepCard, DRepDetailsCard, VotingPowerChips and DirectVoterDashboardCard. The chip's spinner also no longer runs forever when the DRep voting power read fails, and DrepDataDTO.votingPower is now number | null. The formatters still return "0" (deposits and amounts use them); every caller whose figure can be missing goes through adaOrUnknown.
  6. The unavailable note: 8bbf9a2 shows nothing while the totals load, and once they settle it names the reason: "the totals could not be loaded", or (DRep only) "the total stake is no larger than the stake that abstained".
  7. Feat/frontend redesign #4316: agreed. We maintain both, so whichever lands second carries sharesNote and the nullable types across.

Checks on ebbb7d0: backend npm run verify (467 tests); frontend tsc, lint and vitest (651 tests); Storybook play tests 99/99. ebbb7d0 makes the votes story assert no percentages and no "not voted" row instead of waiting for the note, which now appears only after the retried requests fail.

@mesudip mesudip left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed on ebbb7d0. Thanks for the point-by-point reply, and you're right that my follow-up quoted code your earlier commits had already fixed. All seven points are fixed. Checks pass here: provider-dbsync (154 tests), provider-koios (100), backend verify (467), and the frontend's tsc, lint and vitest (651).

On my first request (a 501 or a missing figure must not reach the screen as 0), I traced every route that can answer 501 to the screens that read it. These are done: the connected wallet's voting power, the vote totals on an action, the directory's Abstain and No Confidence options, and the lists that now say they could not be loaded. These are not:

Must fix

  1. A DRep's voting power has two meanings for one null.

    • The db-sync provider sends null on purpose for a DRep registered since the newest snapshot (govtool-provider-dbsync/src/governance/dreps/sql.ts:110, "One registered since has no snapshot figure yet: NULL").
    • The directory card and the DRep page now show that null as "₳ —" (DRepCard.tsx:311, DRepDetailsCard.tsx:199). The CHANGELOG says so, and so does DrepDataDTO's comment (models/api.ts:174), which cites D179.
    • /drep/get-voting-power still turns the same null into 0 (drep.service.ts:223-225), and so does /drep/voting-power-list for an ordinary DRep (drep.service.ts:295-298).
    • So that DRep sees ₳ 0 in its top-bar chip (DashboardTopNav reads /drep/get-voting-power) and "₳ —" on its own card, and the forum's comment cards show it as ₳ 0.
    • D179 (decisions.md:5986-5988) calls that 0 correct, "which the ledger counts as 0". The decision log is append-only, so please pick one meaning before merge and use it in D179, the CHANGELOG, the DTO comment and both routes.
  2. Deposits are shown as ₳ 0 when they are not known.

    • The formatters return "0" for a missing value. The backend types allow drep_deposit and gov_action_deposit to be null (epoch.type.ts:64-65), and the contract's DRep deposit is optional.
    • Register as DRep: RolesAndResponsibilities.tsx:51.
    • Create governance action: WhatGovernanceActionIsAbout.tsx:44, and the insufficient-balance message (useCreateGovernanceActionForm.ts:413).
    • Register as direct voter: RegisterAsDirectVoter.tsx:155. Its ?? 500 never applies, because correctAdaFormat returns 0, not undefined.
    • The DRep dashboard card's retirement text (DRepDashboardCard.tsx:68, :75) and retire as direct voter (RetireAsDirectVoter.tsx:125).
    • The transactions themselves refuse to build without the deposit, so only the text is wrong, but it is the screen where people decide to pay it. These should go through adaOrUnknown too.

Should fix

  1. /network/metrics still reports missing figures as 0 (network.service.ts, getNetworkMetrics).

    • totalDRepDistr is stake.data.totalStakeControlledByDReps ?? '0': the same total that /network/total-stake now sends as null (D179).
    • The DRep counts and totalGovernanceActions fall back to ?? 0, and five counters are always 0.
    • No screen shows these today, here or in #4316, but the API answers them as facts. Make them null, or say in D179 why this route keeps its zeros.
  2. A 501 is retried three times. main.tsx:31-37 retries every failure, so where the provider has no per-account voting power (the fixture, Blockfrost) the dashboard and the DRep directory show their spinner for about 7 seconds on every load before the "—". A 501 will not change on retry. D179 says the frontend "no longer waits for the figure".

Minor

  1. Spinners that never stop. The CHANGELOG says the DRep directory no longer shows a loader forever. It still does when /ada-holder/get-current-delegation fails (DRepDirectoryContent.tsx:184), and the whole dashboard spins for good when that read or the voter info fails (DashboardCards.tsx:38-44). Fix them here, or narrow the CHANGELOG wording.

  2. Merge conflict with develop, now that #4318 is in: only docs/api/decisions.md, where its D180 and this D179 both follow D177. D179 goes above D180.

@kusssal
kusssal force-pushed the fix/4321-drep-vote-percentages branch from ebbb7d0 to 63f2518 Compare December 4, 2026 06:50
@kusssal

kusssal commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for tracing every route that can answer 501. I rebased on develop for point 6 and force-pushed, so the earlier commits have new hashes; this review's fixes are five commits on top:

  1. One meaning for a DRep's null voting power (8e62005): it means "no figure", never 0. db-sync sends it for a DRep registered since the snapshot, and Koios also sends it when drep_info has no amount, so 0 would be wrong for the second.
    • /drep/get-voting-power now answers JSON null for it, and for an id that names no DRep. /drep/voting-power-list answers null for an ordinary DRep too.
    • The top-bar chip, the directory card and the DRep page all show "—".
    • D179, the CHANGELOG, the DrepDataDTO comment and the backend README say so. The pytest contract tests and Playwright 4E accept null.
    • The controller writes the body itself, since Nest sends an empty body for a handler's null; test/drep-voting-power.routes.spec.ts pins the JSON null.
    • The forum's comment cards here show only the DRep's name and id. Feat/frontend redesign #4316's redesigned cards read the figure and will take adaOrUnknown when it rebases.
  2. Deposits (cb7011f): all six places go through adaOrUnknown, RegisterAsDirectVoter's ?? 500 included. VoterInfo.deposit is now number | null, so useDelegateToDrep narrows it explicitly for the refund certificate; the behaviour is unchanged.
  3. /network/metrics (496abf6): null for every counter the backend does not have. That covers the five with no source, the DRep counts and the action total when the provider omits them, and totalDRepDistr when the DRep total is missing.
    • The dashboard.metrics caveat, govtool/AGENTS.md and D179 say so.
    • pytest's NetworkMetrics and NetworkTotalStake models mark those fields Optional, and assert_data_type now accepts Optional. The total-stake model still expected an int after D179.
  4. Retries (af3faa6): the QueryClient no longer retries a 501. A search the backend can't run yet keeps its minute of retries, and anything else its three. The rule is in utils/queryRetry.ts, with tests.
  5. Spinners (63f2518):
    • The DRep directory stops waiting for a delegation it couldn't read, and lists the DReps without marking the wallet's own.
    • The dashboard hides the delegation card when the delegation read fails, as it does when the feature is unavailable, rather than say "not delegated".
    • The dashboard shows the could-not-be-loaded message when the voter info read fails.
  6. Conflict: rebased; D179 now sits above D180.

Checks on 63f2518: backend npm run verify (31 suites, 644 tests); frontend tsc, lint and vitest (108 files, 665 tests); Storybook play tests 99/99. Not run here: the pytest suite and the Playwright specs, which need a deployed stack.

@kusssal
kusssal requested a review from mesudip December 4, 2026 06:54

@mesudip mesudip left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two small leftovers, neither blocking:

  • govtool/govtool-backend/README.md:213-214 still says /network/metrics "reports 0 for the five" unused counters. govtool/AGENTS.md and D179 now say null.

  • drep.service.ts has two doc comments stacked above getVotingPower. The old one still says an unknown credential "becomes the same 0".

@kusssal

kusssal commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both fixed in fd341fc: the backend README now says /network/metrics reports null for the five unused counters and for any counter the provider omits (D179), and getVotingPower keeps one doc comment, which says an unknown credential is null (the legacy endpoint answered 0). Backend npm run verify passes (644 tests).

@kusssal
kusssal merged commit 00df4c1 into develop Dec 4, 2026
11 checks passed
@kusssal
kusssal deleted the fix/4321-drep-vote-percentages branch December 4, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants