Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions scripts/resolver/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Chain settings.
# ============================================================================

# Ethereum network: mainnet (the SNRC `.testing` contracts live on mainnet)
# Ethereum network: mainnet (the SNRC `.testing` and `.simplex` contracts are on mainnet)
# or holesky (test). Mainnet full sync needs ~1 day and ~1.2 TB NVMe.
NETWORK=mainnet

Expand All @@ -30,9 +30,3 @@ TRUSTED_NODE_URL=https://mainnet-checkpoint-sync.attestant.io
# SNRC_LOG_COLOR=always # coloured `docker compose logs`
# SNRC_LOG_LEVEL=debug # also log health checks and idle connections
# SNRC_TRUSTED_PROXIES=172.16.0.0/12 # behind a reverse proxy on the host; see README

# .simplex contracts on mainnet; unset, .simplex names answer 400. See README,
# "Configuring addresses".
# SNRC_REGISTRY_SIMPLEX=0xa7f6497be2f1aa41aa2db55aba8a6e0145dff0d2
# SNRC_REGISTRAR_SIMPLEX=0x44052f7dc9c1cef20b0319a6b75288988dbb12a1
# SNRC_CONTROLLER_SIMPLEX=0x8005011c6e966656cdb9a222e9a4792600a37219 # proxy
78 changes: 50 additions & 28 deletions scripts/resolver/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Self-hosted SNRC stack

One `docker compose up` runs the self-hosted SimpleX Namespace (SNRC) backend
against **Ethereum mainnet** (where the `.testing` contracts live):
against **Ethereum mainnet** (where the `.testing` and `.simplex` contracts are deployed):

| # | Component | What it does |
|---|---|---|
Expand Down Expand Up @@ -46,8 +46,10 @@ docker compose logs --tail=20 reth
```

This is the long pole (~1 day on mainnet). Until reth is synced the resolver
returns `502`. A TLD whose controller has a name policy then still answers `502`
until `docker compose restart resolver` (see Configuring addresses).
returns `502`. If the resolver started before the node reached block 26459168,
where the `.simplex` controller's name policy was set, every lookup under
`.simplex` then still returns `502` until `docker compose restart resolver` (see
Configuring addresses).

## Verify

Expand All @@ -63,8 +65,9 @@ curl -s -X POST http://127.0.0.1:8545 \
**2. resolver is healthy:**
```sh
curl -s http://127.0.0.1:8000/health | jq
# → {"ok": true, "rpc": "http://reth:8545", "registries": {"testing": "0x…", "simplex": ""},
# "blockNumber": 23400000, "chainLagSeconds": 12}
# → {"ok": true, "rpc": "http://reth:8545", "registries": {"testing": "0x58fc46996d975c57883564648bda5206d1a0102b",
# "simplex": "0x3ce23ef6a00d89105299b52aadd72b92681414be"},
# "blockNumber": 26462784, "chainLagSeconds": 12}
```

`chainLagSeconds` is how far the node is behind the wall clock. A resolver that
Expand All @@ -80,9 +83,19 @@ curl -s http://127.0.0.1:8000/resolve/foobar.testing | jq
**4. the route your router will call** (check 3 passes on an older resolver too):
```sh
curl -s http://127.0.0.1:8000/v2/resolve/foobar.testing | jq
# → {"type":"registered","expires":1780000000,"graceUntil":…,"nameRecord":{…}}
# → {"lastBlockTs":…,"registration":{"type":"registered","expires":1780000000,"graceUntil":…,"reservedReason_":…,"nameRecord":{…}}}
```

**5. a reservation read from `.simplex`'s name policy:**
```sh
curl -s http://127.0.0.1:8000/v2/resolve/simplex.simplex | jq
# → {"lastBlockTs":…,"registration":{"type":"reserved","reservedReason":"internal"}}
```

If check 5 returns `502` while check 4 passes, and the `listening` log line
shows `simplex=-` in `name_policies`, run `docker compose restart resolver` once
the node is synced.

**Wire your smp-server:** in its `[NAMES]` section set
`resolver_endpoint: http://127.0.0.1:8000` (no auth needed for loopback).

Expand All @@ -100,6 +113,13 @@ curl -s http://127.0.0.1:8000/v2/resolve/foobar.testing | jq

- **All images track `:latest`** (reth, nimbus) — you get upstream fixes on each
`docker compose pull`; re-run the verify checks after pulling.
- The resolver image contains the script: after updating this directory, run
`docker compose up -d --build resolver`, then checks 2 and 5.
- A `SNRC_*_SIMPLEX` setting added to `.env`, to `docker-compose.yml`, or to the
environment of a direct run, for the earlier `.simplex` deployment (registry
`0xa7f6497be2f1aa41aa2db55aba8a6e0145dff0d2`) overrides the defaults. Remove
all three; `docker compose exec resolver env | grep _SIMPLEX` then prints
nothing.
- All ports bind to loopback; expose only what you put behind a TLS reverse proxy.

## Teardown
Expand All @@ -119,7 +139,7 @@ The resolver (`snrc-resolve.py`, host `127.0.0.1:8000`) is also runnable
standalone for local dev (no Docker), via [`uv`](https://docs.astral.sh/uv/):

```sh
uv run scripts/resolver/service/snrc-resolve.py # defaults to local reth + mainnet .testing
uv run scripts/resolver/service/snrc-resolve.py # defaults to local reth + mainnet .testing and .simplex
```

Tests and lint run from `scripts/resolver/service`:
Expand Down Expand Up @@ -221,7 +241,7 @@ name already knows when it expires. Both timestamps are Unix seconds, and
| `grace` | lapsed, but only the previous owner may renew it, until `graceEnds` |
| `expired` | lapsed and past grace; anyone may register it |
| `unregistered` | never registered, and free to take |
| `unknown` | no `SNRC_REGISTRAR_<TLD>` configured, so status could not be read |
| `unknown` | the resolver has no registrar for the TLD, so status could not be read |

A reservation is orthogonal to the status: a name held back by the registry
carries `reasonCode` and `reason` whether or not it is registered.
Expand Down Expand Up @@ -266,7 +286,7 @@ look free.

| Status | Meaning |
|---|---|
| 200 | resolved (`status` is `registered` or `grace`, or `unknown` when no registrar is configured) |
| 200 | resolved (`status` is `registered` or `grace`, or `unknown` when the resolver has no registrar for the TLD) |
| 400 | TLD not configured, or not a fully-qualified name |
| 404 | `unregistered` |
| 410 | `expired`: lapsed and past grace, so anyone may take it |
Expand Down Expand Up @@ -334,9 +354,6 @@ per second, and charges a premium on a lapsed name that it does not expose. A
quote from one is therefore only safe for a name that was never registered: an
`expired` name gets no price rather than one below what the registrar charges.

**Set `SNRC_CONTROLLER_<TLD>` wherever `SNRC_REGISTRAR_<TLD>` is.** Without a
controller there is no oracle, so no name can be priced.

**Upgrade this service before the routers that query it.** Routers from SMP v22
call `/v2/resolve`, which an older resolver does not serve. Every name then
answers `ERR NAME RESOLVER "HTTP 404"` until this service is upgraded, while
Expand Down Expand Up @@ -371,16 +388,12 @@ is where every expiry field comes from, and `labelOf`, which is how a hashed
query is answered with a name. A name registered without recording its label
cannot answer one, and `/v2/resolve` refuses it rather than answer with a name
the client will reject. Its `subnameHook()` names the subname registrar, whose
`ownerOf` says who holds a subname it owns. With no registrar for a TLD,
`/resolve` still works and reports `"status": "unknown"`, and only subnames the
2LD's holder owns in the registry are answered. The **controller** holds
`reservedNames`, which is where `reasonCode` comes from. With no controller a
held-back name reads as not reserved, and no name can be priced.
`ownerOf` says who holds a subname it owns. The **controller** holds
`reservedNames`, which is where `reasonCode` comes from.

All three default to the mainnet `.testing` deployment. `.simplex` has no
default; `.env.example` lists its mainnet addresses.
All three default to the mainnet deployments of `.testing` and `.simplex`.

Newer contracts, which `.simplex` will run, keep `reservedNames` in a **name
Newer contracts, which the `.simplex` deployment uses, keep `reservedNames` in a **name
policy** (`SimplexNamePolicy`), with the same `Reason`, and their controller
answers no `reservedNames` call. The resolver reads each controller's
`namePolicy()` once at startup, before its workers start, and reads reservations
Expand All @@ -394,18 +407,27 @@ does not answer, the resolver does not listen and reads again, waiting 1 s,
then twice as long each time, up to 30 s. After the controller's owner calls
`setNamePolicy`, restart the resolver.

The controller default is the **proxy**, not `SimplexControllerImpl`. Storage
lives in the proxy, so the implementation address answers nothing. The two
deployment files use different names for that proxy:
`deployments.mainnet.testing.json` records it under the ENS role name
`ETHRegistrarController`, and `verification.mainnet.testing.json` calls it
`SimplexControllerProxy`. Both are the same address, and it is the one used
here.
Each default is the address that `deployments.mainnet.<tld>.json` of
[brenzi/simplex-namespace-contract](https://github.com/brenzi/simplex-namespace-contract/tree/2ecae1a77bd605dcc236ba3c3cd93e690345af2c)
records, the **proxy** where the contract is upgradeable: the controller of
`.testing` and all three of `.simplex`. The implementations, the entries named
`<contract>@<address>` or `SimplexControllerImpl` in its
`verification.mainnet.<tld>.json`, hold no names: a registrar implementation
returns 0 from `nameExpires` for every name, so every unreserved name is
answered as available. Each setting is the address of one entry of the deployments file:

| Setting | Entry of `deployments.mainnet.<tld>.json` |
|---|---|
| `SNRC_REGISTRY_<TLD>` | `ENSRegistry` |
| `SNRC_REGISTRAR_<TLD>` | `BaseRegistrarImplementation` |
| `SNRC_CONTROLLER_<TLD>` | `ETHRegistrarController` |

To override any of them, set `SNRC_REGISTRY_<TLD>`, `SNRC_REGISTRAR_<TLD>` or
`SNRC_CONTROLLER_<TLD>` on the `resolver` service in `docker-compose.yml`, or
as env vars when you run the script directly. With docker compose, the
`.simplex` ones can be set in `.env`.
`.simplex` ones can be set in `.env`. An empty value is replaced by the
default. Override the three settings of a TLD together: an unset setting is left
at its mainnet default, which belongs to a different deployment.

### Load and scaling

Expand Down
5 changes: 2 additions & 3 deletions scripts/resolver/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ services:
SNRC_RPC: http://reth:8545
SNRC_BIND: 0.0.0.0
# Registry addresses cascade through the script's own defaults
# (mainnet `.testing`; `.simplex` unconfigured). Set explicitly here
# (mainnet `.testing` and `.simplex`). Set explicitly here
# only if you're deploying against a different network or contract.
# SNRC_REGISTRY_TESTING: 0x...
# Registrar and controller, same cascade. Without the registrar `status`
# is "unknown"; without the controller a reserved name is "unregistered".
# Registrar and controller, same cascade.
# SNRC_REGISTRAR_TESTING: 0x...
# SNRC_CONTROLLER_TESTING: 0x...
# Set in .env (see .env.example); unset or empty means the resolver's default.
Expand Down
19 changes: 11 additions & 8 deletions scripts/resolver/service/snrc-resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@
(default: mainnet,
0x58fc46996d975c57883564648bda5206d1a0102b)
SNRC_REGISTRY_SIMPLEX ENSRegistry for the .simplex deployment
(default: empty — TLD not yet deployed)
(default: mainnet,
0x3ce23ef6a00d89105299b52aadd72b92681414be)
SNRC_REGISTRAR_<TLD> BaseRegistrar (ERC-721) for the TLD; expiry and status
(default: mainnet for .testing, empty for .simplex)
(default: mainnet)
SNRC_CONTROLLER_<TLD> SimplexController (proxy) for the TLD; reservations,
read from the policy its `namePolicy()` names, if any,
and through its `prices()` oracle what registering costs
(default: mainnet for .testing, empty for .simplex)
(default: mainnet)
SNRC_PORT Listen port (default: 8000)
SNRC_BIND Bind address (default: 0.0.0.0)
SNRC_WORKERS Worker processes sharing the port (default: CPU count, at most 4)
Expand Down Expand Up @@ -118,30 +119,32 @@
)

# Each TLD is its own SNRC deployment with its own ENSRegistry. Dispatch
# happens on the rightmost label of the queried name. Empty / unset means
# "not deployed" — requests for that TLD return 400 with a clear error.
# happens on the rightmost label of the queried name.
# `... or "..."` makes the script's defaults the single source of truth:
# unset AND empty-string both fall through to the literal. docker-compose
# can therefore pass `SNRC_REGISTRY_TESTING=${SNRC_REGISTRY_TESTING:-}`
# without duplicating the registry address.
REGISTRIES = {
"testing": os.environ.get("SNRC_REGISTRY_TESTING", "")
or "0x58fc46996d975c57883564648bda5206d1a0102b", # mainnet .testing
"simplex": os.environ.get("SNRC_REGISTRY_SIMPLEX", ""), # not deployed yet
"simplex": os.environ.get("SNRC_REGISTRY_SIMPLEX", "")
or "0x3ce23ef6a00d89105299b52aadd72b92681414be",
}

REGISTRARS = {
"testing": os.environ.get("SNRC_REGISTRAR_TESTING", "")
or "0xef47eb4384b46c89e4482a677c2cbcbd2a6fd85a", # mainnet .testing
"simplex": os.environ.get("SNRC_REGISTRAR_SIMPLEX", ""), # not deployed yet
"simplex": os.environ.get("SNRC_REGISTRAR_SIMPLEX", "")
or "0x4c0589dbc22862babb25eb72d11bba49d84aabe8",
}

CONTROLLERS = {
"testing": os.environ.get("SNRC_CONTROLLER_TESTING", "")
# Proxy address, not SimplexControllerImpl: storage is held by the proxy.
# Recorded in deployments.json as ETHRegistrarController.
or "0xeeb9b6bf5fb68fb726005f7ba549c2f4b32f2dad", # mainnet .testing
"simplex": os.environ.get("SNRC_CONTROLLER_SIMPLEX", ""), # not deployed yet
"simplex": os.environ.get("SNRC_CONTROLLER_SIMPLEX", "")
or "0x68fab655a0204865a2f3ab3a607037e09648c92b",
}

# The name policy each TLD's controller names, which holds its reservations in
Expand Down
Loading
Loading