mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
There are certain crates which we re-export within `types` which creates a fragmented DevEx, where there are various ways to import the same crates.
```rust
// consensus/types/src/lib.rs
pub use bls::{
AggregatePublicKey, AggregateSignature, Error as BlsError, Keypair, PUBLIC_KEY_BYTES_LEN,
PublicKey, PublicKeyBytes, SIGNATURE_BYTES_LEN, SecretKey, Signature, SignatureBytes,
get_withdrawal_credentials,
};
pub use context_deserialize::{ContextDeserialize, context_deserialize};
pub use fixed_bytes::FixedBytesExtended;
pub use milhouse::{self, List, Vector};
pub use ssz_types::{BitList, BitVector, FixedVector, VariableList, typenum, typenum::Unsigned};
pub use superstruct::superstruct;
```
This PR removes these re-exports and makes it explicit that these types are imported from a non-`consensus/types` crate.
Co-Authored-By: Mac L <mjladson@pm.me>
71 lines
2.6 KiB
Rust
71 lines
2.6 KiB
Rust
use clap::ArgMatches;
|
|
use fixed_bytes::FixedBytesExtended;
|
|
use lighthouse_network::{
|
|
NETWORK_KEY_FILENAME, NetworkConfig,
|
|
discovery::{CombinedKey, ENR_FILENAME, build_enr},
|
|
libp2p::identity::secp256k1,
|
|
};
|
|
use network_utils::enr_ext::CombinedKeyExt;
|
|
use std::io::Write;
|
|
use std::path::PathBuf;
|
|
use std::{fs, net::Ipv4Addr};
|
|
use std::{fs::File, num::NonZeroU16};
|
|
use types::{ChainSpec, EnrForkId, Epoch, EthSpec, Hash256};
|
|
|
|
pub fn run<E: EthSpec>(matches: &ArgMatches, spec: &ChainSpec) -> Result<(), String> {
|
|
let ip: Ipv4Addr = clap_utils::parse_required(matches, "ip")?;
|
|
let udp_port: NonZeroU16 = clap_utils::parse_required(matches, "udp-port")?;
|
|
let tcp_port: NonZeroU16 = clap_utils::parse_required(matches, "tcp-port")?;
|
|
let output_dir: PathBuf = clap_utils::parse_required(matches, "output-dir")?;
|
|
let genesis_fork_version: [u8; 4] =
|
|
clap_utils::parse_ssz_required(matches, "genesis-fork-version")?;
|
|
|
|
if output_dir.exists() {
|
|
return Err(format!(
|
|
"{:?} already exists, will not override",
|
|
output_dir
|
|
));
|
|
}
|
|
|
|
let mut config = NetworkConfig::default();
|
|
config.enr_address = (Some(ip), None);
|
|
config.enr_udp4_port = Some(udp_port);
|
|
config.enr_tcp6_port = Some(tcp_port);
|
|
|
|
let secp256k1_keypair = secp256k1::Keypair::generate();
|
|
let enr_key = CombinedKey::from_secp256k1(&secp256k1_keypair);
|
|
let genesis_fork_digest = spec.compute_fork_digest(Hash256::zero(), Epoch::new(0));
|
|
let enr_fork_id = EnrForkId {
|
|
fork_digest: genesis_fork_digest,
|
|
next_fork_version: genesis_fork_version,
|
|
next_fork_epoch: Epoch::max_value(), // FAR_FUTURE_EPOCH
|
|
};
|
|
let enr = build_enr::<E>(
|
|
&enr_key,
|
|
&config,
|
|
&enr_fork_id,
|
|
spec.custody_requirement,
|
|
genesis_fork_digest,
|
|
spec,
|
|
)
|
|
.map_err(|e| format!("Unable to create ENR: {:?}", e))?;
|
|
|
|
fs::create_dir_all(&output_dir).map_err(|e| format!("Unable to create output-dir: {:?}", e))?;
|
|
|
|
let mut enr_file = File::create(output_dir.join(ENR_FILENAME))
|
|
.map_err(|e| format!("Unable to create {}: {:?}", ENR_FILENAME, e))?;
|
|
enr_file
|
|
.write_all(enr.to_base64().as_bytes())
|
|
.map_err(|e| format!("Unable to write ENR to {}: {:?}", ENR_FILENAME, e))?;
|
|
|
|
let mut key_file = File::create(output_dir.join(NETWORK_KEY_FILENAME))
|
|
.map_err(|e| format!("Unable to create {}: {:?}", NETWORK_KEY_FILENAME, e))?;
|
|
|
|
let secret_bytes = secp256k1_keypair.secret().to_bytes();
|
|
key_file
|
|
.write_all(&secret_bytes)
|
|
.map_err(|e| format!("Unable to write key to {}: {:?}", NETWORK_KEY_FILENAME, e))?;
|
|
|
|
Ok(())
|
|
}
|