Skip to content
Open
Changes from 11 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
18 changes: 18 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,22 @@ A fresh node joins no network by itself: it starts from the genesis bundled in t

A node forges only while at least the quorum of the genesis `shardSize` (2/3 + 1: 7 of 10, 3 of 3) of its validators are online. A genesis whose validator set has fewer validators active at block 0 than that never gets past block 0. The smallest `shardSize` a node accepts is 3, with a quorum of 3, so a network of fewer than 3 validators never forges: a rehearsal needs at least 3 validators at `shardSize` 3. `genesis-hash.ts` and `node-doctor --production` report such a genesis before the start.

A fresh node does **not** run as an isolated single-validator chain, and the code has no solo or single-validator mode. Started alone from the bundled files it stays at block 0: the 35 validators of the bundled snapshot take precedence over the 4 listed in the bundled `genesis.json` (`shardSize` 10), a freshly generated identity is in neither list, and a node forges only in a committee that includes its own identity (otherwise it logs `We are not in the shard`).
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

For a local chain that forges, use the repository's devnet ([testing/devnet/README.md](testing/devnet/README.md)). Its `scripts/setup.sh` runs `generate-genesis.sh`, which rewrites the validator list in `testing/devnet/genesis.devnet.json` to the newly generated node identities (4 by default, set by `NODE_COUNT`). That genesis applies only with `testing/devnet/docker-compose.fixture.yml` as an overlay: it mounts `genesis.devnet.json` over `/app/data/genesis.json` and `./empty-snapshot`, a directory with no `manifest.json`, over `/app/data/snapshot/`, so with no snapshot the genesis validators are seeded at block 0. The devnet nodes run with `NODE_ENV=development` and the devnet genesis has a test network's chain id (1337), so the pin requirement of step 3 does not apply there.

The devnet genesis has a `shardSize` of 10 (quorum 7), so the default 4 validators never get past block 0, and `NODE_COUNT` cannot reach 7: `generate-genesis.sh` rejects node 6, and Compose defines at most five nodes (`node-5` is in the `rehearsal` profile). To get a devnet that forges, run `setup.sh` (it regenerates identities on every run and overwrites `testing/devnet/identities/node<N>.identity` and `node<N>.pubkey` for each node, so copy any you still need first), then lower `properties.shardSize` to the validator count in a copy of `genesis.devnet.json` and mount the copy over `/app/data/genesis.json` with one more compose file, listed after the fixture file; four validators at `shardSize` 4 have a quorum of 3. `testing/devnet/scripts/test-tx-status-e2e.sh` does this with `jq '.properties.shardSize = (.validators | length)'`. Start on an empty database: the Postgres data is a named volume that survives `docker compose down` (`testing/devnet/.env.example` sets `PERSISTENT=0`, and any non-empty value mounts it), and a node that already holds block 0 reads `shardSize` from that block, so the copy has no effect. Run `docker compose` with the same `--profile` and `-f` options and `down -v` first, as that script does. For `NODE_COUNT=5`, add `--profile rehearsal` and mount the copy on `node-5` too.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Sources for the paragraphs above and the snapshot paragraph of step 3:

- `data/genesis.json` (`properties.shardSize`, `validators`), `data/snapshot/manifest.json` and `data/snapshot/validators.jsonl` (35 rows), `Dockerfile:99` (`COPY data/ ./data/`)
- `src/libs/blockchain/genesis/restoreGenesisState.ts:86-96` and `src/libs/blockchain/routines/ensureValidatorSeed.ts:107-151` (snapshot validators take precedence over the genesis list; the genesis list is the fallback at block 0), `src/libs/blockchain/genesis/loadSnapshot.ts:444-452` (no snapshot directory or no `manifest.json` means no snapshot)
- `src/libs/consensus/v2/quorum.ts:10-12` and `src/libs/consensus/v2/routines/getShard.ts:32-34` (committee floor), `src/libs/consensus/v2/types/secretaryManager.ts:276-281` (`We are not in the shard`)
- `Dockerfile:290` (`NODE_ENV=production`), `docker-compose.yml:192-194` (the pin variables pass through empty), `src/libs/blockchain/routines/findGenesisBlock.ts:159-166` and `src/libs/blockchain/genesis/genesisPin.ts:75-95` (without a pin, boot is refused on a chain id that is not a test network's, and in production unless `DEMOS_ALLOW_UNPINNED_GENESIS` is set), `src/forks/forkConfig.ts:653` (chain ids 1 and 1337 are test networks'), `src/libs/blockchain/genesis/genesisPin.ts:261-273,286-291` and `src/libs/blockchain/routines/findGenesisBlock.ts:240-251` (while a snapshot is present, a genesis that does not declare `snapshot.manifestSha256` is refused with either pin set, before block 0 is written), `docs/mainnet/genesis.template.json` (declares `snapshot.manifestSha256`)
- `testing/devnet/scripts/generate-genesis.sh:1-10,27`, `testing/devnet/scripts/setup.sh:24`, `testing/devnet/genesis.devnet.json` (`properties.id`, `properties.shardSize`), `testing/devnet/docker-compose.fixture.yml:9-13,27-28`, `testing/devnet/docker-compose.yml:62` (`NODE_ENV=development`), `testing/devnet/quorum-drills/README.md:131` (the `floor` drill boots the default 4 validators and expects no block past 0)
- `testing/devnet/scripts/setup.sh:18` (calls `generate-identities.sh` on every run), `testing/devnet/scripts/generate-identities.sh:6,18-34` (`node${i}.identity` and `node${i}.pubkey` in `testing/devnet/identities` are written unconditionally, with no existence check)
- `testing/devnet/scripts/generate-genesis.sh:30-39,45-54` (node index 6 is rejected), `testing/devnet/docker-compose.yml:221-222` (`node-5`, `rehearsal` profile; no `node-6`), `testing/devnet/scripts/test-tx-status-e2e.sh:44,75-89,95-97` (the `rehearsal` profile, the `shardSize` copy and the override file, `down -v` before `up`), `testing/devnet/.env.example:35` and `testing/devnet/docker-compose.yml:13` (`PERSISTENT=0` still mounts the `postgres-data` volume), `src/libs/consensus/genesisShardSize.ts:63-85` and `src/libs/blockchain/routines/findGenesisBlock.ts:173-223` (a node with block 0 reads `shardSize` from the stored block)

**1. Set `EXPOSED_URL` to your reachable address.**

The default `http://localhost:53550` is fine for local dev but useless for any peer trying to connect to you. Before going live:
Expand Down Expand Up @@ -418,6 +434,8 @@ EXPECTED_GENESIS_BLOCK_HASH=<published block 0 hash>

`scripts/genesis-hash.ts --genesis <file> --snapshot <dir>` prints both values for a genesis file and the snapshot it declares; the block 0 hash is the one labelled "genesis block hash". Without `--snapshot` it reads `DEMOS_SNAPSHOT_DIR`; a genesis that declares a snapshot and gets none is reported as a problem. A Docker host has no Bun: run it inside the image, as in step 4 of [Run a released image](#run-a-released-image-validators). What each hash covers, and where mainnet's are published, is in [docs/mainnet/genesis-hash.md](docs/mainnet/genesis-hash.md).

While a snapshot is present, a pin is accepted only for a genesis that declares `snapshot.manifestSha256` for it, as the mainnet genesis template does. The genesis bundled in the image declares none and the bundled snapshot is present, so on an empty database the image starts on its own files only with neither pin set and `DEMOS_ALLOW_UNPINNED_GENESIS=true`.

A validator never leaves these set in `.env`: `DEMOS_ALLOW_UNPINNED_GENESIS`, and the one-start switches `DEMOS_GENERATE_IDENTITY`, `DEMOS_IDENTITY_TAKEOVER`, `DEMOS_SIGNING_RECORD_REBIND` and `DEMOS_ACCEPT_FORK_SCHEDULE_DIGEST`. Each of the last four is for the single start that needs it (see [docs/runbooks/validator-key.md](docs/runbooks/validator-key.md) and below); remove it once the node runs. `./scripts/node-doctor --production` fails while any of them is set.

At every start the node checks it before it signs anything: on an empty database against the genesis file (`data/genesis.json`, or `DEMOS_GENESIS_FILE`) and the snapshot that genesis declares, before block 0 is written; on an existing database against the stored block 0. A mismatch stops the node with exit code 1 and leaves the database as it was. A network that publishes no hash can opt out with `DEMOS_ALLOW_UNPINNED_GENESIS=true`; mainnet validators never set it. A node started without a pin and without that opt-out (a bare-metal `./run` install runs as development, so nothing refuses it) logs a `[GENESIS] EXPECTED_GENESIS_HASH is not set` warning at every boot.
Expand Down
Loading