-
Notifications
You must be signed in to change notification settings - Fork 19
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
Conversation
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(), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
## 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.
Fixes #7
0.10.0
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.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.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 themax_bytes
should be higher than the existingmax_bytes
.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 theContract
struct to include aLookupMap
for shared storage pools. Additionally, it introduces a new methodmigrate_state
to handle state migration during contract upgrades.legacy.rs
module, which includes a legacy version of the Account struct.shared_storage.rs
module, which manages shared storage usingSharedStoragePool
andAccountSharedStorage
structs.Contract
struct inlib.rs
to include aLookupMap
for shared storage pools.migrate_state
method in theupgrade.rs
module for state migration during contract upgrades.These changes enable more flexible and efficient storage allocation among accounts using shared storage pools.