FIP: Storage lending #250
aditiharini
announced in
FIP Stage 3: Review
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Title: Storage lending
Type: Implementation FIP
Authors: aditi, sanjay, v
Problem
Apps want to sponsor users so that they can onboard users for free. If apps are paying for storage, they need a way to reallocate storage as they wish so that they don’t have to allocate an infinite budget to for signups.
We propose a mechanism to allow one fid to lend storage to another fid (and revoke it), so apps can buy storage for themselves via the storage contract and then lend it out to their users for free.
Specification
Message specification
We add a new
LEND_STORAGEmessage type. The lender’s fid is the fid on theMessageData. This message set has no “remove” message type, similar toUserData. Snapchain stores the last submittedMESSAGE_TYPE_LEND_STORAGEmessage per (lender, borrower) pair. In order to revoke storage from a user, the lending fid should submit aMESSAGE_TYPE_LEND_STORAGEmessage settingnum_unitsto 0 for the borrower.Snapchain implementation
Shard 0 will include
BlockEventmessages in its transactions upon successfully processing aLendStoragemessage.BlockEventmessages will be consumed by shards 1 and 2.Validations
num_units+ 1 of storage available that they have not lent out, not counting borrowed storage. We disallow lending borrowed storage because this makes it very difficult to track down where to evict storage if storage starts to expire. We require lenders to maintain at least 1 extra storage unit so they have the ability to revoke storage they’ve already lent. Rate limits are based on a user’s available storage.LEND_STORAGEmessage. This is to protect against accidentally lending way too much storage to a single user (e.g. fatfinger, app bug).Pruning
The number of
LEND_STORAGEmessages maintained on the protocol for a given lender fid is bounded by the number of storage units they own. The protocol supports at most 1 message per unit. Messages that set lent storage to 0 are pruned immediately upon merging to avoid bloating storage. Snapchain will emit separateMERGE_MESSAGEandPRUNE_MESSAGEevents indicating revoke is merged then pruned to work cleanly with existing event stream consumer implementations.Using borrowed storage
Shards 1 and 2 consume
MergeMessageblock events from shard 0 containing the storage lending information.Shards 1 and 2 compute the total storage available for an fid (used for rate limits and pruning) by subtracting units the fid has lent and adding units the fid has borrowed. The number of messages pruned will be determined based on this computed storage number.Client updates
The changes requires to handle
LEND_STORAGEmessages inshuttlewill be shipped with (or prior to) the Snapchain changes.In addition to shuttle changes, clients may need to consider updating any logic that computes the total storage available to a user to account for borrowed storage.
Apps that intend to lend storage should carefully consider how to go about revoking storage from users they no longer want to sponsor. If a user has no storage (including borrowed storage), all their data will be pruned from Snapchain the next time they attempt to submit a message. The user can retain their data by purchasing their own storage, but they should do this before the app revokes their borrowed storage to eliminate risk of losing data on the protocol.
Future work
Storage unit expiration
As of yet, no storage units have expired, but if units do expire Shard 0 must realize that units have expired and decide who to revoke storage from if a lender no longer has enough storage to support all the lending it has done. One logical approach is starting to evict from the earliest lent storage and proceeding until the user has lent less storage than it has available. This mechanism will be implemented with some grace period so that the lender has enough time to purchase storage again to back the lending they’ve done.
Release
This change will go live in Snapchain mainnet on October 7 as a part of the next release.
Beta Was this translation helpful? Give feedback.
All reactions