mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
Fix local testnet scripts (#2229)
## Issue Addressed Resolves #2094 ## Proposed Changes Fixes scripts for creating local testnets. Adds an option in `lighthouse boot_node` to run with a previously generated enr.
This commit is contained in:
@@ -1,58 +1,67 @@
|
||||
# Simple Local Testnet
|
||||
|
||||
These scripts allow for running a small local testnet with two beacon nodes and
|
||||
one validator client. This setup can be useful for testing and development.
|
||||
These scripts allow for running a small local testnet with multiple beacon nodes and validator clients.
|
||||
This setup can be useful for testing and development.
|
||||
|
||||
## Requirements
|
||||
|
||||
The scripts require `lci` and `lighthouse` to be installed on `PATH`. From the
|
||||
The scripts require `lcli` and `lighthouse` to be installed on `PATH`. From the
|
||||
root of this repository, run:
|
||||
|
||||
```bash
|
||||
cargo install --path lighthouse --force --locked
|
||||
cargo install --path lcli --force --locked
|
||||
make
|
||||
make install-lcli
|
||||
```
|
||||
|
||||
## Starting the testnet
|
||||
|
||||
Assuming you are happy with the configuration in `var.env`, create the testnet
|
||||
directory, genesis state and validator keys with:
|
||||
Start a local eth1 ganache server
|
||||
```bash
|
||||
./ganache_test_node.sh
|
||||
```
|
||||
|
||||
Assuming you are happy with the configuration in `var.env`, deploy the deposit contract, make deposits,
|
||||
create the testnet directory, genesis state and validator keys with:
|
||||
|
||||
```bash
|
||||
./setup.sh
|
||||
```
|
||||
|
||||
Start the first beacon node:
|
||||
Generate bootnode enr and start a discv5 bootnode so that multiple beacon nodes can find each other
|
||||
```bash
|
||||
./bootnode.sh
|
||||
```
|
||||
|
||||
Start a beacon node:
|
||||
|
||||
```bash
|
||||
./beacon_node.sh
|
||||
./beacon_node.sh <DATADIR> <NETWORK-PORT> <HTTP-PORT> <OPTIONAL-DEBUG-LEVEL>
|
||||
```
|
||||
e.g.
|
||||
```bash
|
||||
./beacon_node.sh $HOME/.lighthouse/local-testnet/node_1 9000 8000
|
||||
```
|
||||
|
||||
In a new terminal, start the validator client which will attach to the first
|
||||
beacon node:
|
||||
|
||||
```bash
|
||||
./validator_client.sh
|
||||
./validator_client.sh <DATADIR> <BEACON-NODE-HTTP> <OPTIONAL-DEBUG-LEVEL>
|
||||
```
|
||||
|
||||
In a new terminal, start the second beacon node which will peer with the first:
|
||||
|
||||
e.g. to attach to the above created beacon node
|
||||
```bash
|
||||
./second_beacon_node.sh
|
||||
./validator_client.sh $HOME/.lighthouse/local-testnet/node_1 http://localhost:8000
|
||||
```
|
||||
|
||||
You can create additional beacon node and validator client instances with appropriate parameters.
|
||||
|
||||
## Additional Info
|
||||
|
||||
### Debug level
|
||||
|
||||
The beacon nodes and validator client have their `--debug-level` set to `info`.
|
||||
Specify a different debug level like this:
|
||||
|
||||
```bash
|
||||
./validator_client.sh debug
|
||||
./beacon_node.sh trace
|
||||
./second_beacon_node.sh warn
|
||||
```
|
||||
### Adjusting number and distribution of validators
|
||||
The `VALIDATOR_COUNT` parameter is used to specify the number of insecure validator keystores to generate and make deposits for.
|
||||
The `NODE_COUNT` parameter is used to adjust the division of these generated keys among separate validator client instances.
|
||||
For e.g. for `VALIDATOR_COUNT=80` and `NODE_COUNT=4`, the validator keys are distributed over 4 datadirs with 20 keystores per datadir. The datadirs are located in `$DATADIR/node_{i}` which can be passed to separate validator client
|
||||
instances using the `--datadir` parameter.
|
||||
|
||||
### Starting fresh
|
||||
|
||||
@@ -62,7 +71,6 @@ Delete the current testnet and all related files using:
|
||||
./clean.sh
|
||||
```
|
||||
|
||||
|
||||
### Updating the genesis time of the beacon state
|
||||
|
||||
If it's been a while since you ran `./setup` then the genesis time of the
|
||||
|
||||
@@ -2,20 +2,22 @@
|
||||
|
||||
#
|
||||
# Starts a beacon node based upon a genesis state created by
|
||||
# `./local_testnet_genesis_state`.
|
||||
# `./setup.sh`.
|
||||
#
|
||||
# Usage: ./beacon_node.sh <DATADIR> <NETWORK-PORT> <HTTP-PORT> <OPTIONAL-DEBUG-LEVEL>
|
||||
|
||||
source ./vars.env
|
||||
|
||||
DEBUG_LEVEL=${1:-info}
|
||||
DEBUG_LEVEL=${4:-info}
|
||||
|
||||
exec lighthouse \
|
||||
--debug-level $DEBUG_LEVEL \
|
||||
bn \
|
||||
--datadir $BEACON_DIR \
|
||||
--datadir $1 \
|
||||
--testnet-dir $TESTNET_DIR \
|
||||
--dummy-eth1 \
|
||||
--http \
|
||||
--staking \
|
||||
--enr-address 127.0.0.1 \
|
||||
--enr-udp-port 9000 \
|
||||
--enr-tcp-port 9000 \
|
||||
--enr-udp-port $2 \
|
||||
--enr-tcp-port $2 \
|
||||
--port $2 \
|
||||
--http-port $3
|
||||
|
||||
33
scripts/local_testnet/bootnode.sh
Executable file
33
scripts/local_testnet/bootnode.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Generates a bootnode enr and saves it in $TESTNET/boot_enr.yaml
|
||||
# Starts a bootnode from the generated enr.
|
||||
#
|
||||
|
||||
source ./vars.env
|
||||
|
||||
echo "Generating bootnode enr"
|
||||
|
||||
lcli \
|
||||
generate-bootnode-enr \
|
||||
--ip 127.0.0.1 \
|
||||
--udp-port $BOOTNODE_PORT \
|
||||
--tcp-port $BOOTNODE_PORT \
|
||||
--genesis-fork-version $GENESIS_FORK_VERSION \
|
||||
--output-dir $DATADIR/bootnode
|
||||
|
||||
bootnode_enr=`cat $DATADIR/bootnode/enr.dat`
|
||||
echo "- $bootnode_enr" > $TESTNET_DIR/boot_enr.yaml
|
||||
|
||||
echo "Generated bootnode enr and written to $TESTNET_DIR/boot_enr.yaml"
|
||||
|
||||
DEBUG_LEVEL=${1:-info}
|
||||
|
||||
echo "Starting bootnode"
|
||||
|
||||
exec lighthouse boot_node \
|
||||
--testnet-dir $TESTNET_DIR \
|
||||
--port $BOOTNODE_PORT \
|
||||
--listen-address 127.0.0.1 \
|
||||
--network-dir $DATADIR/bootnode \
|
||||
@@ -1,8 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source ./vars.env
|
||||
|
||||
ganache-cli \
|
||||
--defaultBalanceEther 1000000000 \
|
||||
--gasLimit 1000000000 \
|
||||
--accounts 10 \
|
||||
--mnemonic "vast thought differ pull jewel broom cook wrist tribe word before omit" \
|
||||
--mnemonic "$ETH1_NETWORK_MNEMONIC" \
|
||||
--port 8545 \
|
||||
--blockTime 3 \
|
||||
--networkId 4242 \
|
||||
--chainId 4242
|
||||
@@ -1,21 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Starts a beacon node based upon a genesis state created by
|
||||
# `./local_testnet_genesis_state`.
|
||||
#
|
||||
|
||||
source ./vars.env
|
||||
|
||||
DEBUG_LEVEL=${1:-info}
|
||||
|
||||
exec lighthouse \
|
||||
--debug-level $DEBUG_LEVEL \
|
||||
bn \
|
||||
--datadir $BEACON_DIR-2 \
|
||||
--testnet-dir $TESTNET_DIR \
|
||||
--dummy-eth1 \
|
||||
--http \
|
||||
--port 9902 \
|
||||
--http-port 6052 \
|
||||
--boot-nodes $(cat $BEACON_DIR/beacon/network/enr.dat)
|
||||
@@ -1,18 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Deploys the deposit contract and makes deposits for $VALIDATOR_COUNT insecure deterministic validators.
|
||||
# Produces a testnet specification and a genesis state where the genesis time
|
||||
# is now.
|
||||
# is now + $GENESIS_DELAY.
|
||||
#
|
||||
# Generates datadirs for multiple validator keys according to the
|
||||
# $VALIDATOR_COUNT and $NODE_COUNT variables.
|
||||
#
|
||||
|
||||
source ./vars.env
|
||||
|
||||
lcli \
|
||||
deploy-deposit-contract \
|
||||
--eth1-http http://localhost:8545 \
|
||||
--confirmations 1 \
|
||||
--validator-count $VALIDATOR_COUNT
|
||||
|
||||
NOW=`date +%s`
|
||||
GENESIS_TIME=`expr $NOW + $GENESIS_DELAY`
|
||||
|
||||
|
||||
lcli \
|
||||
--spec mainnet \
|
||||
new-testnet \
|
||||
--deposit-contract-address 1234567890123456789012345678901234567890 \
|
||||
--deposit-contract-address $DEPOSIT_CONTRACT_ADDRESS \
|
||||
--testnet-dir $TESTNET_DIR \
|
||||
--min-genesis-active-validator-count $VALIDATOR_COUNT \
|
||||
--min-genesis-active-validator-count $GENESIS_VALIDATOR_COUNT \
|
||||
--min-genesis-time $GENESIS_TIME \
|
||||
--genesis-delay $GENESIS_DELAY \
|
||||
--genesis-fork-version $GENESIS_FORK_VERSION \
|
||||
--eth1-id $BOOTNODE_PORT \
|
||||
--eth1-follow-distance 1 \
|
||||
--seconds-per-eth1-block 1 \
|
||||
--force
|
||||
|
||||
echo Specification generated at $TESTNET_DIR.
|
||||
@@ -21,16 +41,17 @@ echo "Generating $VALIDATOR_COUNT validators concurrently... (this may take a wh
|
||||
lcli \
|
||||
insecure-validators \
|
||||
--count $VALIDATOR_COUNT \
|
||||
--validators-dir $VALIDATORS_DIR \
|
||||
--secrets-dir $SECRETS_DIR
|
||||
--base-dir $DATADIR \
|
||||
--node-count $NODE_COUNT
|
||||
|
||||
echo Validators generated at $VALIDATORS_DIR with keystore passwords at $SECRETS_DIR.
|
||||
echo Validators generated with keystore passwords at $DATADIR.
|
||||
echo "Building genesis state... (this might take a while)"
|
||||
|
||||
lcli \
|
||||
--spec mainnet \
|
||||
interop-genesis \
|
||||
--genesis-time $GENESIS_TIME \
|
||||
--testnet-dir $TESTNET_DIR \
|
||||
$VALIDATOR_COUNT
|
||||
$GENESIS_VALIDATOR_COUNT
|
||||
|
||||
echo Created genesis state in $TESTNET_DIR
|
||||
echo Created genesis state in $TESTNET_DIR
|
||||
@@ -2,17 +2,18 @@
|
||||
|
||||
#
|
||||
# Starts a validator client based upon a genesis state created by
|
||||
# `./local_testnet_genesis_state`.
|
||||
# `./setup.sh`.
|
||||
#
|
||||
# Usage: ./validator_client.sh <DATADIR> <BEACON-NODE-HTTP> <OPTIONAL-DEBUG-LEVEL>
|
||||
|
||||
source ./vars.env
|
||||
|
||||
DEBUG_LEVEL=${1:-info}
|
||||
DEBUG_LEVEL=${3:-info}
|
||||
|
||||
exec lighthouse \
|
||||
--debug-level $DEBUG_LEVEL \
|
||||
vc \
|
||||
--datadir $DATADIR \
|
||||
--datadir $1 \
|
||||
--testnet-dir $TESTNET_DIR \
|
||||
--init-slashing-protection \
|
||||
--allow-unsynced
|
||||
--beacon-nodes $2
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
# Base directories for the validator keys and secrets
|
||||
DATADIR=~/.lighthouse/local-testnet
|
||||
TESTNET_DIR=$DATADIR/testnet
|
||||
BEACON_DIR=$DATADIR/beacon
|
||||
VALIDATORS_DIR=$DATADIR/validators
|
||||
SECRETS_DIR=$DATADIR/secrets
|
||||
|
||||
VALIDATOR_COUNT=1024
|
||||
# Directory for the eth2 config
|
||||
TESTNET_DIR=$DATADIR/testnet
|
||||
|
||||
# Mnemonic for the ganache test network
|
||||
ETH1_NETWORK_MNEMONIC="vast thought differ pull jewel broom cook wrist tribe word before omit"
|
||||
|
||||
# Hardcoded deposit contract based on ETH1_NETWORK_MNEMONIC
|
||||
DEPOSIT_CONTRACT_ADDRESS=8c594691c0e592ffa21f153a16ae41db5befcaaa
|
||||
|
||||
GENESIS_FORK_VERSION=0x42424242
|
||||
|
||||
VALIDATOR_COUNT=80
|
||||
GENESIS_VALIDATOR_COUNT=80
|
||||
|
||||
# Number of validator client instances that you intend to run
|
||||
NODE_COUNT=4
|
||||
|
||||
GENESIS_DELAY=180
|
||||
BOOTNODE_PORT=4242
|
||||
|
||||
Reference in New Issue
Block a user