Chia blockchain python implementation (full node, farmer, harvester, timelord, and wallet)
Go to file
2019-12-13 14:57:51 -08:00
.github/workflows Update pythonpackage.yml 2019-11-24 18:55:22 +09:00
config Remove useless connection close, and fix ssh ui bug 2019-12-06 03:27:40 +09:00
db Start work on local API 2019-11-26 15:23:17 +09:00
docs 1-consensus-doc spelling 2019-12-05 10:31:49 -08:00
lib Fix pos (#45) 2019-12-10 08:10:43 +09:00
plots Scripts (#14) 2019-11-08 16:51:01 -05:00
scripts Fix pos (#45) 2019-12-10 08:10:43 +09:00
src Fix self connection leak (#43) 2019-12-10 08:27:38 +09:00
tests Fix self connection leak (#43) 2019-12-10 08:27:38 +09:00
.flake8 New blockchain class implementation 2019-09-24 15:01:32 +09:00
.gitignore Fix self connection leak (#43) 2019-12-10 08:27:38 +09:00
definitions.py Scripts (#14) 2019-11-08 16:51:01 -05:00
install.sh Only configure flint2 once 2019-12-02 11:08:57 -08:00
LICENSE Initial commit 2019-07-16 17:32:40 +09:00
mypy.ini Changed to mypy from pyright, fix tests (full node still broken) 2019-10-22 16:44:01 +09:00
README.md Update README.md. 2019-12-13 13:22:12 -08:00
requirements.txt Upgrade blspy version to 0.1.13 2019-12-10 12:51:11 +09:00
setup.py Fix problem with zip download. 2019-12-13 14:57:51 -08:00

Note due to the use of setuptools-scm, you must clone the repo. Downloading the zip file provided by github will not work as the .git metadata used to calculate the version number is not present in the zip file.

chia-blockchain

Python 3.7 is used for this project. Make sure your default python version is >=3.7 by typing python3.

You will need to enable UPnP 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.

Install on Debian/Ubuntu

sudo apt-get update
sudo apt-get install build-essential cmake python3-dev python3-venv --no-install-recommends

# Update boost version to 1.71.0 or greater if needed, check version: dpkg -s libboost-dev | grep 'Version'
# Install from www.boost.org

sh install.sh

# Install MongoDB Community Edition
# Instructions - https://docs.mongodb.com/manual/administration/install-on-linux/

# Run mongo database
mongod --fork --dbpath ./db/ --logpath mongod.log

. .venv/bin/activate

Install on MacOS

Make sure brew is available before starting the setup.

brew tap mongodb/brew
brew upgrade python
brew install cmake boost gmp mpir mpfr mongodb-community@4.2

git clone https://github.com/Chia-Network/chia-blockchain.git && cd chia-blockchain

git clone https://github.com/wbhart/flint2

sh install.sh

# Run mongo database
mongod --fork --dbpath ./db/ --logpath mongod.log

. .venv/bin/activate

Generate keys

First, create some keys by running the following script:

python -m scripts.regenerate_keys

Run a full node

To run a full node on port 8002, and connect to the testnet, run the following command. This wil also start an ssh server in port 8222 for the UI, which you can connect to to see the state of the node.

python -m src.server.start_full_node "127.0.0.1" 8444 -id 1 -u 8222 &
ssh -p 8222 localhost

Run a farmer + full node

Farmers are entities in the network who use their hard drive space to try to create blocks (like Bitcoin's miners), and earn block rewards. First, you must generate some hard drive plots, which can take a long time depending on the size of the plots (the k variable). Then, run the farmer + full node with the following script. A full node is also started, which you can ssh into to view the node UI (previous ssh command).

python -m scripts.create_plots -k 20 -n 10
sh ./scripts/run_farming.sh

Run a timelord + full node

Timelords execute sequential verifiable delay functions (proofs of time), that get added to blocks to make them valid. This requires fast CPUs and a lot of memory.

sh ./scripts/run_timelord.sh

Tips

When running the servers on Mac OS, allow the application to accept incoming connections.

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

Due to the nature of proof of space lookups by the harvester you should limit the number of plots on a physical drive to 50 or less.

You can also run the simulation, which runs all servers and multiple full nodes, locally, at once. If you want to run the simulation, change the introducer ip in ./config/config.yaml so that the full node points to the local introducer (127.0.0.1:8445). Note the the simulation is local only. The introducer will only know the local ips of the full nodes, so it cannot broadcast the correct ips to external peers.

sh ./scripts/run_all_simulation.sh

Run tests and linting

The first time the tests are run, BlockTools will create and persist many plots. These are used for creating proofs of space during testing. The next time tests are run, this won't be necessary. Make sure to run mongo before running the tests.

mongod --dbpath ./db/ &
black src tests && flake8 src && mypy src tests
py.test tests -s -v

Configure VS code

  1. Install Python extension
  2. Set the environment to ./.venv/bin/python
  3. Install mypy plugin
  4. Preferences > Settings > Python > Linting > flake8 enabled
  5. Preferences > Settings > Python > Linting > mypy enabled
  6. Preferences > Settings > Formatting > Python > Provider > black
  7. Preferences > Settings > mypy > Targets: set to ./src and ./tests