Start supporting double map #843
Conversation
f2f4d39 to
3e48232
Compare
|
Thank you! |
|
The metadata versions is starting getting messy and adding a new feature is not easy because it needs to downgrade from latest version back to v0. Any plan to refactor so that it is performing upgrade instead of downgrade?
|
|
Needs to be done, yes. Agreed that it is sprawling a bit atm. Have not been able to get there myself. @amaurymartiny could you take a peek at this PR please - cannot give it the right kind of attention with limited access. |
amaury1093
left a comment
There was a problem hiding this comment.
Yeah, I agree there's some cleaning to be done here. It's planned, I'll be able to personally start cleaning stuff starting May.
| } | ||
|
|
||
| export class MetadataStorageType extends EnumType<PlainType | MapType> { | ||
| export class MetadataStorageType extends EnumType<PlainType | MapType | DoubleMapType> { |
There was a problem hiding this comment.
You can remove this class, and import StorageFunctionType from v0/modules
| } | ||
|
|
||
| export class MetadataStorageType extends EnumType<PlainType | MapType> { | ||
| export class MetadataStorageType extends EnumType<PlainType | MapType | DoubleMapType> { |
There was a problem hiding this comment.
You can remove this class, and import StorageFunctionType from v0/modules
| } | ||
|
|
||
| export class StorageFunctionType extends EnumType<PlainType | MapType> { | ||
| export class StorageFunctionType extends EnumType<PlainType | MapType | DoubleMapType> { |
There was a problem hiding this comment.
Just to understand your intent here: we agree that v0 doesn't have DoubleMapType, but you're still putting it here to be able to factorize code, as this change doesn't break compatibility, correct?
If yes, then see my 2 comments above where we can factorize code a bit more.
| import Text from '../../primitive/Text'; | ||
| import Type from '../../primitive/Type'; | ||
| import { MetadataStorageModifier } from '../v1/Storage'; | ||
| import { DoubleMapType } from '../v0/Modules'; |
There was a problem hiding this comment.
tiny nit: we tend to order things alphabetically by default, when there's no other natural ordering
There was a problem hiding this comment.
Regarding the ordering and spacing rules, can we have them in tslint?
There was a problem hiding this comment.
That's a good idea. But I think since TypeScript is officially moving towards eslint, we'd like to use eslint everywhere in the mid-term, this looks for for our case.
But now in this "transition" period before eslint is officially supported, i propose not to overbloat tslint.json, and to manually enforce this few rules.
In any case, you can create an issue on https://github.com/polkadot-js/dev
|
Hey @xlc I refactored types/Metadata a bit, so that it's less entangled, but conflicts with this implementation. imo there's only small stuff like https://github.com/polkadot-js/api/pull/843/files#diff-023179d9a94bd59761a7319a645b1dd0R112 to be added in this PR (+ eventually the actual key hashing, but can be done later if needed) |
|
Hi @amaurymartiny. Thank you for taking the time to review the code. I will change the code based on the suggestions and rebase this branch on the master to fix the conflict. |
| } | ||
|
|
||
| export class StorageFunctionType extends EnumType<PlainType | MapType> { | ||
| export class StorageFunctionType extends EnumType<PlainType | MapType | DoubleMapType> { |
There was a problem hiding this comment.
There's no DoubleMap in v0, everything that's related to DoubleMap in this file should be deleted
There was a problem hiding this comment.
I got ‘FATAL: Unable to initialize the API: Object.values(...)[index] is not a constructor’ error at EnumType.ts:109:14 without having DoubleMapType here. I have to add DoubleMapType for fixing this issue.
In function
private static createValue (def: TypesDef, index: number = 0, value?: any): Decoded { return { index, value: new (Object.values(def)[index])(value) }; }
, index is 2 but def only have MapType and PlainType. Call stack says, it's because of const extrinsics = extrinsicsFromMeta(this.runtimeMetadata.asV0);
There was a problem hiding this comment.
Ah, I suspected this would happen...
I think there's a small refactoring to do, have a look at point 1 in #858 (comment):
- create v0/ and v4/ folders in type-extrinsic
- move current fromMetadata to fromMetadataV0
- fromMetadata should call fromMetadataV0 if it's v0-3
- in v4/, create a fromMetadataV4, which correctly creates extrinsics from v4
Have a look at type-storage, type-extrinsics should follow the same pattern, and this would allow adding hacks like adding DoubleMap in v0
Edit: if this seems confusing to you, ping me here and I'll do this small refactoring tomorrow 1st thing, so that you can rebase on my PR and then we can merge this PR
There was a problem hiding this comment.
Thank you @amaurymartiny. I got the idea. I will do the refactoring following your guide.
There was a problem hiding this comment.
@AlexWZ0129 I've done similar stuffs, you can reuse code from my refactor branch.
| import Text from '../../primitive/Text'; | ||
| import Type from '../../primitive/Type'; | ||
| import { PlainType, StorageFunctionModifier } from '../v1/Storage'; | ||
| import { DoubleMapType } from '../v4/Storage'; |
There was a problem hiding this comment.
Same as above, remove DoubleMap from v2
| key1: Type, | ||
| key2: Type, | ||
| value: Type, | ||
| key2Hasher: StorageHasher |
There was a problem hiding this comment.
Unfortunately key2Hasher is still a Text, revert. Please see https://github.com/paritytech/substrate/blob/master/srml/metadata/src/lib.rs
There was a problem hiding this comment.
Thank you for the review. When using Text, if the type of the key has trait prefix like ’T::AssetId’, I got an error ‘Unknown types found, no types for T::AccountId’. Using Type fix the issue. I guess it’s because Type does some format optimise when decoding (such as removing all the trait prefixes Type._removeTraits()).
There was a problem hiding this comment.
Changed type of key2Hasher to Text. Thanks for the suggestion.
| key1: Type, | ||
| key2: Type, | ||
| value: Type, | ||
| key2Hasher: StorageHasher |
Thanks @amaurymartiny ! |
* double map fix * update metadata to prevent error using double map
* double map fix * update metadata to prevent error using double map
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
We are upgrading our modules to use double map so there will be a set of contributions from us to make double map actually works with polkadot.js.
This doesn't actually support double map, just fixed some crashing error I encountered while working on apps.