Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local-network improvements #32

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class BesuContainer(network: NetworkImpl, number: Int, ip: String)(implicit http
protected override val container = new GenericContainer(DockerImages.BesuExecutionClient)
.withNetwork(network)
.withExposedPorts(RpcPort, EnginePort)
.withEnv("NODE_NUMBER", s"$number")
.withEnv("LOG4J_CONFIGURATION_FILE", "/config/log4j2.xml")
.withEnv("ROOT_LOG_FILE_LEVEL", "TRACE")
.withFileSystemBind(s"$ConfigsDir/ec-common/genesis.json", "/genesis.json", BindMode.READ_ONLY)
.withFileSystemBind(s"$ConfigsDir/ec-common", "/etc/secrets", BindMode.READ_ONLY)
.withFileSystemBind(s"$ConfigsDir/besu", "/config", BindMode.READ_ONLY)
.withFileSystemBind(s"$ConfigsDir/besu/run-besu.sh", "/tmp/run.sh", BindMode.READ_ONLY)
.withFileSystemBind(s"$ConfigsDir/ec-common/p2p-key-$number.hex", "/etc/secrets/p2p-key", BindMode.READ_ONLY)
.withFileSystemBind(s"$logFile", "/opt/besu/logs/besu.log", BindMode.READ_WRITE)
.withCreateContainerCmdModifier { cmd =>
cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ class GethContainer(network: NetworkImpl, number: Int, ip: String)(implicit http
protected override val container = new GenericContainer(DockerImages.GethExecutionClient)
.withNetwork(network)
.withExposedPorts(RpcPort, EnginePort)
.withFileSystemBind(s"$ConfigsDir/ec-common/genesis.json", "/tmp/genesis.json", BindMode.READ_ONLY)
.withEnv("NODE_NUMBER", s"$number")
.withFileSystemBind(s"$ConfigsDir/ec-common", "/etc/secrets", BindMode.READ_ONLY)
.withFileSystemBind(s"$ConfigsDir/geth/run-geth.sh", "/tmp/run.sh", BindMode.READ_ONLY)
.withFileSystemBind(s"$ConfigsDir/ec-common/p2p-key-$number.hex", "/etc/secrets/p2p-key", BindMode.READ_ONLY)
.withFileSystemBind(s"$ConfigsDir/ec-common/jwt-secret-$number.hex", "/etc/secrets/jwtsecret", BindMode.READ_ONLY)
.withFileSystemBind(s"$logFile", "/root/logs/log", BindMode.READ_WRITE)
.withCreateContainerCmdModifier { cmd =>
cmd
Expand Down
31 changes: 22 additions & 9 deletions local-network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@

You have to build consensus client. Run [./consensus_client-image-build.sh](./consensus_client-image-build.sh)

## How to add additional nodes

1. Uncomment in [./docker-compose.yml](./docker-compose.yml)
2. Optionally: Enable EL mining for these nodes in [./deploy/local/network.py](./deploy/local/network.py) (see the CL
section).

## How to start

- Run `./all-images-build.sh` after pulling the repository, so docker compose will pull new external images and rebuild
the `deploy` image.
- Available docker compose contexts:
- BlockScout services: `bs`
- Tests in the end `tests`
- Run [./restart.sh](./restart.sh)
- With selected contexts, for example, `COMPOSE_PROFILES=bs,tests ./restart.sh`
- Or without any context: `./restart.sh`
- BlockScout services: `bs`
- Tests in the end `tests`
- Run [./restart.sh](./restart.sh)
- With selected contexts, for example, `COMPOSE_PROFILES=bs,tests ./restart.sh`
- Or without any context: `./restart.sh`

To retry failed:

To retry failed:
- deploy - run `./deploy-run.sh`.
- tests - run `./tests-run.sh`.

Expand All @@ -39,12 +46,18 @@ See [./deploy](./deploy/).
* Node HTTP API Key: `testapi`
* CL accounts: see [genesis-template.conf](configs/wavesnode/genesis-template.conf)
* EL mining reward accounts:
* Reward account for **Miner 1** (`wavesnode-1`, `besu-1`):
* Reward account for **Miner 1** (`wavesnode-1`, `ec-1`):
* Address: `0x7dBcf9c6C3583b76669100f9BE3CaF6d722bc9f9`
* Private key: `16962bb06858ec2e4f252b01391196a5e3699329ff0ce1cc185c213a3844b1cf`
* Reward account for **Miner 2** (`wavesnode-2`, `besu-2`):
* Reward account for **Miner 2** (`wavesnode-2`, `ec-2`):
* Address: `0xcF0b9E13FDd593f4Ca26D36aFCaA44dd3FDCCbeD`
* Private key: `ab49fee4fc326ecbc7abc7f2e5870bf1f86076eb0979c524e20c843f2a73f647`
* Reward account for **Miner 3** (`wavesnode-3`, `ec-3`):
* Address: `0xf1FE6d7bfebead68A8C06cCcee97B61d7DAA0338`
* Private key: `40151189dda26e893252542f1e628f469871f8770bc9cbe3d095419541a01bd0`
* Reward account for **Miner 4** (`wavesnode-4`, `ec-4`):
* Address: `0x10eDdE5dc07eF63E6bb7018758e6fcB5320d8cAa`
* Private key: `716aacab2cb83b57ce399f0d4e625e7a7ab242d3ee1b29858b0866e146be6086`
* To see all information, run `npx tsx common-settings-show.ts` from [./deploy](./deploy/) directory.
* Ethereum addresses and private keys for `besu` nodes in [config](configs/ec-common/genesis.json):
* `fe3b557e8fb62b89f4916b721be55ceb828dbd73`: `8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63`
Expand Down Expand Up @@ -96,7 +109,7 @@ For example, we will deploy a `HelloWorld`:
3. Press "Clear activity tab data" button.
2. If you want to deploy a contract via Explorer ("Contracts" tab), make sure you've chosen not a nightly version and it
matches [bridge.sol](./deploy/setup/el/bridge.sol).

# Useful links

## Besu configuration
Expand Down
4 changes: 2 additions & 2 deletions local-network/configs/besu/besu.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# See https://besu.hyperledger.org/public-networks/reference/cli/options
# /opt/besu belongs to besu user: https://github.com/hyperledger/besu/blob/main/docker/openjdk-17/Dockerfile
# so it is the only writable path
data-path = "/opt/besu/data"
genesis-file = "/genesis.json"
node-private-key-file = "/etc/secrets/p2p-key"
genesis-file = "/etc/secrets/genesis.json"

sync-mode = "FULL"
host-allowlist = ["*"]
Expand Down
2 changes: 1 addition & 1 deletion local-network/configs/besu/besu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
besu:
image: hyperledger/besu:latest
volumes:
- ../ec-common/genesis.json:/genesis.json:ro
- ../ec-common/:/etc/secrets/:ro
- .:/config:ro
- ./run-besu.sh:/tmp/run.sh:ro
env_file:
Expand Down
3 changes: 2 additions & 1 deletion local-network/configs/besu/run-besu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ EOF
# --p2p-host="ec-1" # Doesn't work: https://github.com/hyperledger/besu/issues/4380
besu \
--config-file=/config/besu.conf \
--p2p-host=${IP}
--p2p-host=${IP} \
--node-private-key-file="/etc/secrets/p2p-key-${NODE_NUMBER}.hex"
1 change: 0 additions & 1 deletion local-network/configs/ec-common/p2p-key-bootnode.hex

This file was deleted.

2 changes: 1 addition & 1 deletion local-network/configs/geth/geth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
stop_grace_period: 10s
entrypoint: /tmp/run.sh
volumes:
- ../ec-common/genesis.json:/tmp/genesis.json:ro
- ../ec-common/:/etc/secrets/:ro
- ./run-geth.sh:/tmp/run.sh:ro
env_file:
- ../ec-common/peers.env
Expand Down
6 changes: 3 additions & 3 deletions local-network/configs/geth/run-geth.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env sh

if [ ! -d /root/.ethereum/geth ] ; then
geth init /tmp/genesis.json 2>&1 | tee /root/logs/init.log
geth init /etc/secrets/genesis.json 2>&1 | tee /root/logs/init.log
fi

IP_RAW=$(ip -4 addr show dev eth0 | awk '/inet / {print $2}')
Expand Down Expand Up @@ -29,8 +29,8 @@ geth \
--ws.origins=* \
--authrpc.addr=0.0.0.0 \
--authrpc.vhosts=* \
--authrpc.jwtsecret=/etc/secrets/jwtsecret \
--nodekey=/etc/secrets/p2p-key \
--authrpc.jwtsecret="/etc/secrets/jwt-secret-${NODE_NUMBER}.hex" \
--nodekey="/etc/secrets/p2p-key-${NODE_NUMBER}.hex" \
--nat="extip:${IP}" \
--netrestrict="${NETWORK}/${PREFIX}" \
--bootnodes="${BESU_BOOTNODES}" \
Expand Down
18 changes: 18 additions & 0 deletions local-network/configs/wavesnode/genesis-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ genesis-generator {
# Address: 3FSrRN8X7cDsLyYTScS8Yf8KSwZgJBwf1jU
{ seed-text = "devnet-2", nonce = 0, amount = 800900102030000 }

# Miner on wavesnode-3
# Seed text: devnet-3
# Nonce: 0
# Seed: HnyGuCEnV1C
# Private key: 6xx38JtyDrCBUox2HZ1F6qPZYcFHnfkYQzHRvs3wyRfH
# Public key: 4rfG6p3Ep2dUr4QqWtJwDvy3ySumMejgTE5sdJLzB756
# Address: 3Fkh3dNmLS6NQtVbHcrADegwLo9DviBL5Ro
{ seed-text = "devnet-3", nonce = 0, amount = 700050007000500 }

# Miner on wavesnode-4
# Seed text: devnet-4
# Nonce: 0
# Seed: HnyGuCEnV1D
# Private key: 26mAQWx1hKjDgiJHLpgGJnp8GWp23ueHjqy3vDJtCtTz
# Public key: CxeyqUAbsfCWHhQfrTq7g7t7PengjQpDejG5cd7i4Pqa
# Address: 3FXMRA1tPsn8LApkqVEQJgzsVdMBrnnd8vp
{ seed-text = "devnet-4", nonce = 0, amount = 600100102030000 }

# Additional addresses

# Seed text: devnet rich
Expand Down
18 changes: 18 additions & 0 deletions local-network/deploy/local/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ def cl_miners(self) -> List[Miner]:
"0xcf0b9e13fdd593f4ca26d36afcaa44dd3fdccbed"
),
),
# Miner(
# account=pw.Address(
# seed="devnet-3",
# nonce=0,
# ),
# el_reward_address_hex=HexStr(
# "0xf1FE6d7bfebead68A8C06cCcee97B61d7DAA0338"
# ),
# ),
# Miner(
# account=pw.Address(
# seed="devnet-4",
# nonce=0,
# ),
# el_reward_address_hex=HexStr(
# "0x10eDdE5dc07eF63E6bb7018758e6fcB5320d8cAa"
# ),
# ),
]

@cached_property
Expand Down
2 changes: 1 addition & 1 deletion local-network/deploy/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "0.1"
description = "Scripts and tests for a locally deployed Unit network"
dependencies = [
"solc-select",
"units-network @ git+https://github.com/UnitsNetwork/examples.git@dao-rewards",
"units-network @ git+https://github.com/UnitsNetwork/examples.git",
]
readme = "README.md"
requires-python = ">=3.9"
Expand Down
91 changes: 83 additions & 8 deletions local-network/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,60 @@ services:
extends:
file: ./configs/besu/besu.yml
service: besu
environment:
NODE_NUMBER: 1
ports:
- "127.0.0.1:18551:8551" # Engine port - doesn't have all APIs
- "127.0.0.1:18545:8545" # RPC port, for Metamask e.g.
- "127.0.0.1:18546:8546" # WebSocket
volumes:
- ./configs/ec-common/p2p-key-1.hex:/etc/secrets/p2p-key:ro
- ./logs/ec-1:/opt/besu/logs

ec-2:
container_name: ec-2
hostname: ec-2
extends:
file: ./configs/geth/geth.yml
service: geth
file: ./configs/besu/besu.yml
service: besu
ports:
- "127.0.0.1:28551:8551" # Engine port
- "127.0.0.1:28545:8545" # RPC port
- "127.0.0.1:28551:8551"
- "127.0.0.1:28545:8545"
- "127.0.0.1:28546:8546"
environment:
NODE_NUMBER: 2
volumes:
- ./configs/ec-common/p2p-key-2.hex:/etc/secrets/p2p-key:ro
- ./configs/ec-common/jwt-secret-2.hex:/etc/secrets/jwtsecret:ro
- ./logs/ec-2:/root/logs
- ./logs/ec-2:/opt/besu/logs

# Make sure, you have enough RAM to run additional nodes
# ec-3:
# container_name: ec-3
# hostname: ec-3
# extends:
# file: ./configs/besu/besu.yml
# service: besu
# environment:
# NODE_NUMBER: 3
# ports:
# - "127.0.0.1:38551:8551"
# - "127.0.0.1:38545:8545"
# - "127.0.0.1:38546:8546"
# volumes:
# - ./logs/ec-3:/opt/besu/logs

# Geth is not recommended for now, because of rollback issue
# ec-4:
# container_name: ec-4
# hostname: ec-4
# extends:
# file: ./configs/geth/geth.yml
# service: geth
# environment:
# NODE_NUMBER: 4
# ports:
# - "127.0.0.1:48551:8551"
# - "127.0.0.1:48545:8545"
# volumes:
# - ./logs/ec-4:/root/logs

wavesnode-1:
container_name: wavesnode-1
Expand Down Expand Up @@ -70,6 +103,48 @@ services:
update-genesis:
condition: service_completed_successfully

# wavesnode-3:
# container_name: wavesnode-3
# hostname: wavesnode-3
# extends:
# file: ./configs/wavesnode/wavesnode.yml
# service: wavesnode
# image: ${WAVES_NODE_IMAGE_3:-${WAVES_NODE_IMAGE:-consensus-client:local}}
# ports:
# - "127.0.0.1:36869:6869"
# environment:
# NODE_NUMBER: 3
# WAVES_WALLET_SEED: HnyGuCEnV1C # devnet-3, addr: 3Fkh3dNmLS6NQtVbHcrADegwLo9DviBL5Ro
# JAVA_OPTS: -Dwaves.miner.enable=no
# volumes:
# - ./logs/wavesnode-3:/var/log/waves
# depends_on:
# ec-3:
# condition: service_healthy
# update-genesis:
# condition: service_completed_successfully

# wavesnode-4:
# container_name: wavesnode-4
# hostname: wavesnode-4
# extends:
# file: ./configs/wavesnode/wavesnode.yml
# service: wavesnode
# image: ${WAVES_NODE_IMAGE_4:-${WAVES_NODE_IMAGE:-consensus-client:local}}
# ports:
# - "127.0.0.1:46869:6869"
# environment:
# NODE_NUMBER: 4
# WAVES_WALLET_SEED: HnyGuCEnV1D # devnet-4, addr: 3FXMRA1tPsn8LApkqVEQJgzsVdMBrnnd8vp
# JAVA_OPTS: -Dwaves.miner.enable=no
# volumes:
# - ./logs/wavesnode-4:/var/log/waves
# depends_on:
# ec-3:
# condition: service_healthy
# update-genesis:
# condition: service_completed_successfully

update-genesis:
container_name: update-genesis
image: ${WAVES_NODE_IMAGE:-ghcr.io/wavesplatform/waves:test-gengen}
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ units {
known-peers = []
file = null
}

# Optional:
# jwt-secret-file = "/path/to/jwt/secret"
}

chains = [
Expand All @@ -27,6 +30,8 @@ units {
# "5.6.7.8:6865"
# ]
# }
# # Optional:
# # jwt-secret-file = "/path/to/jwt/secret"
# }
]
}
Loading