Initializations: version-addressed init contracts run atomically at publish - #86
Merged
Conversation
Collaborator
Author
|
Revised the Solidity convention per review: initializations are now addressed by (contract, version) uniformly — Rust |
…les; initialize() entry point
… note the initializations convention in CLAUDE.md
… drop unused bytecodeSize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds initializations: code that runs exactly once, in the same transaction that publishes a version, against the name's proxy storage. Covers both first-publish setup and upgrade-time storage migration. Closes #77.
How it works
An initialization is addressed by (contract, version) and runs when that version is published. No file for a version → plain publish. A file for an already-published version never runs again.
Each file exposes
initialize(uint128 from, address owner)—fromis the previous latest version (0 on first publish),ownerthe name's registry owner. A revert rolls back the whole publish.cdm deploybuilds the file through a generated shim crate. Each file declares its own copy of the contract's storage fields, so old initializations are frozen text that later contract changes can't break.contract Init is Counter); the directory name routes it.A deploy-time layout guard compares the initialization's storage layout against the implementation's and refuses on mismatch.
On-chain changes
callCode(address, bytes)— delegatecall into proxy storage, live while frozen (so freeze → publish+init → unfreeze works). The frozen proxy blob is regenerated:0x9c918a8b…542e86.publishWithInit(...), which publishes and then callscallCodeon the proxy. Initialization contracts are never registered versions, socallCodeis the only path to them — no access-control boilerplate needed in user code.Also
initializations/0.1.0.{rs,sol}; empty constructors removed.trie-db).initializations.e2e.test.ts(Rust matrix) + Solidity cases; full local suite green.