Skip to content

[Backend] Reputation engine: make scoring weights and thresholds config-driven, not hardcoded #1005

Description

@Baskarayelu

Description

The reputation engine hardcodes scoring constants — BOND_SCORE_MAX = 50, DURATION_SCORE_MAX = 20, ATTESTATION_SCORE_MAX = 30, ONE_ETH_WEI, the 365-day cap, and the 5-attestation cap — directly in src/services/reputationService.ts and src/services/reputation/. Tuning the trust model requires a code change and redeploy, and there is no audit trail of weight changes. We should externalize these into versioned configuration so the model can be tuned and snapshotted.

Requirements and context

  • Move weights/caps into src/config/index.ts (validated with Zod) with sane defaults preserving current behavior.
  • Include a scoringModelVersion so src/jobs/scoreSnapshot.ts can record which model produced a score.
  • Keep computeBondScore/computeDurationScore/computeAttestationScore pure but parameterized.
  • Document the model in src/services/reputation/README.md.

Suggested execution

Create branch feature/config-driven-reputation.

  • Refactor src/services/reputationService.ts and src/services/reputation/score.ts.
  • Add config schema + validation in src/config/.
  • Update src/services/reputation/score.test.ts and add config tests.
  • Update docs/ reputation/model docs.

Test and commit

Run npm run test. Edge cases: default config == current scores (regression), invalid config rejected at boot, total capped at 100. Security: config from env validated, no eval.

Example commit message

feat: externalize reputation scoring weights into versioned config

Guidelines

  • Minimum 95% test coverage
  • Clear documentation in src/services/reputation/README.md
  • Timeframe: 96 hours

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions