Skip to content

Commit bef6947

Browse files
authored
fixes and readme (#528)
Signed-off-by: turuslan <[email protected]>
1 parent 8c7c60e commit bef6947

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+318
-213
lines changed

CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ set(
1818

1919
include("cmake/Hunter/init.cmake")
2020
HunterGate(
21-
URL "https://github.com/soramitsu/soramitsu-hunter/archive/tags/v0.23.257-soramitsu13.tar.gz"
22-
SHA1 "8c88d8bac2dee771926b84a6e28642a267f88ea8"
21+
URL "https://github.com/soramitsu/soramitsu-hunter/archive/tags/v0.23.257-soramitsu16.tar.gz"
22+
SHA1 "64a1180e8cbeb98d2cfd786bfb725dcdc81d8fa9"
2323
LOCAL
2424
)
2525

@@ -125,3 +125,5 @@ if (TESTING)
125125
enable_testing()
126126
add_subdirectory(test)
127127
endif ()
128+
129+
install(TARGETS fuhon-node fuhon-miner)

README.md

+82-133
Original file line numberDiff line numberDiff line change
@@ -20,160 +20,109 @@ You can also read about lotus minimal requirements in [filecoin-docs](https://do
2020

2121
All C++ dependencies are managed using [Hunter](https://github.com/cpp-pm/hunter).
2222
It uses cmake to download required libraries and do not require downloading and installing packages manually.
23-
Target C++ compilers are:
24-
* GCC 7.4
25-
* Clang 6.0.1
26-
* AppleClang 11.0
27-
28-
### Rust Installation
29-
30-
C++ Filecoin implementation uses Rust libraries as dependencies for BLS providers.
31-
All you need to build these targets successfully - is Rust lang installed to your `${HOME}/.cargo/bin`.
32-
33-
You can do it manually following the instructions from [rust-lang.org](https://www.rust-lang.org/tools/install) or any other way.
34-
35-
Otherwise, CMake would not be able to compile Rust-related targets and will produce a warning about that during configuration.
36-
37-
### CodeStyle
38-
39-
We follow [CppCoreGuidelines](https://github.com/isocpp/CppCoreGuidelines).
40-
41-
Please use clang-format 11.0.0 with provided [.clang-format](.clang-format) file to autoformat the code.
42-
43-
## Maintenance
44-
45-
Maintainers: @zuiris, @turuslan, @Elestrias, @ortyomka, @wer1st, @Alexey-N-Chernyshov
46-
47-
Tickets: Can be opened in GitHub Issues.
48-
49-
50-
# Cpp-Filecoin install and setup guide
51-
## Fuhon node establishing
52-
There are 2 ways of getting an executable version of filecoin node or miner. The First is to get executables by [downloading](https://github.com/filecoin-project/cpp-filecoin/releases "cpp-filecoin releases"). The second is to build executables by yourself, see **Advanced building**. To begin running a node you will need `node` executable.
53-
54-
1. To configure a node you also need to make:
55-
* **configuration file**
56-
example `config.cfg`:
57-
58-
```
59-
bootstrap=<enter your peer here>
60-
drand-server=api.drand.sh
61-
drand-pubkey=868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31
62-
drand-genesis-time=1595431050
63-
drand-period=30
64-
```
65-
* **genesis file** - this is a special pre-set file with the initial block, which will configure the initial state of your node, sets network parameters like sector size, recalls time, e.t.c and defines miner-list with the first network miner.
66-
67-
you also can download that [snapshots](https://fil-chain-snapshots-fallback.s3.amazonaws.com/mainnet/minimal_finality_stateroots_latest.car "snapshots store") for a less time-assuming connection and synchronization to the popular filecoin networks.
68-
More about snapshot management [here](https://docs.filecoin.io/get-started/lotus/chain/#restoring-a-custom-snapshot "snapshot documentation").
69-
2. After all the preparations you can launch a node:
70-
* link working directory, which will be a storage for all node-associated files. It can be done with `--repo` flag
71-
* One more important linking is configuration and genesis files, you can pass paths to them with `--config CONFIG_FILE` and `--genesis GENESIS_FILE` respectively.
72-
* For specifying peers listening port you need to pass `--port PORT` flag
73-
* In case you want to specify api port for a node + miner configuration or multi-node configuration, you can do that with `--api API_PORT`
74-
* Example of the command: `node_exec --repo path_to_node_repo --genesis genesis.car --config config.cfg --port 8080 --api 1235`
75-
76-
## Lotus-CLI establishing
77-
### User approach:
78-
1. Download [lotus executable](https://github.com/filecoin-project/lotus/releases/ "lotus releases")
79-
2. You can use CLI client with your node by linking it with `--repo <path to your node working directory>` flag,
80-
more about lotus-CLI flags will be covered in **Work with Lotus-CLI**
8123

82-
### Advanced approach:
83-
1. clone [lotus repository](https://github.com/filecoin-project/lotus "lotus project")
84-
2. build lotus cli client with command: `make build`
85-
3. In case you want to connect to interopnet, build lotus with `make interopnet`
86-
## Work with Lotus-CLI
87-
88-
1. For proper miner work you will need a bls wallet, which can be made with lotus-cli by using the following command: `$lotus --repo REPO wallet new bls`, after the execution of this command you will revive the public address of your new account, and a private key in `<repo of your working node>/keystore`.
89-
2. Also, you may need to put some Filecoins on your account from other addresses you may have, and you can do it with `lotus --repo REPO send --from SENDER_ADDRESS DISTANATION_ADDRESS`
90-
91-
3. In case you want to get some Filecoins, you can buy them on stocks with the usage of your public address.
92-
93-
4. Other advanced commands you may find in [filecoin-docs about lotus CLI](https://docs.filecoin.io/get-started/lotus/installation/#interact-with-the-daemon "lotus CLI documentation").
94-
## Fuhon miner establishing
95-
To start mining at first you need to configure and run Fuhon or Lotus node. Before all make sure that your node had successfully **connected** and updated to the current **block height** (actual network block number). Also, your node's api port should be opened for connection.
96-
97-
To provide wallet functions and oracle information be sure to run lotus-cli at first. You can find how to do it in **Lotus-CLI establishing**.
98-
99-
Once all the needed modules will be started, you can continue with the miner configuration.
100-
101-
1. Create miner work directory (f.e. `$mkdir miner`)
102-
2. Download [miner executable](https://github.com/filecoin-project/cpp-filecoin/releases "executables releases") and put it in work directory
103-
3.Copy proof parameters json file with command: `cp /<path to cpp-filecoin>/core/proofs/parameters.json MINER_REPO/proof-params.json`
104-
4. Run your miner with ` --repo REPO --miner-repo MINER_REPO --owner PUBLIC_ADRESS --miner-api MINER_API_PORT --sector-size SECTOR_SIZE`
24+
Target C++ compilers are:
25+
* GCC 9.3.0
26+
* Clang 9.0.1
27+
* AppleClang 12.0.0
28+
29+
### Lotus CLI
30+
`fuhon-node` supports subset of `lotus` CLI commands.
31+
You may download [pre-built binaries](https://github.com/filecoin-project/lotus/releases) or build [lotus](https://github.com/filecoin-project/lotus) from source.
32+
Lotus CLI [introduction](https://docs.filecoin.io/get-started/lotus/installation/#interact-with-the-daemon).
33+
34+
### Rust
35+
[filecoin-ffi](https://github.com/filecoin-project/filecoin-ffi) provides pre-built binaries for some platforms.
36+
If they are unavailable, you need Rust compiler to build them.
37+
Rust [installation instruction](https://www.rust-lang.org/tools/install).
38+
39+
## Build
40+
```sh
41+
# clone project
42+
git clone --recursive https://github.com/filecoin-project/cpp-filecoin
43+
# configure cmake
44+
cmake cpp-filecoin -B cpp-filecoin/build
45+
# build and install fuhon-node and fuhon-miner
46+
cmake --build cpp-filecoin/build --target install
47+
# check that fuhon-node and fuhon-miner are now available
48+
fuhon-node --help
49+
fuhon-miner --help
50+
```
10551

106-
## Advanced Building
107-
This approach allows you to build our project with your modifications,
108-
but be sure that your realization follows consensus rules.
52+
## Usage
10953

110-
1. clone [funon-filecoin project](https://github.com/filecoin-project/cpp-filecoin "cpp-filecoin project")
54+
### Interopnet node
11155

112-
2. go to `./cpp-filecoin` directory
56+
Create the following `fuhon-interopnet/config.cfg` file
57+
```properties
58+
# use interopnet profile, corresponds to "make interopnet" lotus target
59+
profile=interopnet
11360

114-
3. run `$git submodule update --init --recursive`
61+
# enable debug logs to see sync progress
62+
log=d
11563

116-
4. To finish your building you may also want to add your GitHub token, In such case you need to set up two environment variables:
117-
```
118-
GITHUB_HUNTER_USERNAME=<github account name>
119-
GITHUB_HUNTER_TOKEN=<github token>
64+
# bootstrap peers from https://github.com/filecoin-project/lotus/blob/master/build/bootstrap/interopnet.pi
65+
bootstrap=/dns4/bootstrap-0.interop.fildev.network/tcp/1347/p2p/12D3KooWLGPq9JL1xwL6gHok7HSNxtK1Q5kyfg4Hk69ifRPghn4i
66+
bootstrap=/dns4/bootstrap-1.interop.fildev.network/tcp/1347/p2p/12D3KooWFYS1f31zafv8mqqYu8U3hEqYvaZ6avWzYU3BmZdpyH3h
12067
```
121-
To generate GitHub token follow the [instructions](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). Make sure `read:packages` and `write:packages` permissions are granted.
12268

123-
5. At this stage you will need a build directory, which can be created with `mkdir BUILD_REPO`
124-
125-
6. Build cmake with the following command: `cmake . -B BUILD_DIR`
69+
Start node
70+
```sh
71+
fuhon-node --repo fuhon-interopnet --genesis cpp-filecoin/core/node/main/interopnet.car
72+
# you can omit --genesis flag after first run
73+
fuhon-node --repo fuhon-interopnet
74+
```
12675

127-
7. build targets: node - for node executable, miner_main- for miner executable.
128-
example: `cmake --build BUILD_DIR --target node miner_main`
76+
To use lotus CLI add `--repo` flag
77+
```sh
78+
lotus --repo fuhon-interopnet net peers
79+
```
12980

130-
8. First time build will likely take a long time. However, you can cache binaries to [hunter-binary-cache].
81+
### Mainnet node (from snapshot)
13182

132-
9. Node executable can be found at: `<build_repository>/core/node/main`.
133-
10. Miner executable can be found at:
134-
`<build_repository>/core/miner/main`
135-
11.The next steps are similar to common miner and node establishing which can be found at **Fuhon node establishing** and **Fuhon miner establishing**
83+
Download mainnet snapshot ([docs](https://docs.filecoin.io/get-started/lotus/chain)).
84+
```sh
85+
LATEST_SNAPSHOT=$(curl -sI https://fil-chain-snapshots-fallback.s3.amazonaws.com/mainnet/minimal_finality_stateroots_latest.car | perl -ne '/x-amz-website-redirect-location:\s(.+\.car)/ && print $1')
86+
curl -o mainnet-snapshot.car $LATEST_SNAPSHOT
87+
```
13688

137-
## Configuration Lotus-Fuhon
138-
### Lotus-node and Fuhon-miner
139-
1. To start up a lotus node at first you need to get a [lotus executable](https://github.com/filecoin-project/lotus/releases/ "lotus releases")
140-
2. You can run your lotus node with the next command: `$lotus --repo REPO daemon --genesis genesis.car --profile bootstrapper`, more about running lotus software can be found in [filecoin-docs](https://docs.filecoin.io/get-started/lotus/installation "lotus filecoin documentation").
141-
3. Fuhon-miner establishing is described in **Fuhon miner establishing**
142-
### Fuhon-node and Lotus-miner
143-
1. Establishing a Fuhon node is described in **Fuhon node establishing**
144-
2. Lotus miner can be established in the following way:
145-
- to begin with you need your own bls wallet(described in **Working with Lotus-CLI**)
146-
- init your miner with the command: `lotus-miner --repo REPO --miner-repo MINER_REPO init --nosync --owner BLS_WALLET_ADDR --sector-size SECTOR_SIZE`
147-
- to know more about lotus software establishing, read [filecoin-docs](https://docs.filecoin.io/get-started/lotus/installation/#minimal-requirements "lotus establishing guide")
89+
Create following `fuhon-mainnet/config.cfg` file
90+
```properties
91+
# use downloaded snapshot file (do not delete that file)
92+
use-snapshot=mainnet-snapshot.car
14893

149-
## Docker configuration
150-
Will be soon!
94+
# bootstrap peers from https://github.com/filecoin-project/lotus/blob/master/build/bootstrap/mainnet.pi
95+
bootstrap=/dns4/node.glif.io/tcp/1235/p2p/12D3KooWBF8cpp65hp2u9LK5mh19x67ftAam84z9LsfaquTDSBpt
96+
```
15197

152-
## Your new Filecoin network start
98+
Start node (first run may take some time)
99+
```sh
100+
fuhon-node --repo fuhon-mainnet --genesis cpp-filecoin/core/node/main/mainnet.car
101+
```
153102

154-
To run a new filecoin network, you should run at least one node, and a miner (miners are a representation of the network power, so the more miners connected and sealed, the more power your network will have). In this guide, we will consider a network of two nodes and two miners(genesis and common ones)
103+
### Docker-compose example
155104

156-
1. To run the first node you will need to generate a new genesis file which will be an initial instruction for all new connected nodes.
157-
This can be done with lotus-seed tools:
158-
- Clone [lotus repository](https://github.com/filecoin-project/lotus "lotus project")
105+
```sh
106+
docker-compose up
107+
```
159108

160-
- build lotus-seed with `$make lotus-seed` or `make debug` - for debug version initiation,
161-
or `make 2k` for a version with 2 KiB sector size or `make interopnet` for interopnet version.
109+
## CodeStyle
162110

163-
- Generate genesis and preseal. Ensure lotus-seed was built in the previous step and run script node `$genesis.js DIR 1` to generate genesis. `DIR` - directory where genesis and presealed sectors will be generated, 1 - number of sectors for a miner. In case your lotus executables lay in a custom directory or script can not find them, you can link lotus target with `LOTUS=/<path to your lotus executable>/lotus node genesis.js <directory where results will be> <sealing sectors upper bound>`
111+
We follow [CppCoreGuidelines](https://github.com/isocpp/CppCoreGuidelines).
164112

165-
2. Run your node-1 with new genesis file as it was done in chapter **Fuhon node establishing**
113+
Please use clang-format 11.0.0 with provided [.clang-format](.clang-format) file to autoformat the code.
166114

167-
3. Run your node-2 as the 1st one, but be sure to open api port on it with `--api API_PORT`
115+
## Maintenance
168116

169-
4. Connect node-2 to node-1 by commands:
170-
`addr=$(lotus --repo REPO1 net listen | grep 127.0.0.1)`
171-
`lotus --repo REPO2 net connect $addr`t
117+
Maintainers: @zuiris, @turuslan, @Elestrias, @ortyomka, @wer1st, @Alexey-N-Chernyshov
172118

173-
5. After generating a new genesis file, you will also receive genesis.json with declared miners list, these are addresses of the initial miners.
119+
Tickets: Can be opened in GitHub Issues.
174120

175-
6. To start miner that is declared in genesis file (step 5) you can use chapter **Fuhon miner establishing** but with some major changes.
176-
You will also need the following flags to be provided: `--genesis-miner`, `--actor ACTOR`, `--pre-sealed-sectors PRESEAL_DIR`, `--pre-sealed-metadata PRESEAL_JSON`.
121+
## Hunter cache upload
177122

178-
7. To start a new miner just follow the steps declared in **Fuhon miner establishing**, or you can run lotus miner using [filecoin-docs](https://docs.filecoin.io/get-started/lotus/installation/#minimal-requirements "lotus establishing guide")
179-
8. After two nodes will be connected and your miner will work, a new filecoin network starting to exist, since that moment you can share your peers to invite new participants.
123+
If you have access and want to upload to [hunter-binary-cache](https://github.com/soramitsu/hunter-binary-cache), you need to add your GitHub token with `read:packages` and `write:packages` permissions.
124+
To generate GitHub token follow the [instructions](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line).
125+
```sh
126+
export GITHUB_HUNTER_USERNAME=<github account name>
127+
export GITHUB_HUNTER_TOKEN=<github token>
128+
```

cmake/Hunter/config.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ hunter_config(
1717
)
1818

1919
hunter_config(libp2p
20-
URL https://github.com/soramitsu/cpp-libp2p/archive/b6de6a91eeeb23bcb1eefeb4a99f1bdcda3d86bd.tar.gz
21-
SHA1 fa41c751cab65f8e3ee2e62df9dceb4894ee2e9a
20+
URL https://github.com/soramitsu/cpp-libp2p/archive/3587bdcef771d6ca93b3f00bb26a6603653bdb5f.tar.gz
21+
SHA1 45ae022b61dac3fb5396cfa1eb89cbc41e9a3b43
2222
CMAKE_ARGS TESTING=OFF EXAMPLES=OFF EXPOSE_MOCKS=ON
2323
KEEP_PACKAGE_SOURCES
2424
)

cmake/dependencies.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# https://docs.hunter.sh/en/latest/packages/pkg/GTest.html
55
hunter_add_package(GTest)
66
find_package(GTest CONFIG REQUIRED)
7-
find_package(GMock CONFIG REQUIRED)
87

98
hunter_add_package(libarchive)
109
find_package(libarchive CONFIG REQUIRED)

cmake/functions.cmake

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ function(addtest test_name)
99
add_executable(${test_name} ${ARGN})
1010
addtest_part(${test_name} ${ARGN})
1111
target_link_libraries(${test_name}
12-
GTest::main
13-
GMock::main
12+
GTest::gmock_main
1413
)
1514
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/xunit)
1615
set(xml_output "--gtest_output=xml:${CMAKE_BINARY_DIR}/xunit/xunit-${test_name}.xml")

core/miner/main/CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# SPDX-License-Identifier: Apache-2.0
44
#
55

6-
add_executable(miner_main
6+
add_executable(fuhon-miner
77
main.cpp
88
)
9-
target_link_libraries(miner_main
9+
target_link_libraries(fuhon-miner
1010
Boost::program_options
1111
filecoin_config
1212
clock
@@ -33,3 +33,6 @@ target_link_libraries(miner_main
3333

3434
miner_actor_state
3535
)
36+
set_target_properties(fuhon-miner PROPERTIES
37+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
38+
)

core/miner/main/main.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
#include "storage/ipfs/impl/datastore_leveldb.hpp"
5151
#include "storage/leveldb/leveldb.hpp"
5252
#include "storage/piece/impl/piece_storage_impl.hpp"
53+
#include "vm/actor/builtin/types/market/deal_info_manager/impl/deal_info_manager_impl.hpp"
5354
#include "vm/actor/builtin/v0/miner/miner_actor.hpp"
5455
#include "vm/actor/builtin/v0/storage_power/storage_power_actor.hpp"
55-
#include "vm/actor/builtin/types/market/deal_info_manager/impl/deal_info_manager_impl.hpp"
5656

5757
namespace fc {
5858
using boost::asio::io_context;
@@ -137,6 +137,7 @@ namespace fc {
137137

138138
po::options_description desc("Fuhon miner options");
139139
auto option{desc.add_options()};
140+
option("help,h", "print usage message");
140141
option("miner-repo", po::value(&config.repo_path)->required());
141142
option("repo", po::value(&raw.node_repo));
142143
option("miner-api", po::value(&config.api_port)->default_value(2345));
@@ -156,6 +157,10 @@ namespace fc {
156157

157158
po::variables_map vm;
158159
po::store(parse_command_line(argc, argv, desc), vm);
160+
if (vm.count("help") != 0) {
161+
std::cerr << desc << std::endl;
162+
exit(EXIT_SUCCESS);
163+
}
159164
po::notify(vm);
160165
boost::filesystem::create_directories(config.repo_path);
161166
std::ifstream config_file{config.join("config.cfg")};

core/node/main/CMakeLists.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ target_link_libraries(node_builder
4949
miner_types
5050
)
5151

52-
add_executable(node
52+
add_executable(fuhon-node
5353
main.cpp
5454
)
55-
56-
target_link_libraries(node
55+
target_link_libraries(fuhon-node
5756
node_builder
5857
)
58+
set_target_properties(fuhon-node PROPERTIES
59+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
60+
)

core/node/main/builder.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ namespace fc::node {
160160
snapshot_key->getCbor(snapshot_cids);
161161
if (!config.snapshot) {
162162
log()->warn(
163-
"snapshot was imported before, but snapshot argument is missing");
163+
"snapshot was used before, but snapshot argument is missing");
164164
}
165165
}
166166
if (config.snapshot) {
167167
auto roots{storage::car::readHeader(*config.snapshot).value()};
168168
if (!snapshot_cids.empty() && snapshot_cids != roots) {
169-
log()->error("another snapshot already imported");
169+
log()->error("another snapshot already used");
170170
exit(EXIT_FAILURE);
171171
}
172172
// TODO(turuslan): max memory
@@ -175,7 +175,7 @@ namespace fc::node {
175175
o.ipld = o.ipld_cids;
176176
if (snapshot_cids.empty()) {
177177
snapshot_cids = roots;
178-
log()->info("snapshot imported");
178+
log()->info("snapshot is ready to use");
179179
snapshot_key->setCbor(snapshot_cids);
180180
}
181181
}

0 commit comments

Comments
 (0)