BEP-364: Primary Storage Provider acts as the upload agent for object creation and update on Greenfield #364
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BEP-364: Primary Storage Provider acts as the upload agent for object creation and update on Greenfield
1. Summary
This BEP introduces a new method where the primary storage provider (SP) acts as the upload agent for creating objects in Greenfield. It allows users to send objects directly to the primary SP without sending transactions on chain. The primary SP will then create the object on-chain on behalf of the user, eliminating the requirement for users to switch over to the Greenfield network and incur gas fees when they create objects on Greenfield.
2. Motivation
The current object creation process requests users to send a MsgCreateObject transaction to the Greenfield chain. After the object is successfully created on chain, users would then send the object's payload data to the primary SP for data storage. Once the primary SP confirms the object’s integrity and distributes the EC chunks to secondary SPs, a MsgSealObject transaction will be sent to the Greenfield chain to finalize the object, enabling regular access to the object afterward.
This approach ensures the safety of object creation. However, when integrating with Greenfield, developers often face the following challenges:
Developers must conduct erasure coding (EC) processing and calculate checksums for objects on the client side. This increases integration complexity and resource usage on the client, particularly affecting user experience when handling large objects on web platforms.
When a user uploads an object on Greenfield, they are required to initiate a transaction to create the object. This process presents several challenges:
Users must switch to the Greenfield network before uploading objects.
Users need to possess BNB on the Greenfield network.
Each object upload requires a transaction confirmation, resulting in multiple wallet pop-ups for signatures when uploading many objects. Greenfield provides a batch upload solution using temporary accounts, but this method complicates integration.
The process for uploading objects is too complex, needing many interactions with SP and the Greenfield chain, making integration harder. Some project stakeholders may find integration exceptionally challenging if they can't use the official SDK directly due to version problems.
In light of the challenges encountered during the previous object creation process in Greenfield, we are planning to introduce a new method of object creation while retaining the existing approach.
The new solution enables users to send objects to the Primary SP directly using SP's API, eliminating the need for users to perform any additional steps. This significantly streamlines the complexity of object creations for users.
3. Status
This BEP is in progress.
4. Specification
4.1 APIs
4.1.1 SP APIs
SP currently exposes two APIs for users to upload object after they created/updated the object on-chain:
for delegators who want to upload objects to SP, APIs are almost the same and users just need to specify it is a delegated request using the query parameter “delegate”, if it is for object update, specify the query parameter “is_update”.
SDK
There are encapsulated interfaces provided by
greenfiled-go-sdk
to fulfill users' needs.DelegatePutObject
The
DelegatePutObject
interface enables users to send objects to the primary SP, allowing the primary SP to create objects on the chain on behalf of the user. It supports resumable uploads, by automatically fetching previously uploaded segments to allow for seamless continuation, improving upload efficiency.DelegateUpdateObjectContent
The
DelegateUpdateObjectContent
interface enables users to send updated objects to the primary SP directly without interaction with the Greenfield chain to update their existing object, allowing the primary SP to update objects on the chain on behalf of the user.4.1.2 Greenfield Chain New Messages
Greenfield introduces several new messages for SP acts as the upload agent feature
MsgDelegateCreateObject
The MsgDelegateCreateObject message enables the primary SP linked to a bucket to create objects on behalf of users authorized to do so within the bucket. It includes below attributes:
The MsgDelegateUpdateObjectContent message enables the primary SP linked to a bucket to update objects on behalf of users authorized to do so within the bucket. It includes below attributes:
MsgSealObjectV2
In our previous implementation, users were responsible for calculating the checksum themselves and specifying it during object creation. However, in this new method, when the SP creates an object, it does not have the complete object information. It has to wait until the SP seals the object to fill this information into the object info. To address this, we need to upgrade the MsgSealObject message to MsgSealObjectV2 to enhance this functionality.
MsgToggleSPAsDelegatedAgent
It is used by bucket owners to enable/disable the delegated create/update feature for a specific bucket.
4.2 New workflow for object creation/update on Greenfield
The delegate create/update object workflows is outlined below:
4.2.1 Users
Users can simply use the APIs introduced in section 4.1, to upload objects to the primary SP of the bucket, without incurring any transaction fees or having to switch to the Greenfield network.
Users are required to sign the message. This step ensures SPs can verify the user's identity.
If users use go-sdk/js-sdk to send the “create/update object” request to SPs, the wallet signature will be added to the request automatically.
If users use a web-based Dapp, the Dapp needs to integrate Greenfield off-chain-auth mechanism, which has a built-in EDDSA signing process and makes sure that the request sent to SPs are attached with users’ signature. About EDDSA authentication, see BEP-346
4.2.2 SP
SP needs to do the following tasks:
4.3 Security
This type of proxy for creating objects provides users with great convenience, but it also introduces potential security issues:
Once users detect malicious behavior from the primary SP, they have the following options:
ToggleSPAsDelegatedAgent
to prevent the Primary SP from creating files further, users can create object on their own.MigrateBucket
operation, users can switch the primary SP and select a trusted SP to act as the new primary SP for the Bucket.5. License
The content is licensed under CC0.