Skip to content

Implement a deterministic voting power snapshot calculator with delegation-safe accounting #383

Description

@Lakes41

Difficulty: Expert
Type: Feature
Recommended labels (if available in this repo): governance, backend, consistency, expert

Background

Governance systems often need to freeze voting power at a specific logical snapshot so that later balance or membership changes do not alter an already active vote.

This issue introduces a pure snapshot calculator. It does not create proposals, persist snapshots or integrate with Stellar balances.

Problem

There is currently no standard Core primitive for converting a set of eligible participants and weighted sources into an immutable, deterministic voting-power snapshot.

Without explicit rules, duplicate identities or duplicated source entries can inflate voting power and result ordering may vary across runs.

Expected Outcome

Implement a deterministic voting-power snapshot calculator that validates source records, aggregates power safely and produces a canonical snapshot representation suitable for hashing or persistence by future modules.

Suggested Implementation

Inputs may resemble:

interface VotingPowerSource {
  participantId: string;
  sourceId: string;
  power: bigint;
}

The calculator should:

  • validate non-negative voting power;
  • define uniqueness rules for source IDs;
  • reject duplicate source records that would double-count power;
  • aggregate multiple legitimate sources for the same participant;
  • support very large bigint values;
  • sort snapshot entries deterministically;
  • calculate total voting power;
  • optionally calculate a deterministic snapshot fingerprint using a local self-contained hashing implementation;
  • preserve input immutability;
  • expose structured validation errors;
  • remain independent of membership and delegation persistence.

Do not depend on the separate canonical-JSON or delegation-graph campaign issues. If fingerprinting is implemented, include the minimal deterministic encoding needed within this task.

Acceptance Criteria

  • Voting power is aggregated correctly per participant.
  • Total voting power equals the sum of valid participant allocations.
  • Duplicate source records cannot inflate voting power.
  • Negative power values are rejected.
  • Zero-power entries have explicitly documented behaviour.
  • Output ordering is deterministic regardless of input order.
  • Very large bigint values are supported.
  • Input arrays and objects are not mutated.
  • If a snapshot fingerprint is provided, identical logical snapshots produce identical fingerprints regardless of input order.
  • Unit tests cover duplicates, aggregation, reordered input and large values.
  • pnpm typecheck passes.
  • pnpm build passes.
  • pnpm test passes.
  • No proposal, Stellar balance, delegation database or API functionality is introduced.

Likely Affected Files/Directories

packages/voting-power-snapshot/ or equivalent isolated governance package
unit tests

Independence Requirement

This issue must be independently implementable from the current main branch. It must not depend on the delegation graph, quorum engine or another governance campaign issue.

Activity

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

    GrantFox OSSGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesThird CampaignOfficial FWC26 campaign issue — eligible for campaign scoring and rewardsbackendBackend services, application logic, persistence integration, and server-side functionalityconsistencyPattern and convention standardization across the codebase for uniformityexpertExpert difficulty tasks requiring deep expertise and architectural decision-makinggovernanceCommunity governance rules, governance evaluation, permissions, and decision-making infrastructure

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions