Repository navigation
refactor(deployments): replace Zone routers by their compiled code, not a release number #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,7 @@ import { | |
| import { | ||
| captureDeploymentSource, | ||
| earliestDeploymentBlock, | ||
| replacedComponents, | ||
| runtimeCodeHashes, | ||
| verifyDeploymentProvenance, | ||
| } from './provenance.js' | ||
|
|
@@ -174,6 +175,22 @@ async function deployEarnProfileLocked(options: LifecycleOptions): Promise<EarnD | |
| const reconciling = committed | ||
| ? changedIntentComponents(committed.componentDeploymentIntentHashes, profile) | ||
| : new Set<IntentComponent>() | ||
| // Immutable periphery built from other code than this checkout's is replaced like changed intent. | ||
| const compile = (contract: string) => | ||
| compiledRuntimeCode(options.root, contract, options.environment) | ||
| const replaced = committed | ||
| ? await replacedComponents(client, profile, committed, compile) | ||
| : new Set<IntentComponent>() | ||
| for (const component of replaced) reconciling.add(component) | ||
| // A paused replacement may itself predate this checkout's build, so cached contracts are checked too. | ||
| const staleCached = committed | ||
| ? await replacedComponents( | ||
| client, | ||
| profile, | ||
| { addresses: cachedPendingOutputs(options.profilePath, profile) }, | ||
| compile, | ||
| ) | ||
| : new Set<IntentComponent>() | ||
|
Comment on lines
+185
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Medium: First-deployment resume keeps a router built from an older checkout The PR now decides router replacement by comparing compiled code and freezes the router intent hashes. However, the cached-output code check runs only when a committed record exists. An interrupted first deployment therefore resumes with a router built by an older checkout. Full findingThe PR now decides router replacement by comparing compiled code and freezes the router intent hashes. However, the cached-output code check runs only when a committed record exists. An interrupted first deployment therefore resumes with a router built by an older checkout. On hosted chains, record building then fails. On other chains, the record publishes the stale router. Valid? React with 👍 / 👎.
Comment on lines
+185
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs review · unverified: Missing code in disposable cache blocks a valid committed deployment A formerly mined replacement address can remain in pending outputs after a chain rollback that leaves the committed address intact. If the operator resumes on the committed build with unchanged intent, committed state should override that cache, as it did before this PR. Full findingA formerly mined replacement address can remain in pending outputs after a chain rollback that leaves the committed address intact. If the operator resumes on the committed build with unchanged intent, committed state should override that cache, as it did before this PR. Instead, the new cache scan runs before restoration and sends the obsolete cached address to the strict provenance helper. An empty getCode response throws, preventing the valid committed address from being restored. The command continues to fail while the cache remains, without broadcasting or charging additional transaction fees; moving the cache aside recovers the valid committed path. The precondition is a lost cached replacement and surviving committed state; no ability for an unprivileged party to cause that chain state was established. Check only cache entries eligible to be retained, or classify a definite empty-code response as stale for cached addresses only. Keep RPC failures and missing committed code fatal. Valid? React with 👍 / 👎. |
||
| syncFoundryOutputs(options.root, options.profilePath) | ||
|
Comment on lines
+185
to
194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Medium (trigger unconfirmed) · unverified: Stale Foundry checkpoints bypass router build reconciliation On a profile with a committed record, stop after Forge broadcasts an intermediate SingleZoneEarnRouter replacement and writes latestOutputs, but before the lifecycle records the action. Resume from another checkout with a different router build and the same profile. The new cache probe reads only outputs and runs before external staging synchronization; restoration also preserves latestOutputs unchanged. Full findingOn a profile with a committed record, stop after Forge broadcasts an intermediate SingleZoneEarnRouter replacement and writes latestOutputs, but before the lifecycle records the action. Resume from another checkout with a different router build and the same profile. The new cache probe reads only outputs and runs before external staging synchronization; restoration also preserves latestOutputs unchanged. Reconciliation then overlays the older address from latestOutputs and accepts its bindings before considering a new broadcast. If the old successful receipt is recoverable on a hosted chain, the current initcode check rejects it and retries hit the same checkpoint rather than deploying the current build. On a non-hosted chain that creation check is skipped, so the old build can be reused. This requires an interrupted operator deployment and an intervening build change; no unprivileged trigger or affected live deployment was established. On hosted chains the interruption blocks progress without further transaction spend on each retry; the ordinary successful path needs a replacement broadcast. Synchronize staging first, classify mined latestOutputs independently of materialized outputs, and remove definitively stale checkpoint entries before recovery while preserving current-build checkpoints and receipt validation. Valid? React with 👍 / 👎. |
||
| let pending: PendingDeployment | ||
| if (committed) { | ||
|
|
@@ -189,7 +206,13 @@ async function deployEarnProfileLocked(options: LifecycleOptions): Promise<EarnD | |
| committed.source.factoryDeploymentId, | ||
| ) | ||
| } | ||
| pending = restorePendingDeployment(options.profilePath, profile, committed) | ||
| pending = restorePendingDeployment( | ||
| options.profilePath, | ||
| profile, | ||
| committed, | ||
| replaced, | ||
| staleCached, | ||
| ) | ||
| } else { | ||
| pending = loadPendingDeployment(options.profilePath, profile) | ||
| } | ||
|
|
@@ -257,6 +280,7 @@ async function deployEarnProfileLocked(options: LifecycleOptions): Promise<EarnD | |
| const candidate = await buildDeploymentRecord(client, { | ||
| pending: deployed.pending, | ||
| committed, | ||
| replaced, | ||
| rpcUrl: options.rpcUrl, | ||
| environment: options.environment, | ||
| profile, | ||
|
|
@@ -447,6 +471,7 @@ async function buildDeploymentRecord( | |
| options: { | ||
| pending: PendingDeployment | ||
| committed: EarnDeploymentRecord | undefined | ||
| replaced: ReadonlySet<IntentComponent> | ||
| rpcUrl: string | ||
| environment: NodeJS.ProcessEnv | ||
| profile: EarnDeploymentProfile | ||
|
|
@@ -468,7 +493,10 @@ async function buildDeploymentRecord( | |
| ) as EarnDeploymentRecord['actions'] | ||
| const previous = options.committed | ||
| const changed = previous | ||
| ? changedIntentComponents(previous.componentDeploymentIntentHashes, profile) | ||
| ? new Set([ | ||
| ...changedIntentComponents(previous.componentDeploymentIntentHashes, profile), | ||
| ...options.replaced, | ||
| ]) | ||
| : undefined | ||
| // Carry proof with its creator's unchanged intent, address, and action, not with consumers that may change independently. | ||
| const contracts = Object.fromEntries( | ||
|
|
@@ -748,6 +776,15 @@ export function publicFixtureAddresses() { | |
| ) | ||
| } | ||
|
|
||
| /** The contracts a resumable pending file holds, or none when there is no usable one. */ | ||
| function cachedPendingOutputs(profilePath: string, profile: EarnDeploymentProfile) { | ||
| try { | ||
| return loadPendingDeployment(profilePath, profile).outputs as DeploymentAddresses | ||
| } catch { | ||
| return {} | ||
| } | ||
| } | ||
|
|
||
| /** Compiles one release contract with the deploy profile and reads its immutable slots. */ | ||
| function compiledRuntimeCode( | ||
| root: string, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| deploymentAddressComponents, | ||
| deploymentAddressKeys, | ||
| type DeploymentAddressKey, | ||
| type IntentComponent, | ||
| } from './components.js' | ||
| import { | ||
| parseCompletedAction, | ||
|
|
@@ -169,6 +170,10 @@ | |
| EarnDeploymentRecord, | ||
| 'addresses' | 'actions' | 'componentDeploymentIntentHashes' | ||
| >, | ||
| // Components whose recorded contracts are replaced although their intent is unchanged. | ||
| replaced: ReadonlySet<IntentComponent> = new Set(), | ||
| // Components whose cached pending contracts do not run this checkout's build either. | ||
| staleCached: ReadonlySet<IntentComponent> = replaced, | ||
| ): PendingDeployment { | ||
| let cached: PendingDeployment | ||
| try { | ||
|
|
@@ -178,10 +183,9 @@ | |
| } | ||
| const currentComponents = componentDeploymentIntentHashes(profile) | ||
| const recordedComponents = committed.componentDeploymentIntentHashes | ||
| const componentMatches = (id: EarnDeploymentActionId) => | ||
| deploymentStep(id).intent.every( | ||
| (component) => recordedComponents[component] === currentComponents[component], | ||
| ) | ||
| const retained = (component: IntentComponent) => | ||
| !replaced.has(component) && recordedComponents[component] === currentComponents[component] | ||
| const componentMatches = (id: EarnDeploymentActionId) => deploymentStep(id).intent.every(retained) | ||
| const committedDeploymentActions = Object.fromEntries( | ||
| deploymentActions(profile).flatMap((action) => | ||
| committed.actions[action.id] && componentMatches(action.id) | ||
|
|
@@ -191,17 +195,34 @@ | |
| ) as PendingDeployment['actions'] | ||
| const addressComponentMatches = (key: DeploymentAddressKey) => { | ||
| const component = deploymentAddressComponents[key] | ||
| return component !== undefined && recordedComponents[component] === currentComponents[component] | ||
| return component !== undefined && retained(component) | ||
| } | ||
| const committedAddresses = Object.fromEntries( | ||
| Object.entries(committed.addresses).filter(([key]) => | ||
|
Comment on lines
200
to
201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Operators who resume from a leftover pending file can get the old router reused, and the record republished with it, even though its code differs from the build. Why this was flaggedA pending file with the same intent hash survives any run that called restorePendingDeployment (pending.ts:208 saves committed addresses such as Verification: Trigger: a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The latest push brings this issue back at 🔴 Operators who resume a paused router replacement after another router code change keep the first replacement, which is also stale. Hosted chains then hit a creation mismatch on every run; other chains silently record it. Why this was flaggedRouter change A lands and Deploy deploys router A. The run then stops at a handoff or is interrupted before the record is rebuilt, so Verification: A is not C, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The latest push brings this issue back at 🔴 An operator resuming after an interrupted router deploy can still get a router built from superseded code adopted, because only Why this was flaggedTrigger: the router is being replaced, and a Forge run writes Verification: |
||
| addressComponentMatches(key as DeploymentAddressKey), | ||
| ), | ||
| ) | ||
| // A cached contract built from other code, or an action completed against one, is stale; a cached | ||
| // replacement that runs this checkout's build is resumed. | ||
| const staleAddress = (key: string) => { | ||
| const component = deploymentAddressComponents[key as DeploymentAddressKey] | ||
| return component !== undefined && staleCached.has(component) | ||
| } | ||
| const cachedOutputs = Object.fromEntries( | ||
| Object.entries(cached.outputs).filter(([key]) => !staleAddress(key)), | ||
| ) | ||
| const cachedActions = Object.fromEntries( | ||
| Object.entries(cached.actions).filter( | ||
| ([id]) => | ||
| !deploymentStep(id as EarnDeploymentActionId).intent.some((component) => | ||
| staleCached.has(component), | ||
| ), | ||
| ), | ||
| ) as PendingDeployment['actions'] | ||
| const pending: PendingDeployment = { | ||
| ...cached, | ||
|
Check failure on line 223 in deployments/core/pending.ts
|
||
| outputs: { ...cached.outputs, ...committedAddresses }, | ||
| actions: { ...cached.actions, ...committedDeploymentActions }, | ||
| outputs: { ...cachedOutputs, ...committedAddresses }, | ||
| actions: { ...cachedActions, ...committedDeploymentActions }, | ||
| } | ||
| savePendingDeployment(profilePath, profile, pending) | ||
| return pending | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟣 pre-existing, not blocking: After merging, any router bytecode change makes the next Deploy run silently swap in a new router. The superseded router keeps its Zone Portal role and PropAMM pool admission, and nobody is told.
replacedComponentsdrops the oldearnRouter/zoneRouterand re-runs only the grant steps for the new address. No step revokes the old router's roles or flags it for revocation. Fix: when a replaced component's old router still holds Portal roles or pool admission, report it as a blocker or handoff that names the old address (or emit its revoke calls), so replacement never leaves two privileged routers.A small fix can ride a push you are already making; otherwise a short reply is enough.
Why this was flagged
Trigger: a source, compiler (solar.lock) or metadata-only change to SingleZoneEarnRouter or ZoneRouterFactory/ZoneRouter, then a broadcast Deploy run. At deploy.ts:178-184,
replacedComponents(provenance.ts:47-70) flagszoneorzoneRouterFactory/zoneRouter. restorePendingDeployment (pending.ts:184-200) then drops the old address. The new router is deployed. Steps such asauthorize-router(pool admission, earn/zone-router/steps.ts:134-147) andregister-zone-gateway(chain/zone.ts:340) check and grant only the newearnRouter. There is no revoke step for the replaced router. The old immutable, ownerless router therefore stays admitted on the pool and the Portal, and the run reportscomplete. On the base branch this only happened when someone deliberately bumpedrouterContractRelease/zoneRouterContractRelease, a reviewed event where an operator could also revoke. Now it happens automatically and more often, so privileged routers pile up unnoticed.Verification: Pre-existing, made wider by this change. deploy.ts:178-184 adds what
replacedComponentsreturns toreconciling, and pending.tsretaineddrops the recordedearnRouter/zoneRouteraddress.authorize-router(earn/zone-router/steps.ts:133-163) then admits only the new address, and no step revokes or reports the old router.