2020-05-26 08:30:44 +00:00
# Simple Local Testnet
2023-05-17 05:51:54 +00:00
These scripts allow for running a small local testnet with multiple beacon nodes and validator clients and a geth execution client.
2021-03-30 05:17:58 +00:00
This setup can be useful for testing and development.
2020-05-26 08:30:44 +00:00
## Requirements
2023-05-17 05:51:54 +00:00
The scripts require `lcli` , `lighthouse` , `geth` , `bootnode` to be installed on `PATH` .
MacOS users need to install GNU `sed` and GNU `grep` , and add them both to `PATH` as well.
From the
2020-05-26 08:30:44 +00:00
root of this repository, run:
```bash
2021-03-30 05:17:58 +00:00
make
make install-lcli
2020-05-26 08:30:44 +00:00
```
## Starting the testnet
2021-10-01 06:32:37 +00:00
Modify `vars.env` as desired.
2023-05-17 05:51:54 +00:00
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 `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.
2021-10-01 06:32:37 +00:00
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`
2023-05-17 05:51:54 +00:00
2021-10-01 06:32:37 +00:00
```bash
2023-05-17 05:51:54 +00:00
./start_local_testnet.sh genesis.json
2021-10-01 06:32:37 +00:00
```
## Stopping the testnet
This is not necessary before `start_local_testnet.sh` as it invokes `stop_local_testnet.sh` automatically.
```bash
./stop_local_testnet.sh
```
## Manual creation of local testnet
These scripts are used by ./start_local_testnet.sh and may be used to manually
2023-05-17 05:51:54 +00:00
Assuming you are happy with the configuration in `vars.env` ,
create the testnet directory, genesis state with embedded validators and validator keys with:
2021-03-30 05:17:58 +00:00
```bash
2023-05-17 05:51:54 +00:00
./setup.sh
2021-03-30 05:17:58 +00:00
```
2023-05-17 05:51:54 +00:00
Note: The generated genesis validators are embedded into the genesis state as genesis validators and hence do not require manual deposits to activate.
2020-05-26 08:30:44 +00:00
2023-05-17 05:51:54 +00:00
Generate bootnode enr and start an EL and CL bootnode so that multiple nodes can find each other
2020-05-26 08:30:44 +00:00
```bash
2023-05-17 05:51:54 +00:00
./bootnode.sh
./el_bootnode.sh
2020-05-26 08:30:44 +00:00
```
2023-05-17 05:51:54 +00:00
Start a geth node:
2021-03-30 05:17:58 +00:00
```bash
2023-05-17 05:51:54 +00:00
./geth.sh < DATADIR > < NETWORK-PORT > < HTTP-PORT > < AUTH-HTTP-PORT > < GENESIS_FILE >
```
e.g.
```bash
./geth.sh $HOME/.lighthouse/local-testnet/geth_1 5000 6000 7000 genesis.json
2021-03-30 05:17:58 +00:00
```
Start a beacon node:
2020-05-26 08:30:44 +00:00
```bash
2023-05-17 05:51:54 +00:00
./beacon_node.sh < DATADIR > < NETWORK-PORT > < HTTP-PORT > < EXECUTION-ENDPOINT > < EXECUTION-JWT-PATH > < OPTIONAL-DEBUG-LEVEL >
2021-03-30 05:17:58 +00:00
```
e.g.
```bash
2023-05-17 05:51:54 +00:00
./beacon_node.sh $HOME/.lighthouse/local-testnet/node_1 9000 8000 http://localhost:6000 ~/.lighthouse/local-testnet/geth_1/geth/jwtsecret
2020-05-26 08:30:44 +00:00
```
In a new terminal, start the validator client which will attach to the first
beacon node:
```bash
2021-03-30 05:17:58 +00:00
./validator_client.sh < DATADIR > < BEACON-NODE-HTTP > < OPTIONAL-DEBUG-LEVEL >
2020-05-26 08:30:44 +00:00
```
2021-03-30 05:17:58 +00:00
e.g. to attach to the above created beacon node
2020-05-26 08:30:44 +00:00
```bash
2021-03-30 05:17:58 +00:00
./validator_client.sh $HOME/.lighthouse/local-testnet/node_1 http://localhost:8000
2020-05-26 08:30:44 +00:00
```
2021-03-30 05:17:58 +00:00
You can create additional beacon node and validator client instances with appropriate parameters.
2020-05-26 08:30:44 +00:00
2021-03-30 05:17:58 +00:00
## Additional Info
2020-05-26 08:30:44 +00:00
2021-03-30 05:17:58 +00:00
### 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.
2021-10-01 06:32:37 +00:00
The `BN_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 `BN_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
2021-03-30 05:17:58 +00:00
instances using the `--datadir` parameter.
2020-05-26 08:30:44 +00:00
### Starting fresh
2021-10-01 06:32:37 +00:00
Delete the current testnet and all related files using. Generally not necessary as `start_local_test.sh` does this each time it starts.
2020-05-26 08:30:44 +00:00
```bash
2020-08-11 02:16:33 +00:00
./clean.sh
2020-05-26 08:30:44 +00:00
```
### Updating the genesis time of the beacon state
If it's been a while since you ran `./setup` then the genesis time of the
genesis state will be far in the future, causing lots of skip slots.
Update the genesis time to now using:
```bash
2020-08-11 02:16:33 +00:00
./reset_genesis_time.sh
2020-05-26 08:30:44 +00:00
```
2021-10-01 06:32:37 +00:00
> Note: you probably want to just rerun `./start_local_testnet.sh` to start over
> but this is another option.
2023-09-09 06:10:15 +00:00
### Testing builder flow
1. Add builder URL to `BN_ARGS` in `./var.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:
```bash
./start_local_testnet.sh -p genesis.json
```
5. Block production using builder flow will start at epoch 4.