Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Add StorageList support in decl_storage#2261

Closed
sorpaas wants to merge 3 commits intomasterfrom
sp-storage-list
Closed

Add StorageList support in decl_storage#2261
sorpaas wants to merge 3 commits intomasterfrom
sp-storage-list

Conversation

@sorpaas
Copy link
Contributor

@sorpaas sorpaas commented Apr 12, 2019

Add back storage list support in decl_storage macro. Can fix issues like #2228.

A QoL function StorageList::push is also added.

@sorpaas sorpaas added the A0-please_review Pull request needs code review. label Apr 12, 2019
@sorpaas sorpaas requested a review from bkchr April 12, 2019 01:06
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub enum StorageFunctionType {
Plain(DecodeDifferentStr),
List(DecodeDifferentStr),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put this to the end to improve backward compatibility


/// Push a new item to the list.
fn push(item: &T);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no pop method? how do I delete the last item?

@bkchr
Copy link
Member

bkchr commented Apr 12, 2019

I thought we won't bring back storage list because of the performance issues. See here #772

@tomusdrw
Copy link
Contributor

We do have linked_map now that should be more efficient

@tomusdrw
Copy link
Contributor

tomusdrw commented Apr 12, 2019

To clarify on my "more efficient" comment, after discussing that with @bkchr .
linked_map and StorageList have many similarities and in most cases the performance would be similar, so iterating over unbounded collection inside runtime is still not recommended.

However:

  1. linked_map offers arbitrary (sparse) keys (not only a consistent range of 0..len)
  2. That makes removals more efficient (no need to re-order) and also makes the key persistent, hence reliable

@xlc
Copy link
Contributor

xlc commented Apr 12, 2019

I see some use cases of storage list. Every data structure have its trade offs.
Storage list can be used as a stack, an append only storage (like events). It use less storage than linked map (which needs to store next and prev for every item).

I think Substrate should offer (secure and safe) options and guidances to help developers to make right decisions.

@bkchr
Copy link
Member

bkchr commented Apr 12, 2019

You will need to iterate events at the end of each block and that will create a lot of database accesses.

@xlc
Copy link
Contributor

xlc commented Apr 12, 2019

Why do I need to iterate events? To conver to Vec for compatibility reason? I believe polkadotjs is able to somehow detects the format and handle both cases just like metadata versions

@bkchr
Copy link
Member

bkchr commented Apr 12, 2019

Yeah, good point^^

@sorpaas
Copy link
Contributor Author

sorpaas commented Apr 13, 2019

@bkchr

You will need to iterate events at the end of each block and that will create a lot of database accesses.

It does not necessarily need any database access. For something like Events, things are directly stored in the overlay. We only need to generate trie structure when storage_root is called, which usually happens after Events are killed.

@bkchr
Copy link
Member

bkchr commented Apr 13, 2019

Yeah I know that we don't always access the real database. Nevertheless, we still need to have 1 lookups + 2 writes for storing one event.

(events are also part of the storage root, as they stay for the client to inspect them)

@gavofyork
Copy link
Member

Indeed. Events are not free - the stick around until the next block and therefore bloat the trie and increase hashing required and then you'll need to iterate over all of the last block's events to delete them, increasing I/O.

@bkchr
Copy link
Member

bkchr commented Apr 19, 2019

Events bottleneck is also already fixed in master.

So how do we continue with this one? Close?

@sorpaas sorpaas closed this Apr 19, 2019
@arkpar arkpar deleted the sp-storage-list branch April 23, 2020 18:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_review Pull request needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants