hailong
Implementation of the Ethereum 2.0 Beacon Chain.
Based on the (evolving) specification.
Build Instructions
Install Prerequisites
1) Java 11
Ubuntu: sudo apt install openjdk-11-jdk
MacOS: brew tap AdoptOpenJDK/openjdk && brew cask install adoptopenjdk11
Other systems: [https://adoptopenjdk.net/] is very helpful.
2) Gradle
Ubuntu:
- Download Gradle
wget https://services.gradle.org/distributions/gradle-5.0-bin.zip -P /tmp
sudo unzip -d /opt/gradle /tmp/gradle-*.zip
- Setup environment variables
Create gradle.sh in /etc/profile.d/
export GRADLE_HOME=/opt/gradle/gradle-5.0
export PATH=${GRADLE_HOME}/bin:${PATH}
Make gradle.sh executable and source the script
sudo chmod +x /etc/profile.d/gradle.sh
source /etc/profile.d/gradle.sh
OSX: brew install gradle
Build and Dist
To create a ready to run distribution:
bash <(curl -s https://raw.githubusercontent.com/DevelGao/hailong/master/scripts/clone-repo.sh)
cd hailong && ./gradlew distTar installDist
This will produce:
- a fully packaged distribution in
build/distributions
- an expanded distribution, ready to run in
build/install/hailong
Build and Test
To build, clone this repo and run with gradle
like so:
bash <(curl -s https://raw.githubusercontent.com/DevelGao/hailong/master/scripts/clone-repo.sh)
cd hailong && ./gradlew
Or clone it manually:
git clone [email protected]:jrhea/eth2.0-spec-tests-template.git /tmp/eth2.0-spec-tests-template
git clone --recursive --template=/tmp/eth2.0-spec-tests-template [email protected]:DevelGao/hailong.git
cd hailong && ./gradlew
After a successful build, distribution packages will be available in build/distributions
.
Other Useful Gradle Targets
Target | Description |
---|---|
distTar | Builds a full distribution in build/distributions (as .tar.gz) |
distZip | Builds a full distribution in build/distributions (as .zip) |
installDist | Builds an expanded distribution in build/install/hailong |
distDocker | Builds the develgao/hailong docker image |
Run Multiple Hailong nodes
Prereqs:
- tmux
After building with ./gradlew distTar
, the simplest way to run is by using this command:
cd scripts && sh run.sh -n=[NUMBER OF NODES]
Help is available for this script as well:
sh run.sh -h
Runs a simulation of hailong with NODES nodes, where NODES > 0 and NODES < 256
Usage: sh run.sh [--numNodes, -n=NODES] [--config=/path/to/your-config.toml] [--logging, -l=OFF|FATAL|WARN|INFO|DEBUG|TRACE|ALL]
[--help, -h]
- If config files are specifed for specific nodes, those input files will be used to
configure their respective nodes.
- If no logging option is specified, then INFO is the default
Run in Interop Mode
An interop script is provided to create a network with Hailong and a number of other clients.
Prereqs:
- tmux
- zcli
- You will need to have at least one other client built on your machine for this to work
The simplest way to run in interop mode is by using this command:
cd scripts
sh interop.sh [validator_count] [owned_validator_start_index] [owned_validator_count] [start_delay]
Help is available for this script as well:
sh interop.sh
Runs a multiclient testnet
Usage: sh interop.sh [validator_count] [owned_validator_start_index] [owned_validator_count] [start_delay]
Example: Run multiple clients in interop mode using static peering. 16 validators and all are assigned to Hailong
sh interop.sh 16 0 16 10
Manual configuration
To configure it manually, set these options in the config.toml:
[interop]
genesisTime = 5778872 #seconds since 1970-01-01 00:00:00 UTC
ownedValidatorStartIndex = 0
ownedValidatorCount = 8
startState = "/tmp/genesis.ssz"
privateKey = 0x00 #libp2p private key associated with this node's peerID
[deposit]
numValidators = 16
Deposit Simulation
Click here for setup instructions
Code Style
We use Google's Java coding conventions for the project. To reformat code, run:
./gradlew spotlessApply
Code style will be checked automatically during a build.
Testing
All the unit tests are run as part of the build, but can be explicitly triggered with:
./gradlew test
Run Options
To view the run menu:
./gradlew run --args='-h'
hailong [OPTIONS] [COMMAND]
Description:
Run the Hailong beacon chain client and validator
Options:
-c, --config=<FILENAME> Path/filename of the config file
-h, --help Show this help message and exit.
-l, --logging=<LOG VERBOSITY LEVEL>
Logging verbosity levels: OFF, FATAL, WARN, INFO,
DEBUG, TRACE, ALL (default: INFO).
-V, --version Print version information and exit.
Commands:
transition Manually run state transitions
peer Commands for LibP2P PeerID
Hailong is licensed under the Apache License 2.0
You can run the executable from the CLI with this command:
./gradlew run
Refer to config/config.toml
for a set of default configuration settings.
To run with logging level set to DEBUG
./gradlew run --args='-l=DEBUG'
To profile and/or generate flow diagrams for Hailong:
Setup:
source hailong.env
Run:
Terminal 1:
flow
Terminal 2:
./gradlew run -PgenerateFlow
Special thanks
YourKit for providing us with a free profiler open source license.
YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications. YourKit is the creator of YourKit Java Profiler, YourKit .NET Profiler, and YourKit YouMonitor.