Skip to content

Commit

Permalink
impl dev
Browse files Browse the repository at this point in the history
  • Loading branch information
haxjump committed Oct 8, 2024
1 parent 1f8fb58 commit 21ed7a1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fmt:
cargo fmt

fmtall:
bash -x tools/fmt.sh
bash tools/fmt.sh

lint:
cargo clippy
72 changes: 51 additions & 21 deletions src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ impl NodeCmdGenerator<Node<Ports>, EnvMeta<CustomInfo, Node<Ports>>> for CmdGene
})
.unzip();

let prepare_cmd = format!(
r#"
if [ ! -d {genesis_dir} ]; then
tar -C {home} -xpf {home}/{NODE_HOME_GENESIS_DST} || exit 1
mv {home}/$(tar -tf {home}/{NODE_HOME_VCDATA_DST} | head -1) {genesis_dir} || exit 1
fi "#
);

////////////////////////////////////////////////
// EL
////////////////////////////////////////////////
Expand Down Expand Up @@ -239,13 +247,9 @@ impl NodeCmdGenerator<Node<Ports>, EnvMeta<CustomInfo, Node<Ports>>> for CmdGene
let cmd_init_part = format!(
r#"
if [ ! -d {el_dir} ]; then
mkdir {genesis_dir} || exit 1
tar -xpf {home}/{NODE_HOME_GENESIS_DST} --directory {genesis_dir} || exit 1
mv {genesis_dir}/*/* {genesis_dir}/ || exit 1
{geth} init --datadir={el_dir} --state.scheme=hash \
{el_genesis} >>{el_dir}/{EL_LOG_NAME} 2>&1 || exit 1
fi
"#
fi "#
);

let cmd_run_part_0 = format!(
Expand Down Expand Up @@ -284,21 +288,17 @@ fi
let cmd_init_part = format!(
r#"
if [ ! -d {el_dir} ]; then
mkdir {genesis_dir} || exit 1
tar -xpf {home}/{NODE_HOME_GENESIS_DST} --directory {genesis_dir} || exit 1
mv {genesis_dir}/*/* {genesis_dir}/ || exit 1
{reth} init --datadir={el_dir} --chain={el_genesis} \
--log.file.directory={el_dir}/logs >>{el_dir}/{EL_LOG_NAME} 2>&1 || exit 1
fi
"#
fi "#
);

let cmd_run_part_0 = format!(
r#"
{reth} node \
--chain={el_genesis} \
--datadir={el_dir} \
--log.file.directory=${el_dir}/logs \
--log.file.directory={el_dir}/logs \
--ipcdisable \
--nat=extip:{ext_ip} \
--discovery.port={el_discovery_port} \
Expand Down Expand Up @@ -336,7 +336,8 @@ fi

let lighthouse = &e.custom_data.cl_bin;

let cl_dir = format!("{home}/cl");
let cl_bn_dir = format!("{home}/cl/bn");
let cl_vc_dir = format!("{home}/cl/vc");
let cl_genesis = genesis_dir;
let cl_bn_discovery_port = n.ports.cl_discovery;
let cl_bn_discovery_quic_port = n.ports.cl_discovery_quic;
Expand Down Expand Up @@ -373,7 +374,7 @@ fi
r#"
{lighthouse} beacon_node \
--testnet-dir={cl_genesis} \
--datadir=${cl_dir} \
--datadir={cl_bn_dir} \
--staking \
--slots-per-restore-point={cl_slots_per_rp} \
--enr-address={ext_ip} \
Expand Down Expand Up @@ -405,23 +406,52 @@ fi
// Disable this line in the `ddev` mod
cmd_run_part_1.push_str(" --enable-private-discovery");

let cmd_run_part_2 = format!(" >>{cl_dir}/{EL_LOG_NAME} 2>&1 ");
let cmd_run_part_2 = format!(" >>{cl_bn_dir}/{CL_BN_LOG_NAME} 2>&1 ");

cmd_run_part_0 + &cmd_run_part_1 + &cmd_run_part_2
};

let cl_vc_cmd = format!("");
let cl_vc_cmd = {
let beacon_nodes = format!("http://{local_ip}:{}", n.ports.cl_bn_rpc);

let cmd_run_part_0 = if n.id == *e.bootstraps.keys().next().unwrap() {
// The first bootstrap node
format!(
r#"
if [[ ! -d '{cl_vc_dir}/validators' ]]; then
mkdir -p {cl_vc_dir} || exit 1
tar -C {cl_vc_dir} -xpf {home}/{NODE_HOME_VCDATA_DST} || exit 1
mv $(tar -tf {home}/{NODE_HOME_VCDATA_DST} | head -1)/* ./ || exit 1
fi "#
)
} else {
String::new()
};

let cmd_run_part_1 = format!(
r#"
{lighthouse}/lighthouse validator_client \
--testnet-dir={cl_genesis} \
--datadir={cl_vc_dir}\
--beacon-nodes='{beacon_nodes} \
--init-slashing-protection \
--suggested-fee-recipient={FEE_RECIPIENT} \
--unencrypted-http-transport \
--http --http-address={ext_ip} \
--http-port={cl_vc_rpc_port} --http-allow-origin='*' \
--metrics --metrics-address={ext_ip} \
--metrics-port={cl_vc_metric_port} --metrics-allow-origin='*' \
>>{cl_vc_dir}/{CL_VC_LOG_NAME} 2>&1 "#
);

cmd_run_part_0 + &cmd_run_part_1
};

////////////////////////////////////////////////
// FINAL
////////////////////////////////////////////////

format!(
"{el_cmd} >>{0}/{EL_LOG_NAME} 2>&1 &
{cl_bn_cmd} >>{0}/{CL_BN_LOG_NAME} 2>&1 &
{cl_vc_cmd} >>{0}/{CL_VC_LOG_NAME} 2>&1 &",
n.home
)
format!("{prepare_cmd} & {el_cmd} & {cl_bn_cmd} & {cl_vc_cmd} &")
}

fn cmd_for_stop(
Expand Down

0 comments on commit 21ed7a1

Please sign in to comment.