# Pre-requisites

Before diving into deployment of your mining operation, please make sure you go through the following steps.


It is recommended that you test your setup in calibration network before deploying on mainnet.

# Setup your permanent storage

Choose a network file system that you are familiar with (NFS for example) and deploy your storage cluster.

# Software dependencies

You will need to install these software dependencies (opens new window) (same as Lotus) before running venus.

# Install sophon-auth

Download and compile the source code of venus-auth.

$ git clone https://github.com/ipfs-force-community/sophon-auth.git
$ cd sophon-auth
$ git checkout <RELEASE_TAG>
$ make 
$ nohup ./sophon-auth run > auth.log 2>&1 &


Default config file for Venus-auth is located at ~/.sophon-auth/config.toml.


Log defaults printing to console. InfluxDB is supported through configuration.


The default port of sophon-auth is 8989.

# Using MySQL (Optional)

MySQL 5.7 or above is supported and can be used as a substitute for the dedault Badger key-value database. To use MySQL database, modify the db section of the config.

$ vim ~/.sophon-auth/config.toml

# Data source configuration item
# support: badger (default), mysql 
# the mysql DDL is in the script package 
type = "mysql" 
# The following parameters apply to MySQL
# conns 1500 concurrent
maxOpenConns = 64
maxIdleConns = 128
maxLifeTime = "120s"
maxIdleTime = "30s"

Restart sophon-auth for the configuration to take into effect.

$ ps -ef | grep auth
$ nohup ./sophon-auth run > auth.log 2>&1 &

# Token gerneration

sophon-auth manages jwt (opens new window) tokens used by other venus modules for them to talk to each other securely on the network.

Generate tokens for shared modules.

# add user SHARED
$ ./sophon-auth user add <SHARED>

# --perm specifies admin, sign, write or read permission of the token generated
$ ./sophon-auth token gen --perm admin <SHARED>

Generate tokens for independent modules. Tokens can be logically grouped by <USER> as individual miner joining the mining pool.

$ ./sophon-auth user add <USER>

$ ./sophon-auth token gen --perm write <USER>
$ ./sophon-auth token gen --perm read <USER>


Use ./sophon-auth user add <USER> to logically group different tokens. Activate the user, which was just created, then bind miner to it:

$ ./sophon-auth user update --name <USER> --state 1
$ ./sophon-auth user miner add <USER> <MINER_ID>

# 查看user列表
$ ./sophon-auth user list

# Install sophon-gateway

Download and compile the source code of sophon-gateway.

$ git clone https://github.com/ipfs-force-community/sophon-gateway.git
$ cd sophon-gateway
$ git checkout <RELEASE_TAG>
$ make

Start sophon-gateway.

$ ./sophon-gateway --listen=/ip4/ run \
# Use either a http or https url
--auth-url=<http://VENUS_AUTH_IP_ADDRESS:PORT> \
--auth-token=<SHARED_ADMIN_AUTH_TOKEN> \
> sophon-gateway.log 2>&1 &


If you encounter the following compilation errors, execute firstgo get github.com/google/flatbuffers@v1.12.1

github.com/dgraph-io/badger/v3@v3.2011.1/fb/BlockOffset.go:6:2: missing go.sum entry for module providing package github.com/google/flatbuffers/go (imported by github.com/dgraph-io/badger/v3/table); to add:
        go get github.com/dgraph-io/badger/v3/table@v3.2011.1

# Install venus daemon

Download and compile the source code of venus.

$ git clone https://github.com/filecoin-project/venus.git
$ cd venus
$ git checkout <RELEASE_TAG>
$ make deps
$ make

Start venus daemon for chain synchronization. Use --network to specify the network venus is connecting to.

$ nohup ./venus daemon --network=calibrationnet --auth-url=<http://VENUS_AUTH_IP_ADDRESS:PORT> --auth-token=<SHARED_ADMIN_AUTH_TOKEN> > venus.log 2>&1 &


Use tail -f venus.log or ./venus sync status to check if there is any errors during synchronization.

# Grant access to venus daemon

By default, venus daemon only respond to local access. Change the following configuration to allow access from other addresses.

vim ~/.venus/config.json

Change apiAddress from /ip4/ to /ip4/ Save and close the config file.

	"api": {"apiAddress": "/ip4/"}

Restart venus daemon for the config to take into effects.

$ ps -ef | grep venus
$ kill <VENUS_PID>
$ nohup ./venus daemon --network=calibrationnet --auth-url <http://VENUS_AUTH_IP_ADDRESS:PORT> --auth-token <SHARED_ADMIN_AUTH_TOKEN> > venus.log 2>&1 &


In order for the chain service to interact with the chain, daemon needs to be synced with the network by importing a snapshot of the filecoin chain. Please refer to this guide for more details.

# Install sophon-messager

Download and compile the source code of sophon-messager.

$ git clone https://github.com/ipfs-force-community/sophon-messager.git
$ cd sophon-messager
$ git checkout <RELEASE_TAG>
$ make 

Start sophon-messager. Note that --auth-url, --node-url and --auth-token are for sophon-messager to be aware of other venus modules and be properly authenticated.

$ nohup ./sophon-messager run \
--auth-url=<http://VENUS_AUTH_IP_ADDRESS:PORT> \
--node-url /ip4/<VENUS_DAEMON_IP_ADDRESS>/tcp/3453 \
--gateway-url=/ip4/<IP_ADDRESS_OF_VENUS_GATEWAY>/tcp/45132 \
--auth-token <SHARED_ADMIN_AUTH_TOKEN> \
--db-type mysql \
--mysql-dsn "<USER>:<PASSWORD>@(" \
> msg.log 2>&1 &


If no database related params are specified, sophon-messager will default to use sqlite.

# Install sophon-miner

Download and compile the source code of sophon-miner.

$ git clone https://github.com/ipfs-force-community/sophon-miner.git
$ cd sophon-miner
$ git checkout <RELEASE_TAG>
$ make

Initialize sophon-miner.

$ ./sophon-miner init
--auth-api <http://VENUS_AUTH_IP_ADDRESS:PORT> \
--gateway-api /ip4/<VENUS_GATEWAY_IP_ADDRESS>/tcp/45132 \
--api /ip4/<VENUS_DAEMON_IP_ADDRESS>/tcp/3453 \
--slash-filter local

Run sophon-miner.

$ nohup ./sophon-miner run >> miner.log 2>& 1 &

# Miner management

Once a user, damocles (opens new window) with proper miner id, connected to your Sophon service. You can query the status of said miner id by the following.

$ ./sophon-miner address state 
		"Addr": "<MINER_ID>",
		"IsMining": true,
		"Err": null

If IsMining of your miner is false, you can run the following command to start the miner id.

$ ./sophon-miner address start <MINER_ID>

List all miner ids that have connected to sophon-miner.

$ ./sophon-miner address list

# Configure unified endpoint for chain service

Given the complexity that a Sophon chain service consists of multiple chain service components (endpoints), it can be cumbersome for downstream consumers to configure multiple endpoints to chain service components before they can use the Sophon chain service.

To simplify this process and provide a unified endpoint for chain services, you can use sophon-gateway as a proxy for requests to chain services. Details can be found at configuring unified entry (opens new window).

# Next steps

Next, please follow this guide to connect to the Sophon service you just deployed!

# Questions?

Find us on Slack (opens new window)!