Update local testnet doc and parameters (#4749)

* update

* revise link

* update parameters

* update doc

* Update doc

* add quic port

* remove debug log

* Fix el_bootnode not being killed

* Fix time

* Fix doc in manual creation of testnet

* Update file

* update api doc

* Revert "update api doc"

This reverts commit ed695743deca4818ad074e5285e04764965b1be5.

* add git clone

* Fix path

* Fix path

* Update scripts/local_testnet/setup_time.sh

Co-authored-by: Jimmy Chen <jchen.tc@gmail.com>

* Update scripts/local_testnet/README.md

Co-authored-by: Jimmy Chen <jchen.tc@gmail.com>

* Fix SLOT_PER_EPOCH that changes with mainnet or minimal

* Embedded setup_time.sh in start_local_testnet.sh

* fix slot per epoch constant

* Add comment

* Add CANCUN_TIME

* Fix CANCUN_TIME constant 32 slots

* Correct typo

* chmod +x ./setup_time.sh

---------

Co-authored-by: Jimmy Chen <jchen.tc@gmail.com>
This commit is contained in:
chonghe 2023-11-09 12:06:10 +08:00 committed by GitHub
parent 7fd9389a8c
commit 1b8c0ed987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 111 additions and 34 deletions

View File

@ -5,58 +5,105 @@ This setup can be useful for testing and development.
## Requirements
The scripts require `lcli`, `lighthouse`, `geth`, `bootnode` to be installed on `PATH`.
The scripts require `lcli`, `lighthouse`, `geth`, `bootnode` to be installed on `PATH` (run `echo $PATH` to view all `PATH` directories).
MacOS users need to install GNU `sed` and GNU `grep`, and add them both to `PATH` as well.
From the
root of this repository, run:
The first step is to install Rust and dependencies. Refer to the [Lighthouse Book](https://lighthouse-book.sigmaprime.io/installation-source.html#dependencies) for installation. We will also need [jq](https://jqlang.github.io/jq/), which can be installed with `sudo apt install jq`.
Then, we clone the Lighthouse repository:
```bash
cd ~
git clone https://github.com/sigp/lighthouse.git
cd lighthouse
```
We are now ready to build Lighthouse. Run the command:
```bash
make
make install-lcli
```
This will build `lighthouse` and `lcli`. For `geth` and `bootnode`, go to [geth website](https://geth.ethereum.org/downloads) and download the `Geth & Tools`. For example, to download and extract `Geth & Tools 1.13.1`:
```bash
cd ~
curl -LO https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-1.13.1-3f40e65c.tar.gz
tar xvf geth-alltools-linux-amd64-1.13.1-3f40e65c.tar.gz
```
After extraction, copy `geth` and `bootnode` to the `PATH`. A typical directory is `/usr/local/bin`.
```bash
cd geth-alltools-linux-amd64-1.13.1-3f40e65c
sudo cp geth bootnode /usr/local/bin
```
After that We can remove the downloaded files:
```bash
cd ~
rm -r geth-alltools-linux-amd64-1.13.1-3f40e65c geth-alltools-linux-amd64-1.13.1-3f40e65c.tar.gz
```
We are now ready to start a local testnet.
## Starting the testnet
Modify `vars.env` as desired.
To start a testnet using the predetermined settings:
```bash
cd ~
cd ./lighthouse/scripts/local_testnet
./start_local_testnet.sh genesis.json
```
This will execute the script and if the testnet setup is successful, you will see "Started!" at the end.
The testnet starts with a post-merge genesis state.
Start a consensus layer and execution layer boot node along with `BN_COUNT`
number of beacon nodes each connected to a geth execution client and `VC_COUNT` validator clients.
The testnet starts a consensus layer and execution layer boot node along with `BN_COUNT`
(the number of beacon nodes) each connected to a geth execution client and `VC_COUNT` (the number of validator clients). By default, `BN_COUNT=4`, `VC_COUNT=4`.
The `start_local_testnet.sh` script takes four options `-v VC_COUNT`, `-d DEBUG_LEVEL`, `-p` to enable builder proposals and `-h` for help. It also takes a mandatory `GENESIS_FILE` for initialising geth's state.
A sample `genesis.json` is provided in this directory.
The `ETH1_BLOCK_HASH` environment variable is set to the block_hash of the genesis execution layer block which depends on the contents of `genesis.json`. Users of these scripts need to ensure that the `ETH1_BLOCK_HASH` variable is updated if genesis file is modified.
The options may be in any order or absent in which case they take the default value specified.
- VC_COUNT: the number of validator clients to create, default: `BN_COUNT`
- DEBUG_LEVEL: one of { error, warn, info, debug, trace }, default: `info`
The `ETH1_BLOCK_HASH` environment variable is set to the block_hash of the genesis execution layer block which depends on the contents of `genesis.json`. Users of these scripts need to ensure that the `ETH1_BLOCK_HASH` variable is updated if genesis file is modified.
To view the beacon, validator client and geth logs:
```bash
./start_local_testnet.sh genesis.json
tail -f ~/.lighthouse/local-testnet/testnet/beacon_node_1.log
taif -f ~/.lighthouse/local-testnet/testnet/validator_node_1.log
tail -f ~/.lighthouse/local-testnet/testnet/geth_1.log
```
where `beacon_node_1` can be changed to `beacon_node_2`, `beacon_node_3` or `beacon_node_4` to view logs for different beacon nodes. The same applies to validator clients and geth nodes.
## Stopping the testnet
This is not necessary before `start_local_testnet.sh` as it invokes `stop_local_testnet.sh` automatically.
To stop the testnet, navigate to the directory `cd ~/lighthouse/scripts/local_testnet`, then run the command:
```bash
./stop_local_testnet.sh
```
Once a testnet is stopped, it cannot be continued from where it left off. When the start local testnet command is run, it will start a new local testnet.
## Manual creation of local testnet
These scripts are used by ./start_local_testnet.sh and may be used to manually
In [Starting the testnet](./README.md#starting-the-testnet), the testnet is started automatically with predetermined parameters (database directory, ports used etc). This section describes some modifications of the local testnet settings, e.g., changing the database directory, or changing the ports used.
Assuming you are happy with the configuration in `vars.env`,
create the testnet directory, genesis state with embedded validators and validator keys with:
The testnet also contains parameters that are specified in `vars.env`, such as the slot time `SECONDS_PER_SLOT=3` (instead of 12 seconds on mainnet). You may change these parameters to suit your testing purposes. After that, in the `local_testnet` directory, run the following command to create genesis state with embedded validators and validator keys, and also to update the time in `genesis.json`:
```bash
./setup.sh
./setup_time.sh genesis.json
```
Note: The generated genesis validators are embedded into the genesis state as genesis validators and hence do not require manual deposits to activate.
@ -73,17 +120,17 @@ Start a geth node:
```
e.g.
```bash
./geth.sh $HOME/.lighthouse/local-testnet/geth_1 5000 6000 7000 genesis.json
./geth.sh $HOME/.lighthouse/local-testnet/geth_1 7001 6001 5001 genesis.json
```
Start a beacon node:
```bash
./beacon_node.sh <DATADIR> <NETWORK-PORT> <HTTP-PORT> <EXECUTION-ENDPOINT> <EXECUTION-JWT-PATH> <OPTIONAL-DEBUG-LEVEL>
./beacon_node.sh <DATADIR> <NETWORK-PORT> <QUIC-PORT> <HTTP-PORT> <EXECUTION-ENDPOINT> <EXECUTION-JWT-PATH> <OPTIONAL-DEBUG-LEVEL>
```
e.g.
```bash
./beacon_node.sh $HOME/.lighthouse/local-testnet/node_1 9000 8000 http://localhost:6000 ~/.lighthouse/local-testnet/geth_1/geth/jwtsecret
./beacon_node.sh $HOME/.lighthouse/local-testnet/node_1 9001 9101 8001 http://localhost:5001 ~/.lighthouse/local-testnet/geth_1/geth/jwtsecret
```
In a new terminal, start the validator client which will attach to the first
@ -94,10 +141,16 @@ beacon node:
```
e.g. to attach to the above created beacon node
```bash
./validator_client.sh $HOME/.lighthouse/local-testnet/node_1 http://localhost:8000
./validator_client.sh $HOME/.lighthouse/local-testnet/node_1 http://localhost:8001
```
You can create additional beacon node and validator client instances with appropriate parameters.
You can create additional geth, beacon node and validator client instances by changing the ports, e.g., for a second geth, beacon node and validator client:
```bash
./geth.sh $HOME/.lighthouse/local-testnet/geth_2 7002 6002 5002 genesis.json
./beacon_node.sh $HOME/.lighthouse/local-testnet/node_2 9002 9102 8002 http://localhost:5002 ~/.lighthouse/local-testnet/geth_2/geth/jwtsecret
./validator_client.sh $HOME/.lighthouse/local-testnet/node_2 http://localhost:8002
```
## Additional Info
@ -109,7 +162,7 @@ instances using the `--datadir` parameter.
### Starting fresh
Delete the current testnet and all related files using. Generally not necessary as `start_local_test.sh` does this each time it starts.
You can delete the current testnet and all related files using the following command. Alternatively, if you wish to start another testnet, doing the steps [Starting the testnet](./README.md#starting-the-testnet) will automatically delete the files and start a fresh local testnet.
```bash
./clean.sh
@ -131,12 +184,12 @@ Update the genesis time to now using:
### Testing builder flow
1. Add builder URL to `BN_ARGS` in `./var.env`, e.g. `--builder http://localhost:8650`. Some mock builder server options:
1. Add builder URL to `BN_ARGS` in `./vars.env`, e.g. `--builder http://localhost:8650`. Some mock builder server options:
- [`mock-relay`](https://github.com/realbigsean/mock-relay)
- [`dummy-builder`](https://github.com/michaelsproul/dummy_builder)
2. (Optional) Add `--always-prefer-builder-payload` to `BN_ARGS`.
3. The above mock builders do not support non-mainnet presets as of now, and will require setting `SECONDS_PER_SLOT` and `SECONDS_PER_ETH1_BLOCK` to `12` in `./vars.env`.
4. Start the testnet with the following command (the `-p` flag enables the validator client `--builder-proposals` flag:
4. Start the testnet with the following command (the `-p` flag enables the validator client `--builder-proposals` flag):
```bash
./start_local_testnet.sh -p genesis.json
```

View File

@ -1,3 +1,3 @@
priv_key="02fd74636e96a8ffac8e7b01b0de8dea94d6bcf4989513b38cf59eb32163ff91"
source ./vars.env
$EL_BOOTNODE_BINARY --nodekeyhex $priv_key
exec $EL_BOOTNODE_BINARY --nodekeyhex $priv_key

View File

@ -32,7 +32,7 @@ lcli \
--ttd $TTD \
--eth1-block-hash $ETH1_BLOCK_HASH \
--eth1-id $CHAIN_ID \
--eth1-follow-distance 1 \
--eth1-follow-distance 128 \
--seconds-per-slot $SECONDS_PER_SLOT \
--seconds-per-eth1-block $SECONDS_PER_ETH1_BLOCK \
--proposer-score-boost "$PROPOSER_SCORE_BOOST" \

View File

@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -Eeuo pipefail
source ./vars.env
# Function to output SLOT_PER_EPOCH for mainnet or minimal
get_spec_preset_value() {
case "$SPEC_PRESET" in
mainnet) echo 32 ;;
minimal) echo 8 ;;
gnosis) echo 16 ;;
*) echo "Unsupported preset: $SPEC_PRESET" >&2; exit 1 ;;
esac
}
SLOT_PER_EPOCH=$(get_spec_preset_value $SPEC_PRESET)
echo "slot_per_epoch=$SLOT_PER_EPOCH"
genesis_file=$1
# Update future hardforks time in the EL genesis file based on the CL genesis time
GENESIS_TIME=$(lcli pretty-ssz --spec $SPEC_PRESET --testnet-dir $TESTNET_DIR BeaconState $TESTNET_DIR/genesis.ssz | jq | grep -Po 'genesis_time": "\K.*\d')
echo $GENESIS_TIME
CAPELLA_TIME=$((GENESIS_TIME + (CAPELLA_FORK_EPOCH * $SLOT_PER_EPOCH * SECONDS_PER_SLOT)))
echo $CAPELLA_TIME
sed -i 's/"shanghaiTime".*$/"shanghaiTime": '"$CAPELLA_TIME"',/g' $genesis_file
CANCUN_TIME=$((GENESIS_TIME + (DENEB_FORK_EPOCH * $SLOT_PER_EPOCH * SECONDS_PER_SLOT)))
echo $CANCUN_TIME
sed -i 's/"cancunTime".*$/"cancunTime": '"$CANCUN_TIME"',/g' $genesis_file
cat $genesis_file

View File

@ -102,16 +102,8 @@ execute_command_add_PID() {
echo "executing: ./setup.sh >> $LOG_DIR/setup.log"
./setup.sh >> $LOG_DIR/setup.log 2>&1
# Update future hardforks time in the EL genesis file based on the CL genesis time
GENESIS_TIME=$(lcli pretty-ssz --spec $SPEC_PRESET --testnet-dir $TESTNET_DIR BeaconState $TESTNET_DIR/genesis.ssz | jq | grep -Po 'genesis_time": "\K.*\d')
echo $GENESIS_TIME
CAPELLA_TIME=$((GENESIS_TIME + (CAPELLA_FORK_EPOCH * 32 * SECONDS_PER_SLOT)))
echo $CAPELLA_TIME
sed -i 's/"shanghaiTime".*$/"shanghaiTime": '"$CAPELLA_TIME"',/g' $genesis_file
CANCUN_TIME=$((GENESIS_TIME + (DENEB_FORK_EPOCH * 32 * SECONDS_PER_SLOT)))
echo $CANCUN_TIME
sed -i 's/"cancunTime".*$/"cancunTime": '"$CANCUN_TIME"',/g' $genesis_file
cat $genesis_file
# Call setup_time.sh to update future hardforks time in the EL genesis file based on the CL genesis time
./setup_time.sh genesis.json
# Delay to let boot_enr.yaml to be created
execute_command_add_PID bootnode.log ./bootnode.sh

View File

@ -56,7 +56,7 @@ SPEC_PRESET=mainnet
SECONDS_PER_SLOT=3
# Seconds per Eth1 block
SECONDS_PER_ETH1_BLOCK=1
SECONDS_PER_ETH1_BLOCK=3
# Proposer score boost percentage
PROPOSER_SCORE_BOOST=40