Harden oracle: attestation spam guard, Prometheus metrics, ops hygiene - #20
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hardens the off-chain reputation oracle for mainnet readiness with three key improvements:
/metricsendpoint for operational monitoring and alertingChanges
Attestation Cooldown Guard
The
/attestendpoint now requires anattesterfield identifying the party submitting the attestation. The same attester cannot re-attest the same agent within the cooldown period (default: 1 hour, configurable viaATTEST_COOLDOWN_MS).{ "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 executioncountersig_oracle_propose_total{result="success|error"}— score proposalscountersig_oracle_finalize_total{result="success|error"}— score finalizationscountersig_oracle_attest_total{result="accepted|rejected_cooldown|rejected_other"}— attestation handlingcountersig_oracle_flags_total,countersig_oracle_links_total— flag/link countscountersig_oracle_rate_limit_hits_total— rate limit rejectionscountersig_oracle_last_successful_epoch_timestamp_seconds— for staleness alertscountersig_oracle_uptime_seconds,countersig_oracle_active_agentsEnhanced Health Check (
GET /health)The
/healthendpoint 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:
Documentation
oracle/README.md: Comprehensive operator documentation with API reference, environment variables, Docker deployment, and production checklist.env.example: AddedORACLE_STATE_PATHandATTEST_COOLDOWN_MSwith descriptionsTesting
All 88 tests pass:
New tests cover:
store.test.jsmetrics.test.jsHow to Verify
curl localhost:3030/metrics # Prometheus text format outputcurl localhost:3030/health # JSON with operational signalsBreaking Changes
POST /attestnow requires theattesterfield. Existing clients must be updated to include this field.Checklist
/metricsreturns scrapeable Prometheus metrics/healthincludes signals for production alertingoracle/README.mddocuments env vars and operations.env.exampleupdated with new configuration optionsnode --test)