Skip to content
Open
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
84 changes: 82 additions & 2 deletions doc/package-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ Repository counts and migration observations belong to dated audit reports; see

**SPEC-M06: A variant `upstream[]` keeps the root's positions.** Root and variant manifests are merged by array position. A variant may list fewer or more entries than the root, but an entry at an existing position must refer to the same `repo`.

**SPEC-M07: Only fields from the manifest schema.** Fields outside the published manifest schema (plus `upnpDisable`, supported by DAPPMANAGER but not yet published) are ignored or stripped at install.
**SPEC-M07: Only fields from the manifest schema.** Fields outside the published manifest schema (plus `upnpDisable` and `nodes`, supported by DAPPMANAGER but not yet published) are ignored or stripped at install.

**SPEC-M08: `repository.url` points to the package repository.** When a manifest declares `repository`, its URL is the package's own GitHub repository (`https://` or `git+https://`, with or without `.git`).

**SPEC-M09: Exposable services exist in the compose.** `exposable[].serviceName` names a service in the compose.

**SPEC-M10: Manifest service references exist in the resolved compose.** Explicit `mainService`, `chain.serviceName`, `backup[].service` and `globalEnvs[].services[]` references name services present after root and variant files are merged. Omitted optional references retain their runtime defaults; the spec does not choose a service implicitly. Findings identify the manifest field, its defining source fragment and the affected variant.
**SPEC-M10: Manifest service references exist in the resolved compose.** Explicit `mainService`, `chain.serviceName`, `backup[].service`, `globalEnvs[].services[]`, `nodes` keys and `nodes.<service>.validatorService` references name services present after root and variant files are merged. Omitted optional references retain their runtime defaults; the spec does not choose a service implicitly. Findings identify the manifest field, its defining source fragment and the affected variant.

**SPEC-M11: Global environment names match the runtime catalogue.** Entries in `globalEnvs[].envs` use short names from the `GLOBAL_ENVS` catalogue bundled with `@dappnode/types`, for example `PUBLIC_IP`, `HOSTNAME` or `ENVS_ACTIVE`. DAPPMANAGER adds `_DAPPNODE_GLOBAL_` at install, so `_DAPPNODE_GLOBAL_PUBLIC_IP` in the manifest would be prefixed twice. Catalogue keys are not aliases: the key `ACTIVE` maps to `ENVS_ACTIVE`, which is the valid manifest value. Catalogue updates must be released through shared types and consumed by the SDK before packages adopt newly supported names.

**SPEC-M12: Node declarations are complete.** Checked on the merged manifest of each variant (see [Node declarations](#node-declarations)). Every entry of `nodes` is an object with a string `role` and `probe.kind` and, after merging, a string `network`. A missing `network` is reported in the variant manifest. `ethereum-execution` nodes declare `probe.rpcPort` and `probe.enginePort`, `ethereum-beacon` nodes `probe.apiPort`, as port numbers. A `status-report` node declares `report`. With `report: "healthcheck"` the service defines a `healthcheck` in the compose. Unknown `role`, `probe.kind` and `report` values are not reported: the contract only grows and DAPPMANAGER ignores what it does not know.

**SPEC-M13: Node declarations contain no addresses.** No value under `nodes` looks like a URL (`scheme://`, `//`) or a hostname (`localhost`, an IP address, `name:port`, a dotted domain), and no key is named like an address (`url`, `uri`, `host`, `hostname`, `endpoint`, as a whole word of the key, e.g. `rpcUrl`). DAPPMANAGER decides which address to call; a package declares ports only.

### Manifest semantics

The source manifest describes package metadata and installation instructions. A template root and its variant manifests are source fragments; the merged result is the installable manifest and is validated against the full shared schema. Root fragments need not repeat each variant’s required identity fields.
Expand All @@ -59,6 +63,82 @@ The current manifest merge recursively combines objects, replaces scalar values

For example, if the root upstream list is `[app, scripts]` and a variant supplies only a compatible `[appOverride]`, the resolved list is `[mergedApp, scripts]`. SPEC-M06 requires the root and variant to retain the same repository at every overlapping position. Checks of argument values and service references run on this resolved result. A move to whole-array replacement or merging by a stable key requires a coordinated migration across the SDK and consumers.

### Node declarations

A node package declares in the optional top-level `nodes` field which of its services run a node, and reports what each node's client is doing through that service's Docker healthcheck. The package says what its own client is doing; DAPPMANAGER decides whether the node is synced, waiting on another node or stalled, and how long is left. Today DAPPMANAGER reads the healthcheck reports of `ethereum-execution` nodes (looked up by `role: execution` and `report: "healthcheck"`). The `status-report` probe kind and the HTTP report source are defined but not consumed yet.

`nodes` is keyed by compose service name. Each entry:

| Field | Value |
|---|---|
| `role` | Required. `execution`, `consensus`, `node` or `validator`. |
| `network` | Required after merging. The DAPPMANAGER network name: `mainnet`, `gnosis`, `hoodi`, `sepolia`, `lukso`. |
| `probe.kind` | Required. `ethereum-execution`, `ethereum-beacon` or `status-report`. |
| `probe.rpcPort`, `probe.enginePort` | Required for `ethereum-execution`: JSON-RPC and Engine API ports of the service. |
| `probe.apiPort` | Required for `ethereum-beacon`: Beacon API port of the service. |
| `report` | `"healthcheck"` when the service's healthcheck prints a status report. `{ "http": { "port", "path" } }` is reserved for a report served by the service. |
| `validatorService`, `requires`, `probe.maxHeadAgeSeconds` | Defined by the schema (validator client service of a consensus node, `[{ "network", "role" }]` this node needs, head age after which a `status-report` node is shown as behind); not used by DAPPMANAGER yet. |

Ports are the service's own ports; never add hostnames or URLs (SPEC-M13). Values outside these lists are allowed and ignored by DAPPMANAGER.

In a template, the root manifest holds everything the variants share and each variant manifest adds only the network. Objects are deep-merged by service name (see [Variant inheritance](#variant-inheritance)):

```json
"nodes": {
"reth": {
"role": "execution",
"probe": { "kind": "ethereum-execution", "rpcPort": 8545, "enginePort": 8551 },
"report": "healthcheck"
}
}
```

```json
"nodes": { "reth": { "network": "mainnet" } }
```

The SDK checks the merged result: SPEC-M10 (the key and `validatorService` are compose services), SPEC-M12 (complete) and SPEC-M13 (no addresses).

#### Status report

With `report: "healthcheck"`, the service's healthcheck prints one JSON object as the last line of stdout, at most 2,048 bytes. Only `version` and `state` are required; leave out what is unknown instead of sending `null` or `0`.

| Field | Value |
|---|---|
| `version` | `1`. |
| `state` | `starting` (the node's API does not answer yet: start-up, snapshot or checkpoint download, database opening), `syncing`, `synced` or `error`. The client's own view. |
| `phase` | What the node is doing, e.g. `"Downloading state"`. Sentence case, no trailing period, at most 60 characters. |
| `progress` | Progress of the current phase, 0-100. Omit it when it cannot be measured; never 100 while the phase runs (cap at 99.9). |
| `height`, `headTime` | Latest block the node serves and its timestamp in Unix seconds. |
| `position`, `target` | For a phase measured in blocks: the block the phase has reached, and the block the node syncs towards when the client knows it. |
| `unit` | Unit of `height`, `position` and `target`. Default `blocks`. |
| `peers` | Connected peers. |
| `awaitingTarget` | `true` when the client has nothing to sync towards yet (an execution client no consensus client has driven since it started). Omit it otherwise. |
| `background` | Work that continues after reaching the head, e.g. `"Indexing transactions"`, at most 60 characters. |
| `issues` | Up to 5 problems the client reports about itself, at most 120 characters each. Not "No peers": DAPPMANAGER derives that from `peers`. |
| `details` | Up to 8 `{ "label", "value" }` pairs, already formatted, at most 80 characters each, for a troubleshooting tooltip. |

A phase is measured either with `progress` or with `position` and `target`, not both; for a block-measured phase DAPPMANAGER computes the percentage, blocks left and time left. Strings are untrusted: DAPPMANAGER removes control characters, cuts them to the lengths above and shows them as plain text. A report larger than 2,048 bytes, with another `version` or an unknown `state` is ignored, and so is the latest report once it is older than three healthcheck intervals.

For an `ethereum-execution` node, DAPPMANAGER decides synced or not itself (latest block recent, consensus client at the head) and ignores `state: synced`. It takes `phase`, `progress`, `position`, `target`, `awaitingTarget`, `background`, `issues` and `details` from the report, shows `phase` and `progress` of a `starting` report while the RPC does not answer, and with `awaitingTarget: true` shows "Waiting for the consensus client" while the consensus client is not at the head.

#### Healthcheck

```yaml
healthcheck:
test: ["CMD", "/usr/local/bin/node-status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
```

- Exit 0 whenever the script printed a report with state `starting`, `syncing` or `synced`; non-zero only for `error` or when nothing could be determined. A syncing node must not be unhealthy.
- Nothing else on stdout on success. Diagnostics go to stderr and stay short: Docker keeps 4,096 bytes of combined output per run.
- Answer before the node's API is up: report `starting`, with a `phase` (and `progress` when the entrypoint leaves one to read) for long pre-start work.
- Finish well inside the timeout: every network call has its own 2-3 s timeout and calls only `127.0.0.1` or `localhost`. Write nothing to the data directory and never print credentials or secrets.
- POSIX `sh` with `curl` and `jq` only. Client-specific logic stays in the package; shared helpers (JSON-RPC calls, Prometheus metrics, printing the report) live in `dappnode/staker-package-scripts`.

### Templates (multi-variant packages)

**SPEC-T01: The template root manifest has no `name` or `version`.** When a package has variants, each variant manifest declares its own `name` and `version` and the root holds only shared fields. A named root becomes a phantom package for pin cleanup, dashboards and on-chain sync.
Expand Down
17 changes: 16 additions & 1 deletion src/spec/checkPackageSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import {
checkManifestReferences,
manifestFieldIsDefined
} from "./manifestReferences.js";
import { checkNodes } from "./nodes.js";

const manifestFileName = "dappnode_package.json";
const packageNamePattern =
/^[a-z0-9]+(-[a-z0-9]+)*\.(dnp|public)\.dappnode\.eth$/;
const variantNamePattern = /^[a-z0-9]+(-[a-z0-9]+)*$/;
/** Supported by DAPPMANAGER but not yet in the published manifest schema. */
const knownUnreleasedManifestFields = ["upnpDisable"];
const knownUnreleasedManifestFields = ["upnpDisable", "nodes"];
/** Single release files that are copied (not merged) from the root or the variant. */
const singleCopiedReleaseFiles = [
"avatar",
Expand Down Expand Up @@ -427,6 +428,20 @@ export function checkPackageSpec({
);
}

for (const finding of checkNodes(sourceManifest, compose, {
inTemplate: isTemplate
})) {
// A missing network belongs in the package's own manifest (the variant, in a template).
const dir = finding.fixInVariant
? manifestDirs[manifestDirs.length - 1]
: manifestOrigin(m => manifestFieldIsDefined(m, finding.field));
const checked =
pkg.variant && (finding.perVariant || dir !== rootDir)
? ` Checked for variant "${pkg.variant}".`
: "";
add(finding.rule, `${finding.message}${checked}`, manifestFileIn(dir));
}

const services = Object.keys(compose.services || {});
for (const exposable of manifest.exposable || [])
if (exposable.serviceName && !services.includes(exposable.serviceName)) {
Expand Down
21 changes: 20 additions & 1 deletion src/spec/manifestReferences.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Compose, GLOBAL_ENVS, Manifest } from "@dappnode/types";
import { getManifestNodes, nodeField } from "./nodes.js";

interface ManifestReferenceFinding {
rule: "SPEC-M10" | "SPEC-M11";
Expand Down Expand Up @@ -38,6 +39,20 @@ export function checkManifestReferences(
checkService(`backup[${i}].service`, entry?.service)
);

for (const [service, node] of Object.entries(
getManifestNodes(manifest) || {}
)) {
const field = nodeField(service);
if (!services.has(service))
findings.push({
rule: "SPEC-M10",
field,
message: `${field} declares a node for service "${service}", which is not in the compose.`
});
if (node && typeof node === "object" && "validatorService" in node)
checkService(`${field}.validatorService`, node.validatorService);
}

if (Array.isArray(manifest.globalEnvs))
manifest.globalEnvs.forEach((entry, i) => {
if (Array.isArray(entry?.services))
Expand Down Expand Up @@ -72,7 +87,11 @@ export function manifestFieldIsDefined(
field: string
): boolean {
let value: unknown = manifest;
for (const key of field.replace(/\[(\d+)\]/g, ".$1").split(".")) {
// Paths such as backup[0].service or nodes["bind.dnp.dappnode.eth"].role
const keys = [
...field.matchAll(/([^.[\]]+)|\[(\d+)\]|\[("(?:[^"\\]|\\.)*")\]/g)
].map(([, name, index, quoted]) => name ?? index ?? JSON.parse(quoted));
for (const key of keys) {
if (
value === null ||
typeof value !== "object" ||
Expand Down
Loading
Loading