fix(payments): drop the notification sender-IP gate; re-check on its own cadence
CI / changes (pull_request) Successful in 3s
CI / unit (pull_request) Successful in 11s
CI / integration (pull_request) Successful in 21s
CI / ui (pull_request) Successful in 1m16s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m55s
CI / changes (pull_request) Successful in 3s
CI / unit (pull_request) Successful in 11s
CI / integration (pull_request) Successful in 21s
CI / ui (pull_request) Successful in 1m16s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m55s
A real test payment on the contour exposed both problems at once. YooKassa
delivered the notification five times; all five were rejected because the
backend saw the sender as 10.77.0.1 — the contour sits behind a tunnel and
cannot observe real client addresses, the same reason the IP bans in this
repository are prod-only. The chips were not lost (the reconcile sweep would
have credited them), but the primary path was dead and the customer was left
watching an unchanged balance.
The address check is removed rather than made conditional. It never was the
security boundary — the confirming GET /v3/payments/{id} is — and the one thing
it bought is already bought earlier and far more tightly: the order is resolved
from the notification's metadata *before* any provider call, so a notification
naming no known order costs a single indexed read and stops there. Guessing a
live order id means guessing a uuid. Against that, an address check adds nothing
and breaks every deployment that cannot see real client addresses, while turning
any future change to YooKassa's published ranges into a silent degradation.
The second problem was mine. The reconcile threshold was keyed off the order
lifetime, so a lost notification cost the customer the full 30-minute TTL before
the chips landed. Those are different questions: the lifetime governs how long a
customer may take to pay, the re-check governs how soon we notice a lost
callback. Split apart — `payments.ReconcileAfter`, one minute, swept on every
reaper tick. The bound D49 was chosen for survives: the calls one order can
cause are still its lifetime divided by the sweep interval, a handful, not an
open-ended poll. Worst case for a failed notification drops from ~30 minutes to
~5; an order the customer is still paying for is left alone.
Tests: the foreign-sender test is replaced by the two properties that now carry
the load — a notification naming an unknown order makes no provider call at all,
and a genuine notification is honoured whatever address it appears to come from.
Plus one pinning that a seconds-old order is not polled.
The shared bundle budget goes 31 -> 32 KB, with the reason recorded in the
script header: every user-visible string lands in that chunk and it had been
sitting 40 bytes under the cap.
Decisions D48 and D49 revised.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -127,16 +128,24 @@ func (s *Service) OrderByProviderPayment(ctx context.Context, provider, provider
|
||||
// run of provider calls.
|
||||
const reconcileBatch = 50
|
||||
|
||||
// PendingForReconcile returns the pending orders that have reached their expiry age while carrying a
|
||||
// provider payment id — the ones where the money may well have moved but no callback ever told us.
|
||||
// The caller asks the provider for each one's real outcome before ExpireOrders writes them off.
|
||||
// Orders that never reached a payment are not returned: there is nothing to ask about.
|
||||
// ReconcileAfter is how old a pending order must be before the provider is asked what became of it.
|
||||
// It is deliberately NOT the order lifetime: that governs when an unpaid order is written off, which
|
||||
// answers "how long may a customer take to pay", a different question from "how soon should we
|
||||
// notice a lost callback". Tying the two together would make a customer wait a full lifetime for
|
||||
// chips whenever the notification path fails. A minute is long enough that an order the customer is
|
||||
// still paying for is not polled, and short enough that a failure costs minutes, not half an hour.
|
||||
const ReconcileAfter = time.Minute
|
||||
|
||||
// PendingForReconcile returns the pending orders old enough to re-check that carry a provider payment
|
||||
// id — the ones where the money may well have moved but no callback ever told us. The caller asks the
|
||||
// provider for each one's real outcome. Orders that never reached a payment are not returned: there
|
||||
// is nothing to ask about, and neither are orders younger than ReconcileAfter, so an order the
|
||||
// customer is still paying for is left alone.
|
||||
//
|
||||
// The sweep repeats until the order settles or is written off, which bounds the provider calls one
|
||||
// order can cause to its lifetime divided by the sweep interval — a handful, not an open-ended poll.
|
||||
func (s *Service) PendingForReconcile(ctx context.Context) ([]OrderRef, error) {
|
||||
ttl, err := s.store.orderTTL(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows, err := s.store.pendingForReconcile(ctx, ttl, s.clock(), reconcileBatch)
|
||||
rows, err := s.store.pendingForReconcile(ctx, int(ReconcileAfter.Seconds()), s.clock(), reconcileBatch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user