Introducing a new way to review your PRs.

Read the announcement

solana-foundation / pay

CLI for Agentic payments (x402, MPP, AP2).

View on GitHub

30 documents · Updated Nov 11, 2026

docs / deployment-payment-policy

Deployment payment policy

Deployment payment policy controls paid access for each deployed service. It binds a request to the named deployment, checks the current price and payout rules, and creates a durable payment session only when the policy is valid and the payment path is available.

Policy resolution

Policy source

The policy resolver is an authenticated lookup between the payment gateway and the deployment control plane. It uses the request host and path as selectors, but the gateway controls the lookup origin and identity audience. The resolver checks the policy on every paid admission so a deleted, expired, or changed deployment does not keep access through an old result.

Configuration is either fully enabled or fully disabled. Enabling policy mode requires the policy URL, token audience, and deployment domain. The URL must use HTTPS and the fixed /__402/payment-policy route. Invalid or partial configuration stops policy mode from starting rather than silently switching to another authority.

The lookup has bounded response size, time, and concurrent work. A failed identity lookup or policy lookup returns an unavailable result. It never falls back to a static policy or follows a redirect.

References: rust/…/deployment_policy.rs• L13-15 rust/…/deployment_policy.rs• L109-173 rust/…/deployment_policy.rs• L215-241

Policy content

Each response carries the deployment identity, a policy version, a price in six-decimal USDC base units, an expiry time, the supported payment scheme, and an ordered payout allocation. The identity must agree with the requested host and with the deployment resource named by that host. This prevents one deployment from using another deployment's price or seller.

The policy accepts only mpp-session. Its allocations use basis points and exact micro-USD amounts. The amounts must equal the price, the basis points must total 10,000, recipients must be distinct valid non-zero Solana keys, and the primary allocation must receive any rounding remainder. Unknown fields and malformed values fail closed.

The policy expiry controls new admissions. It is not part of the durable payment identity, so an already authorized channel can still settle the funds it accepted.

References: rust/…/deployment_policy.rs• L41-62 rust/…/deployment_policy.rs• L285-370 rust/…/deployment_policy.rs• L19-52

Request enforcement

Host and request admission

The gateway treats the exact configured apex as control-plane traffic and treats only canonical deployment subdomains as paid deployment traffic. It rejects alternate host forms and invalid deployment identifiers before it asks for a policy. The request path is also checked as an exact bounded selector, with reserved control routes excluded.

For a deployment request, the gateway performs this sequence:

flowchart TD
    A[Request] --> B[Read trusted gateway host]
    B --> C{Canonical deployment host?}
    C -- No --> D[Reject invalid deployment host]
    C -- Yes --> E[Validate path]
    E --> F{Valid policy lookup?}
    F -- No --> G[Return policy unavailable]
    F -- Yes --> H[Validate identity price expiry and payout]
    H --> I{Valid payment policy?}
    I -- No --> G
    I -- Yes --> J[Build deployment session]
    J --> K{Payment supplied?}
    K -- No --> L[Return MPP session challenge]
    K -- Yes --> M[Verify session and forward request]

Every failure before forwarding blocks paid access. A deployment request cannot select a policy with a caller-controlled forwarded host, and it cannot use a fleet-wide fallback when its own policy is missing.

References: rust/…/gate.rs• L549-577 rust/…/deployment_policy.rs• L198-241 rust/…/deployment_policy.rs• L429-452

Payment session

The gate turns a valid policy into a fixed-price MPP session. It uses the policy price and ordered payout rules to create the challenge. An x402 payment is rejected for deployment traffic because deployment access supports the MPP session scheme only.

An authenticated session must match the expected session intent and Solana method before the gateway forwards the request. If the upstream returns an error or a streaming response that cannot be charged safely, the request is not treated as a paid success.

References: rust/…/gate.rs• L480-545 rust/…/http402.rs• L887-962

Durable payment state

Session binding

The deployment session stores a validated snapshot of the deployment identity and monetary terms. The snapshot includes the policy version, price, and allocation order, so later settlement does not need the live policy service. A new policy version therefore affects new sessions without changing the payout terms of an existing session.

The operator owns the payment channel used for delegated deployment sessions. The policy's primary recipient and remaining allocations become the ordered payout after delegation. The conversion preserves the primary recipient's rounding remainder and rejects a binding that could redirect it.

References: rust/…/deployment_policy.rs• L36-64 rust/…/deployment_policy.rs• L249-363 rust/…/session.rs• L1656-1710

Reservation and settlement lifecycle

The session lifecycle protects payment capacity while a request is being opened or used. A reservation has an owner, amount, and expiry. A close claim cannot overtake a live reservation, and a stale release cannot clear a newer reservation. These transitions share the durable channel update so close, reservation, and voucher work remain ordered.

After a gateway restart, the settlement worker restores the binding and payment configuration from durable channel state. It checks the saved payout, amount, decimals, network, and operator before settlement. Settlement uses the saved snapshot rather than the current policy service, and a second worker run does not distribute the same accepted vouchers again.

References: rust/…/deployment_policy.rs• L66-246 rust/…/settle_sessions.rs• L590-636 rust/…/settle_sessions.rs• L667-692

Integration coverage

End-to-end payment behavior

The end-to-end test runs the gateway with a real local payment-channel program, dedicated Redis state, local policy and identity services, and a real settlement worker. It checks the full path from host-specific policy lookup to funded request, reconnect, channel close, and on-chain distribution.

The scenario covers these product guarantees:

  • Two deployments keep their prices, sellers, and channel proofs separate.
  • Invalid host forwarding, missing policy, provider failure, expired identity, upstream failure, and unsupported response types do not charge the payer.
  • A policy update affects only a new session. Removing the policy blocks new access but does not invalidate an existing accepted session.
  • Gateway restart does not lose accepted payment state.
  • Recipient balances match the saved allocation after settlement. Unused funds return to the payer.
  • Concurrent or repeated settlement does not pay the same channel twice.

References: rust/…/deployment_policy_e2e.rs• L229-359 rust/…/deployment_policy_e2e.rs• L362-442

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the wire policy fields and the durable binding fields aligned. The live response includes expiry and scheme data, while the durable snapshot intentionally keeps the terms needed for later settlement.
  • Keep allocation rounding rules consistent between policy validation, delegated payout conversion, and worker snapshot checks.
  • Keep host derivation and deployment identity checks aligned. A new host format must not allow a policy for a different deployment.
  • Keep deployment session requirements aligned with the external lifecycle worker. Static stores, non-operator vouchers, or chain adoption cannot safely serve this policy mode.
  • Keep the end-to-end fixture on real channel state. Replacing it with prebuilt channel data would no longer verify restart recovery or settlement idempotence.

Important failure modes

TriggerConsequenceGuard
Policy fields do not match the requested deployment hostPaid admission stopsIdentity, owner, resource, and host checks reject the response
Policy service or identity provider is missing or failsThe request is unavailable and is not chargedPer-request authenticated lookup with no stale or static fallback
Allocation amounts or basis points do not reconcileNo session is createdExact total, recipient, and rounding validation
A caller supplies an alternate host or reserved pathThe request cannot select another policy routeCanonical host and path checks before policy lookup
A policy changes after a channel opensExisting accepted funds use the wrong live terms if settlement re-reads policyDurable binding and worker validation use the original snapshot
Two workers try to settle one channelA recipient could receive duplicate payoutDurable close claims and idempotent distributed channel state

Key files

FileWhy to read it
rust/…/deployment_policy.rsDefines policy lookup, request selectors, response checks, and the fixed payment contract.
rust/…/deployment_policy.rsDefines the durable policy snapshot, payout conversion, reservation, and close state.
rust/…/gate.rsShows how a resolved policy becomes an admission decision or an MPP challenge.
rust/…/session.rsShows how deployment policy terms become a request-only payment session and what the session template requires.
rust/…/settle_sessions.rsShows how durable policy state is restored and checked before settlement.
rust/…/deployment_policy_e2e.rsVerifies isolation, failure behavior, reconnect recovery, payout, and settlement idempotence end to end.