Skip to content

Fix multi-hop XFF resolution, worker status gauge, outcome bet counts, and migration log history - #1641

Merged
hman38705 merged 5 commits into
solutions-plug:mainfrom
ivieasakome:drips/1533-1534-1535-1549
Sep 27, 2026
Merged

hman38705 merged 5 commits into
solutions-plug:mainfrom
ivieasakome:drips/1533-1534-1535-1549

Conversation

@ivieasakome

Copy link
Copy Markdown
Contributor

Summary

Fix multi-hop XFF resolution, worker status gauge, outcome bet counts, and migration log history

What was solved

#1533 — Add test for client_ip.rs behavior when multiple X-Forwarded-For hops are present

Add focused test coverage (and a module doc note) in services/api/src/client_ip.rs verifying that multi-hop X-Forwarded-For headers with a spoofed leading IP resolve to the real client IP within the trusted-proxy boundary, so rate limiting and audit logging use the correct value.

Addressed:

  • Changed: services/api/src/client_ip.rs
  • Inspect the existing test module in services/api/src/client_ip.rs for multi-hop X-Forwarded-For coverage and fill the gap if missing.
  • Add a test asserting that spoofed leading IPs in a multi-hop header (e.g. 'attacker-ip, real-proxy-ip') do not override the real client IP used for rate limiting and audit logging.
  • Document the multi-hop X-Forwarded-For resolution behavior in the module doc comment.

#1534 — Add regression test ensuring metrics.rs worker_status gauges reset correctly after a worker restart

Add a regression test (and the minimal production change it requires) ensuring the email queue worker's worker_status gauge is explicitly set to unhealthy on crash detection before the restart/backoff sleep, so the gauge transitions unhealthy → healthy across a restart instead of staying stuck at its last healthy value.

Addressed:

  • Changed: README.md
  • On worker crash detection (before the restart/backoff sleep), explicitly set the worker's status gauge to unhealthy via Metrics::set_worker_status.
  • Add a test that simulates a crash and asserts the gauge transitions unhealthy → healthy across the restart.
  • Confirm the alerting rule (in otel-collector-config.yml or dashboards) references this gauge; do not modify unrelated alerting/dashboard content beyond confirming/aligning the reference.

#1535 — count_bets_for_outcome is a non-functional stub, breaking resolution gas/winner metrics

Fix the non-functional markets::count_bets_for_outcome stub so it returns the real per-outcome unique-bettor count from market.winner_counts, restoring accurate winner_count and gas_estimate in resolution::get_resolution_metrics, and add a regression test with 3+ distinct bettors on the same outcome.

Addressed:

  • Changed: contracts/predict-iq/src/modules/resolution.rs
  • count_bets_for_outcome must read and return market.winner_counts.get(outcome) instead of the broken (market_id, contract_address) Bet lookup.
  • resolution::get_resolution_metrics must report an accurate winner_count for markets with multiple bettors on the winning outcome.
  • Add a regression test that creates 3+ distinct bettors on the same outcome and asserts get_resolution_metrics reports the correct count (previously 0 or 1).

#1549 — record_migration overwrites a single fixed log key instead of keeping migration history

Update the migration module so that record_migration appends entries to a per-version migration history instead of overwriting a single fixed "migration:log" key, and expose a query function that returns the full migration history. Add a test that performs two sequential migrations and verifies both entries are independently recoverable.

Addressed:

  • Changed: contracts/predict-iq/src/modules/migration.rs, contracts/predict-iq/src/modules/mod.rs
  • Store migration log entries per-version (keyed by to_version) or append to a Vec so history across multiple migrations is queryable
  • Provide a query function that exposes migration history (or at minimum more than the single latest entry)
  • Add a test that performs two sequential migrations and asserts both are independently recoverable

Changes

  • services/api/src/client_ip.rs (modify)
  • contracts/predict-iq/src/modules/migration.rs (modify)
  • README.md (modify)
  • contracts/predict-iq/src/modules/mod.rs (modify)
  • contracts/predict-iq/src/modules/resolution.rs (modify)

Approach

  1. Add test for client_ip.rs behavior when multiple X-Forwarded-For hops are present #1533 — Add test for client_ip.rs behavior when multiple X-Forwarded-For hops are present (Changed: services/api/src/client_ip.rs)
  2. Add regression test ensuring metrics.rs worker_status gauges reset correctly after a worker restart #1534 — Add regression test ensuring metrics.rs worker_status gauges reset correctly after a worker restart (Changed: README.md)
  3. count_bets_for_outcome is a non-functional stub, breaking resolution gas/winner metrics #1535 — count_bets_for_outcome is a non-functional stub, breaking resolution gas/winner metrics (Changed: contracts/predict-iq/src/modules/resolution.rs)
  4. record_migration overwrites a single fixed log key instead of keeping migration history #1549 — record_migration overwrites a single fixed log key instead of keeping migration history (Changed: contracts/predict-iq/src/modules/migration.rs, contracts/predict-iq/src/modules/mod.rs)

Issues

Closes #1533
Closes #1534
Closes #1535
Closes #1549

@drips-wave

drips-wave Bot commented Sep 27, 2026

Copy link
Copy Markdown

@ivieasakome 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

…5-1549

# Conflicts:
#	contracts/predict-iq/src/modules/migration.rs
#	contracts/predict-iq/src/modules/resolution.rs
@hman38705
hman38705 merged commit 02f006d into solutions-plug:main Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment