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

Wrong handling of storage maps with tuple keys #1928

Open
mateuszaaa opened this issue Feb 22, 2025 · 2 comments
Open

Wrong handling of storage maps with tuple keys #1928

mateuszaaa opened this issue Feb 22, 2025 · 2 comments

Comments

@mateuszaaa
Copy link

mateuszaaa commented Feb 22, 2025

Seems like subxt generates wrong static types in case of using (u32, u32) as a key to a substrate StorageMap

given 2 similiar StorageMaps where one is raw tuple

    #[pallet::storage]
    pub type TupleStorageMap<T: Config> =
        StorageMap<_, Blake2_128Concat, (u32, u32), Option<u32>, ValueQuery>;

and the other is wrapper type

    #[derive(
        Default, Eq, PartialEq, RuntimeDebug, Clone, Encode, Decode, TypeInfo, Serialize, Copy, MaxEncodedLen
    )]
    pub struct TupleWrapper(pub (u32, u32));

    #[pallet::storage]
    pub type TupleWrapperStorageMap<T: Config> =
        StorageMap<_, Blake2_128Concat, TupleWrapper, Option<u32>, ValueQuery>;

The raw tuple doesnt work well... First of all when queried it returns None while value is clearly there as data are inserted in genesis block(link to reproducible example below)

Image

There are at least to problems:

  • for raw tuple storage is recogniced to have 2 parameters of type u32 while it should be single parameter of type (u32,u32).

Image

  • for similiar case where TupleWrapper is used instead, it defines single query parameter

Image

I created repository with minimal reproducible examples that includes minimal node runtime based on substrate minimal template that defines 2 storage maps(as described above) and inserts some data into the storage automatically. It also contains bindings generated from node metadata as well as example prooving that querying data from storage map doesnt work...

Image

@mateuszaaa
Copy link
Author

Im willing to contribute and help solving the issue but some guidance would be appreciated 🙏

@mateuszaaa
Copy link
Author

btw i also tried dynamic query. According to polkadot spec tuple is encoded as concatenation of inner types. and integers are encoded using little endian representation. But somehow it doesnt work as well

Image

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant