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

chain-spec-builder: Add support for codeSubstitutes #4685

Merged
merged 13 commits into from
Jun 25, 2024

Conversation

skunert
Copy link
Contributor

@skunert skunert commented Jun 3, 2024

While working on #4600 I found that it would be nice if chain-spec-builder supported codeSubstitutes. After this PR is merged you can do:

chain-spec-builder add-code-substitute chain_spec.json my_runtime.compact.compressed.wasm 1234

In addition, the chain-spec-builder was silently removing relay_chain and para_id fields when used on parachain chain-specs. This is now fixed by providing a custom chain-spec extension that has these fields marked as optional.

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

LGTM, do we explain anywhere in which clusterfuck situations one needs to even use this? 😂 would be good to maybe post to the postmortem of when we used it at least for some reference.

@@ -0,0 +1,14 @@
[package]
name = "cumulus-client-chain-spec-extension"
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a new crate for them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My idea was that we can refer to this crate from small tools like chain-spec-builder without pulling in the whole world of dependencies. Which would be the case if I put it in some other bigger crate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could be also done with features, one of which could be 'api' exposing necessary types only.

Copy link
Contributor

Choose a reason for hiding this comment

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

or maybe move it to sc_chain_spec::common, as it is typical/common of parachains?

Copy link
Member

Choose a reason for hiding this comment

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

#4685 (comment) given this, we should revert these changes. Merge the pr with the codeSubstitute support and add a new one that ignores the unknown fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tracking of follow up #4873


/// Chain-spec extension that provides access to optional `relay_chain` and `para_id` fields.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
pub struct OptionalParaFieldsExtension {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed. If you are asking why we need it at all, without any extension relay_chain and para_id fields are silently removed from the chain specs.

Copy link
Member

Choose a reason for hiding this comment

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

Then we should change this to pass through any unknown fields and just modify the stuff we know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, modified this PR to just allow adding substitutes

@skunert skunert marked this pull request as ready for review June 4, 2024 12:51
@skunert skunert added the T0-node This PR/Issue is related to the topic “node”. label Jun 4, 2024
@michalkucharczyk michalkucharczyk changed the title Chain-spec-builder: Add support for codeSubstitutes and unify chain-spec-extensions chain-spec-builder: Add support for codeSubstitutes and unify chain-spec-extensions Jun 4, 2024
let chain_spec_json = serde_json::to_string_pretty(&chain_spec_json)
.map_err(|e| format!("to pretty failed: {e}"))?;
fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())?;
},
Copy link
Contributor

@michalkucharczyk michalkucharczyk Jun 4, 2024

Choose a reason for hiding this comment

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

nit: to avoid code duplication in UpdateCode and AddCodeSubstitute match arms we could add a function update_chain_spec_file_in_place which could take a closure that modifies &mut chain_spec_json provided as its input.

/// Add a code substitute in the chain spec.
///
/// The `codeSubstitute` object of the chain spec will be updated with the block height as key and
/// runtime code as value. This operation supports both plain and raw formats.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth mentioning why would we want to do this?

/// The block height at which the code should be substituted.
pub block_height: u64,
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Also this does not modify the file in-place. Maybe would be good to add a note about this. (Same case as in updateCode).

@skunert skunert changed the title chain-spec-builder: Add support for codeSubstitutes and unify chain-spec-extensions chain-spec-builder: Add support for codeSubstitutes Jun 25, 2024
@bkchr bkchr added this pull request to the merge queue Jun 25, 2024
Merged via the queue into master with commit 3c21372 Jun 25, 2024
155 of 161 checks passed
@bkchr bkchr deleted the skunert/chain-spec-builder-substitute branch June 25, 2024 13:24
TarekkMA pushed a commit to moonbeam-foundation/polkadot-sdk that referenced this pull request Aug 2, 2024
While working on paritytech#4600 I
found that it would be nice if `chain-spec-builder` supported
`codeSubstitutes`. After this PR is merged you can do:

```
chain-spec-builder add-code-substitute chain_spec.json my_runtime.compact.compressed.wasm 1234
```

In addition, the `chain-spec-builder` was silently removing
`relay_chain` and `para_id` fields when used on parachain chain-specs.
This is now fixed by providing a custom chain-spec extension that has
these fields marked as optional.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T0-node This PR/Issue is related to the topic “node”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants