Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

remove serde derive for BlockId #13457

Merged
merged 1 commit into from
Mar 7, 2023

Conversation

yjhmelody
Copy link
Contributor

The BlockId serde is never used in substrate.
And I think it's a bad design. It could not be used in rpc api.

@yjhmelody
Copy link
Contributor Author

BTW, What's the best practice to support a rpc both for BlockNumber and Hash?

@bkchr
Copy link
Member

bkchr commented Feb 24, 2023

BTW, What's the best practice to support a rpc both for BlockNumber and Hash?

#[derive(Copy, Clone, Serialize, Deserialize, Debug, PartialEq)]
#[serde(untagged)]
pub enum NumberOrHex {
/// The number represented directly.
Number(u64),
/// Hex representation of the number.
Hex(U256),
}

@bkchr
Copy link
Member

bkchr commented Feb 24, 2023

The BlockId serde is never used in substrate.

You don't know what downstream is doing. Having there serde is not harming anyone. Please revert, but we can keep the const fn change.

@yjhmelody
Copy link
Contributor Author

yjhmelody commented Feb 24, 2023

BTW, What's the best practice to support a rpc both for BlockNumber and Hash?

#[derive(Copy, Clone, Serialize, Deserialize, Debug, PartialEq)]
#[serde(untagged)]
pub enum NumberOrHex {
/// The number represented directly.
Number(u64),
/// Hex representation of the number.
Hex(U256),
}

Very strange, the hex is not about hash but block number( and if it's about block hash, it must be u256, could not be other. e.g. u512. Although u256 is main stream).

@bkchr
Copy link
Member

bkchr commented Feb 25, 2023

Very strange, the hex is not about hash but block number

Yeah you are right, I mixed this up. All RPCs also work with hash, besides the one that can give you a block number for a hash. In general, using hash is much better to address blocks to ensure that you are accessing the correct block.

@yjhmelody
Copy link
Contributor Author

yjhmelody commented Mar 1, 2023

It's very easy for downstream to define a old BlockId type and impl From if they need.

The BlockId even have not #[serde(untagged)], I do not think anyone will use the serde derive

@yjhmelody
Copy link
Contributor Author

I think it's better to also derive deserialize and add #[serde(untagged)].
But this leads to a silent behavior change, so I think remove the serde derive first, then after a while, add it back as needed

@bkchr
Copy link
Member

bkchr commented Mar 1, 2023

And I think it's a bad design. It could not be used in rpc api.

If you give some better description than just "bad design", I'm okay with merging this.

@yjhmelody
Copy link
Contributor Author

yjhmelody commented Mar 2, 2023

i don't know what you want to express

There is no such word in the title.

I can close this PR. I just think that BlockId can be integrated into many substrate and third parties RPCs in the future

@bkchr
Copy link
Member

bkchr commented Mar 2, 2023

You are saying it is a bad design and I just want to understand why it is a bad design. Not more.

@yjhmelody
Copy link
Contributor Author

yjhmelody commented Mar 7, 2023

You are saying it is a bad design and I just want to understand why it is a bad design. Not more.

Hi, I means it have no #[serde(untagged)], I think no one will use it when serialize it to json. And it doesn't even support deserialization.

If someone did, I think it is also very bad, it should be kept in the same style as NumberOrHex

@bkchr bkchr added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Mar 7, 2023
@bkchr bkchr merged commit c09ce08 into paritytech:master Mar 7, 2023
@yjhmelody yjhmelody deleted the block-id-remove-serde branch March 7, 2023 09:02
ukint-vs pushed a commit to gear-tech/substrate that referenced this pull request Apr 10, 2023
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants