Skip to content

Commit

Permalink
impl get_boot_nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
haxjump committed Oct 8, 2024
1 parent 86950b7 commit 1714abc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
60 changes: 55 additions & 5 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use chaindev::beacon_based::common::{NodeMark, NodePorts};
use rayon::prelude::*;
use ruc::*;
use serde::{Deserialize, Serialize};
use serde_json::Value;

pub const GETH_MARK: NodeMark = 0;
pub const RETH_MARK: NodeMark = 1;
Expand Down Expand Up @@ -149,11 +151,59 @@ impl NodePorts for Ports {
}

/// Return: "enode,enode,enode"
pub fn el_get_bootnodes(rpc_endpoints: &[&str]) -> Result<String> {
todo!()
pub fn el_get_boot_nodes(rpc_endpoints: &[&str]) -> Result<String> {
let ret = rpc_endpoints
.par_iter()
.map(|addr| {
let body =
r#"{"jsonrpc":"2.0","method":"admin_nodeInfo","params":[],"id":1}"#;
let ret = ruc::http::post(
addr,
body.as_bytes(),
Some(&[("Content-Type", "application/json")]),
)
.c(d!())
.and_then(|(_code, resp)| serde_json::from_slice::<Value>(&resp).c(d!()))
.map(|v| pnk!(v["result"]["enode"].as_str()).to_owned());
info!(ret)
})
.filter(|i| i.is_ok())
.collect::<Result<Vec<_>>>()
.unwrap();

if ret.is_empty() {
return Err(eg!("No valid data return"));
}

Ok(ret.join(","))
}

/// Return: "enr,enr,enr"
pub fn cl_get_bootnodes(rpc_endpoints: &[&str]) -> Result<String> {
todo!()
/// Return: "(<enr,enr,enr>,<peer_id,peer_id,peer_id>)"
pub fn cl_get_boot_nodes(rpc_endpoints: &[&str]) -> Result<(String, String)> {
let ret: (Vec<_>, Vec<_>) = rpc_endpoints
.par_iter()
.map(|addr| {
let ret = ruc::http::get(
&format!("{addr}/eth/v1/node/identity"),
Some(&[("Content-Type", "application/json")]),
)
.c(d!())
.and_then(|(_code, resp)| serde_json::from_slice::<Value>(&resp).c(d!()))
.map(|v| {
(
pnk!(v["data"]["enr"].as_str()).to_owned(),
pnk!(v["data"]["peer_id"].as_str()).to_owned(),
)
});
info!(ret)
})
.filter(|i| i.is_ok())
.map(|i| i.unwrap())
.unzip();

if ret.0.is_empty() {
return Err(eg!("No valid data return"));
}

Ok((ret.0.join(","), ret.1.join(",")))
}
3 changes: 1 addition & 2 deletions src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use chaindev::{
};
use ruc::*;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::fs;

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -222,7 +221,7 @@ impl NodeCmdGenerator<Node<Ports>, EnvMeta<CustomInfo, Node<Ports>>> for CmdGene
.map(|i| i.as_str())
.collect::<Vec<_>>();
let el_bootnodes =
info!(el_get_bootnodes(&el_rpc_endpoints)).unwrap_or_default();
info!(el_get_boot_nodes(&el_rpc_endpoints)).unwrap_or_default();

let el_gc_mode = if matches!(n.kind, NodeKind::ArchiveNode) {
"archive"
Expand Down

0 comments on commit 1714abc

Please sign in to comment.