-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple Mapping Storage Primitive #945
Comments
Hi, I've already tested the change like this, so I can briefly describe the result and later provide the full report. |
@xgreenx Is there anywhere we can look up your implementation for the Solidity-like storage mapping? |
Nit: |
Yes, you can find The problem with this solution is that after the creation of the map, we don't know the storage key of the map. So we can't immediately start insert and get items. This map only shows how the size of the contract can be reduced. Current master with default storage hash map Erc20: Later I will work on resolving the issue with the storage key. I see three possible solutions:
balance_of: SimpleHashMap::new(storage_key!("balance_of")); In this case, we need to store the storage key directly in the storage and load it during |
Thank you for linking your solution. Some remarks and questions:
The idea is to store no state in the contract storage for the field that is associated to the |
The map has a
Yes, it should be In the current implementation, the storage key is optional, because it can be evaluated during |
Ah yeah makes sense!
holy! ... x(
For Solidity arrays it makes sense to store a |
Implemented in #946. Closed. |
Motivation
At the moment,
ink!
data structures, such as theink_storage::LazyHashMap
, are quitecomplicated. This is because they were designed in a very "polite" way. That's to say,
they did a lot of internal bookkeeping to ensure that they cleaned up after themselves,
and that they were only going to the contract storage database when it was absolutely
neccessary.
While this was great from a user's point of view, this approach to data structure in
ink!
has lead to contract sizes being larger than they probably need to be.As such, we want to experiment with some simpler data structures, such as a Solidity-like
mapping.
ink_storage::Mapping
The new
ink_storage::Mapping
would be a paper thin type-safe wrapper around some of theink_storage
andink_env
storage primitives.The
Mapping
type would look as follows:Note that we may also need some sort of
Key
field to differentiate between differentinstances of
Mapping
and avoid collisions. This would be similar to whatLazyHashMap
does.
The API of the
Mapping
would look (roughly) like this:It would also need to implement the
SpreadLayout
andPackedLayout
traits. This iswhat would actually be doing the heavy lifting as far as talking to the contract storage
goes.
Another thing that will have to get done is adding some new low level push/pull
functions which allow the return values to be empty. At the moment these functions assume
that if you're querying for a key, that it already exists.
This would not be the case with the new
Mapping
, since you can query any key and if itdoesn't exist you'd get the
Default
value back.ERC-20 Benchmarking
After implementing the new
Mapping
type we want to implement a new ERC-20 examplecontract with it. The thing to look for here is how much better (or worse) the contract
sizes are compared to our current ERC-20 example.
The text was updated successfully, but these errors were encountered: