Skip to content
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

0.10.0: Adding shared storage pools #8

Merged
merged 6 commits into from
Apr 19, 2023
Merged

0.10.0: Adding shared storage pools #8

merged 6 commits into from
Apr 19, 2023

Conversation

evgenykuzyakov
Copy link
Collaborator

@evgenykuzyakov evgenykuzyakov commented Apr 14, 2023

Fixes #7

0.10.0

  • Remove 1 yoctoNEAR requirement when writing from the matching predecessor. It allows to write under your account with a simple limited access key without requesting the permission first.
  • Introduce Shared Storage Pools. Pools can share available storage bytes to new or existing accounts. The total shared storage may exceed the prepaid storage, but the prepaid storage is still limits the total amount of bytes that can be written by the accounts using this shared pool. It allows optimistically provide storage quotas.
    • Add pub fn shared_storage_pool_deposit(&mut self, owner_id: Option<AccountId>) - requires at least 100N in deposit. This creates a shared storage pool for a given owner_id (or predecessor) with the attached deposit. If the pool already exists for this owner, then the deposit is added to the existing pool.
    • Add pub fn share_storage(&mut self, account_id: AccountId, max_bytes: StorageUsage) that should be called by the pool owner. It will share the storage from the owner's pool with the given account. If the account already has shared storage, then the max_bytes should be higher than the existing max_bytes.
    • Add pub fn get_account_storage(&self, account_id: AccountId) -> Option<StorageView> that returns the amount of used bytes and the amount of bytes available. It accounts for the shared storage.

GPT-4 generated summary

This patch introduces the concept of shared storage pools to the contract. It adds a new module shared_storage and modifies the Contract struct to include a LookupMap for shared storage pools. Additionally, it introduces a new method migrate_state to handle state migration during contract upgrades.

  1. Adding a legacy.rs module, which includes a legacy version of the Account struct.
  2. Introducing a shared_storage.rs module, which manages shared storage using SharedStoragePool and AccountSharedStorage structs.
  3. Updating the Contract struct in lib.rs to include a LookupMap for shared storage pools.
  4. Implementing methods for managing shared storage pools, such as creating, depositing, withdrawing, and sharing storage.
  5. Implementing a migrate_state method in the upgrade.rs module for state migration during contract upgrades.

These changes enable more flexible and efficient storage allocation among accounts using shared storage pools.

@evgenykuzyakov evgenykuzyakov marked this pull request as ready for review April 18, 2023 21:09
@evgenykuzyakov evgenykuzyakov changed the title WIP adding shared storage pools 0.10.0: Adding shared storage pools Apr 19, 2023
@evgenykuzyakov evgenykuzyakov merged commit aa7fafa into master Apr 19, 2023
@evgenykuzyakov evgenykuzyakov deleted the shared-pool branch April 19, 2023 22:35
Comment on lines 254 to +263
available: U128(
storage.storage_balance
- Balance::from(storage.used_bytes) * env::storage_byte_cost(),
account.storage_balance
- Balance::from(
account.used_bytes
- account
.shared_storage
.as_ref()
.map(|s| s.used_bytes)
.unwrap_or(0),
) * env::storage_byte_cost(),
Copy link

@ChaoticTempest ChaoticTempest Apr 21, 2023

Choose a reason for hiding this comment

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

@evgenykuzyakov Is this math correct? I'm not able to save a widget after sharing a balance from a shared pool without having to provide my own deposit. After looking into VM and seeing that it uses storage_balance_of => storage.available to check for whether additional storage is needed, I think the math here looks odd.

Shouldn't it be something more like this:

available = (account.storage_balance - account.used_bytes * storage_byte_cost)
          + (shared.max_bytes - shared.used_bytes) * storage_byte_cost

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason why storage_balance_of implements it this way, because the standard requires available_storage to be withdrawable. There is a separate implementation with a different name get_account_storage that accounts for shared storage

evgenykuzyakov pushed a commit to NearSocial/VM that referenced this pull request Apr 24, 2023
## 1.3.0

- Support `ethers.js` based on NearSocial/viewer#130
  - Expose `Ethers` and `ethers` in the global scope.
  - Add custom `Web3Connect` component that renders Web3 connect/disconnect button. Currently, the API is heavily influenced by Web3Onboard API.
  - VM now exports `EthersProviderContext` React context type. A gateway that wants to support Ethers.js should wrap the app with `EthersProviderContext.Provider` component with the object value `{provider}`. Provider is Web3 provider that can be used to create an Ethers.js provider.
- Fix `initNear` logic to assign provided `config` values on top of the default values, instead of reverse.
- Update `near-api-js` dependency to ^2.1.0
- Fix `elliptic` library by doing a lazy `deepClone` when it's first requested a VM instance.
- Update VM to reflect `0.10.0` SocialDB changes. NearSocial/social-db#8
  - Assume the permission to write is granted by default when `set` is called on the current account.
  - Use `get_account_storage` to account for the shared storage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implemenent shared storage pools
2 participants