substrate
substrate copied to clipboard
Wrong impl of `KeyLenOf` for `Map` and `DoubleMap`
If I am not mistaken the length of the Patricia-Key for a storage object is determined by
- StorageValue =
Twox_128("PALLET_NAME") + Twox_128("STORAGE_NAME") - StorageMap =
Twox_128("PALLET_NAME") + Twox_128("STORAGE_NAME") + HASHER(key) - StorageDoubleMap =
Twox_128("PALLET_NAME") + Twox_128("STORAGE_NAME") + HASHER(key_1) + HASHER(key_2)
But the current implementation of KeyLenOf for both StorageMap and StorageDoubleMap ignores this. It returns a key length derived from the actual BYTES of the names of pallet and storage elements, ignoring the constant size hash length.
- Map impl of
Get<u32>: https://github.com/paritytech/substrate/blob/ef890f5598e0d3fd1b6a5fcc8c3322f7570089d1/frame/support/src/storage/types/map.rs#L65 - DoubleMap impl of
Get<u32>: https://github.com/paritytech/substrate/blob/ef890f5598e0d3fd1b6a5fcc8c3322f7570089d1/frame/support/src/storage/types/double_map.rs#L94-L98
This, in my understanding, leads to a wrong assumption about the maximal trie depth and subsequently a wrong assumption about the maximal amount of elements in the maps.