fix(deploy): persist session key only after map_account confirms on chain (#94)#106
Merged
Merged
Conversation
Contributor
|
Dev build ready — try this branch: |
Contributor
E2E Test Pass · ✅ PASSTag:
Sentry traces: view spans for this run |
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.
Closes #94.
Bug
Session-key creation writes to
accounts.jsonBEFORE the on-chainmap_accountextrinsic is confirmed. Ifmap_accountfails (race-inducedStalenonce, network blip, etc), the local file says "key created" but the chain has no mapping. Retries find the existing key (created=false), skip the mapping step, and dry-run fails withRevive::AccountUnmapped.Fix
Split create-from-or-load-disk from persist-to-disk. The deploy flow now:
getOrCreateSessionAccount— returns key (created in-memory if new, loaded from disk if existing). Does NOT write to disk.created:map_accountextrinsic — fail loudly here if anything goes wrong, no on-disk side effect.persistSessionAccount— write to disk only AFTER mapping confirmed.Failures between (1) and (3) leave the on-disk state untouched, so retries treat it as a fresh create and re-map.
Implementation notes
InMemoryKvStoreadded tosession-account.tsto backSessionKeyManager.create()without touching the filesystem.persistSessionAccount(info)exported fromsession-account.ts— writes the mnemonic under the"default"key, same shape as before.run.tsupdated:persistSessionAccountcalled immediately aftersubmitAndWatch(map_account())returns, inside theif (created)branch.run.ts); no back-compat wrapper needed.Test plan
getOrCreateSessionAccountfresh call: valid key returned, file absentgetOrCreateSessionAccount→persistSessionAccount: file written with correct mnemonicgetOrCreateSessionAccountafter persist:created=false, same mnemonic loadedcreated=truewith different key → retry would re-map