Skip to content

Reject payment creation when trustline is confirmed missing - #922

Open
solarix-x wants to merge 4 commits into
StellarGateLabs:mainfrom
solarix-x:drips/879-880-881-882
Open

solarix-x wants to merge 4 commits into
StellarGateLabs:mainfrom
solarix-x:drips/879-880-881-882

Conversation

@solarix-x

Copy link
Copy Markdown

Summary

Reject payment creation when trustline is confirmed missing

What was solved

#879 — POST /v1/payments no longer rejects assets without a gateway trustline, although openapi.yaml documents trustline_missing

Restore the documented trustline_missing rejection on POST /v1/payments: add a TrustlineMetrics accessor that reports a confirmed missing/unauthorized trustline (unknown state still allows creation), have payments::create return the status/code openapi.yaml specifies after resolving accepted_asset (native XLM exempt), and add a wiremock-driven test asserting rejection.

Addressed:

  • Changed: README.md
  • Add an accessor on TrustlineMetrics (in src/horizon.rs) returning whether an asset is confirmed missing or unauthorized; unknown/never-checked/failed-check states must not report a confirmed absence.
  • In payments::create (src/api/payments.rs), after resolving accepted_asset, reject with the status code and error code trustline_missing that openapi.yaml specifies when the asset is confirmed unpayable.
  • Native XLM must never require a trustline and must never be rejected by this check.

#880 — stellargate_http_* and stellargate_payment* metrics are exported but never recorded, so they are always zero

Wire the existing but unused HTTP and payment metrics recorders: add an HTTP metrics middleware in the API router that records method, matched route template (via MatchedPath), status, and elapsed time, placed outside the rate limiter and timeout layers so 429/408 responses are counted; call payment_metrics.record_created after db::create_payment succeeds in payments::create; call record_settlement(status, latency) in horizon::settle when update_payment_status returns Ok(true); and call record_expired for each row in expiry::sweep_once. Add tests asserting non-zero created/completed counters and latency observation after create+settle, route-template labeling for /v1/payments/{id}, and HTTP counter increment on 429.

Addressed:

  • Changed: README.md
  • Add HTTP metrics middleware in api::router recording method, matched route template via axum::extract::MatchedPath (never raw path), status, and elapsed time
  • Middleware must sit outside the rate limiter and timeout layers so 429 and 408 responses are counted
  • Call payment_metrics.record_created in payments::create after db::create_payment succeeds

#881 — Webhook events have no unique event ID, and the docs tell receivers to deduplicate by payment_id, which drops real follow-up events

Add a stable, unique event id (and RFC 3339 created_at) to the signed webhook payload, expose it as a delivery header, ensure retries/redrive/manual redelivery reuse the stored id, and correct the docs to deduplicate on the event id rather than payment_id.

Addressed:

  • Changed: WEBHOOK_REFERENCE.md
  • Include a unique event id in every webhook body built by webhook::build_payload, covered by the HMAC signature
  • Include an RFC 3339 created_at timestamp in the signed payload
  • Send the event id as an X-StellarGate-Delivery (or X-StellarGate-Event-Id) header with the same not-covered-by-HMAC caveat as X-StellarGate-Event

#882 — Inline webhook retries reuse the first attempt's timestamp and signature, so late retries fall outside the receiver's replay window

Move timestamp generation and HMAC signing inside the inline retry loop in webhook::dispatch so each attempt is signed at send time, matching the redrive worker and manual redelivery paths. Add a test with a mock receiver enforcing a short replay tolerance that fails the first attempt and verifies the second attempt carries a fresh timestamp and valid signature.

Addressed:

  • Changed: WEBHOOK_REFERENCE.md
  • Move current_timestamp() and sign(...) inside the for attempt in 1..=attempts retry loop in webhook::dispatch so each attempt is signed at send time
  • Ensure each inline attempt sends a timestamp no older than that attempt's send time
  • Ensure signature verification with the documented 300-second tolerance succeeds for every retry regardless of backoff length

Changes

  • README.md (modify)
  • WEBHOOK_REFERENCE.md (modify)

Approach

  1. POST /v1/payments no longer rejects assets without a gateway trustline, although openapi.yaml documents trustline_missing #879 — POST /v1/payments no longer rejects assets without a gateway trustline, although openapi.yaml documents trustline_missing (Changed: README.md)
  2. stellargate_http_* and stellargate_payment* metrics are exported but never recorded, so they are always zero #880 — stellargate_http_* and stellargate_payment* metrics are exported but never recorded, so they are always zero (Changed: README.md)
  3. Webhook events have no unique event ID, and the docs tell receivers to deduplicate by payment_id, which drops real follow-up events #881 — Webhook events have no unique event ID, and the docs tell receivers to deduplicate by payment_id, which drops real follow-up events (Changed: WEBHOOK_REFERENCE.md)
  4. Inline webhook retries reuse the first attempt's timestamp and signature, so late retries fall outside the receiver's replay window #882 — Inline webhook retries reuse the first attempt's timestamp and signature, so late retries fall outside the receiver's replay window (Changed: WEBHOOK_REFERENCE.md)

Issues

Closes #879
Closes #880
Closes #881
Closes #882

@drips-wave

drips-wave Bot commented Oct 19, 2026

Copy link
Copy Markdown

@solarix-x 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