Skip to content

Commit

Permalink
Use proposal ballots for voting state (#5559)
Browse files Browse the repository at this point in the history
# Motivation

There are multiple reports from users who can’t vote. We believe the
root cause of this issue is the 100-ballot limit for neurons. If a user
has voted on more than 100 proposals (a likely scenario over a 4-day
period), they don’t receive ballots for proposals they’ve already voted
on, which remain technically votable due to this limit. The suggested
solution is to switch from using neuron ballots to proposal ballots when
calculating the votable state.

The utilities have already been already updated in `ic-js` -
dfinity/ic-js#725

# Changes

- `npm run upgrade:next`
- Update the displayed votable neurons on proposal changes as well,
since we use the proposal ballots to determine the neurons’ voting
state.

# Tests

- Updated.
- Manually
1.	Created 100+ proposals.
2.	Voted on them.
3. Ensured that some of them were still displayed as votable (due to the
recentBallots limit).
4.	Switched to the utilities that rely on the proposal ballots.
5. Verified that all the proposals previously displayed as votable
(despite having already been voted on) were now displayed as voted.

# Todos

- [x] Add entry to changelog (if necessary).
  • Loading branch information
mstrasinskis authored Oct 4, 2024
1 parent 41b48fe commit 6ad5330
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 73 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-Nns-Dapp-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ proposal is successful, the changes it released will be moved from this file to

* Fixed a bug where a performance counter in `init` is wiped during state initialization.
* Bug with parsing nervous system parameters from aborted SNSes.
* Bug where neurons are displayed as eligible to vote, even though they have already voted.

#### Security

Expand Down
109 changes: 49 additions & 60 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@
type Vote,
votableNeurons as getVotableNeurons,
} from "@dfinity/nns";
import type { NeuronInfo } from "@dfinity/nns";
import { getContext } from "svelte";
export let proposalInfo: ProposalInfo;
const votableNeurons = () =>
const votableNeurons = ({
neurons,
proposal,
}: {
neurons: NeuronInfo[];
proposal: ProposalInfo;
}) =>
getVotableNeurons({
neurons: $definedNeuronsStore,
proposal: proposalInfo,
}).map((neuron) =>
nnsNeuronToVotingNeuron({ neuron, proposal: proposalInfo })
);
neurons,
proposal,
}).map((neuron) => nnsNeuronToVotingNeuron({ neuron, proposal }));
let visible = false;
/** Signals that the initial checkbox preselection was done. To avoid removing of user selection after second queryAndUpdate callback. */
Expand All @@ -53,17 +58,36 @@
$: $definedNeuronsStore,
(visible = isProposalDeadlineInTheFuture(proposalInfo));
const updateVotingNeuronSelectedStore = () => {
const updateVotingNeuronSelectedStore = ({
neurons,
proposal,
}: {
neurons: NeuronInfo[];
proposal: ProposalInfo;
}) => {
if (!initialSelectionDone) {
initialSelectionDone = true;
votingNeuronSelectStore.set(votableNeurons());
votingNeuronSelectStore.set(
votableNeurons({
neurons,
proposal,
})
);
} else {
// preserve user selection after neurons update (e.g. queryAndUpdate second callback)
votingNeuronSelectStore.updateNeurons(votableNeurons());
votingNeuronSelectStore.updateNeurons(
votableNeurons({
neurons,
proposal,
})
);
}
};
$: $definedNeuronsStore, updateVotingNeuronSelectedStore();
$: updateVotingNeuronSelectedStore({
neurons: $definedNeuronsStore,
proposal: proposalInfo,
});
const { store } = getContext<SelectedProposalContext>(
SELECTED_PROPOSAL_CONTEXT_KEY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ describe("VotingCard", () => {
const neuronIds = [111, 222].map(BigInt);
const proposalInfo: ProposalInfo = {
...mockProposalInfo,
ballots: neuronIds.map((neuronId) => ({ neuronId }) as Ballot),
ballots: neuronIds.map(
(neuronId) =>
({ neuronId, vote: Vote.Unspecified, votingPower: 1n }) as Ballot
),
proposalTimestampSeconds: 2_000n,
status: ProposalStatus.Open,
};
Expand Down
Loading

0 comments on commit 6ad5330

Please sign in to comment.