Paper Sats: design and print paper notes that carry sats. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 KiB
Runbook
For whoever operates Paper Sats. Commands assume infra/docker-compose.prod.yml, abbreviated as dc.
Deploy
The Docker images and compose file have never been run. Docker was unavailable where they were written, so only docker compose config was checked. Expect to fix small things the first time.
git pull, thendc up -d --build. Migrations run on their own beforewebandworkerstart, and a failed migration stops both.- Check
GET /api/health. It should answer 200 with{ "ok": true, "db": true, "worker": true }. It answers 503 until the worker's first heartbeat, then whenever the database or the worker is down. Point your uptime monitor here.
/api/live only says the web process is serving. Containers use it, so a dead worker doesn't restart the site.
First deploy
Set these in .env. A live web or worker exits at startup and lists the keys if the required ones are missing or unsafe.
| Key | Note |
|---|---|
APP_URL |
Required. https |
SESSION_SECRET |
Required. openssl rand -base64 32 |
FEE_WALLET_SEED |
Required. openssl rand -hex 32. Back it up: see below |
DEFAULT_MINTS, DEFAULT_RELAYS, DEFAULT_BLOSSOM_SERVERS, ADMIN_NPUBS |
Required |
LEGAL_OPERATOR, LEGAL_CONTACT |
Required. Shown on /terms and /privacy |
FEE_PAYOUT_LNBITS_URL, FEE_PAYOUT_LNBITS_INVOICE_KEY |
Required, unless PAYOUTS_DISABLED=true says on purpose that nothing is paid out |
FEE_ACCEPTED_MINTS |
Optional. Tokens from other mints must settle over Lightning before they count |
ALERT_WEBHOOK_URL |
Optional, recommended. Receives { text, event, ... } |
POSTGRES_PASSWORD, DOMAIN, TLS_DIR, BACKUP_DIR |
Required by the compose file |
Keep SSRF_ALLOW_ORIGINS, CSP_EXTRA_ORIGINS and PRODUCTION_CHECK empty.
TLS
TLS_DIR holds fullchain.pem and privkey.pem. nginx doesn't renew them. With certbot on the host, renew on a timer and reload afterwards: certbot renew --deploy-hook "docker compose -f infra/docker-compose.prod.yml exec nginx nginx -s reload".
HSTS is sent without preload. Preload is hard to undo, so add it only once the domain is settled.
Rotate secrets
SESSION_SECRETalso protects held fee proofs. Before rotating it, run a payout so no proofs are held (select sum(amount_sats) from fee_proofs where paid_out_at is null and spent_at is nullshould be empty). A proof row sealed under an old secret can't be read: it raisesfee.proofs_unreadable, is skipped, and its value stays stuck until the old secret is back. Rotating logs nobody out, because sessions are hashes, but stored IP hashes stop matching, which is harmless.FEE_WALLET_SEEDrecovers fee swaps whose answer was lost. Rotating only affects orders still in flight. Losing it loses nothing already saved.- LNbits keys. Replace them in
.envand restartwebandworker.
Fees and payouts
How a Cashu fee is counted:
- Accepted mint: swapped into server proofs, saved, and counted as received (
cashu-held). Paid out later in a group. - Any other mint: counted only after its melt is seen by LNbits (
cashu-melted). Until then the order staysfee_state = 'pending'and the user can still download their notes. The worker retries every 10 minutes for 24 hours, then the order isfailed.
Every melt writes a payouts row first and reserves its proofs through fee_proofs.payout_id.
payouts.state |
Meaning | Action |
|---|---|---|
pending |
Melt started or about to. After 5 minutes the reconcile job decides | None |
paid |
LNbits saw the payment | None |
failed |
Nothing was spent, and the proofs were released to try again | Read error if it repeats |
unconfirmed |
The mint says the proofs are spent but LNbits never saw the payment. Reconcile keeps checking. The proofs stay reserved, so they can't block other fees | Compare the mint and LNbits by payment_hash. Value may be lost to the mint |
stub |
No LNbits credentials. Nothing was paid. Written once a day per mint | Set LNbits |
fee_proofs.spent_at is set when the mint calls proofs spent with no payout of ours behind them. That value is gone. It should not happen, so look into it.
An unknown mint's proofs from a failed order stay stored and are never melted again automatically. They can be junk from a mint that signs anything, so don't treat them as revenue.
A Cashu fee is resent by the user's browser when they next open the download page, because the server never keeps the token. If its swap went through but the answer was lost, that resend restores the proofs from FEE_WALLET_SEED. If they never come back, the fee stays lost. The notes aren't affected. Change from a melt is saved only if the melt's answer arrives.
Alerts
Each is an error log line and, with ALERT_WEBHOOK_URL, a webhook post at most once an hour per subject.
| Event | Means | Do |
|---|---|---|
fee.failed_permanently |
An order's fee never arrived in 24 hours. The user isn't affected | Review in the admin area. Many at once from one mint suggests abuse or an outage |
fee.proofs_unreadable |
A proof row can't be decrypted | Check whether SESSION_SECRET changed |
fee.proofs_already_spent |
See spent_at above |
Investigate |
payout.failed |
A group payout could not start | Check the mint and LNbits |
payout.spent_not_received |
See unconfirmed above |
Compare the mint and LNbits |
payout.stuck_pending |
The mint has held proofs as pending for over 7 days | Contact the mint |
Also watch for job.failed and unhandled in the logs. Both carry a redacted stack.
A mint is down
Orders in progress resume when it returns, because the browser keeps its journal. Status shows Could not check and keeps the last known state. Remove the mint from DEFAULT_MINTS if the outage is long. New fee tokens from it fail and stay fee_pending.
A relay or Blossom server is down
The library keeps working with the others and shows "Loaded from n of m relays". Publishing succeeds on any relay that accepts. Replace a dead default in .env and restart.
Restore the index
design_index can be rebuilt. To rebuild it:
truncate design_index;
delete from settings where key = 'indexer_cursor';
The worker refills it from relays within a minute, and uses are recomputed from design_uses.
Backups
The backup service writes a dump a day to BACKUP_DIR and keeps 14. Copy them off the machine: a dump on the same disk doesn't survive losing the disk. The dumps hold no note secrets, but they do hold encrypted fee proofs, so restoring needs the same SESSION_SECRET. Keep that and FEE_WALLET_SEED somewhere separate from the dumps.
Check the log for backup FAILED, and practise a restore before you need one:
createdb restore_test
pg_restore --no-owner -d restore_test paper-YYYY-MM-DD.dump
psql restore_test -c 'select count(*) from orders'
Release checklist
pnpm lint,pnpm typecheck,pnpm test,pnpm buildpass.pnpm test:e2epasses against local services.pnpm audit --prod --audit-level=highis clean. CI requires it.E2E_LOAD=1 pnpm --filter @paper-sats/web exec playwright test --project=chromium e2e/load-500.spec.tspasses.- A small real Lightning payment and a real LNbits payout, including a melt from a mint outside the accepted list.
- A real printed note scanned by real wallets of both types.
/privacyand/termsreviewed for your jurisdiction.