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

gensis-config: patching default RuntimeGenesisConfig fixed #6382

Merged
merged 17 commits into from
Nov 7, 2024

Conversation

michalkucharczyk
Copy link
Contributor

@michalkucharczyk michalkucharczyk commented Nov 6, 2024

This PR changes the behavior of json_patch::merge function which no longer removes any keys from the base JSON object.

fixes: #6306

@michalkucharczyk
Copy link
Contributor Author

/cmd prdoc --bump major --audience node_dev,runtime_dev

@michalkucharczyk michalkucharczyk added the T0-node This PR/Issue is related to the topic “node”. label Nov 6, 2024
@michalkucharczyk michalkucharczyk marked this pull request as ready for review November 6, 2024 09:50
@michalkucharczyk
Copy link
Contributor Author

/cmd prdoc --bump major --audience node_dev,runtime_dev

@bkchr
Copy link
Member

bkchr commented Nov 6, 2024

Do we really need these two functions? IMO null should not be handled differently than any other kind of value. If someone gives such a json, just accept it.

TLDR: I would just fix the merge function and not introduce a new one.

@michalkucharczyk
Copy link
Contributor Author

Do we really need these two functions? IMO null should not be handled differently than any other kind of value. If someone gives such a json, just accept it.

Idea of removing null comes from this document https://www.rfc-editor.org/rfc/rfc7386

But yes, we can change the behavior of merge function and introduce merge_allow_removal (which is already used here):

// We want to extract only raw genesis ("genesis::raw" key), and apply it as a patch
// for the original json file. However, the file also contains original plain
// genesis ("genesis::runtimeGenesis") so set it to null so the patch will erase it.
genesis_json.as_object_mut().map(|map| {
map.retain(|key, _| key == "genesis");
map.get_mut("genesis").map(|genesis| {
genesis.as_object_mut().map(|genesis_map| {
genesis_map
.insert("runtimeGenesis".to_string(), serde_json::Value::Null);
});
});
});
let mut org_chain_spec_json = extract_chain_spec_json(input_chain_spec.as_path())?;
json_patch::merge(&mut org_chain_spec_json, genesis_json);

We can also change behaviour of merge and remove keys manually when needed.

I just don't want to break downstream which potentially can use json_patch::merge for actually removing fields. I think proposed approach is "safest" from this point of view..

@michalkucharczyk
Copy link
Contributor Author

/cmd prdoc --bump major --audience node_dev

@bkchr
Copy link
Member

bkchr commented Nov 6, 2024

Idea of removing null comes from this document https://www.rfc-editor.org/rfc/rfc7386

Yeah I saw this.

I just don't want to break downstream which potentially can use json_patch::merge for actually removing fields. I think proposed approach is "safest" from this point of view..

I mean already break downstream by removing the function export from sc_chain_spec 🙈 I would still vote for simplicity. Question is how many people downstream are using the field removal. We would also need to change the chain-spec-generator to not remove the fields, which is also a behavior change in the program. Generally, I think that merging the null values into the final json makes more sense any way.

prdoc/pr_6382.prdoc Outdated Show resolved Hide resolved
@michalkucharczyk michalkucharczyk requested a review from a team November 6, 2024 19:23
@michalkucharczyk michalkucharczyk added this pull request to the merge queue Nov 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 7, 2024
@michalkucharczyk michalkucharczyk added this pull request to the merge queue Nov 7, 2024
Merged via the queue into master with commit 566706d Nov 7, 2024
195 of 197 checks passed
@michalkucharczyk michalkucharczyk deleted the mku-patching-default-genesis-config-fix branch November 7, 2024 14:52
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.

Benchmark command fail due to json deserialize error
6 participants