Skip to content

fix(dispute): add voting window deadline and quorum requirement to resolve_dispute (#58) - #66

Closed
produckq-boop wants to merge 1 commit into
trustflow-protocol:mainfrom
produckq-boop:fix/dispute-voting-window-quorum-58
Closed

produckq-boop wants to merge 1 commit into
trustflow-protocol:mainfrom
produckq-boop:fix/dispute-voting-window-quorum-58

Conversation

@produckq-boop

Copy link
Copy Markdown

Closes #58

Summary

Adds an admin-configurable dispute voting window (dispute_deadline on DisputeRecord) and minimum juror vote quorum (DataKey::DisputeQuorum) to resolve_dispute.

Previously, resolve_dispute did not enforce a minimum vote quorum alongside a configurable dispute voting window, leaving early or low-turnout dispute resolution without quorum guarantees. This change enforces a quorum-OR-deadline gate after the commit phase closes: resolution before dispute_deadline requires at least DisputeQuorum revealed votes, while post-deadline sub-quorum disputes settle via fallback plurality tally without slashing jurors on a thin sample.

Changes

  • Voting window & DisputeRecord::dispute_deadline:
    • Add dispute_deadline: u32 to DisputeRecord, computed and persisted in raise_dispute from DataKey::DisputeVotingWindow (default 34,560 ledgers = COMMIT_WINDOW_LEDGERS + REVEAL_WINDOW_LEDGERS, split evenly into commit and reveal phases).
    • Add set_dispute_voting_window / get_dispute_voting_window (admin-authenticated, bounded to 2..=PERSISTENT_BUMP_AMOUNT, returning TrustFlowError::InvalidVotingWindow outside that range). Updating the window applies to newly raised disputes without shifting deadlines on already-open disputes.
  • Configurable minimum quorum (DataKey::DisputeQuorum):
    • Add set_dispute_quorum / get_dispute_quorum (admin-authenticated, default 2, MIN_DISPUTE_QUORUM = 2, returning TrustFlowError::InvalidQuorum for < 2 so single-vote early resolution cannot be re-enabled).
  • Quorum-OR-deadline gate & sub-quorum fallback in resolve_dispute:
    • Always reject calls during the commit phase (now < dispute.commit_deadline) with TrustFlowError::RevealPhaseNotEnded.
    • Before dispute.dispute_deadline, reject calls when voters.len() < quorum (RevealPhaseNotEnded), and allow early settlement (with normal majority/tie-break tally and minority slashing) once voters.len() >= quorum.
    • At or after dispute.dispute_deadline, settle sub-quorum disputes (1 <= voters.len() < quorum) using the revealed vote plurality tally (ties break in favour of the depositor) while skipping minority slashing so escrow funds cannot be stranded by low turnout and dissenting jurors are not penalized without quorum (0 revealed votes still return TrustFlowError::NoVotesCast).
  • Tests (contracts/trustflow/src/lib.rs):
    • Update dispute_round helper to advance ledgers dynamically using dispute.commit_deadline and dispute.dispute_deadline.
    • Add unit tests covering single-vote early-resolution rejection, early resolution once quorum is met before dispute_deadline, post-deadline sub-quorum settlement without slashing, deadline snapshotting across window updates, and admin auth/bounds validation.

Verification

Run from contracts/:

  • cargo fmt --all --check
  • cargo clippy --all-features --workspace --lib
  • cargo check --workspace
  • cargo test --package trustflow (69 passed; 0 failed)
  • cargo build --target wasm32-unknown-unknown --release --workspace

…solve_dispute (trustflow-protocol#58)

- Add `dispute_deadline` to `DisputeRecord`, computed on `raise_dispute`
  from the admin-configurable `DataKey::DisputeVotingWindow` (default
  34,560 ledgers = commit + reveal windows, bounded to 2..=90 days) so
  updating the global window never retroactively alters open disputes.
- Add admin-configurable `DataKey::DisputeQuorum` (`set_dispute_quorum` /
  `get_dispute_quorum`, minimum and default = 2) so a single colluding
  juror can never settle a dispute early before the voting window closes.
- Enforce a quorum-OR-deadline gate in `resolve_dispute`: revert before
  `commit_deadline`, and revert before `dispute_deadline` unless at least
  `DisputeQuorum` revealed votes have been cast; once `dispute_deadline`
  passes, settle sub-quorum disputes (>= 1 vote) via fallback plurality
  tally without thin-sample slashing (0 votes still return `NoVotesCast`).
- Update `dispute_round` test helper to advance to `dispute_deadline`
  dynamically and add unit tests covering single-vote early-resolve
  rejection, early quorum resolution before deadline, post-deadline
  sub-quorum fallback settlement, and admin configuration bounds.

Closes trustflow-protocol#58
@meshackyaro meshackyaro closed this Nov 8, 2026
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.

Add dispute voting window and quorum requirement to resolve_dispute

2 participants