4

This is what I read from the substrate storage docs: https://docs.substrate.io/v3/runtime/storage/

Runtime storage allows you to store data in your blockchain that is persisted between blocks and can be accessed from within your runtime logic.

Does this mean every single block saves a copy of this data? If true, isn't it a waste of resources? I'm trying to implement a public note system where everyone's note is saved on the blockchain. Should I use this Storage Runtime? If not, what should I use?

2 Answers 2

7

The underlying mechanism is not copying. At any given block, non-archive nodes need to know only one value for one storage item. Even when the node keeps the trace of the historical values, it does it super efficiently by using a kind of a Merkle Trie structure. In designing dApps, you store those sensitive data on the blockchain that could be disputed in the absence of a consensus mechanism. The very obvious example is people's account balances. You can however use that storage for anything but it wouldn't then be a good use of that expensive resource.In your example, if that public note would be an assertion of something that people shouldn't be able to change in a backward way, meaning claiming that their note at that time was a different thing, then it should go to the runtime storage.

3
  • 1
    Thank you for your answer!
    – Minh Mốc
    Commented Feb 12, 2022 at 8:02
  • What do you mean by . In designing dApps, you store those sensitive data on the blockchain that could be disputed in the absence of a consensus mechanism.? When you say on the blockchain do you mean as inherents or as transactions? Commented Feb 13, 2022 at 8:49
  • @Purple_Turtle I meant as storage items (in substrate architecture) which keep the state of blockchain. Whatever happens on-chain impacts the state.
    – Alex Sed
    Commented Feb 14, 2022 at 22:23
2

I'm trying to implement a public note system where everyone's note is saved on the blockchain. Should I use this Storage Runtime? If not, what should I use?

Saving everything on-chain is indeed wasteful.
A simple trick is to only save the hash of your data on chain and out source the availability of the data itself.

Substrate recently introduced (not live yet) Preimage for that exact reason:

The Preimage pallet allows for the users and the runtime to store the preimage of a hash on chain. This can be used by other pallets for storing and managing large byte-blobs.

Until then your best bet is probably IPFS which addresses data via its hash as well.
PS: NFTs in Ethereum also use that instead of storing the whole image on-chain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.