Skip to content

Add an authenticated, idempotent grants API on an internal listener - #18

Merged
masih merged 4 commits into
mainfrom
masih/1795299140-grants
Nov 22, 2026
Merged

masih merged 4 commits into
mainfrom
masih/1795299140-grants

Conversation

@masih

@masih masih commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Partners, Harpoon and other test workloads need funds beyond what the public faucet gives out, and the only safe sender is wellspring itself: Giga admits a sender's exact next nonce only, so a second process signing with the faucet key would collide with it. This adds a grants API that stores each grant as a claim of kind grant with its own amount, so it goes through the same store, signer, nonce order and receipt check as public claims. Grants skip the captcha, cooldowns and recipient balance cap, are capped per grant by --grant-max-wei (100k SEI by default), and are refused if, together with every unsettled claim, they would take the balance below --min-faucet-balance-wei. That check reads the faucet balance afresh, and counts claims confirmed since that read as unsettled, because the balance may not show them yet.

The API listens on --admin-addr, a separate listener and Service port that the HTTPRoute never routes. Callers present a Kubernetes ServiceAccount token for the wellspring audience, which wellspring checks with the TokenReview API against an allowlist of exact namespace/serviceaccount pairs. Config load refuses wildcards such as namespace/*, because one would let every pod in a namespace, validators and RPC nodes included, make grants. This works the same for a pod with a projected token and for a human, and leaves no shared secret to rotate. Requiring the wellspring audience also means wellspring never receives a token the Kubernetes API itself would accept. With admin.enabled, the chart mounts a token for wellspring's own ServiceAccount (still not automounted), binds it to system:auth-delegator, and admits the allowlisted namespaces to the admin port in the NetworkPolicy. Any failure to review a token refuses the grant with 503.

Every grant carries a caller-chosen ID, scoped to the caller's ServiceAccount and unique in the database, so a retried request or Job returns the grant already made instead of paying again, and reusing an ID for a different address or amount gets 409. topUpToWei sends only what brings the recipient to a balance, computed once when the grant is created. While a transfer to the recipient is unsettled, or confirmed after the balance read, that balance is not final, so the top-up is refused with 503 and the CLI retries; a zero top-up is then truly confirmed. A retry returns that original grant even after the balance moved. The image's new wellspring grant subcommand requests a grant and waits for its receipt, so a test Job can fund itself from an init container. Humans run the same command with --kube-context instead of --url and --token-file, e.g. wellspring grant --kube-context <ctx> --to 0x… --sei 5000 --reason …. It shells out to the user's kubectl to mint a short-lived grants-operator token and port-forward to the admin port, which keeps EKS and other exec auth plugins working without a client-go dependency, then waits for the receipt and stops the forward. Without --id the grant is named <address>-<amount>sei-<UTC date>, so rerunning the same command that day cannot pay twice. Grant responses now carry the chain ID, chain name and public RPC so the CLI can say where to look the transaction up. README documents both patterns and installing with go install …@v0.2.0, and RUNBOOK covers manual grants and the two new alerts.

wellspring_claims_finished_total gains a kind label, and grants add wellspring_grants_total{outcome} and wellspring_granted_wei_total, which dashboards need to count grants in runway estimates.

Partners, load tests and other test workloads need funds beyond the public
faucet's limits. Grants go through the same store, signer and nonce order as
claims, so they never compete for a nonce, and callers authenticate with
Kubernetes ServiceAccount tokens reviewed by the TokenReview API.
@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review November 21, 2026 22:28
seidroid[bot]
seidroid Bot previously requested changes Nov 21, 2026

@seidroid seidroid Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds an authenticated, idempotent grants API on a separate admin listener. Grants are stored as claims of kind grant, and the change also adds the wellspring grant CLI, chart wiring and alerts. Two things block it: the minimum-balance check uses a faucet balance up to 60s old, so back-to-back grants can overspend; and a top-up that pending transfers already cover reports confirmed with no receipt. On the other readings, I kept codex's grants.go:68 (top-up confirms with no receipt) as a blocker and its admin.go:144 (recipient-balance race) as a suggestion. I dropped its grants.go:78 (gas fees not reserved): each transfer costs at most 21000 gas at the 10 gwei fee cap, about 0.0002 SEI, which the 1000 SEI floor absorbs. Go was not available, so tests were not run.

Blocking

2 findings on the changed lines, as inline comments.

Non-blocking

1 finding on the changed lines, as inline comments.

seidroid review · decision request_changes · session dd9d53f09f9f4335a9516ed879781c4e · turn resp_claude_08b3cbbc2373deb69924fac2d9e089c9 · item 33eb233732535a9fa4826734eb570647

Findings: 2 blocking | 1 non-blocking | 3 posted inline

Comment thread internal/api/admin.go Resolved
Comment thread internal/store/grants.go Resolved
Comment thread internal/api/admin.go Resolved
A grant was checked against a faucet balance up to a minute old, so a grant
confirmed since could be spent twice, and a top-up covered by a transfer still
in flight reported confirmed before any funds arrived. Grants now read the
balance when admitted and count claims confirmed since as unsettled, and a
top-up is refused, for the CLI to retry, while a transfer to its recipient is
settling.

@seidroid seidroid Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push fixes all three findings from the first review. Admission now reads the faucet balance fresh and counts claims confirmed since that read as unsettled; a top-up is refused as busy while a transfer to its recipient is in flight or confirmed after the read, so a zero top-up is truly confirmed; and taking the read time before the recipient's balance is read closes the race. Codex's only reading this time (gas fees not reserved at grants.go:83) is dropped as before: a transfer costs at most 21000 gas at the 10 gwei fee cap, about 0.0002 SEI, which the default 1000 SEI floor absorbs. Go was not available, so tests were not run.

seidroid review · decision approve · session dd9d53f09f9f4335a9516ed879781c4e · turn resp_claude_13be7259e43b25c72ad843191ea877ec · item 09a806f8e2e95459914de2b4afcf50e2

Findings: 0 blocking | 0 non-blocking | 0 posted inline

@seidroid
seidroid Bot dismissed their stale review November 21, 2026 22:37

Superseded: the latest review found nothing blocking in this change.

@masih

masih commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@seidroid review

@seidroid seidroid Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three earlier findings are fixed: admission now reads the faucet balance fresh and counts claims confirmed since the read; top-ups are refused as busy while a transfer to the recipient is unsettled or confirmed after the read; and the read time is taken before the recipient balance. This push also drops wildcard allowlist entries and adds a kubectl-based laptop flow to wellspring grant, with no new blockers. Codex's only reading (grants.go:83, fees not reserved) is dropped again because a transfer's fee is at most about 0.0002 SEI against a 1000 SEI floor; Go was not available, so tests were not run.

1 nit, not posted on the code
  • cmd/wellspring/grant.go:278 — A non-JSON response is turned into a retryable error before the status code is checked, so a plain-text 4xx is retried until --timeout (10 minutes by default) instead of failing fast. The mux's own 404/405 and a proxy's 403 are examples.

seidroid review · decision approve · session dd9d53f09f9f4335a9516ed879781c4e · turn resp_claude_068b7cbdc00d6064329cbf7e544227e1 · item 84db4cb8fe1e5575bcb38249127b1582

Findings: 0 blocking | 0 non-blocking | 0 posted inline

@masih
masih merged commit ce75ec6 into main Nov 22, 2026
16 checks passed
@masih
masih deleted the masih/1795299140-grants branch November 22, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant