Skip to content

Commit

Permalink
kurtosis setup to get deposit contract and fill genesis file
Browse files Browse the repository at this point in the history
Signed-off-by: nidhi-singh02 <[email protected]>
  • Loading branch information
nidhi-singh02 committed Jan 16, 2025
1 parent 5d9fb51 commit 75ec992
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ COPY --from=builder /workdir/build/bin/${APP_NAME} /usr/bin/${APP_NAME}
# TODO: We should un hood this part, its very specific
# to our kurtosis setup.
RUN mkdir -p /root/jwt /root/kzg && \
apk add --no-cache bash sed curl
apk add --no-cache bash sed curl jq

EXPOSE 26656
EXPOSE 26657
Expand Down
25 changes: 18 additions & 7 deletions kurtosis/main.star
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,22 @@ def run(plan, network_configuration = {}, node_settings = {}, eth_json_rpc_endpo
# 2. Upload files
jwt_file, kzg_trusted_setup = execution.upload_global_files(plan, node_modules, chain_id)

# 2 a. Create genesis files only once and pass it to the node configs
genesis_files = nodes.create_genesis_files(plan, chain_id)
# 3. Perform genesis ceremony for the CL genesis deposits.
stored_configs = beacond.perform_genesis_deposits_ceremony(plan, validators, jwt_file, chain_id, chain_spec)

# 3. Perform genesis ceremony
beacond.perform_genesis_ceremony(plan, validators, jwt_file, chain_id, chain_spec, genesis_files)
# 4 a. Create genesis files only once and pass it to the node configs
genesis_files = nodes.create_genesis_files_part1(plan, chain_id)

# 4b. Modify the eth genesis file with the premined deposits && finalize CL genesis file.
# Get the deposit storage values stored in env variables
env_vars = beacond.modify_genesis_files_deposits(plan, validators, genesis_files, chain_id, chain_spec, stored_configs)

# Extract values from env_vars
genesis_deposits_root = env_vars.get("GENESIS_DEPOSITS_ROOT")
genesis_deposit_count_hex = env_vars.get("GENESIS_DEPOSIT_COUNT_HEX")

# 4c. Modify the eth genesis files(for both nethermind and default) with the ENV VARS
genesis_files = nodes.create_genesis_files_part2(plan, chain_id, genesis_deposits_root, genesis_deposit_count_hex)

el_enode_addrs = []
metrics_enabled_services = metrics_enabled_services[:]
Expand All @@ -90,7 +101,7 @@ def run(plan, network_configuration = {}, node_settings = {}, eth_json_rpc_endpo
metrics_enabled_services = execution.add_metrics(metrics_enabled_services, seed, seed.el_service_name, seed_node_el_clients[seed.el_service_name], node_modules)
seed_node_configs = {}
for n, seed in enumerate(seed_nodes):
seed_node_config = beacond.create_node_config(plan, seed, consensus_node_peering_info, seed.el_service_name, chain_id, chain_spec, jwt_file, kzg_trusted_setup)
seed_node_config = beacond.create_node_config(plan, seed, consensus_node_peering_info, seed.el_service_name, chain_id, chain_spec, genesis_deposits_root, genesis_deposit_count_hex, jwt_file, kzg_trusted_setup)
seed_node_configs[seed.cl_service_name] = seed_node_config
seed_nodes_clients = plan.add_services(
configs = seed_node_configs,
Expand Down Expand Up @@ -121,7 +132,7 @@ def run(plan, network_configuration = {}, node_settings = {}, eth_json_rpc_endpo

for n, full in enumerate(full_nodes):
# 5b. Launch CL
full_node_config = beacond.create_node_config(plan, full, consensus_node_peering_info, full.el_service_name, chain_id, chain_spec, jwt_file, kzg_trusted_setup)
full_node_config = beacond.create_node_config(plan, full, consensus_node_peering_info, full.el_service_name, chain_id, chain_spec, genesis_deposits_root, genesis_deposit_count_hex, jwt_file, kzg_trusted_setup)
full_node_configs[full.cl_service_name] = full_node_config

if full_node_configs != {}:
Expand Down Expand Up @@ -152,7 +163,7 @@ def run(plan, network_configuration = {}, node_settings = {}, eth_json_rpc_endpo

validator_node_configs = {}
for n, validator in enumerate(validators):
validator_node_config = beacond.create_node_config(plan, validator, consensus_node_peering_info, validator.el_service_name, chain_id, chain_spec, jwt_file, kzg_trusted_setup)
validator_node_config = beacond.create_node_config(plan, validator, consensus_node_peering_info, validator.el_service_name, chain_id, chain_spec, genesis_deposits_root, genesis_deposit_count_hex, jwt_file, kzg_trusted_setup)
validator_node_configs[validator.cl_service_name] = validator_node_config

cl_clients = plan.add_services(
Expand Down

Large diffs are not rendered by default.

82 changes: 74 additions & 8 deletions kurtosis/src/nodes/consensus/beacond/launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ USED_PORTS = {
NODE_API_PORT_ID: shared_utils.new_port_spec(NODE_API_PORT_NUM, shared_utils.TCP_PROTOCOL),
}

def get_config(node_struct, engine_dial_url, chain_id, chain_spec, entrypoint = [], cmd = [], persistent_peers = "", expose_ports = True, jwt_file = None, kzg_trusted_setup_file = None):
def get_config(node_struct, engine_dial_url, chain_id, chain_spec, genesis_deposits_root, genesis_deposit_count_hex, entrypoint = [], cmd = [], persistent_peers = "", expose_ports = True, jwt_file = None, kzg_trusted_setup_file = None):
exposed_ports = {}
if expose_ports:
exposed_ports = USED_PORTS
Expand Down Expand Up @@ -72,6 +72,8 @@ def get_config(node_struct, engine_dial_url, chain_id, chain_spec, entrypoint =
"BEACOND_CHAIN_SPEC": chain_spec,
"WITHDRAWAL_ADDRESS": "0x20f33ce90a13a4b5e7697e3544c3083b8f8a51d4",
"DEPOSIT_AMOUNT": "32000000000",
"GENESIS_DEPOSIT_COUNT_HEX": genesis_deposit_count_hex,
"GENESIS_DEPOSITS_ROOT": genesis_deposits_root,
},
ports = exposed_ports,
labels = node_labels,
Expand All @@ -80,7 +82,7 @@ def get_config(node_struct, engine_dial_url, chain_id, chain_spec, entrypoint =

return config

def perform_genesis_ceremony(plan, validators, jwt_file, chain_id, chain_spec, genesis_files):
def perform_genesis_deposits_ceremony(plan, validators, jwt_file, chain_id, chain_spec):
num_validators = len(validators)

node_peering_info = []
Expand All @@ -94,7 +96,7 @@ def perform_genesis_ceremony(plan, validators, jwt_file, chain_id, chain_spec, g
stored_configs.append(StoreSpec(src = "/tmp/config_genesis/.beacond/config/genesis.json", name = "cosmos-genesis-final"))

multiple_gentx_file = plan.upload_files(
src = "./scripts/multiple-premined-deposits.sh",
src = "./scripts/multiple-premined-deposits-cl.sh",
name = "multiple-premined-deposits",
description = "Uploading multiple-premined-deposits script",
)
Expand All @@ -105,19 +107,81 @@ def perform_genesis_ceremony(plan, validators, jwt_file, chain_id, chain_spec, g
plan.print(multiple_gentx_env_vars)
plan.print(stored_configs)

eth_genesis_file = genesis_files["default"]

plan.run_sh(
run = "chmod +x /app/scripts/multiple-premined-deposits.sh && /app/scripts/multiple-premined-deposits.sh",
run = "chmod +x /app/scripts/multiple-premined-deposits-cl.sh && /app/scripts/multiple-premined-deposits-cl.sh",
image = validators[0].cl_image,
files = {
"/app/scripts": "multiple-premined-deposits",
"/root/eth_genesis": eth_genesis_file,
},
env_vars = multiple_gentx_env_vars,
store = stored_configs,
description = "Collecting beacond genesis files",
)
return stored_configs

def modify_genesis_files_deposits(plan, validators, genesis_files, chain_id, chain_spec, stored_configs):
num_validators = len(validators)

modify_genesis_file = plan.upload_files(
src = "./scripts/modify-genesis-with-deposits.sh",
name = "modify-genesis-with-deposits",
description = "Uploading modify-genesis-with-deposits script",
)

genesis_env_vars = node.get_genesis_env_vars("cl-validator-beaconkit-0", chain_id, chain_spec)

# First operation: Get deposit values and store to files
deposit_count_store = StoreSpec(
src = "/tmp/values/deposit_count.txt",
name = "deposit-count",
)
deposit_root_store = StoreSpec(
src = "/tmp/values/deposit_root.txt",
name = "deposit-root",
)

# Run the script and store the output files
result = plan.run_sh(
run = "chmod +x /app/scripts/modify-genesis-with-deposits.sh && /app/scripts/modify-genesis-with-deposits.sh",
image = validators[0].cl_image,
files = {
"/app/scripts": "modify-genesis-with-deposits",
"/root/eth_genesis": genesis_files["default"],
"/tmp/config_genesis/.beacond/config": "cosmos-genesis-final",
},
env_vars = genesis_env_vars,
store = [deposit_count_store, deposit_root_store, stored_configs[num_validators]],
description = "Running modify genesis with deposits",
)

# Second operation: Read deposit count
result_one = plan.run_sh(
run = "cat /tmp/values/deposit_count.txt",
image = validators[0].cl_image,
files = {
"/tmp/values": "deposit-count",
},
description = "Reading deposit count",
)
deposit_count = result_one.output.strip().rstrip("\n")
plan.print("Deposit count:", deposit_count)

# Third operation: Read deposit root
result_two = plan.run_sh(
run = "cat /tmp/values/deposit_root.txt",
image = validators[0].cl_image,
files = {
"/tmp/values": "deposit-root",
},
description = "Reading deposit root",
)
deposit_root = result_two.output.strip().rstrip("\n")
plan.print("Deposit root:", deposit_root)

# Update env vars with parsed values
genesis_env_vars["GENESIS_DEPOSIT_COUNT_HEX"] = deposit_count
genesis_env_vars["GENESIS_DEPOSITS_ROOT"] = deposit_root
return genesis_env_vars

def get_persistent_peers(plan, peers):
persistent_peers = peers[:]
Expand All @@ -136,7 +200,7 @@ def init_consensus_nodes():
collect_gentx = "/usr/bin/beacond genesis collect-premined-deposits --home {}".format("$BEACOND_HOME")
return "{} && {} && {}".format(init_node, add_validator, collect_gentx)

def create_node_config(plan, node_struct, peers, paired_el_client_name, chain_id, chain_spec, jwt_file = None, kzg_trusted_setup_file = None):
def create_node_config(plan, node_struct, peers, paired_el_client_name, chain_id, chain_spec, genesis_deposits_root, genesis_deposit_count_hex, jwt_file = None, kzg_trusted_setup_file = None):
engine_dial_url = "http://{}:{}".format(paired_el_client_name, execution.ENGINE_RPC_PORT_NUM)

persistent_peers = get_persistent_peers(plan, peers)
Expand All @@ -155,6 +219,8 @@ def create_node_config(plan, node_struct, peers, paired_el_client_name, chain_id
engine_dial_url,
chain_id,
chain_spec,
genesis_deposits_root,
genesis_deposit_count_hex,
entrypoint = ["bash", "-c"],
cmd = [cmd],
persistent_peers = persistent_peers,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# SPDX-License-Identifier: BUSL-1.1
#
# Copyright (C) 2024, Berachain Foundation. All rights reserved.
# Use of this software is governed by the Business Source License included
# in the LICENSE file of this repository and at www.mariadb.com/bsl11.
#
# ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
# TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
# VERSIONS OF THE LICENSED WORK.
#
# THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
# LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
# LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
#
# TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
# AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
# EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
# TITLE.


# Sets the deposit storage in the the new eth-genesis file in the home directory.
/usr/bin/beacond genesis set-deposit-storage $ETH_GENESIS --home /tmp/config_genesis/.beacond

# Get values directly from the storage fields
DEPOSIT_COUNT=$(jq -r '.alloc["0x4242424242424242424242424242424242424242"].storage["0x0000000000000000000000000000000000000000000000000000000000000000"]' /tmp/config_genesis/.beacond/genesis.json)
DEPOSIT_ROOT=$(jq -r '.alloc["0x4242424242424242424242424242424242424242"].storage["0x0000000000000000000000000000000000000000000000000000000000000001"]' /tmp/config_genesis/.beacond/genesis.json)

/usr/bin/beacond genesis execution-payload /tmp/config_genesis/.beacond/genesis.json --home /tmp/config_genesis/.beacond

# Write each value to separate files for easier parsing
mkdir -p /tmp/values
printf "%s" "$DEPOSIT_COUNT" > /tmp/values/deposit_count.txt
printf "%s" "$DEPOSIT_ROOT" > /tmp/values/deposit_root.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ for ((i=1; i<$NUM_VALS; i++)); do
cp -r /tmp/config${i}/.beacond/config/premined-deposits/premined-deposit* /tmp/config_genesis/.beacond/config/premined-deposits/
done

/usr/bin/beacond genesis execution-payload $ETH_GENESIS --home /tmp/config_genesis/.beacond
/usr/bin/beacond genesis collect-premined-deposits --home /tmp/config_genesis/.beacond

Loading

0 comments on commit 75ec992

Please sign in to comment.