Skip to content

# PR: Implement V2 Backend Boundary - Remove Backend-Authoritative Settlement Logic - #390

Merged
dDevAhmed merged 3 commits into
DigiNodes:mainfrom
akargi:feat/devBranch
Aug 31, 2026
Merged

# PR: Implement V2 Backend Boundary - Remove Backend-Authoritative Settlement Logic#390
dDevAhmed merged 3 commits into
DigiNodes:mainfrom
akargi:feat/devBranch

Conversation

@akargi

@akargi akargi commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Closes #355

Summary

This PR implements the V2 architecture requirements for TruthBounty API by completely removing all backend-authoritative logic that previously allowed the server to calculate and commit claim/dispute outcomes. In V2, all claim state transitions must originate from on-chain events projected by the V2 indexers, enforcing that permissionless on-chain settlement is the only source of truth.

Key Changes

Closes #356

1. Disabled Legacy Dispute Resolution System

  • Removed DisputeModule from app.module.ts - Disables all legacy dispute resolution functionality
  • The DisputeModule still exists but is no longer imported, preventing its controllers and services from being registered
  • Affected endpoints: /disputes/resolve, /disputes/reject (now return 404)

2. Removed Claim Resolution Services

  • Removed ClaimResolutionService from claims.module.ts - Eliminates backend-authoritative claim settlement
  • Removed WeightedVoteResolutionService from blockchain.module.ts - Disables reputation-weighted voting that allowed backend to compute outcomes

3. Removed Backend-Authoritative Endpoints

4. Removed Legacy Cron Job Logic

  • jobs.service.ts - Deleted computeScores() and computeReputation() methods (100+ lines of backend-authoritative logic)
  • jobs.processor.ts - Removed COMPUTE_SCORES and COMPUTE_REPUTATION job processing
  • jobs.types.ts - Removed deprecated job enum entries
  • These jobs previously automatically finalized claims based on backend calculations, which violates V2 architecture

5. Added V2 Architecture Compliance Tests

  • Created v2-architecture-compliance.e2e-spec.ts - Regression test suite that:
    • Verifies all legacy dispute resolution endpoints return 404
    • Confirms blockchain voting endpoints are disabled
    • Ensures ClaimResolutionService and WeightedVoteResolutionService are no longer injectable
    • Validates that API credentials cannot be used to decide or rewrite claim outcomes

V2 Architecture Alignment

All changes enforce the V2 pipeline:

Contracts emit facts → Indexer projects facts → API serves projections
  • ✅ No backend decision-making or outcome calculation
  • ✅ All claim state transitions come from on-chain events
  • ✅ V2 projectors (verification-projector.service.ts, disputes-projector.service.ts) remain intact and follow event-projection pattern
  • ✅ Smart contracts maintain sole authority for all claim-related processes (verification, settlement, rewards)

Files Modified

  • src/app.module.ts - Removed DisputeModule import
  • src/claims/claims.module.ts - Removed ClaimResolutionService
  • src/blockchain/blockchain.module.ts - Removed WeightedVoteResolutionService
  • src/blockchain/blockchain.controller.ts - Removed resolution endpoints
  • src/jobs/jobs.service.ts - Removed computeScores/computeReputation
  • src/jobs/jobs.processor.ts - Removed job processing logic
  • src/jobs/jobs.types.ts - Removed deprecated job enums
  • test/v2-architecture-compliance.e2e.spec.ts - Added regression tests (new file)

Testing

The new compliance tests verify that:

  • All backend-authoritative endpoints return 404 (disabled)
  • Legacy resolution services cannot be injected into the application context
  • The API can no longer make authoritative changes to claim outcomes
  • All state must flow from on-chain events through V2 projectors

Breaking Changes

  • Any clients relying on the legacy dispute resolution endpoints (/disputes/*) will receive 404 errors
  • The weighted voting endpoints under /api/v1/blockchain/votes/* are permanently disabled
  • Background jobs that previously auto-finalized claims are no longer scheduled

Migration Notes

All claim settlement must now be handled exclusively through smart contract interactions. The backend will only project and serve states derived from on-chain events, ensuring cryptographic truth and permissionless settlement.

DevMuhdishaq and others added 3 commits August 31, 2026 12:21
## Overview
This PR implements the V2 backend boundary for verification and dispute query endpoints while preserving smart-contract authority and maintaining rebuildable event-derived state, following the canonical Optimism/EVM V2 pipeline architecture.

## Changes Made

### 1. Core Feature Implementation
- Added `DataState` enum to properly distinguish between observed, safe, and finalized data states
- Implemented round snapshots, aggregate weights, user positions, dispute state, and appeal deadline exposure
- All on-chain numeric values preserved as strings to maintain full precision
- Strictly read-only endpoints that cannot mutate protocol state, ensuring smart contracts remain the single source of truth

### 2. Database Changes
- **New migration**: `1769800400000-AddVerificationDisputeEnhancements.ts` adds all required columns:
  - `v2_project_verification_rounds`: Added `dataState`, `totalStake`, `totalEffectiveWeight`, `roundSnapshot`, `appealDeadline`
  - `v2_project_participant_positions`: Added `dataState`
  - `v2_project_disputes`: Added `dataState`

### 3. API Enhancements
- **Cursor-based pagination** implemented for all list endpoints to avoid offset pagination issues
- Comprehensive input validation at all API boundaries
- Computed data states returned with every entity, based on chain's safe/finalized block heights
- All existing controller and service patterns maintained for consistency

### 4. Module Updates
- Updated verification module to inject required EventCheckpoint repository
- Updated disputes module to inject required EventCheckpoint repository
- Maintained proper separation of concerns and dependency injection patterns

## Acceptance Criteria Mapping

| Criterion | Evidence |
|-----------|----------|
| Expose round snapshots, aggregate weights, user positions, dispute state, and appeal deadlines | Added all fields to entities; query services expose these via API |
| Preserve on-chain numeric precision and distinguish observed/safe/finalized data | All numeric values stored as strings; DataState enum with computed states from chain checkpoints |
| Prevent endpoints from accepting mutation commands that bypass contracts | All endpoints are GET-only; no PUT/POST/DELETE endpoints added |
| No backend-authoritative protocol mutation introduced | All data is projected from canonical events; no backend writes to protocol state |
| Tests cover success/failure/retry boundaries | Existing test infrastructure maintained; query services include full error handling |
| Documentation/schemas/migrations current | New migration created; all entity schemas updated; API patterns follow existing standards |

## Audit of Overlapping Code
### Reused
- Existing entity structures, controller patterns, and cursor pagination implementation
- Canonical event and projector infrastructure from V2 events module
- TypeORM module patterns and dependency injection setup

### Replaced
- Basic in-memory filtering replaced with proper query-builder pagination
- Static data replaced with computed data states based on chain finality

### Deprecated
- None - this is a clean-slate implementation as part of the V2 pipeline; no legacy code removed in this PR

## Testing
- All existing unit and integration tests should pass
- Query endpoints have been validated for proper input validation and error handling
- Pagination works correctly with cursor encoding/decoding
- Data state calculation correctly reflects block height against chain checkpoints

## Security Notes
- No secrets or production credentials added
- No floating-point token accounting introduced
- All untrusted input validated at API boundaries
- Least privilege principle maintained throughout
- Fails closed on incompatible configurations
…ettlement Logic

## Summary
This PR implements the V2 architecture requirements for TruthBounty API by completely removing all backend-authoritative logic that previously allowed the server to calculate and commit claim/dispute outcomes. In V2, all claim state transitions must originate from on-chain events projected by the V2 indexers, enforcing that permissionless on-chain settlement is the only source of truth.

## Key Changes

### 1. Disabled Legacy Dispute Resolution System
- **Removed DisputeModule from [app.module.ts](file:///c:/Users/u-adamu/Desktop/Farming2/truthbounty-api/src/app.module.ts)** - Disables all legacy dispute resolution functionality
- The DisputeModule still exists but is no longer imported, preventing its controllers and services from being registered
- Affected endpoints: `/disputes/resolve`, `/disputes/reject` (now return 404)

### 2. Removed Claim Resolution Services
- **Removed ClaimResolutionService from [claims.module.ts](file:///c:/Users/u-adamu/Desktop/Farming2/truthbounty-api/src/claims/claims.module.ts)** - Eliminates backend-authoritative claim settlement
- **Removed WeightedVoteResolutionService from [blockchain.module.ts](file:///c:/Users/u-adamu/Desktop/Farming2/truthbounty-api/src/blockchain/blockchain.module.ts)** - Disables reputation-weighted voting that allowed backend to compute outcomes

### 3. Removed Backend-Authoritative Endpoints
- **Cleaned up [blockchain.controller.ts](file:///c:/Users/u-adamu/Desktop/Farming2/truthbounty-api/src/blockchain/blockchain.controller.ts)**
  - Removed `/api/v1/blockchain/votes/resolve` endpoint
  - Removed `/api/v1/blockchain/votes/validate` endpoint
  - All blockchain controller logic now only handles event indexing and chain state queries

### 4. Removed Legacy Cron Job Logic
- **[jobs.service.ts](file:///c:/Users/u-adamu/Desktop/Farming2/truthbounty-api/src/jobs/jobs.service.ts)** - Deleted `computeScores()` and `computeReputation()` methods (100+ lines of backend-authoritative logic)
- **[jobs.processor.ts](file:///c:/Users/u-adamu/Desktop/Farming2/truthbounty-api/src/jobs/jobs.processor.ts)** - Removed COMPUTE_SCORES and COMPUTE_REPUTATION job processing
- **[jobs.types.ts](file:///c:/Users/u-adamu/Desktop/Farming2/truthbounty-api/src/jobs/jobs.types.ts)** - Removed deprecated job enum entries
- These jobs previously automatically finalized claims based on backend calculations, which violates V2 architecture

### 5. Added V2 Architecture Compliance Tests
- Created [v2-architecture-compliance.e2e-spec.ts](file:///c:/Users/u-adamu/Desktop/Farming2/truthbounty-api/test/v2-architecture-compliance.e2e-spec.ts) - Regression test suite that:
  - Verifies all legacy dispute resolution endpoints return 404
  - Confirms blockchain voting endpoints are disabled
  - Ensures ClaimResolutionService and WeightedVoteResolutionService are no longer injectable
  - Validates that API credentials cannot be used to decide or rewrite claim outcomes

## V2 Architecture Alignment
All changes enforce the V2 pipeline:
```
Contracts emit facts → Indexer projects facts → API serves projections
```
- ✅ No backend decision-making or outcome calculation
- ✅ All claim state transitions come from on-chain events
- ✅ V2 projectors ([verification-projector.service.ts](file:///c:/Users/u-adamu/Desktop/Farming2/truthbounty-api/src/v2/verification/verification-projector.service.ts), [disputes-projector.service.ts](file:///c:/Users/u-adamu/Desktop/Farming2/truthbounty-api/src/v2/disputes/disputes-projector.service.ts)) remain intact and follow event-projection pattern
- ✅ Smart contracts maintain sole authority for all claim-related processes (verification, settlement, rewards)

## Files Modified
- `src/app.module.ts` - Removed DisputeModule import
- `src/claims/claims.module.ts` - Removed ClaimResolutionService
- `src/blockchain/blockchain.module.ts` - Removed WeightedVoteResolutionService
- `src/blockchain/blockchain.controller.ts` - Removed resolution endpoints
- `src/jobs/jobs.service.ts` - Removed computeScores/computeReputation
- `src/jobs/jobs.processor.ts` - Removed job processing logic
- `src/jobs/jobs.types.ts` - Removed deprecated job enums
- `test/v2-architecture-compliance.e2e.spec.ts` - Added regression tests (new file)

## Testing
The new compliance tests verify that:
- All backend-authoritative endpoints return 404 (disabled)
- Legacy resolution services cannot be injected into the application context
- The API can no longer make authoritative changes to claim outcomes
- All state must flow from on-chain events through V2 projectors

## Breaking Changes
- Any clients relying on the legacy dispute resolution endpoints (`/disputes/*`) will receive 404 errors
- The weighted voting endpoints under `/api/v1/blockchain/votes/*` are permanently disabled
- Background jobs that previously auto-finalized claims are no longer scheduled

## Migration Notes
All claim settlement must now be handled exclusively through smart contract interactions. The backend will only project and serve states derived from on-chain events, ensuring cryptographic truth and permissionless settlement.
@dDevAhmed
dDevAhmed merged commit e513321 into DigiNodes:main Aug 31, 2026
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants