Running a Storage Provider (MCSP)
Critical information in this section may be subject to change as the network is in early stages.🔓 The Moca Storage Provider source code is publicly available on GitHub.
Storage Provider Information
Recommended System Requirements
| Component | Recommended Specification | Minimum Specification |
|---|---|---|
| Hardware | VPS running recent versions of macOS, Linux, or Windows | VPS running recent versions of macOS, Linux, or Windows |
| CPU | 16 cores | 8 cores |
| Memory (RAM) | 64 GB | 32 GB |
| Storage | At least 4 TB disk space for backend storage + 50 GB+ SQL database | At least 2 TB disk space for backend storage + 50 GB+ SQL database |
| Bandwidth | 10 MB/s+ upload/download speed | 10 MB/s+ upload/download speed |
Setting Up Moca Chain Data Storage Provider
MCSP Compiling and Dependencies
Compile MCSP
Compilation dependencies:- Golang: MCSP is written in Golang, and you need to install version 1.20+.
- Buf: A new way of working with Protocol Buffers. MCSP uses Buf to manage proto files.
- protoc-gen-gocosmos: Protocol Buffers for Go with Gadgets. MCSP uses this protobuf compiler to generate
pb.gofiles. - mockgen: A mocking framework for the Go programming language that is used in unit tests.
- jq: A command-line JSON processor. Users should install
jqaccording to their operating system.
Note
If you’ve already executed themake install-tools command in your shell, but you failed to make build and encountered one of the following error messages:
Error message 1:
/usr/local/go/bin. Other OS are similar.
/usr/local/go/bin. Other OS are similar.
/usr/local/go/bin. Other OS are similar.
The error messages above are due to users not setting the Go environment correctly. For more info, users can search for GOROOT, GOPATH, and GOBIN.
MCSP Dependencies
If a user wants to start MCSP in local mode or testnet mode, you must prepareSPDB, BSDB, and PieceStore dependencies.
SPDB and BSDB
MCSP usesSPDB and BSDB to store some metadata such as object info, object integrity hash, etc. These two DBs now use RDBMS to complete corresponding functions.
Users can now use MySQL or MariaDB to store metadata. The following lists the supported RDBMS:
- MySQL
- MariaDB
More types of databases such as PostgreSQL or NewSQL will be supported in the future.
PieceStore
Moca Chain is a decentralized data storage system that uses object storage as the main data storage system. MCSP encapsulates data storage asPieceStore, which provides common interfaces to be compatible with multiple data storage systems. Therefore, if a user wants to join MCSP or test the function of MCSP, you must use a data storage system.
The following lists the supported data storage systems:
- AWS S3: An object storage that can be used in a production environment.
- Aliyun OSS: Fully managed object storage service to store and access any amount of data from anywhere.
- B2: Backblaze B2 provides unlimited data storage in the cloud at ⅕th the cost of Amazon S3.
- MinIO: An object storage that can be used in a production environment and is compatible with AWS S3.
- POSIX Filesystem: A local filesystem is used for experiencing the basic features of MCSP and understanding how MCSP works. The piece data created by MCSP cannot be gotten within the network and can only be used on a single machine.
Run Local MCSP Network
This guide helps you to set up a local Moca Chain Storage Provider network for testing and other development-related purposes.Recommended Prerequisites
The following lists the recommended hardware requirements:- VPS running recent versions of Mac OS X, Linux, or Windows;
- 16 cores of CPU, 64 GB of memory (RAM);
- At least 100GB disk space for backend storage;
- 10GB+ SQL Database.
Quickly setup local Moca Chain network
Build Moca ChainSetup local MCSP network
Compile MCSPsp.info, and db.info in seven different directories. This command is used for generating the MCSP env for the first time or regenerating the MCSP env.
The json file path accepted for the first arg is generated by the “Quickly setup local Moca Chain network” step.View directory structure:
Start Four MCSPs
Makeconfig.toml according to db.info, sp.info and start four MCSPs.
Recompile MCSP
If you want to modifyconfig.toml in different MCSP directories or recompile the moca-sp binary file, you can use the following commands to reset and start the local MCSP:
One-step (Recommended)
Quickly setup local Moca Chain network
Build Moca Chain Image and start Moca Chain network with docker-compose.Setup local MCSP network
Operate With MCSP
If you have already started Moca Chain and Moca Chain MCSP successfully locally, you can usemoca-cmd to operate with MCSP such as CreateBucket, PutObject, and GetObject. Detailed info about moca-cmd can be found here.
Next, we provide you a hand-by-hand tutorial to operate with the chain and MCSP.
Generate your test account
First, we need to generate a test account and private key:Use cmd to send requests
If you have come to this step, congratulations, you can operate with your own private chain and MCSP. First, we need to configurecmd:
Users can usemd5to compare your generated file and the downloaded file to see whether it is the same. You can explore other functions ofmoca-cmd.
Run MCSP Node
This guide helps you set up an MCSP Node. Once you set up the MCSP Node successfully, you can follow the “Join SP Network” guide to make it online.Prerequisites
Recommended Hardware
The following lists the recommended hardware requirements:- VPS running recent versions of Mac OS X, Linux, or Windows;
- 16 cores of CPU, 64 GB of memory (RAM);
- 1 Gbps network connection with upload/download speeds of 10MB/s+;
- At least 1 TB disk space for backend storage;
- 50GB+ SQL database;
- Piece Store: AWS S3, MinIO (Beta);
- 6
mocadaccounts with enough $MOCA.IMPORTANT: Each storage provider will hold 7 different accounts serving different purposes.
Wallet Preparation
- Operator Account: Used to edit the information of the StorageProvider. Please make sure it has enough Moca to pay the gas fee of
EditStorageProviderandUpdateStorageProviderStatustransactions. - Funding Account: Used to deposit staking tokens and receive earnings. It is important to ensure that there is enough money in this account, and the MCSP must submit a deposit as a guarantee. At least 500+ Moca are required for staking. You should use this address to send a
CreateStorageProviderproposal on-chain. Besides the 500 Moca for staking, the funding address should have enough tokens for creating VGF to store more data, so we suggest depositing at least 510 Moca into this account. - Seal Account: Used to seal the user’s object. Please make sure it has enough Moca to pay the gas fee of the
SealObjecttransaction. We suggest depositing 10 Moca into this account. - Approval Account: Used to approve user’s requests. This account does not require holding $MOCA.
- GC Account: It is a special address for sp and is used by sp to clean up local expired or unwanted storage. Please make sure it has enough $MOCA because it’s going to keep sending transactions up the chain.
- Maintenance Account: It is used for MCSP self-testing while in maintenance mode. This account for creating buckets and objects will be allow-listed by the Chain, while other users’ create requests will fail.
- Bls Account: Used to create a bls signature when sealing objects to ensure integrity; it does not need to be deposited.
IMPORTANT:If you want to generate a public key and private key ofFundingAddressis used to deposit staking tokens and receive earnings. Therefore, users should prepare their ownFundingAddresspublic key and private key. And keep the private key ofFundingAddressin a cold wallet for safety! The private keys ofOperatorAddress,SealAddress,ApprovalAddress,GCAddress, andBlsAddresscan be kept in a hot wallet because they are often used to send transactions.
FundingAddress in the mocad binary file, you can execute the following commands:
maintenance account is not needed for MCSP deployment, but you should export it to conduct a self-test:
Please keep these seven private keys safe!Moreover, obtain the
bls public key and generate a bls proof to fill in the proposal of creating a Storage Provider.
bls_pub_key:
Database Configuration
You should create two databases:${SpDB.Database} and ${BsDB.Database}.
IMPORTANT:The following example assumes${BsDB.Database}requiresutf8mb4_unicode_cias the character set and collation.
${SpDB.Database} as storage_provider_db and ${BsDB.Database} as block_syncer.
This is the encoding we expect to see.
Create Storage Provider
Compile MCSP
Follow the “Compile MCSP” doc to compile the MCSP binary or you can download the binary from the Moca Chain Storage Provider Release.MCSP Config
Generate config template
Write config
You can learn about how to write yourconfig.toml file here.
It’s recommended to deploy a Kubernetes cluster following this guide. The corresponding config file is here.
Run MCSP
Join MCSP Network
This guide will help you join the MCSP Network: Testnet.Prerequisite for Becoming a Testnet MCSP
To ensure the stable provision of data services, Storage Providers must meet specific criteria to join the testnet.- The MCSP must join the testnet for a minimum of one month.
- The MCSP must store over 1K files across more than 100 buckets on the testnet.
- There were no slash events on the MCSP in the past week.
How to Join MCSP Network
Moca Chain validators are responsible for selecting storage providers. For each on-chain proposal to add a new storage provider, there is a deposit period for depositing Moca and a voting period for validators to cast votes. Once the proposal passes, the new MCSP can join the network afterwards.Submit Proposal
The MCSP needs to initiate an on-chain proposal that specifies theMsg information to be automatically executed after the vote is approved. In this case, the Msg is MsgCreateStorageProvider. It’s worth noting that the deposit tokens need to be greater than the minimum deposit tokens specified on the chain.
Hot Wallet Manual
You can use themocad command to directly send the transaction for creating a storage provider. To do this, please import the private key of the funding account into the Keystore.
However, it is not safe to use a hot wallet for Testnet. Instead, you should refer to the Hardware Wallet Manual for instructions on using a hardware wallet.Command for creating storage provider:
create_storage_provider.json, modify it with the correct values as you need:
Hardware Wallet Manual
Themocad command is not available for connecting with the hardware wallet, so you should use the mocad-tx-sender to send transactions. Here are the steps:
Generate the transaction data:
Note:
- You can get the
govmodule address by this command:curl -X GET "https://testnet-api.mocachain.org/cosmos/auth/v1beta1/module_accounts/gov" -H "accept: application/json"endpointis the URL of your gateway.read_priceandstore_priceunits are wei/bytes/s.free_read_quotaunit is Bytes.creatoris the address of thegovmodule.metadatais optional.
Deposit Moca to Proposal
Note: You can get the minimum deposit for a proposal by the above command. Please make sure that the initial deposit is greater than min_deposit when submitting the proposal.
Wait Voting and Check Voting Result
After submitting the proposal successfully, you must wait for the voting to be completed and the proposal to be approved. It will last 1 day on Testnet. Once it has passed and is executed successfully, you can verify that the storage provider has been joined.Warning: Please ensure that the storage provider service is running before it has been joined.You can check the on-chain MCSP information to confirm whether the MCSP has been successfully created.
Activate MCSP
Storage Provider Standard Test
After the proposal has passed, the status of MCSP isSTATUS_IN_MAINTENANCE. To prevent being slashed due to functional abnormalities, you should first perform a full functional test using the maintenance account. You can refer to the MCSP standard test.
Update MCSP status
Once the testing is completed, you need to send a transaction to activate the MCSP toSTATUS_IN_SERVICE.
MCSP address deposit
Funding Address
As a new MCSP, you need to deposit a minimum amount of Moca into the funding address. Please note the initial deposit requirement varies in different environments. You can check thesp.params.min_deposit value (in wei Moca) from the genesis endpoint response of the Moca Chain testnet. At the time when this doc is written, according to https://testnet-lcd.mocachain.org/genesis, MCSP in testnet requires a minimum of 500 Moca deposited in the funding address.
In addition, to join the network, an MCSP must initiate a proposal using a funding address and have an additional >1 Moca to cover these costs.
Operator Address
The MCSP operator address will be used to send “Create Global Virtual Group”, “Edit Storage Provider”, “Update Storage Provider Status”, and other transactions to the Moca Chain. So it requires some Moca deposited for the transaction fee as well. We recommend the MCSP operator address can hold at least 0.1 Moca but not necessarily as much as possible.Storage Provider Operations
EditStorageProvider
This command is used to edit the information of the MCSP, including endpoint, description, etc. Usage:Update MCSP Price
Update the storage provider read, store price and free read quota. If there is no change to a specific value, the current value should also be provided.- The unit of price is a decimal, which indicates wei Moca per byte per second. E.g. the price is 0.02183945725, which means approximately $0.018/GB/Month.
- The
free-read-quotaunit is bytes; for 1GB free quota, it should be 1073741824.
Update MCSP Quota
Besides theupdate-price command above, you can also use the moca-sp command to update the free read quota for MCSP. The update.quota command is used to update the free quota of the MCSP; it will send a transaction to the blockchain to update the free read quota but keep the storage price and read price unchanged.
Usage:
Recover MCSP Objects
Besides the commands above, you can also use themoca-sp command to recover objects for MCSP, whether it is the primary or secondary sp of the object. The recover.object command is used to recover an object or objects of the MCSP; it will send a request to other MCSPs to get a replicate of the object(s) you want to recover.
Usage:
Claim MCSP Income
To claim income, a storage provider can use thesettle command to settle income in global virtual group families or global virtual groups. To find the global virtual group families or global virtual groups to settle, a storage provider can use query.primary.sp.income or query.secondary.sp.income of moca-sp commands.
To query the income of a primary sp
Usage:
The unit of the unsettled income is aMoca. The first element in the query result array above means that sp 1 gets 2018422795287337 wei Moca in vgf_id 2.
To query the income of a secondary sp
The unit of the unsettled income is wei Moca. The first element in the query result array above means that sp 1 gets 13073138794535490 wei Moca in gvg_id 2531.
Exit MCSP Network
How to exit Moca Chain network
When an MCSP decides to exit the Moca Chain network, there are three main steps to go through, involving both the exiting MCSP and other MCSPs in the network:- Declare the exit
- Data recovery by successor MCSP(s)
- Finalize the exit
Declare the exit
The exiting MCSP needs to initiate aStorageProviderExit transaction to Moca Chain, which will turn its status to STATUS_GRACEFUL_EXITING. To exit the network, you can use the following commands based on the desired network:
Data recovery
For MCSPs interested in becoming successors, you need to perform the following data recovery steps:ReserveSwapIn
The prospective successor MCSP needs to determine the Global Virtual group (GVG) and Global Virtual Group Family (VGF) that the exiting MCSP has. This information can be obtained from Moca ChainScan or by using the provided CLI. Usage:Data Recovery
The data recovery process is triggered by the successor MCSP using the following commands: Usage:CompleteSwapIn
Upon completion of the data recovery process and successful verification, the successor MCSP needs to send aCompleteSwapIn transaction to the Moca Chain. It will be automatically conducted before the recovery process concludes. This will finalize the recovery process and allow the successor MCSP to take over the position in the GVG Family or GVG.
Note: It is crucial to note that under no circumstances should the CompleteSwapIn be triggered manually if the successor MCSP has not completed the data recovery process but acknowledges it. Doing so may result in data availability challenges and potential loss of funds.
Finalize the Exit
Once the successor MCSP has completed the data recovery process and taken over the position in the GVG Family or GVG, by checking the GVG statistic of the exiting MCSP, confirm that there are no more GVGs associated with it. Anyone in the Moca Chain network can send aCompleteStorageProviderExit transaction to the Moca Chain to finalize its exit from the network. Below shows the CLI triggered by the exiting MCSP itself.
Usage:
Deploy Piece Store
Coming soon.MCSP Config
MCSP Config
This section gives you a complete config of MCSP../moca-sp config.dump will generate a template config.toml.
App info
These fields are optional.Database
To config[SpDB], [BsDB], you have to input the username, db password, db address, and db name in these fields.
PieceStore
To config[PieceStore] and [PieceStore.Store], you can read the details in this doc.
Chain info
ChainIDof testnet ismoca_222888-1.ChainAddressis the RPC endpoint of Testnet; you can find RPC info here.
SpAccount
These private keys are generated during wallet setup.Endpoint
[Endpoint] specifies the URL of different services.
For single-machine host (not recommended):
P2P
Note: We don’t use P2P service in Testnet, so users can ignore P2P items.
P2PPrivateKeyandnode_idare generated by./moca-sp p2p.create.key -n 1.P2PAntAddressis your load balance address. If you don’t have a load balance address, you should have a public IP and use it inP2PAddress. It consists ofip:port.P2PBootstrapcan be left empty.
Gateway
The correct configuration should not include the protocol prefix https://.
BlockSyncer
Here is theblock_syncer config. The configuration of BsDBWriteAddress can be the same as the BSDB.Address module here. To enhance performance, you can set up the write database address here and the corresponding read database address in BSDB.
FundingPrivateKey
There is no need to writeFundingPrivateKey in config.toml. It should be kept in a cold wallet for safety.
Rcmgr
ResourceManager manages resources within the MCSP system, tracking and accounting for usage across the stack, from internal components to applications. It also allows for resource usage to be limited based on user-configurable policies. The config schema is shown below:Quota
Here is the quota config. The configuration ofMonthlyFreeQuota defines the free quota for each month. It will be reduced when the charge quota is exhausted.
MCSP Probe
It contains two probes:liveness and readiness probe. If users want to check whether MCSP is healthy and ready, they can refer to the Kubernetes docs to learn related concepts. For detailed MCSP probe info, users can refer to the MCSP probe documentation.