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

the doublemap value allways return 0 or null #2007

Closed
ghost opened this issue Dec 6, 2019 · 11 comments · Fixed by #2015
Closed

the doublemap value allways return 0 or null #2007

ghost opened this issue Dec 6, 2019 · 11 comments · Fixed by #2015
Labels

Comments

@ghost
Copy link

ghost commented Dec 6, 2019

there are my doublemap in substrate:
TokenInfo: double_map T::AccountId, blake2_256(Vec) => Vec;
TokenInfo: double_map T::AccountId, blake2_256(Vec) => u32;

i update the doublemap's key and value successful. but in https://polkadot.js.org/apps/#/chainstate, my doublemap values can't show correctly, allway 0x00. then i change the value type to u32, it allway return 0.
but on the console, return correct Vec or u32.

tell me what can i do? thanks.

@jacogr
Copy link
Member

jacogr commented Dec 6, 2019

As an example on Kusama for -

		/// For each session index, we keep a mapping of `T::ValidatorId` to the
		/// number of blocks authored by the given authority.
		AuthoredBlocks get(fn authored_blocks): double_map SessionIndex,
			blake2_256(T::ValidatorId) => u32;

image

@jacogr jacogr added the support label Dec 6, 2019
@ghost
Copy link
Author

ghost commented Dec 7, 2019

As an example on Kusama for -

		/// For each session index, we keep a mapping of `T::ValidatorId` to the
		/// number of blocks authored by the given authority.
		AuthoredBlocks get(fn authored_blocks): double_map SessionIndex,
			blake2_256(T::ValidatorId) => u32;

image

but why my struct value allways uncorrect? Vec cause ?

@jacogr
Copy link
Member

jacogr commented Dec 7, 2019

So what is Vec in this case? That is not a valid Rust type unless an alias. (You need type info for a vector)

@ghost
Copy link
Author

ghost commented Dec 8, 2019

So what is Vec in this case? That is not a valid Rust type unless an alias. (You need type info for a vector)

i use u8 in vec

@ghost
Copy link
Author

ghost commented Dec 8, 2019

So what is Vec in this case? That is not a valid Rust type unless an alias. (You need type info for a vector)

i use u8 in vec

i am sure that vec <u8> be used for the second key in doublemap, the value can't show correctly in Chain state. there are my code https://github.com/TransactionX/TransX/blob/master/bin/node/runtime/src/register.rs.

@ghost
Copy link
Author

ghost commented Dec 8, 2019

So what is Vec in this case? That is not a valid Rust type unless an alias. (You need type info for a vector)

i use u8 in vec

i am sure that vec be used for the second key in doublemap, the value can't show correctly in Chain state. there are my code https://github.com/TransactionX/TransX/blob/master/bin/node/runtime/src/register.rs.

when use 'TokenInfo: double_map T::AccountId, blake2_256(u32) => Vec<u8>;' replace 'TokenInfo: double_map T::AccountId, blake2_256(Vec<u8>) => Vec<u8>;' , it show correctly value.

@jacogr
Copy link
Member

jacogr commented Dec 8, 2019

So my confusion was around this above - TokenInfo: double_map T::AccountId, blake2_256(Vec) => Vec; - the Vec there has no type info.

So in all cases the variable-length items are encoded (in SCALE), with a length prefix. It could very well be that for storage keys one side does not apply it with the prefix, so could be missing in the API or on the node side. (I(n which case items suck as [u8; 16] would not show the issue.)

Since this requires customisation of entries to replicate, cannot promise I'll be able to take a look immediately, but added to the queue to look at as soon as there is an open spot to customize and build.

@ghost
Copy link
Author

ghost commented Dec 8, 2019

So my confusion was around this above - TokenInfo: double_map T::AccountId, blake2_256(Vec) => Vec; - the Vec there has no type info.

So in all cases the variable-length items are encoded (in SCALE), with a length prefix. It could very well be that for storage keys one side does not apply it with the prefix, so could be missing in the API or on the node side. (I(n which case items suck as [u8; 16] would not show the issue.)

Since this requires customisation of entries to replicate, cannot promise I'll be able to take a look immediately, but added to the queue to look at as soon as there is an open spot to customize and build.

so if i think that the value can show correctly, the doublemap key should use array replace Vec<u8>?

@ghost
Copy link
Author

ghost commented Dec 8, 2019

So my confusion was around this above - TokenInfo: double_map T::AccountId, blake2_256(Vec) => Vec; - the Vec there has no type info.
So in all cases the variable-length items are encoded (in SCALE), with a length prefix. It could very well be that for storage keys one side does not apply it with the prefix, so could be missing in the API or on the node side. (I(n which case items suck as [u8; 16] would not show the issue.)
Since this requires customisation of entries to replicate, cannot promise I'll be able to take a look immediately, but added to the queue to look at as soon as there is an open spot to customize and build.

so if i think that the value can show correctly, the doublemap key should use array replace Vec?

thanks very much. i use [u8;16] replace it, show correctly.

@jacogr
Copy link
Member

jacogr commented Dec 8, 2019

Glad you are sorted.

We will still have to investigate, since something is weird here - as soon as there is a gap, will delve in deep.

(Making "unconfirmed" to investigate)

@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jun 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants