Skip to content

Commit 4eebd09

Browse files
authored
Merge pull request #84 from Chia-Network/alpha-1.3
Alpha 1.3 FullNode performance improvements - Syncing up to the blockchain by importing all blocks is faster due to improvements in VDF verification speed and multithreading block verification. Also fixed a bug where the node may not sync if it restarts close to a tip. VDF improvements - VDF verification and generation speed has increased and dependence on flint2 has been removed. We wish to thank Dr. William Hart (@wbhart) for dual licensing parts of his contributions in [FLINT](http://www.flintlib.org/) and [Antic](https://github.com/wbhart/antic) for inclusion in the Chia blockchain. Implemented an RPC interface with JSON serialization for streamables - currently on port 8555 - and moved the ssh UI to use RPC. Mongodb deprecated. Moved to [SQLite](https://www.sqlite.org/) for the blockchain database. This will require nodes to re-sync with the network. Luckily this is now faster. Changed the displayed process names for harvester, farmer, fullnode, timelords, and VDFs to to chia_full node, chia_harvester, etc. Fixed a bug that could cause inadvertent shutdown of other processes like an ongoing plotting session when new chia services were started. Added details on how to contribute in CONTRIBUTING.md. Thanks @RichardLitt. Also moved documentation from inside the repository to the [wiki](https://github.com/Chia-Network/chia-blockchain/wiki). Added color logging and now chia_harvester will periodically announce which plots it is currently farming and their k sizes. Fixed a typo in the UI. Hat tip to @lvcivs for the pr. Clarified the minimum version of boost required to build timelord/VDFs. Hat tip @AdrianScott Lots of smaller bug and documentation fixes.
2 parents 281be67 + 9db4838 commit 4eebd09

File tree

632 files changed

+46810
-52418
lines changed

Some content is hidden

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

632 files changed

+46810
-52418
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ jobs:
99
strategy:
1010
max-parallel: 4
1111
matrix:
12-
python-version: [3.7]
1312
os: [ubuntu-latest, macOS-latest]
1413

1514
steps:
1615
- uses: actions/checkout@v1
17-
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v1
16+
- name: Setup Python environment
17+
uses: actions/setup-python@v1.1.1
1918
with:
20-
python-version: ${{ matrix.python-version }}
19+
python-version: 3.7 # optional, default is 3.x
2120
- name: Install dependencies
2221
env:
2322
CHIA_MACHINE_SSH_KEY: ${{ secrets.CHIA_MACHINE_SSH_KEY }}
@@ -26,17 +25,11 @@ jobs:
2625
eval "$(ssh-agent -s)"
2726
ssh-add - <<< "${CHIA_MACHINE_SSH_KEY}"
2827
git submodule update --init --recursive
29-
sudo apt-get install --no-install-recommends mongodb|| echo ""
30-
brew tap mongodb/brew || echo ""
31-
brew update && brew install gmp [email protected] || echo ""
28+
brew update && brew install gmp || echo ""
3229
python3 -m venv .venv
3330
. .venv/bin/activate
34-
pip install wheel # For building blspy
3531
pip install -e .
3632
pip install -r requirements.txt
37-
- name: Start mongodb
38-
run: |
39-
mongod --dbpath ./db/ &
4033
- name: Lint with flake8
4134
run: |
4235
./.venv/bin/flake8 src

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ __pycache__/
1111
# Database
1212
nohup.out
1313
mongod.log*
14+
fndb_test*
15+
blockchain_test*
16+
*.db
17+
18+
# Logs
19+
*.log
20+
*.out
1421

1522
# Keys and plot files
1623
config/keys.yaml
@@ -52,4 +59,4 @@ pip-delete-this-directory.txt
5259
.vscode
5360

5461
# Packaging
55-
chia-blockchain.tar.gz
62+
chia-blockchain.tar.gz

CONTRIBUTING.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Introduction
2+
Welcome to the chia-blockchain project!
3+
We are happy that you are taking a look at the code for Chia, a proof of space and time cryptocurrency.
4+
5+
A lot of fascinating new cryptography and blockchain concepts are used and implemented here.
6+
This repo includes the code for the Chia full node, farmer, and timelord (in src), which are all written in python.
7+
It also includes a verifiable delay function implementation under lib/chiavdf (in c/c++), and a proof of space implementation under lib/chiapos.
8+
9+
If you want to learn more about this project, read the [wiki](https://github.com/Chia-Network/chia-blockchain/wiki), or check out the [green paper](https://www.chia.net/assets/ChiaGreenPaper.pdf).
10+
11+
### Contributions
12+
We would be pleased to accept code contributions to this project.
13+
As we are in the alpha stage, the main priority is getting a robust blockchain up and running, with as many of the mainnet features as possible.
14+
You can visit our [Trello project board](https://trello.com/b/ZuNx7sET) to get a sense of what is in the backlog.
15+
Generally things to the left are in progess or done. Some things go through "Coming up soon" but some will come directly out of other columns.
16+
Usually the things closer to the top of each column are the ones that will be worked on soonest.
17+
If you are interested in cryptography, math, or just like hacking in python, there are many interesting problems to work on.
18+
Contact any of the team members on keybase: https://keybase.io/team/chia_network.public, which we use as the main communication method and you can comment on any Trello card.
19+
20+
### Run tests and linting
21+
The first time the tests are run, BlockTools will create and persist many plots. These are used for creating
22+
proofs of space during testing. The next time tests are run, this won't be necessary.
23+
24+
```bash
25+
black src tests && flake8 src && mypy src tests
26+
py.test tests -s -v
27+
```
28+
Black is used as an automatic style formatter to make things easier, and flake8 helps ensure consistent style.
29+
Mypy is very useful for ensuring objects are of the correct type, so try to always add the type of the return value, and the type of local variables.
30+
31+
### Configure VS code
32+
1. Install Python extension
33+
2. Set the environment to ./.venv/bin/python
34+
3. Install mypy plugin
35+
4. Preferences > Settings > Python > Linting > flake8 enabled
36+
5. Preferences > Settings > Python > Linting > mypy enabled
37+
7. Preferences > Settings > Formatting > Python > Provider > black
38+
6. Preferences > Settings > mypy > Targets: set to ./src and ./tests
39+
40+
### Submit changes
41+
To submit changes, please make a pull request to the appropriate development branch.
42+
For example, after the 1.2 release, the 1.3 branch is used for development, etc.
43+
The master branch is updated with the latest releases only.
44+
45+
### Copyright
46+
By contributing to this repository, you agree to license your work under the Apache License Version 2.0, or the MIT License, or release your work to the public domain. Any work contributed where you are not the original author must contain its license header with the original author(s) and be in the public domain, or licensed under the Apache License Version 2.0 or the MIT License.

README.md

Lines changed: 33 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
11
# chia-blockchain
2-
Python 3.7 is used for this project. Make sure your default python version is >=3.7 by typing python3.
2+
Please check out the [wiki](https://github.com/Chia-Network/chia-blockchain/wiki) and [FAQ](https://github.com/Chia-Network/chia-blockchain/wiki/FAQ) for information on this project.
33

4-
You will need to enable [UPnP](https://www.homenethowto.com/ports-and-nat/upnp-automatic-port-forward/) on your router or add a NAT (for IPv4 but not IPv6) and firewall rule to allow TCP port 8444 access to your peer. These methods tend to be router make/model specific.
4+
Python 3.7 is required. Make sure your default python version is >=3.7 by typing `python3`.
5+
6+
You will need to enable [UPnP](https://www.homenethowto.com/ports-and-nat/upnp-automatic-port-forward/) on your router or add a NAT (for IPv4 but not IPv6) and firewall rules to allow TCP port 8444 access to your peer. These methods tend to be router make/model specific.
57

68
For alpha testnet most should only install harvesters, farmers, plotter and full nodes. Building timelords and VDFs is for sophisticated users in most environments. Chia Network and additional volunteers are running sufficient time lords for testnet consensus.
79

8-
## Install harvester, farmer, plotter, and full node
10+
## Step 1: Install harvester, farmer, plotter, and full node
911

1012
### Debian/Ubuntu
1113

1214
```bash
1315
sudo apt-get update
14-
sudo apt-get install build-essential cmake python3-dev python3-venv libssl-dev libffi-dev --no-install-recommends
16+
sudo apt-get install build-essential git cmake libgmp3-dev --no-install-recommends
17+
sudo apt-get install python3-dev python3-venv --no-install-recommends
1518

1619
git clone https://github.com/Chia-Network/chia-blockchain.git
1720
cd chia-blockchain
1821

1922
sh install.sh
2023

21-
# Install MongoDB Community Edition
22-
# Instructions - https://docs.mongodb.com/manual/administration/install-on-linux/
23-
24-
# Run mongo database if not running system-wide
25-
mongod --fork --dbpath ./db/ --logpath mongod.log
26-
2724
. .venv/bin/activate
2825
```
2926
### Amazon Linux 2
3027

3128
```bash
3229
sudo yum update
33-
sudo yum install gcc-c++ cmake3 wget git openssl openssl-devel
34-
sudo yum install python3 python3-devel libffi-devel
30+
sudo yum install gcc-c++ cmake3 wget git openssl openssl-devel
31+
sudo yum install python3 python3-devel libffi-devel gmp-devel
3532

3633
# CMake - add a symlink for cmake3 - required by blspy
3734
sudo ln -s /usr/bin/cmake3 /usr/local/bin/cmake
@@ -41,12 +38,6 @@ cd chia-blockchain
4138

4239
sh install.sh
4340

44-
# Install MongoDB Community Edition
45-
# Instructions - https://docs.mongodb.com/manual/administration/install-on-linux/
46-
47-
# Run mongo database if not running system-wide
48-
mongod --fork --dbpath ./db/ --logpath mongod.log
49-
5041
. .venv/bin/activate
5142
```
5243
### CentOS 7
@@ -55,6 +46,7 @@ mongod --fork --dbpath ./db/ --logpath mongod.log
5546
sudo yum update
5647
sudo yum install centos-release-scl-rh epel-release
5748
sudo yum install devtoolset-8-toolchain cmake3 libffi-devel
49+
sudo yum install gmp-devel libsqlite3x-devel
5850
sudo yum install wget git openssl openssl-devel
5951

6052
# CMake - add a symlink for cmake3 - required by blspy
@@ -71,13 +63,6 @@ git clone https://github.com/Chia-Network/chia-blockchain.git
7163
cd chia-blockchain
7264

7365
sh install.sh
74-
75-
# Install MongoDB Community Edition
76-
# Instructions - https://docs.mongodb.com/manual/administration/install-on-linux/
77-
78-
# Run mongo database if not running system-wide
79-
mongod --fork --dbpath ./db/ --logpath mongod.log
80-
8166
. .venv/bin/activate
8267
```
8368

@@ -98,16 +83,12 @@ sudo apt-get -y update
9883
sudo apt-get -y upgrade
9984
sudo do-release-upgrade
10085

101-
sudo apt-get install -y build-essential cmake python3-dev python3-venv mongodb software-properties-common --no-install-recommends
86+
sudo apt-get install -y build-essential cmake python3-dev python3-venv software-properties-common libgmp3-dev --no-install-recommends
10287

10388
git clone https://github.com/Chia-Network/chia-blockchain.git
10489
cd chia-blockchain
10590

10691
sudo sh install.sh
107-
108-
# Run mongo database if not running system-wide
109-
mongod --fork --dbpath ./db/ --logpath mongod.log
110-
11192
. .venv/bin/activate
11293
```
11394

@@ -118,7 +99,7 @@ Each line that starts with `pip ...` becomes `python -m pip ...`
11899

119100
```bash
120101
sudo apt-get -y update
121-
sudo apt-get install -y build-essential cmake python3-dev python3-venv mongodb software-properties-common --no-install-recommends
102+
sudo apt-get install -y build-essential cmake python3-dev python3-venv software-properties-common libgmp3-dev --no-install-recommends
122103

123104
# Install python3.7 with ppa
124105
sudo add-apt-repository -y ppa:deadsnakes/ppa
@@ -129,35 +110,26 @@ git clone https://github.com/Chia-Network/chia-blockchain.git
129110
cd chia-blockchain
130111

131112
sudo sh install.sh
132-
133-
# Run mongo database if not running system-wide
134-
mongod --fork --dbpath ./db/ --logpath mongod.log
135-
136113
. .venv/bin/activate
137114
```
138115

139116
### MacOS
140117
Make sure [brew](https://brew.sh/) is available before starting the setup.
141118
```bash
142-
brew tap mongodb/brew
143119
brew upgrade python
144-
brew install cmake [email protected]
120+
brew install cmake gmp
145121

146122
git clone https://github.com/Chia-Network/chia-blockchain.git
147123
cd chia-blockchain
148124

149125
sh install.sh
150-
151-
# Run mongo database if not running system-wide
152-
mongod --fork --dbpath ./db/ --logpath mongod.log
153-
154126
. .venv/bin/activate
155127
```
156128

157129

158-
## Install timelord
130+
## Step 2: Install timelord (optional)
159131
Note: this step is needed only if you intend to run a timelord or a local simulation.
160-
These assume you've already successfully installed harvester, farmer, plotting, and full node above.
132+
These assume you've already successfully installed harvester, farmer, plotting, and full node above. boost 1.67 or newer is required on all platforms.
161133
### Ubuntu/Debian
162134
```bash
163135
cd chia-blockchain
@@ -169,7 +141,7 @@ sh install_timelord.sh
169141
#Only for Amazon Linux 2
170142
sudo amazon-linux-extras install epel
171143

172-
sudo yum install gmp-devel mpfr-devel
144+
sudo yum install mpfr-devel
173145

174146
# Install Boost 1.72.0
175147
wget https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz
@@ -178,11 +150,6 @@ cd boost_1_72_0
178150
./bootstrap.sh --prefix=/usr/local
179151
sudo ./b2 install --prefix=/usr/local --with=all; cd ..
180152

181-
# Install Flint2
182-
git clone https://github.com/wbhart/flint2
183-
cd flint2; ./configure; sudo make install; cd ..
184-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
185-
186153
cd chia-blockchain
187154

188155
sh install_timelord.sh
@@ -205,41 +172,43 @@ sudo apt-get install libboost1.70 libboost1.70-dev
205172

206173
### MacOS
207174
```bash
208-
brew install boost gmp mpir mpfr
175+
brew install boost
209176

210177
cd chia-blockchain
211178

212-
git clone https://github.com/wbhart/flint2
213-
214179
sh install_timelord.sh
215180
```
216181

217-
## Generate keys
182+
## Step 3: Generate keys
218183
First, create some keys by running the following script:
219184
```bash
220185
python -m scripts.regenerate_keys
221186
```
222187

223-
## Run a full node
224-
To run a full node on port 8002, and connect to the testnet, run the following command.
225-
This wil also start an ssh server in port 8222 for the UI, which you can connect to
188+
189+
## Step 4a: Run a full node
190+
To run a full node on port 8444, and connect to the testnet, run the following command.
191+
This will also start an ssh server in port 8222 for the UI, which you can connect to
226192
to see the state of the node.
227193
```bash
228-
python -m src.server.start_full_node "127.0.0.1" 8444 -id 1 -u 8222 &
194+
python -m src.server.start_full_node "127.0.0.1" 8444 -id 1 -r 8555 &
229195
ssh -p 8222 localhost
230196
```
231197

232-
## Run a farmer + full node
198+
## Step 4b: Run a farmer + full node
199+
Instead of running only a full node (as in 4a), you can also run a farmer.
233200
Farmers are entities in the network who use their hard drive space to try to create
234201
blocks (like Bitcoin's miners), and earn block rewards. First, you must generate some hard drive plots, which
235-
can take a long time depending on the size of the plots (the k variable). Then, run the farmer + full node with
236-
the following script. A full node is also started, which you can ssh into to view the node UI (previous ssh command).
202+
can take a long time depending on the [size of the plots](https://github.com/Chia-Network/chia-blockchain/wiki/k-sizes)
203+
(the k variable). Then, run the farmer + full node with the following script. A full node is also started,
204+
which you can ssh into to view the node UI (previous ssh command).
237205
```bash
238206
python -m scripts.create_plots -k 20 -n 10
239207
sh ./scripts/run_farming.sh
240208
```
241209

242-
## Run a timelord + full node
210+
211+
## Step 4c: Run a timelord + full node
243212
Timelords execute sequential verifiable delay functions (proofs of time), that get added to
244213
blocks to make them valid. This requires fast CPUs and a lot of memory as well as completing
245214
both install steps above.
@@ -252,12 +221,12 @@ When running the servers on Mac OS, allow the application to accept incoming con
252221

253222
Ubuntu 19.xx, Amazon Linux 2, and CentOS 7.7 or newer are the easiest linux install environments currently.
254223

255-
UPnP is enabled by default, to open the port for incoming connections. If this causes issues,
224+
UPnP is enabled by default, to open port 8444 for incoming connections. If this causes issues,
256225
you can disable it in the configuration. Some routers may require port forwarding, or enabling
257226
UPnP in the router configuration.
258227

259-
Due to the nature of proof of space lookups by the harvester you should limit the number of plots
260-
on a physical drive to 50 or less. This limit should significantly increase before beta.
228+
Due to the nature of proof of space lookups by the harvester in the current alpha you should limit
229+
the number of plots on a physical drive to 50 or less. This limit should significantly increase before beta.
261230

262231
You can also run the simulation, which runs all servers and multiple full nodes, locally, at once.
263232
If you want to run the simulation, change the introducer ip in ./config/config.yaml so that the
@@ -271,23 +240,3 @@ ips to external peers.
271240
```bash
272241
sh ./scripts/run_all_simulation.sh
273242
```
274-
275-
### Run tests and linting
276-
The first time the tests are run, BlockTools will create and persist many plots. These are used for creating
277-
proofs of space during testing. The next time tests are run, this won't be necessary.
278-
Make sure to run mongo before running the tests.
279-
```bash
280-
mongod --dbpath ./db/ &
281-
black src tests && flake8 src && mypy src tests
282-
py.test tests -s -v
283-
```
284-
285-
286-
### Configure VS code
287-
1. Install Python extension
288-
2. Set the environment to ./.venv/bin/python
289-
3. Install mypy plugin
290-
4. Preferences > Settings > Python > Linting > flake8 enabled
291-
5. Preferences > Settings > Python > Linting > mypy enabled
292-
7. Preferences > Settings > Formatting > Python > Provider > black
293-
6. Preferences > Settings > mypy > Targets: set to ./src and ./tests

db/.gitignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)