Skip to content
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

Remove sp_runtime::RuntimeString and replace with Cow<'static, str> or String depending on use case #5693

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nazar-pc
Copy link
Contributor

@nazar-pc nazar-pc commented Sep 12, 2024

Description

As described in #4001 RuntimeVersion was not encoded consistently using serde. Turned out it was a remnant of old times and no longer actually needed. As such I removed it completely in this PR and replaced with Cow<'static, str> for spec/impl names and String for error cases.

Fixes #4001.

Integration

For downstream projects the upgrade will primarily consist of following two changes:

#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
-	spec_name: create_runtime_str!("statemine"),
-	impl_name: create_runtime_str!("statemine"),
+	spec_name: alloc::borrow::Cow::Borrowed("statemine"),
+	impl_name: alloc::borrow::Cow::Borrowed("statemine"),
		fn dispatch_benchmark(
			config: frame_benchmarking::BenchmarkConfig
-		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
+		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {

SCALE encoding/decoding remains the same as before, but serde encoding in runtime has changed from bytes to string (it was like this in std environment already), which most projects shouldn't have issues with. I consider the impact of serde encoding here low due to the type only being used in runtime version struct and mostly limited to runtime internals, where serde encoding/decoding of this data structure is quite unlikely (though we did hit exactly this edge-case ourselves 😅).

Review Notes

Most of the changes are trivial and mechanical, the only non-trivial change is in substrate/primitives/version/proc-macro/src/decl_runtime_version.rs where macro call expectation in sp_version::runtime_version implementation was replaced with function call expectation.

Checklist

  • My PR includes a detailed description as outlined in the "Description" and its two subsections above.
  • My PR follows the labeling requirements of this project (at minimum one label for T required)
    • External contributors: ask maintainers to put the right label on your PR.
  • I have made corresponding changes to the documentation (if applicable)

@nazar-pc nazar-pc requested review from sorpaas, a team and koute as code owners September 12, 2024 15:36
@nazar-pc nazar-pc force-pushed the remove-RuntimeString branch 2 times, most recently from f0df22e to 308d2a9 Compare September 12, 2024 16:02
@nazar-pc
Copy link
Contributor Author

nazar-pc commented Sep 12, 2024

I do not understand why formatter in CI wants those trailing whitespaces, I'm unable to commit them for some reason in IDE.

UPD: nano did it.

@nazar-pc nazar-pc force-pushed the remove-RuntimeString branch 2 times, most recently from 096e2d6 to f3778c1 Compare September 12, 2024 16:30
@@ -82,8 +82,8 @@ impl_opaque_keys! {
/// This runtime version.
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("shell"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_runtime_str macro should stay and annotated as deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about that and to also make RuntimeString a type alias to the Cow, but wasn't sure if it was worth it. Seemed like a trivial change to upgrade, also required re-export of the hidden Cow from the crate, which I also didn't like at all, and if RuntimeString is removed then it is still a breaking change one way or the other.

If still desirable, should I also keep re-exports in sp-version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkchr I'd like to get clarity here so I can update PR with corresponding changes

nazar-pc added a commit to autonomys/polkadot-sdk that referenced this pull request Sep 27, 2024
# Conflicts:
#	cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs
#	polkadot/runtime/rococo/src/genesis_config_presets.rs
#	templates/parachain/runtime/src/genesis_config_presets.rs
@nazar-pc
Copy link
Contributor Author

Fixed merge conflicts and restored create_runtime_str

@nazar-pc nazar-pc requested a review from bkchr September 27, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

serde for RuntimeString is broken
2 participants