Skip to content

Commit

Permalink
dft
Browse files Browse the repository at this point in the history
  • Loading branch information
haxjump committed Oct 8, 2024
1 parent 033d3b6 commit 0d9a1a8
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 26 deletions.
60 changes: 38 additions & 22 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use chaindev::beacon_dev::NodePorts;
use chaindev::beacon_based::common::{NodeMark, NodePorts};
use ruc::*;
use serde::{Deserialize, Serialize};

pub const GETH_MARK: NodeMark = 0;
pub const RETH_MARK: NodeMark = 1;

pub const EL_LOG_NAME: &str = "el.log";
pub const CL_BN_LOG_NAME: &str = "cl.bn.log";
pub const CL_VC_LOG_NAME: &str = "cl.vc.log";

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CustomInfo {
pub el_geth_bin: String,
Expand Down Expand Up @@ -34,18 +41,19 @@ impl CustomInfo {
/// Active ports of a node
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct Ports {
el_discovery: u16,
el_discovery_v5: u16, // reth only
el_engine_api: u16,
el_rpc: u16,
el_metric: u16, // geth only

cl_discovery: u16,
cl_discovery_quic: u16,
cl_bn_rpc: u16,
cl_vc_rpc: u16,
cl_bn_metric: u16,
cl_vc_metric: u16,
pub el_discovery: u16,
pub el_discovery_v5: u16, // reth only
pub el_engine_api: u16,
pub el_rpc: u16,
pub el_rpc_ws: u16,
pub el_metric: u16, // geth only

pub cl_discovery: u16,
pub cl_discovery_quic: u16,
pub cl_bn_rpc: u16,
pub cl_vc_rpc: u16,
pub cl_bn_metric: u16,
pub cl_vc_metric: u16,
}

impl NodePorts for Ports {
Expand All @@ -59,14 +67,15 @@ impl NodePorts for Ports {
el_discovery_v5: ports[1], // reth only
el_engine_api: ports[2],
el_rpc: ports[3],
el_metric: ports[4], // geth only

cl_discovery: ports[5],
cl_discovery_quic: ports[6],
cl_bn_rpc: ports[7],
cl_vc_rpc: ports[8],
cl_bn_metric: ports[9],
cl_vc_metric: ports[10],
el_rpc_ws: ports[4],
el_metric: ports[5], // geth only

cl_discovery: ports[6],
cl_discovery_quic: ports[7],
cl_bn_rpc: ports[8],
cl_vc_rpc: ports[9],
cl_bn_metric: ports[10],
cl_vc_metric: ports[11],
};

Ok(i)
Expand All @@ -80,6 +89,7 @@ impl NodePorts for Ports {
self.el_discovery_v5,
self.el_engine_api,
self.el_rpc,
self.el_rpc_ws,
self.el_metric,
self.cl_discovery,
self.cl_discovery_quic,
Expand All @@ -103,11 +113,17 @@ impl NodePorts for Ports {
}

/// The rpc listening port in the app side,
/// eg. ETH el(geth/reth) web3 API rpc
/// eg. ETH el(geth/reth) web3 http API rpc
fn get_el_rpc(&self) -> u16 {
self.el_rpc
}

/// The rpc listening port in the app side,
/// eg. ETH el(geth/reth) web3 websocket API rpc
fn get_el_rpc_ws(&self) -> u16 {
self.el_rpc_ws
}

/// The p2p(tcp/udp protocol) listening port in the beacon side
/// may be used in generating the ENR address for a beacon node
fn get_cl_p2p_bn(&self) -> u16 {
Expand Down
2 changes: 1 addition & 1 deletion src/ddev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl From<DDevCfg> for EnvCfg {
}
Op::PushNode((
host_addr.map(|a| pnk!(HostAddr::from_str(&a))),
alt!(is_reth, 1, 0),
alt!(is_reth, RETH_MARK, GETH_MARK),
is_archive,
))
}
Expand Down
98 changes: 95 additions & 3 deletions src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ use crate::{
common::*,
};
use chaindev::{
beacon_dev::{self, EnvMeta, Node, NodeCmdGenerator, NodePorts, Op},
beacon_dev::{
self, EnvMeta, Node, NodeCmdGenerator, NodeKind, NodePorts, Op,
NODE_HOME_GENESIS_DST, NODE_HOME_VCDATA_DST,
},
EnvName,
};
use ruc::*;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::fs;

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -122,7 +126,7 @@ impl From<DevCfg> for EnvCfg {
if let Some(n) = env_name {
en = n.into();
}
Op::PushNode((alt!(is_reth, 1, 0), is_archive))
Op::PushNode((alt!(is_reth, RETH_MARK, GETH_MARK), is_archive))
}
DevOp::KickNode { env_name, node_id } => {
if let Some(n) = env_name {
Expand Down Expand Up @@ -172,7 +176,95 @@ impl NodeCmdGenerator<Node<Ports>, EnvMeta<CustomInfo, Node<Ports>>> for CmdGene
n: &Node<Ports>,
e: &EnvMeta<CustomInfo, Node<Ports>>,
) -> String {
todo!()
let mark = n.mark.unwrap_or(GETH_MARK);

let home = &n.home;
let genesis_dir = format!("{home}/genesis");
let auth_jwt = format!("{home}/auth.jwt");

pnk!(fs::write(&auth_jwt, ruc::algo::rand::rand_jwt()));

let ext_ip = &e.host_ip;
let local_ip = &e.host_ip;

let online_nodes = e.nodes_should_be_online.iter().take(3);

let el_cmd = if GETH_MARK == mark {
let geth = &e.custom_data.el_geth_bin;
let el_genesis = format!("{genesis_dir}/genesis.json");
let el_dir = format!("{home}/el");
let el_discovery_port = n.ports.el_discovery;
let el_discovery_v5_port = n.ports.el_discovery_v5;
let el_rpc_port = n.ports.el_rpc;
let el_rpc_ws_port = n.ports.el_rpc_ws;
let el_engine_port = n.ports.el_engine_api;
let el_metric_port = n.ports.el_metric;

let el_bootnodes = ""; // TODO HTTP REQ

let el_gc_mode = if matches!(n.kind, NodeKind::ArchiveNode) {
"archive"
} else {
"full"
};

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 {genesis_dir} \
>>{el_dir}/{EL_LOG_NAME} 2>&1 || exit 1
fi
"#
);

let cmd_run_part_0 = format!(
r#"
{geth} \
--syncmode=full \
--gcmode={el_gc_mode} \
--networkid=$(grep -Po '(?<="chainId":)\s*\d+' {el_genesis} | tr -d ' ') \
--datadir={el_dir} \
--state.scheme=hash \
--nat=extip:{ext_ip} \
--discovery.port={el_discovery_port} \
--discovery.v5={el_discovery_v5_port}
--http --http.addr={local_ip} --http.port={el_rpc_port} --http.vhosts='*' --http.corsdomain='*' \
--http.api='admin,debug,eth,net,txpool,web3,rpc' \
--ws --ws.addr={local_ip} --ws.port={el_rpc_ws_port}--ws.origins='*' \
--ws.api='net,eth' \
--authrpc.addr={local_ip} --authrpc.port={el_engine_port}\
--authrpc.jwtsecret={auth_jwt} \
--metrics \
--metrics.port={el_metric_port}"#
);

let cmd_run_part_1 = if el_bootnodes.is_empty() {
String::new()
} else {
format!(" --bootnodes={el_bootnodes}")
};

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

cmd_init_part + &cmd_run_part_0 + &cmd_run_part_1 + &cmd_run_part_2
} else if RETH_MARK == mark {
format!("")
} else {
pnk!(Err(eg!("The fucking world is over!")))
};

let cl_bn_cmd = format!("");
let cl_vc_cmd = format!("");

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
)
}

fn cmd_for_stop(
Expand Down

0 comments on commit 0d9a1a8

Please sign in to comment.