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

Child trie api changes BREAKING #4857

Merged
merged 74 commits into from
Apr 20, 2020
Merged

Conversation

cheme
Copy link
Contributor

@cheme cheme commented Feb 7, 2020

The child trie api got some questioning recently, so this pr try to make things cleaner and easier to specify.

  • Allows child trie to be build from their storage key only. This relies on two condition
    • storage_key of the child trie is a unique id strong enough to avoid hash collision.
    • storage_key of the child trie should only be use once for the child trie (eg if the child trie is deleted, it cannot be created again at the same place).

Contract code falls in this category, polkadot crowdfund to, I think child trie module do also (cc @thiolliere).

  • Changes the way StorageKey is define to never include ':child_storage:default:' and include it only when needed (when reading or updating parent root).

  • Separates child trie host function into their own runtime api (so future child trie of different kind could use their own).

So this breaks rpc, with this pr rpc would use storage_key without its prefix and no more child_info and child type fields. cc @Stefie
This PR also do break existing runtime by removing the child info and child type too.

This also changes TrieIdGenerator of contract pallet to stop including the child prefixes for the key, the changes needed are in the pr cc @pepyakin Closes #2325.

So for other kind of child trie new rpc api and runtime host function will be needed.

polkadot companion: paritytech/polkadot#950

@cheme cheme added A3-in_progress Pull request is in progress. No review needed at this stage. Z7-question Issue is a question. Closer should answer. labels Feb 7, 2020
@Stefie
Copy link
Contributor

Stefie commented Feb 17, 2020

So this breaks rpc, with this pr rpc would use storage_key without its prefix and default to the child_type 0 with an empty child_info description. cc @Stefie

@cheme: Adding that to the Polkdot JS API shouldn't be much work. So feel free to do these changes any time, I'd just need to change a few lines in the contracts-waterfall repo and the JS API

are not general child struct, but default child struct only).
Applying merge of ChildInfo and OwnedChildInfo.
@cheme cheme added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. Z7-question Issue is a question. Closer should answer. labels Feb 18, 2020
@cheme cheme marked this pull request as ready for review February 18, 2020 12:38
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

There is no reason to keep deprecated functions, if they are not used.



/// Deprecated, please use dedicated runtime apis.
fn child_get(
Copy link
Member

Choose a reason for hiding this comment

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

Is this code used somewhere? I don't think so?

So please remove it, the same goes for all deprecated unused functions.

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 did remove them first, but restore them back to retain compatibility with edgeware chain, but I would also really prefer to remove it (and the associated code).
Think we can break that?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, if we not do it now, we need to keep this code forever.

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 did remove the code (it messed up my last master merge and it is in latest master merge commit).

@arkpar
Copy link
Member

arkpar commented Apr 15, 2020

Changes in client/network/src/protocol/message.rs probably require protocol version bump and some code to support backward compatibility

@arkpar
Copy link
Member

arkpar commented Apr 15, 2020

This might be a good time to rename "child" to "subtree" or "substorage". Please vote if you think this is a good idea.

@cheme
Copy link
Contributor Author

cheme commented Apr 15, 2020

This might be a good time to rename "child" to "subtree" or "substorage". Please vote if you think this is a good idea.

My preference goes toward «substorage» (do not have to be a tree, just some storage with a proof system), I could also propose «substate».
This would be a big renaming but I think it will be worth it.

@gnunicorn gnunicorn added this to the 2.0 milestone Apr 15, 2020
Copy link
Contributor

@NikVolf NikVolf left a comment

Choose a reason for hiding this comment

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

for runtime interface part

@cheme
Copy link
Contributor Author

cheme commented Apr 15, 2020

Changes in client/network/src/protocol/message.rs probably require protocol version bump and some code to support backward compatibility

619b454 is trying to do that, note that it assumes input data is of the right size (I found no other way to remove possible false positive when decoding with the latest encoding without changing to much the way things are encoded).
@arkpar, I do not have code compatibility on the light client handler either, reasoning was that the child trie api should not be use at the moment (one of the latest change remove the sp-io compatibility there). I observe protobuf version is still 1 so it may not be needed (not sure how much support for light client is currently needed).

@arkpar
Copy link
Member

arkpar commented Apr 15, 2020

That's a good point. If it is not used there's no need to bother with compatibility indeed. So 619b454 could be reverted I guess. If not, you could implement custom Decode that would try to decode as previous version and then as new version if it fails. Like here: https://github.com/paritytech/substrate/blob/master/client/network/src/protocol/message.rs#L349

@cheme
Copy link
Contributor Author

cheme commented Apr 15, 2020

Hum custom decoder looks like a better idea indeed (or at least put everything in RemoteReadChildRequest), but I am reverting it right now.

@gavofyork
Copy link
Member

Needs resolving @cheme

Is there any reason we shouldn't merge this before 2.0?

@gavofyork gavofyork added A8-mergeoncegreen and removed A0-please_review Pull request needs code review. labels Apr 17, 2020
@cheme
Copy link
Contributor Author

cheme commented Apr 17, 2020

Is there any reason we shouldn't merge this before 2.0?

It is breaking some compatibility so I would think it is better if merge before 2.0. I am resolving the ci failures.

@gnunicorn
Copy link
Contributor

@cheme this needs one more conflict resolution and can be merged.

@gnunicorn gnunicorn merged commit fc6e2a6 into paritytech:master Apr 20, 2020
lamafab pushed a commit to lamafab/substrate that referenced this pull request Jun 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor redundancy of TrieIdGenerate
10 participants