task(node): unify genesis state source for offline subcommands [PM-20203]#768
Merged
gilescope merged 5 commits intoMar 2, 2026
Merged
Conversation
Contributor
All offline subcommands (check-block, export-blocks, export-state, import-blocks, revert, partner-chains, and benchmark sub-arms) now derive StorageInit.genesis_state from chain_spec.properties() via genesis_state_from_chain_spec(), instead of hardcoding UndeployedNetwork.genesis_state(). This ensures subcommands use the correct genesis state for the active chain specification. Changes: - Add genesis_state_from_properties() and thin wrapper genesis_state_from_chain_spec() to extract hex-encoded genesis state from chain spec properties with descriptive error handling - Add verify_genesis_consistency() for blake2_256 hash comparison between chain spec and compiled-in genesis - Move StorageInit creation from function scope into 7 match arm closures (10 call sites) where config.chain_spec is available - Remove unused MidnightNetwork trait import - Add 6 unit tests covering valid extraction, missing key, non-string value, invalid hex, hash match, and hash mismatch Made-with: Cursor
Add storage_init_from_chain_spec() to eliminate 10 repeated StorageInit struct literals across subcommand match arms. Add doc comments to all new functions. Made-with: Cursor
Add #[allow(dead_code)] to verify_genesis_consistency (not yet wired into a runtime call site). Add change file for CI.
32e1d29 to
1ebefcd
Compare
NachoPal
approved these changes
Mar 1, 2026
Signed-off-by: Giles Cope <gilescope@gmail.com>
Signed-off-by: Giles Cope <gilescope@gmail.com>
gilescope
approved these changes
Mar 2, 2026
gilescope
left a comment
Contributor
There was a problem hiding this comment.
genesis_state_from_properties lacks MAX_GENESIS_STATE_BYTES size guard but that's the only nit.
gilescope
pushed a commit
that referenced
this pull request
Apr 8, 2026
m2ux
added a commit
that referenced
this pull request
Apr 23, 2026
Signed-off-by: Mike Clay <mike.clay@shielded.io>
m2ux
added a commit
that referenced
this pull request
Apr 23, 2026
Signed-off-by: Mike Clay <mike.clay@shielded.io>
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.








Summary
Offline subcommands now derive genesis state from the chain specification instead of the hardcoded UndeployedNetwork default, fixing a Least Authority audit finding (Issue L) where offline commands failed on deployed networks.
🎫 PM-20203 📐 Engineering
Motivation
Offline subcommands (CheckBlock, ExportBlocks, ExportState, ImportBlocks, Revert, and all benchmark variants) constructed
StorageInitusingUndeployedNetwork.genesis_state()at function scope, before the chain specification was available. This meant any network other thanundeployedwould initialize the ledger database with the wrong genesis state, causing silent data corruption or runtime panics.This was identified as Issue L in the Least Authority security audit.
Changes
Architecture Summary
genesis_state_from_chain_specandstorage_init_from_chain_spechelpers that derive genesis state fromconfig.chain_spec.properties()at the point where the chain specification is availableStorageInitconstruction into each subcommand'sasync_run/sync_runclosure (10 call sites across CheckBlock, ExportBlocks, ExportState, ImportBlocks, Revert, PartnerChains, and 4 benchmark variants)verify_genesis_consistencyfor future blake2_256-based genesis validation (currently unused, annotated#[allow(dead_code)])UndeployedNetwork.genesis_state()call and its unusedMidnightNetworkimportchanges/changed/offline-subcommands-undeployed-genesis.md📌 Submission Checklist
🔱 Fork Strategy
🗹 TODO before merging