Skip to main content
Rehearsed end to end for testnet on the deployed service on 2026-11-17, together with the fee sponsor rotation, with step 10 on 2026-11-18; the measured times are from that rehearsal. Not yet rehearsed on mainnet. apps/api/tests/integration/relay-rotation.integration.test.ts runs the same sequence against a local API on every pull request.
The relay account (the code calls it the mediator) co-signs the forward of an exchange close. Clients never store its address: the API puts it into every exchange close it builds, so a rotation changes only the API’s configuration, a repository variable and one row of the monitoring plan.

When

  • Compromise: the key may be exposed, or S4a.Information.1.M.1, S4a.Spoofing.1.M.1 or the forward check fired. Do step 1, then the rest without pausing.
  • Planned: a scheduled rotation, a maintainer leaving. Skip step 1.

Blast radius

  • Only exchange closes. Closes into a wallet the user controls never touch the relay account.
  • A close built against the old account but not yet co-signed is refused once the new revision serves, with 400 transaction_structure_not_allowed, because its forward names the old account. Nothing has been submitted, so the client builds it again and gets the new account.
  • A close co-signed before the switch still lands while the old account exists, which is why step 8 waits before the drain. One submitted after the drain fails as a whole (op_no_account on the merge, op_no_source_account on the forward): no XLM moves, the account pays one fee and stays open, and building again succeeds.
  • On mainnet, at most the old account’s minimum balance, 1 XLM, is ever at risk, because it holds nothing else. A testnet account created through friendbot holds far more: the testnet accounts retired on 2026-11-17 held about 10,000 XLM each, which the drain in step 9 returned to the operator.

Steps

<net> is testnet or mainnet and <NET> the same in capitals. Run every step in one shell, started like this, so a failed command in a pipe stops the step and the keys live only in a throwaway CLI configuration:
Each step that changes the service is an env-only revision. A deploy run that starts in between deploys its candidate with the environment the service has at that moment, so it can carry a half-done rotation forward or undo a step. Hold merges that deploy the API from step 4 until the last env-only revision of the rotation serves (step 5 here, or the sponsor’s switch when both rotate), and check that no run is in progress (gh run list --workflow deploy-api.yml --status in_progress) before each gcloud run services update. operator is the operator account that funds the new relay account and receives the old one’s balance; paste its secret at the prompt. It must not be either relay account, and it must be the address in the Rotation operator (<net>) row of the inventory table and the OPERATOR_ADDRESS_<NET> repository variable: the forward check recognises the drain in step 9 only as a merge into that address.
  1. Compromise only: pause exchange closes.
    Expected: Done., and POST $API/v1/<net>/mediator/sign answers 503 exchange_forward_paused.
  2. Generate the new key, without showing it:
    Expected: a G... address. This is <new> below; <old> is the address in the MEDIATOR_ADDRESS_<NET> repository variable.
  3. Create the account at its minimum balance only, 1 XLM (two base reserves), from the operator account. Never fund it through friendbot or with more: a relay account holds no spendable XLM (threat model, surface 4a).
    Expected: 1.0000000 (use https://horizon.stellar.org on mainnet).
  4. Check the bindings, pin them, then add the secret as a new version. An entry with valueFrom.secretKeyRef comes from Secret Manager. If the relay secret is bound to latest, a new version would reach a fresh instance of the current revision before the public key changes, and that instance would answer 503 mediator_key_misconfiguration: pin the current version number first. On the production service both the relay and the sponsor secret were bound to latest at the 2026-11-17 rehearsal, so expect to pin. When the fee sponsor rotation runs in the same session, pin both secrets in one revision (23 seconds on 2026-11-17):
    Drop the FEE_ACCOUNT_SECRET_<NET> binding from the update when only the relay rotates, and skip the update when the binding already names a version. Expected: the binding names a version number, and Created version [<n>] of the secret [<relay-secret>]. The tr matters: a trailing newline makes the key unreadable. With pipefail set, a failed keys secret stops here instead of storing an empty version.
  5. Switch the API in one revision. The secret and the public key must change together; a revision where they disagree answers 503 mediator_key_misconfiguration.
    If MEDIATOR_PUBLIC_<NET> is bound to a secret as well, add its version as in step 4 and bind it in the same --update-secrets instead. Expected: Done. and the new revision serving 100 percent; a describe now shows version <n> and <new>. Note the time: step 8 counts from it. Then curl -s "https://api.lumenwipe.com/v1/<net>/mediator/check/<an exchange address>" -H "Authorization: Bearer $KEY" | jq .available must print true; false means the secret and MEDIATOR_PUBLIC_<NET> disagree or one is unset, and for a mismatch the API logs the mediator key does not match its configured public key.
  6. Confirm the new account co-signs. On testnet, run the full exchange flow through the deployed web app:
    Expected: it ends with E2E PASS, and its forward shows on Horizon as a payment from <new>. On mainnet there is no scripted check, because it would close a real account: confirm instead with the first real exchange close, whose forward must be a payment from <new>. In a compromise, turn MEDIATOR_FORWARD_ENABLED back to true once this passes.
  7. Point the monitors at the new account and keep the old one watched, before the drain, so the new account is watched from now on and no check reads a drained current address. Edit the repository variables and, in the same hour, merge a pull request that changes the Mediator account (<net>) row of the inventory table to <new> (on mainnet, also ACCOUNTS in apps/web/public/.well-known/stellar.toml). The config step fails until the variable and the table agree. Two more places hold the address:
    • apps/api/tests/unit/service-account-monitors.test.ts pins the current testnet addresses as MEDIATOR and SPONSOR; change them in the same pull request. That makes the pull request deploy the API, so merge it only once the last env-only revision of the rotation serves.
    • On testnet, the playground’s Vercel variable PLAYGROUND_EXPECTED_MEDIATOR_TESTNET (and PLAYGROUND_EXPECTED_FEE_ACCOUNT_TESTNET for the sponsor). After changing it, deploy the playground with vercel deploy --prod from a clean checkout of main linked to the playground project: a plain vercel redeploy is cancelled by the playground’s ignored build step when no playground file changed.
    Expected: every job succeeds, and the config step lists both mediator (<net>): <new> and mediator (retired) (<net>): <old>, drained into <operator address>. Check for the retired line: a misspelled variable name is never passed to the workflow and would leave the old address unwatched without an error.
  8. Wait 6 minutes from the switch in step 5. A signed close is valid for at most 330 seconds (MAX_SIGNED_VALIDITY_SECONDS), so after this no close co-signed by the old key can still land.
  9. Drain the old account. The operator is the transaction source and the old key signs only the merge, so the old address never sources a transaction and its keys check stays quiet. The old key is piped from its previous secret version into the throwaway configuration, never shown:
    Expected: stellar tx send exits with status 0 and prints the transaction result, and Horizon answers 404 for <old>. The next monitor run stays green: the keys check sees no transaction sourced from <old>, and the forward check reads this merge into the operator as the drain. For the rest of the 24 hours, any other transaction the old key signs, or any merge or payment out of <old> to another address, is reported as a suspected key compromise. The bump-sequence to 0 is a no-op that lets the operator be the source; the fee covers its two operations. In a compromise, whoever holds the old key can make the merge fail first (op_has_sub_entries, by adding a trustline or a signer): the most that costs is the old account’s 1 XLM, and the keys check reports the transaction that did it, whoever sourced it.
  10. After 24 hours, stop watching the old account and clean up:
    Use the address of an exchange that requires the relay. Expected: 200 and true, since the service binds version <n>, not the disabled one; false means the key the API holds does not match MEDIATOR_PUBLIC_<NET>. The next monitor run lists only <new>. The new key now lives only in Secret Manager; keep a copy where the team keeps keys before removing the throwaway configuration, if the team’s policy asks for one.

Measured times

From the testnet rehearsal on the production service, run together with the fee sponsor rotation:

Confirm the fix

  • test:mediator passes against the new account (step 6) and Horizon shows <old> as 404 (step 9).
  • The on-chain monitors run green with the new address, and with the retired one for 24 hours (step 7).
  • To roll back before step 9, bind the previous secret version and the old public key in one gcloud run services update, as in step 5. After step 9 the old account is gone; rotate forward instead.