runtimes: presets are provided as config patches#6349
Merged
michalkucharczyk merged 13 commits intomasterfrom Nov 8, 2024
Merged
runtimes: presets are provided as config patches#6349michalkucharczyk merged 13 commits intomasterfrom
michalkucharczyk merged 13 commits intomasterfrom
Conversation
gui1117
approved these changes
Nov 5, 2024
Contributor
gui1117
left a comment
There was a problem hiding this comment.
Looks good to me, minor comments.
gui1117
reviewed
Nov 6, 2024
iulianbarbu
reviewed
Nov 6, 2024
iulianbarbu
approved these changes
Nov 6, 2024
bkchr
approved these changes
Nov 8, 2024
michalkucharczyk
commented
Nov 8, 2024
dudo50
pushed a commit
to paraspell-research/polkadot-sdk
that referenced
this pull request
Jan 4, 2025
This PR introduces usage of `build_struct_json_patch` macro in all runtimes (also guides) within the code base. It also fixes macro to support _field init shorthand_, and _Struct Update_ syntax which were missing in original implementation. Follow up of paritytech#5700 and paritytech#5813
30 tasks
7 tasks
9 tasks
This was referenced Jun 16, 2025
This was referenced Jul 16, 2025
ffarall
added a commit
to Moonsong-Labs/storage-hub
that referenced
this pull request
Mar 13, 2026
### Notable changes: * Downgraded rust toolchain version from `1.91` to `1.90` ```toml # Rust 1.90 is required due to polkadot-sdk stable2503 compatibility. # Rust 1.91+ breaks pallet-revive-fixtures compilation with error: # "target-pointer-width: invalid type: string '64', expected u16" # This is because polkavm-linker generates target specs with "target-pointer-width": "64" (string), # but Rust 1.91 (PR #144443) changed this to require an integer: "target-pointer-width": 64. # polkadot-sdk stable2503 was tested with Rust 1.84.1; 1.90 is the latest compatible version. channel = "1.90" ``` Changes were also caused by this change due to clippy warnings that were not present in 1.91. * paritytech/polkadot-sdk#7634: `DecodeWithMemTracking` trait derivation was added to `RuntimeCall`. ~~This change would have been simply inherited if sp-trie updated their `CompactProof` type which we use extensively in the codebase.~~ ~~To satisfy the bound, proof types at extrinsic boundaries now use `Vec<Vec<u8>>` instead of `CompactProof` (aliased as [`CompactProofEncodedNodes`](https://github.com/Moonsong-Labs/storage-hub/pull/671/files#diff-c35139710c5462fa6b2f0c0376c749266f0edfc94da2acf58ddecab8c39de37dR27-R32). This represents the `encoded_nodes` field of a compact proof which implements `DecodeWithMemTracking` by the parity-scale-code crate. The conversion to `CompactProof` is done internally when needed for trie operations.~~ ~~This was one of the two solutions that posed the least amount of code changes and is easier to change once `CompactProof` implements the new trait. The other more intrusive way was wrapping the `CompactProof` in a struct which implements the trait, but this lead to many changes that were hard to track.~~ > **Note:** This is a **temporary workaround**. Once `CompactProof` implements `DecodeWithMemTracking` upstream in `sp-trie`, this change will be reverted to use `CompactProof` directly again. paritytech/polkadot-sdk#11028 * paritytech/polkadot-sdk#7043 `sp-std` crate is deprecated and all uses of it in the codebase have been replaced with the `alloc` or `core` equivalent imports. * paritytech/polkadot-sdk#6140 Wrapped transaction extensions for both parachain and solochain-evm runtimes with `StorageWeightReclaim`. `StorageWeightReclaim` is meant to be used as a wrapping of the whole transaction extension pipeline, and will take into account all proof size accurately. ```rust /// The TransactionExtension to the basic transaction logic. pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< Runtime, ( frame_system::CheckNonZeroSender<Runtime>, frame_system::CheckSpecVersion<Runtime>, frame_system::CheckTxVersion<Runtime>, frame_system::CheckGenesis<Runtime>, frame_system::CheckEra<Runtime>, frame_system::CheckNonce<Runtime>, frame_system::CheckWeight<Runtime>, pallet_transaction_payment::ChargeTransactionPayment<Runtime>, frame_metadata_hash_extension::CheckMetadataHash<Runtime>, ), >; ``` * **Frontier EVM / `ProofSizeExt` on solochain-evm:** Frontier EVM (stable2503) introduced `get_proof_size()` host function calls at multiple points in the EVM runner to measure actual proof size via the `ProofSizeExt` host extension. If `ProofSizeExt` is present during block building but absent during block import on syncing nodes, `get_proof_size()` returns different values on each path, leading to different gas/weight calculations, different state roots, and digest mismatch panics. To fix this, two changes were made to the solochain-evm node service: * **Block building**: `ProposerFactory::with_proof_recording` (instead of `ProposerFactory::new`) to register `ProofSizeExt` during block authoring. * **Block import**: `sc_service::new_full_parts_record_import(..., true)` (instead of `new_full_parts`) so that the Client registers `ProofSizeExt` during block import on syncing BSP/MSP nodes, matching the block building path. - paritytech/polkadot-sdk#6349: Genesis config preset files have been migrated to use the new `build_struct_json_patch!` macro instead of the previous pattern of constructing a full `RuntimeGenesisConfig` struct and serializing it with `serde_json::to_value()`. Before: ```rust let config = RuntimeGenesisConfig { balances: BalancesConfig { ... }, ..Default::default() }; serde_json::to_value(config).expect("Could not build genesis config.") ``` After: ```rust use frame_support::build_struct_json_patch; build_struct_json_patch!(RuntimeGenesisConfig { balances: BalancesConfig { ... }, }) ``` * paritytech/polkadot-sdk#8461 Substrate based chains are now configured to use `litep2p` as the network backend (before was libp2p) While `litep2p` implements the same wire protocol and is interoperable with `libp2p` nodes, several behavioral differences required fixes: * **GRANDPA notification keepalive**: In dev mode with manual sealing, the GRANDPA voter is not started but its notification protocol is still registered for P2P negotiation. `litep2p` kills all P2P connections if any registered notification protocol's service handle is dropped (unlike `libp2p` which tolerates this). A keepalive task was added that drains GRANDPA notification events without running consensus, keeping the protocol handler alive for the lifetime of the node. * **Chunk uploader retry count**: `litep2p` maps transient connectivity errors (`ConnectionClosed`, `SubstreamClosed`, `dial-failed`, etc.) to `RequestFailure::Refused` instead of `RequestFailure::NotConnected`. The chunk uploader's retry limit for `Refused` errors was increased from 3 to 30 to handle peer recovery scenarios during file uploads. * **Integration tests**: Integration tests were modified to take into account hew new `Refused` error propagation which changed timing and logging assertions in the tests. ##⚠️ Breaking Changes⚠️ - **Short description** The transaction extension pipeline (`SignedExtra` / `TxExtension`) must now be wrapped with `cumulus_pallet_weight_reclaim::StorageWeightReclaim`. This wrapper measures PoV size before and after execution and reclaims unused storage weight, including weight consumed by the extensions themselves. Runtimes must also implement `cumulus_pallet_weight_reclaim::Config`. This affects: - The `SignedExtra` / `TxExtension` type alias - The `from_minimal_extension` implementation (must wrap the inner extension tuple) - The `compute_signed_extra_implicit` runtime API implementation (same wrapping) - **Who is affected** * **Downstream runtimes** that integrate StorageHub pallets and define their own transaction extension pipeline * **Client code** that implements `ExtensionOperations::from_minimal_extension` - **Suggested code changes** Type alias: Before: ```rust pub type SignedExtra = ( frame_system::CheckNonZeroSender<Runtime>, frame_system::CheckSpecVersion<Runtime>, frame_system::CheckTxVersion<Runtime>, frame_system::CheckGenesis<Runtime>, frame_system::CheckEra<Runtime>, frame_system::CheckNonce<Runtime>, frame_system::CheckWeight<Runtime>, pallet_transaction_payment::ChargeTransactionPayment<Runtime>, frame_metadata_hash_extension::CheckMetadataHash<Runtime>, ); ``` After: ```rust pub type SignedExtra = cumulus_pallet_weight_reclaim::StorageWeightReclaim< Runtime, ( frame_system::CheckNonZeroSender<Runtime>, frame_system::CheckSpecVersion<Runtime>, frame_system::CheckTxVersion<Runtime>, frame_system::CheckGenesis<Runtime>, frame_system::CheckEra<Runtime>, frame_system::CheckNonce<Runtime>, frame_system::CheckWeight<Runtime>, pallet_transaction_payment::ChargeTransactionPayment<Runtime>, frame_metadata_hash_extension::CheckMetadataHash<Runtime>, ), >; ``` `from_minimal_extension`: Before: ```rust fn from_minimal_extension(minimal: MinimalExtension) -> Self { ( frame_system::CheckNonZeroSender::<Runtime>::new(), frame_system::CheckSpecVersion::<Runtime>::new(), frame_system::CheckTxVersion::<Runtime>::new(), frame_system::CheckGenesis::<Runtime>::new(), frame_system::CheckEra::<Runtime>::from(minimal.era), frame_system::CheckNonce::<Runtime>::from(minimal.nonce), frame_system::CheckWeight::<Runtime>::new(), pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(minimal.tip), frame_metadata_hash_extension::CheckMetadataHash::new(false), ) } ``` After: ```rust fn from_minimal_extension(minimal: MinimalExtension) -> Self { let inner = ( frame_system::CheckNonZeroSender::<Runtime>::new(), frame_system::CheckSpecVersion::<Runtime>::new(), frame_system::CheckTxVersion::<Runtime>::new(), frame_system::CheckGenesis::<Runtime>::new(), frame_system::CheckEra::<Runtime>::from(minimal.era), frame_system::CheckNonce::<Runtime>::from(minimal.nonce), frame_system::CheckWeight::<Runtime>::new(), pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(minimal.tip), frame_metadata_hash_extension::CheckMetadataHash::new(false), ); cumulus_pallet_weight_reclaim::StorageWeightReclaim::new(inner) } ``` New pallet config required: ```rust impl cumulus_pallet_weight_reclaim::Config for Runtime { type WeightInfo = (); } ``` --- - **Short description** For EVM runtimes using Frontier, both block building and block import must now register the `ProofSizeExt` host extension. Frontier EVM (stable2503) calls `get_proof_size()` at multiple points during EVM execution. If `ProofSizeExt` is present during block building but absent during block import on syncing nodes, `get_proof_size()` returns different values on each path, leading to different gas/weight calculations, different state roots, and digest mismatch panics. Two changes are needed in the node service: 1. `ProposerFactory::new` must be replaced with `ProposerFactory::with_proof_recording` 2. `sc_service::new_full_parts` must be replaced with `sc_service::new_full_parts_record_import` with proof recording enabled - **Who is affected** * **Downstream node implementations** that run Frontier EVM (solochain-evm or any EVM-enabled runtime) Non-EVM runtimes (e.g. parachain-only) are not affected by this specific change, though using `with_proof_recording` is still recommended for accurate `StorageWeightReclaim` operation. - **Suggested code changes** Block building — ProposerFactory: Before: ```rust let proposer_factory = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), client.clone(), transaction_pool.clone(), prometheus_registry.as_ref(), telemetry.as_ref().map(|t| t.handle()), ); ``` After: ```rust let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( task_manager.spawn_handle(), client.clone(), transaction_pool.clone(), prometheus_registry.as_ref(), telemetry.as_ref().map(|t| t.handle()), ); ``` Block import — Client initialization: Before: ```rust let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::<Block, RuntimeApi, _>( config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), executor, )?; ``` After: ```rust let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts_record_import::<Block, RuntimeApi, _>( config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), executor, true, // enable proof recording on import )?; ``` --- - **Short description** StorageHub now targets polkadot-sdk `stable2503` and frontier `stable2503`. Downstream consumers must align their polkadot-sdk and frontier dependency versions. This brings several inherited breaking changes from the Polkadot SDK upgrade. - **Who is affected** * **All downstream runtimes and node implementations** that depend on StorageHub crates - **Suggested code changes** * **`sp_std` deprecated** ([polkadot-sdk#7043](paritytech/polkadot-sdk#7043)): Replace all `sp_std::*` imports with `alloc::*` or `core::*` equivalents. Add `extern crate alloc;` where needed. ```rust // Before use sp_std::{collections::btree_map::BTreeMap, vec::Vec}; // After extern crate alloc; use alloc::{collections::BTreeMap, vec::Vec}; ``` * **Genesis config presets** ([polkadot-sdk#6349](paritytech/polkadot-sdk#6349)): Migrate from `serde_json::to_value()` to the `build_struct_json_patch!` macro. ```rust // Before let config = RuntimeGenesisConfig { balances: BalancesConfig { ... }, ..Default::default() }; serde_json::to_value(config).expect("Could not build genesis config.") // After use frame_support::build_struct_json_patch; build_struct_json_patch!(RuntimeGenesisConfig { balances: BalancesConfig { ... }, }) ``` * **`pallet_session::Config`**: Add `type DisablingStrategy = ();` * **`DecodeWithMemTracking`** ([polkadot-sdk#7634](paritytech/polkadot-sdk#7634)): Custom types used at extrinsic boundaries or in `RuntimeCall` must derive `DecodeWithMemTracking` from the `parity-scale-codec` crate. * **`litep2p` default network backend** ([polkadot-sdk#8461](paritytech/polkadot-sdk#8461)): Substrate chains now use `litep2p` instead of `libp2p` by default. While `litep2p` is wire-compatible with `libp2p`, behavioral differences exist (e.g. notification protocol handling, error mapping for request-response). <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/moonsong-labs/storage-hub/pull/671" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end --> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com>
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.
This PR introduces usage of
build_struct_json_patchmacro in all runtimes (also guides) within the code base.It also fixes macro to support field init shorthand, and Struct Update syntax which were missing in original implementation.
Follow up of #5700 and #5813