Repository navigation
feat(contracts): one dry-run-first command for a network registration - #676
Conversation
…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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedYou'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. View limit details
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. |
PastaPastaPasta
left a comment
There was a problem hiding this comment.
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-rundeploy-v2 call (register) only when the mode isexecute. Self-test,--print-sha256,refresh-dapi --checkand the dry run are all read-only. - No superseding flags.
parseArgsrejects every flag outside its allowlist, and no code path adds--force-new,--abandon-live-set,--update,--replayor--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>.jsonwith no--record, which deploy-v2'srecordPathtreats as live. A scratch run passes--record/--scratch-onto deploy-v2, and--record/--outunder--outto freeze and snapshot. The inner scripts also refuse any--outor--recordunderdeployments/orregistered/.
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-sha256mismatch 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-sha256for every live (non-scratch) mode except--post-only, not only for--execute. - After the
sumsstep, compare the captured sums with the--expect-sha256file (deploy-v2 exportsparseSumsandsumsProblems) and fail on any difference. - Run the
dry-runstep with stderr piped and teed. On the live record, fail the step if any line matchesWARNING(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)
- Low,
launch-network.mjs:80-82.--identityand--expect-sha256are forwarded unresolved, but children run withcwdset 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,--outand--evidenceare resolved against the caller's cwd. Fix:resolve()both inoptions(). - 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. - Nit,
:119-131. The group check verifies the owner and admins but not that all four contracts are enrolled.docs §6.1lists enrolment as a by-hand check. A full deploy-v2 run checks it before recordingcontractGroup, but--post-onlydoes not. Consider addingsdk.contractGroups.forContract(id)for each recorded contract. - Nit,
:33.--skip-dapi-checkis not in the header usage or the docs. - Nit.
--post-onlyis "read-only on chain" but rewrites the committeddeployments/contracts/<net>.jsonsnapshot. 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
left a comment
There was a problem hiding this comment.
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
- Fixed.
options()(launch-network.mjs:67) now refuses a live run without--expect-sha256, dry run included. Thesumsstep (:187-191) compares--print-sha256with the signed file using deploy-v2's ownparseSums/sumsProblems. On a live record thedry-runstep isfailOnWarning(:96, :193-197). I went through everyWARNINGsite 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 insideif (!dryRun). A scratch dry run is exempt, as intended. I ran it: it printed the SCRATCH warning and exited 0. - Fixed.
confirmBroadcast(:143) checks onlyo.network, so a scratch run on mainnet also gets the typed prompt, or needs--confirm mainnet. Any other--confirmvalue refuses. - Fixed.
identityandexpect-sha256are resolved at :72, andrecord,outandevidenceat :70-73. I checked this with a run from/work/scratchusing relative--record/--out/--expect-sha256: the files resolved, and a deliberately wrong sums file failed atstep sums(FAIL sums: forge-core.json ... is not the signed ...) before any SDK step ran. - Fixed. The NETWORK_REGISTRATIONS hint is only printed when the plan has a
freezestep (:202). - Fixed.
--skip-dapi-checkis now described in the header (:14).
Safety properties
- No broadcast without
--execute:registeris the only deploy-v2 call without--dry-run, and it is added only when the mode isexecute(:98). A dry run and--post-onlyrun no broadcasting step. - No superseding flags:
parseArgsonly 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.
reconcilesettles abroadcastingreservation (in a dry runrecord()writes nothing), and the dry-run gates don't look at a dirtydeployments/<net>.jsonunless it's a replay. A stale nonce that needs--acknowledge-noncemakes deploy-v2 refuse, so the operator has to decide by hand, as documented. - Scratch vs live routing: scratch writes only
--recordand--out/{registered,snapshot.json,evidence}, andalreadyFrozenis skipped for scratch. Live usesdeployments/<net>.json, andcontracts/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-heightis 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:
alreadyFrozenreads 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.jsonwould also be skipped next time. Fix: when frozen-but-uncommitted, print a reminder (or checkgit 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.logis also written only whenfailOnWarningis set, so scratch evidence has no dry-run log. - nit, docs/deploying-to-a-network.md §5: the usage block leaves out
--evidence,--confirmand--skip-dapi-check.
🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.
…work # Conflicts: # .github/workflows/contracts.yml
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.mjschains them into one re-runnable command:deploy-v2 --self-test, the set's sha256 sums (saved as evidence),refresh-dapi --check, anddeploy-v2 --dry-run.--executeonly):deploy-v2for 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 typemainnet. With no TTY it needs--confirm mainnet. The live record also needs--expect-sha256.--execute/--post-only):freeze-c1-check(report saved), a contract-group owner and no-admins check,freeze-registered(skipped oncecontracts/registered/<net>/exists), andsnapshot-contracts.--force-new,--update,--replayand--acknowledge-nonceare never forwarded (a unit test pins this).--record … --scratch-on testnet --out <dir>) is the testnet rehearsal of the same steps.Verified:
--network testnet --post-onlyagainst 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-onlystops 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