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

Implement a proper generic resolution in decl_storage!#2913

Merged
bkchr merged 18 commits intomasterfrom
bkchr-srml-support-stuff
Jun 27, 2019
Merged

Implement a proper generic resolution in decl_storage!#2913
bkchr merged 18 commits intomasterfrom
bkchr-srml-support-stuff

Conversation

@bkchr
Copy link
Member

@bkchr bkchr commented Jun 20, 2019

Until now, we are required to add the generic type to types generated by decl_storage! that do not require it.
The worst outcome of this is the requirement of _genesis_phantom_data in GenesisConfig.

All of this is now fixed by this pr. We do not require anymore a phantom field in a GenesisConfig, as we do a proper lookup if a generic type is required.

Fixes: #2219

bkchr and others added 12 commits April 8, 2019 07:26
* remove default hash, introduce twox_128 and blake2

* use blake2_128 & create ext_blake2_128

* refactor code

* add benchmark

* factorize generator

* fix

* parameterizable hasher

* some fix

* fix

* fix

* fix

* metadata

* fix

* remove debug print

* map -> blake2_256

* fix test

* fix test

* Apply suggestions from code review

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* impl twox 128 concat (#2353)

* impl twox_128_concat

* comment addressed

* fix

* impl twox_128->64_concat

* fix test
@bkchr bkchr added the A0-please_review Pull request needs code review. label Jun 20, 2019
@bkchr bkchr requested a review from gui1117 June 20, 2019 08:28
@gui1117
Copy link
Contributor

gui1117 commented Jun 20, 2019

as a note the API change in the following way:

  • storage structs that doesn't need generics are now not generic: <CandidateCount<Test>>::put(1); is now CandidateCount::put(1); for some storages this breaks homogeneity of storages but make more sense with the underlying implementation.
  • GenesisConfig structs that doesn't need generics are now not generic as well, same as above this break homogeneity in favor of actual implementation
  • GenesisConfig no longer implements BuildStorage trait but only some methods which signatures differs depending on if GenesisConfig is generic of not:
    system::GenesisConfig::<Test>::default().build_storage().unwrap().0.into() is now system::GenesisConfig::default().build_storage::<Test>().unwrap().0.into() for some config.

Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

partial review

@bkchr
Copy link
Member Author

bkchr commented Jun 20, 2019

Thx for the extended summary :D

as a note the API change in the following way:

* storage structs that doesn't need generics are now not generic: `<CandidateCount<Test>>::put(1);` is now `CandidateCount::put(1);` for some storages this breaks homogeneity of storages but make more sense with the underlying implementation.

Yeah, I wanted to have it the same way, as it would be in a manual implementation.

* `GenesisConfig` structs that doesn't need generics are now not generic as well, same as above this break homogeneity in favor of actual implementation

This does not break homogeneity, we already could have GenesisConfigs without a generic argument. Now, we just do it the right way. Before, if no generic was required, but a build function was given, we still required the generic.

* `GenesisConfig` no longer implements BuildStorage trait but only some methods which signatures differs depending on if GenesisConfig is generic of not:
  `system::GenesisConfig::<Test>::default().build_storage().unwrap().0.into()` is now `system::GenesisConfig::default().build_storage::<Test>().unwrap().0.into()` for some config.

You could also have system::GenesisConfig::default().build_storage::<Test, Instance>().unwrap().0.into(). This is sadly required, as we can have build function that use some generics.

Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

great PR :-) there is just assimilate_require_generic I have to review again but otherwise everything looks good

($module::Origin < $( $generic, )? $( $module::$generic_instance )? > ),
)*
#[allow(dead_code)]
Void($crate::Void)
Copy link
Contributor

Choose a reason for hiding this comment

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

do you remember what this was for ?

Copy link
Contributor

@gui1117 gui1117 Jun 21, 2019

Choose a reason for hiding this comment

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

I mean I removed it and all test compiles

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question, but I don't really know it and would rather like to keep it for the moment.^^

@@ -634,14 +689,31 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
quote!{ #prefix.as_bytes() }
};
Copy link
Contributor

Choose a reason for hiding this comment

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

now that you generate a inherent instance you could make use of it to factorize this if condition like, maybe even renaming changing prefix and having such condition in transformation.rs but whatever I might take look after and all in all it is fine at the moment.

@bkchr
Copy link
Member Author

bkchr commented Jun 21, 2019

@thiolliere addressed your feedback :)

@gui1117
Copy link
Contributor

gui1117 commented Jun 21, 2019

Yes changes looks good I can approve or do a final review on tuesday.

Also we might want to update decl_storage doc, as the stucture is no longer always generic.

And I was thinking does it make sense to talk about assimilate storage stuff ? I mean it is for used when writing test for your modules, but I think it is something that ppl want to know, though I'm not sure and could added in a second time as it doesn't exist yet.

@bkchr
Copy link
Member Author

bkchr commented Jun 22, 2019

Yes changes looks good I can approve or do a final review on tuesday.

Tuesday is okay.

Also we might want to update decl_storage doc, as the stucture is no longer always generic.

Good point.

And I was thinking does it make sense to talk about assimilate storage stuff ? I mean it is for used when writing test for your modules, but I think it is something that ppl want to know, though I'm not sure and could added in a second time as it doesn't exist yet.

You mean the function assimilate_storage?

@gavofyork
Copy link
Member

did the final review happen?

@bkchr
Copy link
Member Author

bkchr commented Jun 27, 2019

Not yet.

@gui1117
Copy link
Contributor

gui1117 commented Jun 27, 2019

And I was thinking does it make sense to talk about assimilate storage stuff ? I mean it is for used when writing test for your modules, but I think it is something that ppl want to know, though I'm not sure and could added in a second time as it doesn't exist yet.

You mean the function assimilate_storage?

Yes I know construct_runtime handle that you, but someone that create a modules will make use of it for its testing so he wants to be aware of subtelties (though everything is in the generated doc)

@bkchr bkchr merged commit da91f05 into master Jun 27, 2019
@bkchr bkchr deleted the bkchr-srml-support-stuff branch June 27, 2019 11:40
hughlang added a commit to hughlang/substrate-dev that referenced this pull request Jul 5, 2019
…s error:

missing field `_genesis_phantom_data` in initializer of `groups::GenesisConfig<groups::tests::GroupsTest>`

Probably related to this: paritytech/substrate#2913 and Issue #2219
MTDK1 pushed a commit to bdevux/substrate that referenced this pull request Jul 10, 2019
…2913)

* Add failing test case

* move storage maps to blake2_128 (paritytech#2268)

* remove default hash, introduce twox_128 and blake2

* use blake2_128 & create ext_blake2_128

* refactor code

* add benchmark

* factorize generator

* fix

* parameterizable hasher

* some fix

* fix

* fix

* fix

* metadata

* fix

* remove debug print

* map -> blake2_256

* fix test

* fix test

* Apply suggestions from code review

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* impl twox 128 concat (paritytech#2353)

* impl twox_128_concat

* comment addressed

* fix

* impl twox_128->64_concat

* fix test

* Fix compilation and cleanup some docs

* Lol

* Remove traits from storage types that are not generic

* Get instance test almost working as wanted

* Make `srml-support-test` compile again :)

* Fixes test of srml-support

* Fix compilation

* Break some lines

* Remove incorrect macro match arm

* Integrates review feedback

* Update documentation

* Fix compilation
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_genesis_phantom_data required for unknown reason

4 participants