Skip to content

feat(deployer): add compact.toml patterns and per-deploy options - #193

Merged
0xisk merged 9 commits into
mainfrom
feat/deployer-toml-patterns
Sep 24, 2026
Merged

0xisk merged 9 commits into
mainfrom
feat/deployer-toml-patterns

Conversation

@0xisk

@0xisk 0xisk commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Prepares @openzeppelin/compact-deployer 0.3.0, the first release on the Ledger v9 stack (npm still serves 0.2.0 on v8). It also lets compact-contracts' live harness deploy every mock through the deployer, with compact.toml as the one source of truth.

Unblocks OpenZeppelin/compact-contracts#953 once the harness moves to the deployer.

Not visible in the diff:

  • The three new options exist because the harness deploys once per test from parallel workers, with private state and witnesses built in code. Everything else still comes from compact.toml.
  • ledger-v9 moves to rc.5 because compact-contracts main already runs it, and its resolution would override this pin anyway.
  • The only break is type-level: CompactConfigData.contracts entries are partial now. A config without patterns resolves exactly as before.
  • Verified live, beyond CI. Packed into a compact-contracts checkout, the harness deployed MockOwnable in one tx and MockNonFungibleToken (24 circuits, refused as one tx) as a 12-circuit deploy plus one insert, about 36 s each. The integration suite passes on node 2.0.0-rc.4 / indexer 4.4.0-rc.2 / proof-server 9.0.0-rc.6.

Before running "Release Package" with minor: re-date the changelog if this merges after 2026-09-24, and check that npm trusted publishing is registered for compact-deployer (still pending on 2026-09-15). compact-cli needs its own release afterwards.

PR Checklist

  • I have read the Contributing Guide
  • I have added tests that prove my fix is effective or that my feature works
  • I have added documentation of new methods and any new behavior or changes to existing behavior
  • CI Workflows Are Passing

Summary by CodeRabbit

  • New Features
    • Contract configuration can now use name and source-path patterns, with matching settings merged in order and exact entries taking precedence.
    • Deployments can receive private state and witnesses directly in code, and can run without saving deployment records.
    • Fragmented deployments reuse an accepted circuit batch size for later deployments of the same artifact and network during the same process.
  • Bug Fixes
    • Deployment errors now provide clearer transaction details when no deployment record is saved.
  • Documentation
    • Updated deployment guidance and examples to cover pattern configuration and programmatic deployment options.

compact-contracts main already runs rc.5. With rc.3 pinned here, a
consumer's resolution overrides the pin anyway, so the deployer would
run on a ledger it was never tested against.
The 0.2.0 release shipped the fragmented deploy (#174), but its entries
stayed under Unreleased and would have been published again as 0.3.0
changes.
A key with glob characters matches the contract name, and a key with
"/" matches its .compact path under the new [profile].src_dir.
Matching patterns apply in file order and the exact entry applies
last, so one table can cover every test mock in a repo.
A test harness deploys once per test from parallel workers, with
private state and witnesses built in code. initialPrivateState and
witnesses override the TOML entry, and record: false skips the
deployments ledger and its lock. Failure messages under record: false
name the address and txIds instead of a record to resume from.
With no budget set, a later deploy of the same artifact on the same
network starts at the size an earlier halving in the process settled
on, so only the first deploy pays for the refused attempt. The size
lives in memory; a pinned budget and a resume ignore it.
The spec has its own compact.toml with a pinned budget, so no halving
here can reach fragmented.spec.ts through the remembered size: the
suite runs every spec in one process.
Known issue 7 now records that one forced compact-runtime copy deploys:
compact-contracts pins 0.19.0 and its live harness deployed a
24-circuit mock through the split path on that tree.
@0xisk
0xisk requested review from a team as code owners September 24, 2026 09:40
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 7b63b43a-dd2f-4172-af88-96cc69c0a4a4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 4499ed4c-05a2-4510-8c89-7c3bffbc932e

📥 Commits

Reviewing files that changed from the base of the PR and between 3fee9df and a472fc0.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (30)
  • package.json
  • packages/deployer/CHANGELOG.md
  • packages/deployer/README.md
  • packages/deployer/package.json
  • packages/deployer/src/config/compact-config.test.ts
  • packages/deployer/src/config/compact-config.ts
  • packages/deployer/src/config/patterns.test.ts
  • packages/deployer/src/config/patterns.ts
  • packages/deployer/src/config/schema.test.ts
  • packages/deployer/src/config/schema.ts
  • packages/deployer/src/deployer.options.test.ts
  • packages/deployer/src/deployer.ts
  • packages/deployer/src/errors.test.ts
  • packages/deployer/src/errors.ts
  • packages/deployer/src/loaders/artifact.test.ts
  • packages/deployer/src/loaders/artifact.ts
  • packages/deployer/src/loaders/contract-resolve.test.ts
  • packages/deployer/src/loaders/contract-resolve.ts
  • packages/deployer/src/loaders/init-state.test.ts
  • packages/deployer/src/loaders/init-state.ts
  • packages/deployer/src/runDeploy.test.ts
  • packages/deployer/src/runDeploy.ts
  • packages/deployer/src/services/chain-state.test.ts
  • packages/deployer/src/services/chain-state.ts
  • packages/deployer/src/services/deploy-tx.ts
  • packages/deployer/src/services/fragment-size.ts
  • tests/integrations/README.md
  • tests/integrations/pattern-no-record.compact.toml
  • tests/integrations/specs/deploy/patternNoRecord.spec.ts
  • tests/integrations/specs/deploy/witnesses.type-test.ts

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.


Walkthrough

The deployer adds patterned contract configuration, in-code private state and witness options, a mode that disables deployment-ledger access, and reuse of fragment sizes reached through halving. The package also updates its Ledger v9 resolution and adds tests, integration coverage, and documentation for these changes.

Changes

Deployer configuration and deployment

Layer / File(s) Summary
Pattern-based contract configuration
packages/deployer/src/config/*, packages/deployer/src/loaders/contract-resolve.*, packages/deployer/README.md
Contract entries can match contract names or source paths. Matching entries merge in file order, with exact entries applied last. The config validates resolved entries and lists exact keys separately from patterns.
In-code state and witness options
packages/deployer/src/deployer.ts, packages/deployer/src/runDeploy.ts, packages/deployer/src/loaders/*, tests/integrations/specs/deploy/witnesses.type-test.ts, packages/deployer/README.md
Deployer.prepare and runDeploy accept in-code initial private state and witnesses. Supplied values take precedence over file references.
Deployments without ledger recording
packages/deployer/src/deployer.ts, packages/deployer/src/errors.ts, packages/deployer/src/services/*, packages/deployer/src/runDeploy.ts, tests/integrations/specs/deploy/patternNoRecord.spec.ts, tests/integrations/pattern-no-record.compact.toml
With record: false, deployments skip ledger reads and writes and do not resume existing partial deployments. Split-deployment failures report deploy transaction details instead of ledger recovery hints.
Remembered fragment sizes
packages/deployer/src/deployer.ts, packages/deployer/src/services/fragment-size.ts
The deployer remembers accepted sizes reached through halving by artifact and network, then uses them for eligible later deployments without an explicit budget or resume.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~50 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant runDeploy
  participant DeployerPrepare as Deployer.prepare
  participant ArtifactLoad as Artifact.load
  participant StateLoad as InitialPrivateState.load
  Caller->>runDeploy: initialPrivateState and witnesses options
  runDeploy->>DeployerPrepare: forward deployment options
  DeployerPrepare->>ArtifactLoad: load in-code witnesses
  DeployerPrepare->>StateLoad: load in-code initial state
Loading

Suggested reviewers: andrew-fleming

Merge Risk: ⚪ Minimal · up to a472f

No actionable merge-blocking issue is established for this change; it is mergeable after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 40 functions across 24 files. (6 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main changes: adding compact.toml contract patterns and per-deploy options.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 40 functions across 24 files. (6 skipped: 6 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

A rabbit checks the pattern keys,
Then packs state and witnesses with ease.
It skips the ledger, counts circuits anew,
Saves smaller batches for the next pass through.
“Hops!” says the rabbit, “the deploy is complete!”

Comment @coderabbitai help to get the list of available commands.

"@midnight-ntwrk/midnight-js-utils": "5.0.0-beta.7",
"@midnight-ntwrk/testkit-js": "5.0.0-beta.7",
"@midnightntwrk/ledger-v9": "1.0.0-rc.3",
"@midnightntwrk/ledger-v9": "1.0.0-rc.5",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Blocker for 0.3.0 (claude, codex): npm consumers get two ledger copies.

This line pins @midnightntwrk/ledger-v9 to exactly 1.0.0-rc.5. The deployer's own dependencies pin exactly 1.0.0-rc.3: for example @midnightntwrk/wallet-sdk-facade@5.0.0-beta.2, the other wallet-sdk-* packages, and midnight-js-protocol. In this repo the root resolutions forces rc.5 on all of them, so CI passes. npm does not read resolutions. An npm resolution of the published stack gives one top-level rc.5 copy plus eight nested rc.3 copies. With 0.2.0 it gave one copy.

The deployer passes its own ledger objects into the other copy, for example ZswapSecretKeys.fromSeed and DustSecretKey.fromSeed in wallet/handler.ts:226-227, and the deploy txs that go through midnight-js. The README says it at line 54: "a second ledger copy breaks every deploy". The README gives the pin for yarn and pnpm, but not for npm, although the install line at README.md:30 uses npm i.

Suggested fix, one of:

  1. Add the npm form to the README next to the yarn and pnpm pins, "overrides": { "@midnightntwrk/ledger-v9": "1.0.0-rc.5" }, and say that npm and bun users need it too.
  2. Add a fail-fast check in Deployer.prepare: resolve @midnightntwrk/ledger-v9/package.json from the deployer and from @midnightntwrk/wallet-sdk-facade, and throw a ConfigError that names both versions and the override when the paths differ.
  3. Keep rc.3 until the midnight-js and wallet-sdk releases pin rc.5, and let compact-contracts override it locally.

Options 1 and 2 together are the safest.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agree — fixed in 07487d8.

The wallet SDK and midnight-js-protocol pin ledger-v9 1.0.0-rc.3
exactly, so npm nests rc.3 copies next to the deployer's rc.5. The
README only gave the yarn and pnpm forms of the pin.
@0xisk
0xisk requested a review from pepebndc September 24, 2026 10:29

@pepebndc pepebndc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@0xisk
0xisk disabled auto-merge September 24, 2026 10:30
@0xisk
0xisk enabled auto-merge (squash) September 24, 2026 10:31
@0xisk
0xisk merged commit cfdad2d into main Sep 24, 2026
11 checks passed
@0xisk
0xisk deleted the feat/deployer-toml-patterns branch September 24, 2026 10:31
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.

2 participants