Search code examples
substrate

What does it mean in Substrate when a value is stored at Twox128(Prefix::pallet_prefix()) ++ Twox128(Prefix::STORAGE_PREFIX)?


From docs:

pub struct StorageValue<Prefix, Value, QueryKind = OptionQuery, OnEmpty = GetDefault>(_);

A type that allow to store a value.

Each value is stored at:

Twox128(Prefix::pallet_prefix()) ++ Twox128(Prefix::STORAGE_PREFIX)

What does the "Twox128(Prefix::pallet_prefix()) ++ Twox128(Prefix::STORAGE_PREFIX)" mean here?


Solution

  • This is telling you how the storage key is calculated by combining two hashes. From the docs:

    To calculate the key for a simple Storage Value, take the TwoX 128 hash of the name of the pallet that contains the Storage Value and append to it the TwoX 128 hash of the name of the Storage Value itself.

    e.g.

    twox_128("Sudo")                   = "0x5c0d1176a568c1f92944340dbfed9e9c"
    twox_128("Key")                    = "0x530ebca703c85910e7164cb7d1c9e47b"
    twox_128("Sudo") + twox_128("Key") = "0x5c0d1176a568c1f92944340dbfed9e9c530ebca703c85910e7164cb7d1c9e47b"