Skip to content

Feat/config management#457

Open
Mrchinedum wants to merge 4 commits intorinafcode:mainfrom
Mrchinedum:feat/config-management
Open

Feat/config management#457
Mrchinedum wants to merge 4 commits intorinafcode:mainfrom
Mrchinedum:feat/config-management

Conversation

@Mrchinedum
Copy link
Copy Markdown

fixed #384

feat: implement comprehensive configuration management

Configuration was scattered across 13 contract modules as isolated
pub const values with no shared convention, no validation, and no
runtime reload capability. This change centralizes all constants into
a single contract config module and adds a validated, hot-reloadable
ConfigManager to the indexer.

Changes

contracts/teachlink/src/config.rs (new — 184 lines)

  • Single source of truth for all 45 tunable constants, organized into
    15 documented sections:
    Analytics METRICS_UPDATE_INTERVAL
    Atomic Swaps SWAP_MIN_TIMELOCK, SWAP_MAX_TIMELOCK, SWAP_HASH_LENGTH
    Audit AUDIT_MAX_RECORDS, AUDIT_COMPLIANCE_PERIOD
    BFT Consensus BFT_MIN_VALIDATOR_STAKE, BFT_PROPOSAL_TIMEOUT,
    BFT_ROTATION_EPOCH_ROUNDS, BFT_MIN_ACTIVE_REPUTATION
    Emergency EMERGENCY_SECURITY_COUNCIL_SIZE, EMERGENCY_DAILY_VOLUME_RESET
    Ledger Time LEDGER_EST_SECS
    Liquidity LIQUIDITY_BASE_FEE_BPS, LIQUIDITY_MAX_FEE_BPS,
    LIQUIDITY_MIN_FEE_BPS, LIQUIDITY_UTILIZATION_THRESHOLD
    Message Passing MSG_DEFAULT_PACKET_TIMEOUT, MSG_MAX_RETRY_ATTEMPTS,
    MSG_RETRY_DELAY_BASE
    Multichain MULTICHAIN_MAX_CHAINS, MULTICHAIN_MAX_ASSETS
    Network Recovery RECOVERY_MAX_RETRY_ATTEMPTS, RECOVERY_INITIAL_BACKOFF_SECS,
    RECOVERY_MAX_BACKOFF_SECS, RECOVERY_BACKOFF_MULTIPLIER
    Notifications NOTIF_IMMEDIATE_DELIVERY, NOTIF_MIN_DELAY_SECS,
    NOTIF_MAX_DELAY_SECS, NOTIF_BATCH_SIZE,
    NOTIF_DEFAULT_EVENT_TTL_SECS
    Performance Cache PERF_CACHE_TTL_SECS, PERF_MAX_TOP_CHAINS
    Rate Limiting RATE_LIMIT_DEFAULT_MAX_CALLS, RATE_LIMIT_DEFAULT_WINDOW_LEDGERS
    Slashing SLASH_DOUBLE_VOTE_BPS, SLASH_INVALID_SIGNATURE_BPS,
    SLASH_INACTIVITY_BPS, SLASH_BYZANTINE_BPS, SLASH_MALICIOUS_BPS
    Sustainability SUSTAIN_CONTENT_SCORE_CAP, SUSTAIN_USER_SCORE_CAP
    Upgrade UPGRADE_ROLLBACK_WINDOW_SECS
  • Every constant carries a doc comment with purpose, unit, and default

contracts/teachlink/src/lib.rs

  • Added mod config declaration

13 contract modules refactored (zero behavior change)

  • analytics.rs, atomic_swap.rs, audit.rs, bft_consensus.rs,
    emergency.rs, ledger_time.rs, liquidity.rs, message_passing.rs,
    multichain.rs, network_recovery.rs, notification.rs, performance.rs,
    rate_limiting.rs, slashing.rs, upgrade.rs
  • Each module replaces its local pub const with:
    pub use crate::config::CANONICAL_NAME as LOCAL_NAME;
    preserving all existing call sites while pointing to the single
    source of truth

indexer/src/config/config.manager.ts (new — 175 lines)

  • IndexerConfig interface: 20 typed fields covering Stellar, database,
    indexer, and app settings; every field documents its env var and default
  • ConfigManager NestJS service:
    load() reads all values from ConfigService into a typed snapshot
    validate() enforces 7 rules:
    horizonUrl / sorobanRpcUrl must start with http
    dbPort must be 1–65535
    dbPassword must be non-empty
    pollIntervalMs must be >= 1000
    batchSize must be 1–10000
    port must be 1–65535
    onModuleInit() calls load() + validate() at startup; throws if
    any rule fails, preventing a misconfigured boot
    reload() re-runs load() + validate() and atomically swaps the
    snapshot on success; returns errors without applying
    on failure (safe hot-reload)
    get() returns the current validated snapshot

indexer/src/config/config.module.ts (new)

  • AppConfigModule: wraps NestJS ConfigModule.forRoot + provides and
    exports ConfigManager for injection anywhere in the app

indexer/src/reporting/reporting.controller.ts

  • Inject ConfigManager
  • GET /analytics/config returns current config (dbPassword omitted)
  • POST /analytics/config/reload triggers hot-reload; returns
    { success: true } or { success: false, errors }

indexer/src/reporting/reporting.module.ts

  • Import AppConfigModule, add ConfigManager to providers

indexer/src/app.module.ts

  • Import AppConfigModule alongside existing ConfigModule.forRoot

Acceptance criteria met

✓ Centralize configuration — config.rs (contract) + ConfigManager (indexer)
✓ Add validation — 7 startup rules; boot fails on misconfiguration
✓ Support hot-reload — POST /analytics/config/reload; atomic swap,
no restart required
✓ Document configuration — every constant and field has inline docs
with env var, unit, and default value

- Add SustainabilityMetrics type with KPIs: invocations, storage
  writes, events emitted, rewards distributed, content minted,
  active users, and efficiency score
- Add SUSTAINABILITY_METRICS storage key
- Add SustainabilityMetricsUpdatedEvent
- Add SustainabilityManager with record, query, and health score logic
- Expose 4 public contract entry points in lib.rs
- Include unit tests for core metric tracking and health scoring
- Add 8 sustainability Prometheus gauges to MetricsService
  (invocations, storage writes, events emitted, rewards distributed,
  content minted, active users, efficiency score, health score)
- Add updateSustainabilityMetrics() to push gauges on each query
- Add getSustainabilitySnapshot() to DashboardService: computes
  real-time KPIs (efficiency, health, dispute rate, reward claim rate)
  and pushes them to Prometheus
- Add GET /analytics/sustainability endpoint in ReportingController
- Add teachlink-sustainability alert group to prometheus/alerts.yml
  with 5 rules: low efficiency, critical efficiency, low health score,
  high error rate, no new transactions
- Create teachlink-monitoring-dashboard.json (691 lines, 20 panels):
  - Row 1: Real-Time Platform Health (6 stat panels)
  - Row 2: Historical Trends (4 time-series panels)
  - Row 3: Alert Management (firing alerts, active count, critical count)
  - Row 4: Platform Insights (cache ratio, latency percentiles,
    dependency health, indexer progress, HTTP status breakdown)
- Add docs/MODULE_INTERFACE_STANDARDS.md defining 8 rules:
  module-level doc comment, manager-struct pattern, section comments,
  #[must_use] on pure getters, error handling, auth pattern,
  compliance table, and a minimal example module
- Refactor reputation.rs: free functions -> ReputationManager struct,
  add module doc, section comments (Mutations/Queries/Internal),
  #[must_use] on get_reputation
- Add module doc, Mutations/Queries section comments, and #[must_use]
  on all 3 getters in score.rs
- Add module doc, standardize section comments
  (Initialization/Mutations/Admin/Queries), and #[must_use] on all
  5 getters in rewards.rs
- Update all 4 reputation call sites in lib.rs from free functions
  to ReputationManager::* methods
- Centralize 45 scattered pub const values from 13 contract modules
  into contracts/teachlink/src/config.rs (15 sections, fully documented)
- Each module re-exports its constants from config via pub use aliases
  preserving backward compatibility
- Add mod config to lib.rs
- Add indexer ConfigManager: typed IndexerConfig snapshot, startup
  validation (URL format, port range, poll interval, batch size),
  hot-reload via reload() method
- Add AppConfigModule wrapping NestJS ConfigModule + ConfigManager
- Add GET /analytics/config and POST /analytics/config/reload endpoints
- Wire AppConfigModule into AppModule and ReportingModule
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 26, 2026

@Mrchinedum Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Implement comprehensive configuration management

1 participant