Skip to content

Harden oracle: attestation spam guard, Prometheus metrics, ops hygiene - #20

Merged
RunTimeAdmin merged 4 commits into
masterfrom
cursor/harden-oracle-2462
Sep 8, 2026
Merged

Harden oracle: attestation spam guard, Prometheus metrics, ops hygiene#20
RunTimeAdmin merged 4 commits into
masterfrom
cursor/harden-oracle-2462

Conversation

@RunTimeAdmin

Copy link
Copy Markdown
Owner

Summary

Hardens the off-chain reputation oracle for mainnet readiness with three key improvements:

  1. Attestation spam guard: Prevents score inflation by enforcing a cooldown between attestations from the same attester for the same agent
  2. Prometheus metrics: Adds a /metrics endpoint for operational monitoring and alerting
  3. Ops hygiene: Enhanced health checks, comprehensive documentation, and clearer failure signals

Changes

Attestation Cooldown Guard

The /attest endpoint now requires an attester field identifying the party submitting the attestation. The same attester cannot re-attest the same agent within the cooldown period (default: 1 hour, configurable via ATTEST_COOLDOWN_MS).

  • Prevents a single party from artificially inflating an agent's fee/success scores
  • Cooldowns persist across restarts in the state file
  • Returns clear 429 error with remaining time when blocked:
{
  "error": "Attestation cooldown active",
  "attester": "unique-id",
  "didHash": "0x...",
  "remainingSeconds": 2400,
  "cooldownMs": 3600000
}

Prometheus Metrics (GET /metrics)

New endpoint exposing operational metrics in Prometheus text format:

  • countersig_oracle_epochs_total{status="started|succeeded|failed"} — epoch execution
  • countersig_oracle_propose_total{result="success|error"} — score proposals
  • countersig_oracle_finalize_total{result="success|error"} — score finalizations
  • countersig_oracle_attest_total{result="accepted|rejected_cooldown|rejected_other"} — attestation handling
  • countersig_oracle_flags_total, countersig_oracle_links_total — flag/link counts
  • countersig_oracle_rate_limit_hits_total — rate limit rejections
  • countersig_oracle_last_successful_epoch_timestamp_seconds — for staleness alerts
  • countersig_oracle_uptime_seconds, countersig_oracle_active_agents

Enhanced Health Check (GET /health)

The /health endpoint now returns operational signals useful for production alerting:

{
  "ok": true,
  "epochMs": 3600000,
  "uptimeSeconds": 12345,
  "lastSuccessfulEpochMs": 1234567890000,
  "timeSinceLastEpochMs": 120000,
  "storeWritable": true,
  "statePath": "/data/oracle-state.json",
  "attestCooldownMs": 3600000,
  "epochRunning": false
}

Returns 503 when:

  • State file path is not writable (volume mount issue)
  • No successful epoch in the last 2× epoch interval (stale scoring)

Documentation

  • New oracle/README.md: Comprehensive operator documentation with API reference, environment variables, Docker deployment, and production checklist
  • Updated .env.example: Added ORACLE_STATE_PATH and ATTEST_COOLDOWN_MS with descriptions

Testing

All 88 tests pass:

node --test
# tests 88, pass 88, fail 0

New tests cover:

  • Cooldown check/record/prune functions in store.test.js
  • Metrics inc/set/get/reset and Prometheus export in metrics.test.js

How to Verify

  1. Attest cooldown:
# First attest succeeds
curl -X POST localhost:3030/attest \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"didHash":"0x...","success":true,"attester":"test-client"}'
# Response: 200 with attestation counts

# Immediate re-attest blocked
curl -X POST localhost:3030/attest \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"didHash":"0x...","success":true,"attester":"test-client"}'
# Response: 429 with remainingSeconds

# Different attester works
curl -X POST localhost:3030/attest \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"didHash":"0x...","success":true,"attester":"other-client"}'
# Response: 200
  1. Metrics:
curl localhost:3030/metrics
# Prometheus text format output
  1. Health check:
curl localhost:3030/health
# JSON with operational signals

Breaking Changes

POST /attest now requires the attester field. Existing clients must be updated to include this field.

Checklist

  • Attestation spam blocked with tests proving it
  • /metrics returns scrapeable Prometheus metrics
  • /health includes signals for production alerting
  • oracle/README.md documents env vars and operations
  • .env.example updated with new configuration options
  • All tests pass (node --test)
Open in Web Open in Cursor 

- Add per-(attester, didHash) cooldown tracking in store.js
- Configurable cooldown via ATTEST_COOLDOWN_MS (default: 1 hour)
- Persist cooldowns to state file for restart resilience
- Add checkAttestCooldown and recordAttestation helpers
- Add pruneExpiredCooldowns for cleanup during epoch runs
- Add isStatePathWritable for health check
- Add comprehensive unit tests for cooldown logic
- New metrics.js module with counters and gauges
- Track epochs (started/succeeded/failed)
- Track propose/finalize attempts and outcomes
- Track attest (accepted/rejected by cooldown/other)
- Track flags, links, rate-limit hits, HTTP requests
- Gauge for last successful epoch timestamp and active agents
- toPrometheusText() exports standard Prometheus text format
- Comprehensive tests for all metric operations
- Add /metrics endpoint with Prometheus text format
- Enhance /health endpoint with operational signals:
  - uptimeSeconds, lastSuccessfulEpochMs, timeSinceLastEpochMs
  - storeWritable check for volume mount verification
  - Returns 503 when store not writable or epochs stale
- Update /attest to require 'attester' field for dedupe
- Reject attestations during cooldown with 429 and clear error
- Track all operations in metrics counters
- Prune expired cooldowns after each epoch
- Add oracle/README.md with comprehensive operator documentation:
  - Quick start and Docker deployment instructions
  - API endpoint documentation with examples
  - Environment variable reference (required/optional)
  - Production checklist for mainnet readiness
  - Attestation cooldown explanation
  - State persistence details
- Update .env.example with new configuration options:
  - ORACLE_STATE_PATH
  - ATTEST_COOLDOWN_MS
@RunTimeAdmin
RunTimeAdmin merged commit 3f4a5e4 into master Sep 8, 2026
3 checks passed
@RunTimeAdmin
RunTimeAdmin deleted the cursor/harden-oracle-2462 branch September 8, 2026 18:14
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.

2 participants