threefoldtech / tfchain

Threefold Chain.
Apache License 2.0
15 stars 11 forks source link

Pallet KV: scale the fee with the amount of bytes stored #812

Open DylanVerstraete opened 1 year ago

DylanVerstraete commented 1 year ago

Currently the weight is set to take into a account the cost of writing one entry to the DB. I think the better thing to do here is to scale the weight based on the size of the data stored. This will also make sure the fee is higher when the stored data size is high.

sameh-farouk commented 1 year ago

I would like to share my opinion on how this pallet stored data on chain. First of all, I think the basic rule for blockchain runtime storage is to keep the data items as few and as small as possible. Storing arbitrary data on blockchain seems unnecessary, since it has no function in the runtime. It would be better to store this data somewhere else and remove this pallet. But if you decide to keep this pallet, here is my two cents:

Higher one-time fees are not enough to motivate users to cleanup unused storage items later.

so Besides what Dylan said, I recommend limiting the storage for each account, so that no one can have too many names/keys (restrict the number of key-value pair per account).

Moreover, I suggest looking into one of these two common methods to ensure economic security, storage deposit and storage rent:

This is not only relevant to this pallet, but to all extrinsics that allow users to write to persistent storage. Users should be encouraged to clear up storage by paying a sufficient storage deposit. Otherwise, this could pose a security risk.