Skip to content

feat(contracts): one dry-run-first command for a network registration - #676

Merged
PastaPastaPasta merged 4 commits into
masterfrom
launch/register-network
Nov 24, 2026
Merged

PastaPastaPasta merged 4 commits into
masterfrom
launch/register-network

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

Registering Forge on mainnet means running deploy-v2 plus four separate post-registration scripts in the right order, with the right scratch/live flags, at 8 AM. One typo (for example a missing --dry-run) broadcasts on mainnet.

forge-contracts/scripts/launch-network.mjs chains them into one re-runnable command:

  • preflight (always): deploy-v2 --self-test, the set's sha256 sums (saved as evidence), refresh-dapi --check, and deploy-v2 --dry-run.
  • register (--execute only): deploy-v2 for real. Re-running it after an interruption completes the run (deploy-v2 records each nonce before it broadcasts). On mainnet it asks the operator to type mainnet. With no TTY it needs --confirm mainnet. The live record also needs --expect-sha256.
  • post (--execute / --post-only): freeze-c1-check (report saved), a contract-group owner and no-admins check, freeze-registered (skipped once contracts/registered/<net>/ exists), and snapshot-contracts.
  • It defaults to a dry run. It refuses any flag it does not know, so --force-new, --update, --replay and --acknowledge-nonce are never forwarded (a unit test pins this).
  • The scratch path (--record … --scratch-on testnet --out <dir>) is the testnet rehearsal of the same steps.

Verified:

  • 9 offline unit tests, added to the contracts workflow.
  • --network testnet --post-only against the live testnet record: C1 44/44, group EXgzBMpw… owner = deployer with no admins, and the snapshot rewrite is byte-identical (no diff).
  • --network mainnet --post-only stops with "holds no registration yet".

Part of the mainnet launch prep (docs/launch/mainnet-runbook.md follows in a separate PR).

🤖 Generated with Claude Code

PastaPastaPasta and others added 2 commits November 24, 2026 06:17
…e dry-run-first command

Wraps deploy-v2's preflight, registration and the read-only post checks
(C1, contract group owner/admins, freeze-registered, snapshot) so a mainnet
launch is one re-runnable command. Dry run unless --execute; a mainnet
broadcast needs the operator to type the network name; superseding flags
are never forwarded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8b791670-e4d1-473d-8b2c-3705520a2521
Commits

Reviewing files that changed from the base of the PR and between cf8693e and 887a8f6.

Files selected for processing: 4

  • .github/workflows/contracts.yml
  • docs/deploying-to-a-network.md
  • forge-contracts/scripts/launch-network.mjs
  • forge-contracts/scripts/launch-network.test.mjs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verdict: changes requested

I checked the four launch invariants against the code and the scripts it wraps. All four hold:

  • No broadcast without --execute. plan() adds the only non---dry-run deploy-v2 call (register) only when the mode is execute. Self-test, --print-sha256, refresh-dapi --check and the dry run are all read-only.
  • No superseding flags. parseArgs rejects every flag outside its allowlist, and no code path adds --force-new, --abandon-live-set, --update, --replay or --acknowledge-nonce.
  • Re-runnable. deploy-v2 resumes from its nonce ledger, and freeze-registered is idempotent (skipped once registered/<net>/ exists).
  • Scratch and live records go to the right places. The live path is deployments/<net>.json with no --record, which deploy-v2's recordPath treats as live. A scratch run passes --record/--scratch-on to deploy-v2, and --record/--out under --out to freeze and snapshot. The inner scripts also refuse any --out or --record under deployments/ or registered/.

I checked every flag passed to deploy-v2, freeze-c1-check, freeze-registered, snapshot-contracts and refresh-dapi against their parsers. All are real and correct.

What I ran on head d735746, in a scratch worktree:

  • node --test forge-contracts/scripts/launch-network.test.mjs: 9/9 pass.
  • --post-only --network testnet: c1 44/44 PASS, group PASS (owner 3pjHay…, no admins), freeze skipped as already frozen, snapshot rewritten byte-identical. Exit 0, clean tree.
  • --post-only --network mainnet: correctly stops with "holds no registration yet".
  • refresh-dapi --network mainnet --check: 10/10 recorded seeds pass, chain evo1.

Two problems block, in my view, for a mainnet go/no-go tool. Both fail closed or need deliberate flags, so nothing is lost if someone runs the PR as is. But the first one makes the dry-run go signal untrustworthy, and that signal is the main thing this wrapper offers.

1. Medium: "dry run clean" is printed even when deploy-v2 found refusal problems

forge-contracts/scripts/launch-network.mjs:175 (and :61)

On a production dry run, deploy-v2 only logs the refusals as WARNING … and exits 0 (deploy-v2.mjs:1011-1013). The refusals are:

  • an --expect-sha256 mismatch against the signed sums
  • a missing --expect-sha256
  • set files that differ from HEAD
  • a failing build.py --check
  • HEAD not on origin

The wrapper only looks at the exit code, so it reports dry run clean. Nothing was broadcast. Re-run with --execute. options() also allows a live dry run with no --expect-sha256 at all. The sums step saves sha256sums.txt but never compares it with the signed file.

Failure: the operator passes the wrong or stale signed-sums file, or forgets to push. They get "dry run clean" and then type mainnet, and only then does the register step refuse. It fails closed, but the dry run said go when it should have said stop.

Fix:

  • Require --expect-sha256 for every live (non-scratch) mode except --post-only, not only for --execute.
  • After the sums step, compare the captured sums with the --expect-sha256 file (deploy-v2 exports parseSums and sumsProblems) and fail on any difference.
  • Run the dry-run step with stderr piped and teed. On the live record, fail the step if any line matches WARNING (or at least end with "dry run finished WITH WARNINGS: --execute will refuse" instead of "clean").

2. Medium: a scratch rehearsal on mainnet broadcasts without the typed confirmation

forge-contracts/scripts/launch-network.mjs:134

confirmBroadcast returns true whenever o.scratch is set. So --network mainnet --record r.json --scratch-on mainnet --out o --execute registers four permanent contracts on mainnet and spends real DASH with no prompt. The docs (docs/deploying-to-a-network.md §5) say it "asks the operator to type mainnet before a mainnet broadcast".

Fix: use if (o.network !== 'mainnet') return true;, so every mainnet broadcast is confirmed. Add a test that checks register carries confirm: true in the scratch-on-mainnet plan, and that confirmBroadcast is not skipped for scratch.

Lower / nits (non-blocking)

  1. Low, launch-network.mjs:80-82. --identity and --expect-sha256 are forwarded unresolved, but children run with cwd set to the repo root. A relative path given from any other directory resolves against the repo root. It fails closed (ENOENT), but it is surprising when --record, --out and --evidence are resolved against the caller's cwd. Fix: resolve() both in options().
  2. Nit, :178. When freeze is skipped (frozen), the closing message still says "the NETWORK_REGISTRATIONS line printed above", but nothing printed it. Make the message depend on whether the freeze step ran.
  3. Nit, :119-131. The group check verifies the owner and admins but not that all four contracts are enrolled. docs §6.1 lists enrolment as a by-hand check. A full deploy-v2 run checks it before recording contractGroup, but --post-only does not. Consider adding sdk.contractGroups.forContract(id) for each recorded contract.
  4. Nit, :33. --skip-dapi-check is not in the header usage or the docs.
  5. Nit. --post-only is "read-only on chain" but rewrites the committed deployments/contracts/<net>.json snapshot. This is harmless (byte-identical on testnet today), but worth saying in the header.

🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.

…s the signed sums

A live dry run now needs --expect-sha256, compares the set's sums with it,
and fails on any WARNING line deploy-v2 prints (it only warns in a dry run
about what would refuse the real registration). Every mainnet broadcast,
scratch included, asks for the typed confirmation. Identity and sums paths
are resolved before the child scripts run from the repo root.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verdict: approve

Re-review at cf515d4. All five earlier findings are fixed, and I found nothing new that blocks the mainnet run.

Earlier findings, checked against the code and by running it

  1. Fixed. options() (launch-network.mjs:67) now refuses a live run without --expect-sha256, dry run included. The sums step (:187-191) compares --print-sha256 with the signed file using deploy-v2's own parseSums/sumsProblems. On a live record the dry-run step is failOnWarning (:96, :193-197). I went through every WARNING site in deploy-v2.mjs. On a clean first mainnet dry run, none of them fire unconditionally. The problems list (:1013: dirty set, build.py --check, sums, HEAD not pushed) only warns in a dry run, and every one of those would refuse the real run, so failing on them is correct. The 2058 escrow warning sits inside if (!dryRun). A scratch dry run is exempt, as intended. I ran it: it printed the SCRATCH warning and exited 0.
  2. Fixed. confirmBroadcast (:143) checks only o.network, so a scratch run on mainnet also gets the typed prompt, or needs --confirm mainnet. Any other --confirm value refuses.
  3. Fixed. identity and expect-sha256 are resolved at :72, and record, out and evidence at :70-73. I checked this with a run from /work/scratch using relative --record/--out/--expect-sha256: the files resolved, and a deliberately wrong sums file failed at step sums (FAIL sums: forge-core.json ... is not the signed ...) before any SDK step ran.
  4. Fixed. The NETWORK_REGISTRATIONS hint is only printed when the plan has a freeze step (:202).
  5. Fixed. --skip-dapi-check is now described in the header (:14).

Safety properties

  • No broadcast without --execute: register is the only deploy-v2 call without --dry-run, and it is added only when the mode is execute (:98). A dry run and --post-only run no broadcasting step.
  • No superseding flags: parseArgs only accepts the listed flags and rejects anything else. Nothing builds --force-new/--update/--replay/--acknowledge-nonce, and the test enforces that.
  • Re-run: the dry run that runs first on a re-run handles a half-done record. reconcile settles a broadcasting reservation (in a dry run record() writes nothing), and the dry-run gates don't look at a dirty deployments/<net>.json unless it's a replay. A stale nonce that needs --acknowledge-nonce makes deploy-v2 refuse, so the operator has to decide by hand, as documented.
  • Scratch vs live routing: scratch writes only --record and --out/{registered,snapshot.json,evidence}, and alreadyFrozen is skipped for scratch. Live uses deployments/<net>.json, and contracts/registered/mainnet/ doesn't exist yet, so freeze will run.

What I ran (scratch worktree, since removed): node --test launch-network.test.mjs passed 10/10. --post-only --network testnet: c1 44/44, group PASS, the snapshot was unchanged and the tree stayed clean. A scratch testnet dry run was clean and broadcast nothing. A scratch run with a bad sums file failed at sums. I did not run --execute.

Nits (none block)

  • low, launch-network.mjs:67: --deployer-created-height is optional for a live --execute. deploy-v2 only warns about the missing height after the register step (:2058, outside the dry run), so a mainnet record could be written without the CNT-02 escrow height. A re-run with the flag fills it in. Fix: require it when !scratch && mode === 'execute', or just make sure the operator passes it this morning.
  • low, launch-network.mjs:165/202: alreadyFrozen reads the working tree, not HEAD. A re-run after the freeze ran but a later post step failed skips freeze, and the final message no longer mentions the NETWORK_REGISTRATIONS line, which is still uncommitted. A freeze that dies after writing one .v1.json would also be skipped next time. Fix: when frozen-but-uncommitted, print a reminder (or check git ls-files).
  • nit, :175-185: the live dry-run output is buffered until the child exits, so the operator sees nothing while it runs (about 20 s on testnet). dry-run.log is also written only when failOnWarning is set, so scratch evidence has no dry-run log.
  • nit, docs/deploying-to-a-network.md §5: the usage block leaves out --evidence, --confirm and --skip-dapi-check.

🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.

…work

# Conflicts:
#	.github/workflows/contracts.yml
@PastaPastaPasta
PastaPastaPasta merged commit bda9369 into master Nov 24, 2026
20 checks passed
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