At the moment, dealing with collections of storage items can be difficult to manage. This leads to costly implementations for lookup of stored items, and makes it difficult to delete stored items.
If the API enabled prefix based lookups, and prefixed based deletions, SC storage operations would be much easier to manage.
Example:
An SC wants to store addresses that did something in a certain block:
Storage.Put(Storage.CurrentContext, block_height + address, 'stuff');
Storage.Put(Storage.CurrentContext, block_height + address2, 'stuff2');
Now the SC wants to lookup items that happened in that block
StorageResult[] results = Storage.GetByPrefix(Storage.CurrentContext, block_height);
StorageResult m = results[0];
byte[] resultKey = m.Key; // -> block_height + address
byte[] resultValue = m.Value; // 'stuff'
And finally you can delete items by key
Storage.DeleteByPrefix( Storage.CurrentContext, block_height)
We also thought about the idea of a negative GAS cost for deletion, to incentivize removing unneeded storage from the VM and enhance scalability. Unclear how this would play out with the 10 free GAS and prefix-based deletion, but will be thinking more.
I imagine this is great for semi-relational queries with 'nested' prefixes as well i.e:
Storage.Put(Storage.CurrentContext, block_height + address + keyOne, 'stuff1')
Storage.Put(Storage.CurrentContext, block_height + address + keyTwo, 'stuff2')
Delete items by block height:
Storage.DeleteByPrefix(Storage.CurrentContext, block_height)
Delete items containing specific address, by block height:
Storage.DeleteByPrefix(Storage.CurrentContext, block_height + address)
@Ejhfast but deleting of a key from storage would not free anything at all in the blockchain, right?
Because due to the way the blockchain work, every value that was at a certain key in a certain point in time is stored, so deleting a key or just not touching it anymore takes the same disk space.
It would be deleted going forward. It would still exist in the sense that if you synced the chain from the start, the value would exist for the blocks between when the value was created and when it was deleted.
I responded in the slack. It would obviously not delete the record of
invocation transactions on the blockchain, but it can lessen the amount of
data that needs to be managed by a node in memory (or on disk if "current
state" is being cached there).
On Sat, Dec 23, 2017 at 9:05 PM, Sérgio Flores notifications@github.com
wrote:
@Ejhfast https://github.com/ejhfast but deleting of a key from storage
would not free anything at all in the blockchain, right?
Because due to the way the blockchain work, every value that was at a
certain key in a certain point in time is stored, so deleting a key or just
not touching it anymore takes the same disk space.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/neo-project/neo/issues/128#issuecomment-353760782,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFeEj4gBuFzKz5bui_qm745cdp4sAxmks5tDbFngaJpZM4RLuoY
.
We can add new APIs like this:
c#
Iterator Storage.Find(StorageContext context, byte[] prefix)
+1 this would be very useful. Any updates on this?
NeoAuth needs this badly. I like the idea of ephemeral data that only lives for a certain period of time before being removed (e.g. x number of blocks).
This feature is necessary
I have added new Iterator APIs to support prefixed storage operations. See a234978f2fd7cb622513969c582c6d3b054070cb.
Most helpful comment
I have added new Iterator APIs to support prefixed storage operations. See a234978f2fd7cb622513969c582c6d3b054070cb.