Skip to content

Commit 49665b6

Browse files
authored
chore(kurtosis): kurtosis setup, convenience tasks, and docs (#1202)
1 parent 8e450d0 commit 49665b6

File tree

4 files changed

+215
-1
lines changed

4 files changed

+215
-1
lines changed

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,7 @@ RUN protoc --elixir_out=. proto/libp2p.proto
114114

115115
RUN mix compile
116116

117-
ENTRYPOINT [ "iex", "-S", "mix", "run", "--"]
117+
ARG IEX_ARGS=""
118+
ENV IEX_ARGS_VALUE=${IEX_ARGS}
119+
120+
ENTRYPOINT iex $IEX_ARGS_VALUE -S mix run -- $0 $@

Makefile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,64 @@ PORT_SOURCES := $(shell find native/libp2p_port -type f)
4242
$(OUTPUT_DIR)/libp2p_port: $(PORT_SOURCES) $(PROTOBUF_GO_FILES)
4343
cd native/libp2p_port; go build -o ../../$@
4444

45+
GRAFANA_DASHBOARDS_DIR = ./metrics/grafana/provisioning/dashboards
46+
47+
# Root directory of ethereum-package
48+
KURTOSIS_DIR ?= ../ethereum-package
49+
# Grafana configuration directory for dashboards
50+
KURTOSIS_GRAFANA_DASHBOARDS_DIR ?= $(KURTOSIS_DIR)/static_files/grafana-config/dashboards
51+
# Secret cookie for the lambdaconsesus IEX node built for usage with kurtosis
52+
KURTOSIS_COOKIE ?= secret
53+
# Name of the kurtosis service pointing to the lambdaconsesus node
54+
KURTOSIS_SERVICE ?= cl-3-lambda-geth
55+
4556
##### TARGETS #####
4657

58+
# 💻 kurtosis.setup: @ Setup the kurtosis environment
59+
kurtosis.setup: kurtosis.setup.ethereum-package kurtosis.setup.grafana kurtosis.setup.lambdaconsensus
60+
61+
#💻 kurtosis.setup.ethereum-package: @ Clones the lambda ethereum-package and check out the current active branch
62+
kurtosis.setup.ethereum-package:
63+
git clone https://github.com/lambdaclass/ethereum-package.git $(KURTOSIS_DIR) && \
64+
cd $(KURTOSIS_DIR) && \
65+
git checkout lecc-integration
66+
67+
# 💻 kurtosis.setup.grafana: @ Copies the grafana dashboards to the ethereum-package folder under grafana-config
68+
kurtosis.setup.grafana:
69+
[ -d $(KURTOSIS_GRAFANA_DASHBOARDS_DIR)/lambdaconsensus ] || mkdir $(KURTOSIS_GRAFANA_DASHBOARDS_DIR)/lambdaconsensus
70+
cp -r $(GRAFANA_DASHBOARDS_DIR)/* $(KURTOSIS_GRAFANA_DASHBOARDS_DIR)/lambdaconsensus
71+
72+
#💻 kurtosis.setup.lambdaconsensus: @ Builds the node Docker for the kurtosis environment
73+
kurtosis.setup.lambdaconsensus:
74+
docker build --build-arg IEX_ARGS="--sname lambdaconsensus --cookie $(KURTOSIS_COOKIE)" -t lambda_ethereum_consensus .
75+
76+
#💻 kurtosis.start: @ Starts the kurtosis environment
77+
kurtosis.start:
78+
kurtosis run --enclave lambdanet $(KURTOSIS_DIR) --args-file network_params.yaml
79+
80+
#💻 kurtosis.stop: @ Stops the kurtosis environment
81+
kurtosis.stop:
82+
kurtosis enclave stop lambdanet
83+
84+
#💻 kurtosis.remove: @ Removes the kurtosis environment
85+
kurtosis.remove:
86+
kurtosis enclave rm lambdanet
87+
88+
#💻 kurtosis.clean: @ Clean the kurtosis environment
89+
kurtosis.clean:
90+
kurtosis clean -a
91+
92+
#💻 kurtosis.purge: @ Purge the kurtosis environment
93+
kurtosis.purge: kurtosis.stop kurtosis.remove kurtosis.clean
94+
95+
#💻 kurtosis.connect: @ Connects to the client running in kurtosis, KURTOSIS_SERVICE could be given
96+
kurtosis.connect:
97+
kurtosis service shell lambdanet $(KURTOSIS_SERVICE)
98+
99+
#💻 kurtosis.connect.iex: @ Connects to iex ONCE INSIDE THE KURTOSIS SERVICE
100+
kurtosis.connect.iex:
101+
iex --sname client --remsh lambdaconsensus --cookie $(KURTOSIS_COOKIE)
102+
47103
#💻 nix: @ Start a nix environment.
48104
nix:
49105
nix develop

README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,151 @@ Then you run it with `docker run`, adding CLI flags as needed:
135135
docker run consensus --checkpoint-sync <url> --network <network> ...
136136
```
137137

138+
# Testing Environment with Kurtosis
139+
140+
To test the node locally, we can simulate other nodes and start from genesis using [`Kurtosis`](https://docs.kurtosis.com/) and the Lambda Class fork of [`ethereum-package`](https://github.com/lambdaclass/ethereum-package.git).
141+
142+
### Why Use Kurtosis
143+
We can test the process and transition of the Beacon state and execution of the consensus rules by connecting the node to Sepolia or even Mainnet. However, testing validators requires at least 32 ETH, which is hard to acquire even in Testnet, and being selected as a block proposer can be a never-ending task. For these reasons, and especially the ability to test multiple validators and completely different scenarios, the best approach currently is to use [`Kurtosis`](https://docs.kurtosis.com/). In combination with the [`ethereum-package`](https://github.com/lambdaclass/ethereum-package.git), kurtosis is a great way to simulate local testnets with a high level of control over the network participants.
144+
145+
### Prerequisites
146+
- [`Docker`](https://docs.docker.com/get-docker/)
147+
- [`Kurtosis`](https://docs.kurtosis.com/install/#ii-install-the-cli)
148+
149+
### Consensus node setup + ethereum-package
150+
151+
As stated in the `ethereum-package` README:
152+
> This is a Kurtosis package that will spin up a private Ethereum testnet over Docker or Kubernetes with multi-client support, Flashbot's mev-boost infrastructure for PBS-related testing/validation, and other useful network tools (transaction spammer, monitoring tools, etc). Kurtosis packages are entirely reproducible and composable, so this will work the same way over Docker or Kubernetes, in the cloud or locally on your machine.
153+
154+
After kurtosis is installed, we need to do three setup steps.
155+
156+
1. Clone the lambdaclass ethereum-package fork and checkout a particular branch
157+
2. Copy our Grafana custom dashboards to be able to look at them
158+
3. Build the Docker image of the service
159+
160+
We can accomplish all the steps with a simple.
161+
162+
```bash
163+
make kurtosis.setup
164+
```
165+
166+
or executed each at a time
167+
168+
```bash
169+
make kurtosis.setup.ethereum-package
170+
# git clone https://github.com/lambdaclass/ethereum-package.git ../ethereum-package && \
171+
# cd ../ethereum-package && git checkout lecc-integration
172+
173+
make kurtosis.setup.grafana
174+
# cp -r ./metrics/grafana/provisioning/dashboards/* ../ethereum-package/static_files/grafana-config/dashboards/lambdaconsensus
175+
176+
make kurtosis.setup.lambdaconsensus
177+
# docker build --build-arg IEX_ARGS="--sname lambdaconsensus --cookie secret" -t lambda_ethereum_consensus .
178+
179+
# alternatively, you could build the repo without the node config and cookie just by running
180+
# docker build -t lambda_ethereum_consensus .
181+
```
182+
183+
After that, we will be ready to tweak the configuration.
184+
185+
```bash
186+
# assumming you are still in the lambda_ethereum_consensus repo, you can modify the configuration through
187+
vim network_params.yaml
188+
```
189+
190+
We have some sensible defaults for a simple network of 3 clients with 64 Validators each (ethereum-package default) and a slight tweak to the memory limit. Here is an example of the doc; all parameters are explained in [their documentation](https://github.com/ethpandaops/ethereum-package?tab=readme-ov-file#configuration).
191+
192+
```yaml
193+
participants:
194+
- el_type: geth
195+
cl_type: lighthouse
196+
count: 2
197+
- el_type: geth
198+
cl_type: lambda
199+
cl_image: lambda_ethereum_consensus:latest
200+
use_separate_vc: false
201+
count: 1
202+
cl_max_mem: 4096
203+
```
204+
205+
### Kurtosis Execution and Make tasks
206+
207+
For starting the local environment after the setup run:
208+
209+
```bash
210+
# Using the make task
211+
make kurtosis.start
212+
213+
# which executes
214+
kurtosis run --enclave lambdanet ../ethereum-package --args-file network_params.yaml
215+
```
216+
217+
Then, you can connect to the service (running docker instance) with the following:
218+
219+
```bash
220+
# to connect to the instance
221+
make kurtosis.connect
222+
223+
# you can specify the KURTOSIS_SERVICE if the config is different from the default provided:
224+
make kurtosis.connect KURTOSIS_SERVICE=cl-6-lambda-geth
225+
```
226+
227+
Once inside the service, you can connect to the node with a new IEX session running the following.
228+
229+
```bash
230+
make kurtosis.connect.iex
231+
232+
# if you set a specific cookie, you can add it as an argument as before
233+
make kurtosis.connect.iex KURTOSIS_COOKIE=my_secret
234+
235+
# which is just a convenient task over:
236+
iex --sname client --remsh lambdaconsensus --cookie my_secret
237+
```
238+
239+
Now you can check it is working, for example, by examining some constants:
240+
241+
```elixir
242+
#Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:8:1] [ds:8:1:10] [async-threads:1] [jit]
243+
244+
#Interactive Elixir (1.16.2) - press Ctrl+C to exit (type h() ENTER for help)
245+
246+
Constants.versioned_hash_version_kzg()
247+
# <<1>>
248+
```
249+
250+
### Kurtosis metrics
251+
252+
The [`ethereum-package`](https://github.com/lambdaclass/ethereum-package.git) has prometheus and grafana support built-in. Metrics are being picked up correctly by prometheus, and we have already copied our custom grafana dashboards during the setup step, so you can inspect all of that by accessing the home pages for any of the services (looking for the mapped docker ports). If you want to make changes to the dashboards and see them working with kurtosis afterward, you'll need to update them running again:
253+
254+
```bash
255+
make kurtosis.setup.grafana
256+
```
257+
258+
By default, `ethereum-package` shows it's dashboards in the home page, to see our custom dashboards it's needed to go to `Dashboards` in the left panel and then enter our own `lambdaconsensus` folder.
259+
260+
### Kurtosis cleanup
261+
262+
For a complete cleanup, you could execute the following task.
263+
264+
```bash
265+
# Stop, remove and clean
266+
make kurtosis.purge
267+
```
268+
269+
Suppose the stop was made manually, the purge failed in some step, or the environment was inconsistent for other reasons. In that case, It is also possible to execute every cleanup task individually avoiding the ones not needed:
270+
271+
```bash
272+
# kurtosis enclave stop lambdanet
273+
make kurtosis.stop
274+
# kurtosis enclave rm lambdanet
275+
make kurtosis.remove
276+
# kurtosis clean -a
277+
make kurtosis.clean
278+
279+
# or do it all at once
280+
make kurtosis.purge
281+
```
282+
138283
## Consensus spec tests
139284

140285
You can run all of them with:

network_params.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
participants:
2+
- el_type: geth
3+
cl_type: lighthouse
4+
count: 2
5+
- el_type: geth
6+
cl_type: lambda
7+
cl_image: lambda_ethereum_consensus:latest
8+
use_separate_vc: false
9+
count: 1
10+
cl_max_mem: 4096

0 commit comments

Comments
 (0)