mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Remove error-chain dependency (#6628)
* remove error-chain dependency * rerun CI * rerun CI
This commit is contained in:
@@ -18,7 +18,6 @@ slog = { workspace = true }
|
||||
lighthouse_version = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
error-chain = { workspace = true }
|
||||
dirs = { workspace = true }
|
||||
fnv = { workspace = true }
|
||||
metrics = { workspace = true }
|
||||
|
||||
@@ -8,8 +8,8 @@ pub mod enr_ext;
|
||||
|
||||
// Allow external use of the lighthouse ENR builder
|
||||
use crate::service::TARGET_SUBNET_PEERS;
|
||||
use crate::{error, Enr, NetworkConfig, NetworkGlobals, Subnet, SubnetDiscovery};
|
||||
use crate::{metrics, ClearDialError};
|
||||
use crate::{Enr, NetworkConfig, NetworkGlobals, Subnet, SubnetDiscovery};
|
||||
use discv5::{enr::NodeId, Discv5};
|
||||
pub use enr::{build_enr, load_enr_from_disk, use_or_load_enr, CombinedKey, Eth2Enr};
|
||||
pub use enr_ext::{peer_id_to_node_id, CombinedKeyExt, EnrExt};
|
||||
@@ -205,7 +205,7 @@ impl<E: EthSpec> Discovery<E> {
|
||||
network_globals: Arc<NetworkGlobals<E>>,
|
||||
log: &slog::Logger,
|
||||
spec: &ChainSpec,
|
||||
) -> error::Result<Self> {
|
||||
) -> Result<Self, String> {
|
||||
let log = log.clone();
|
||||
|
||||
let enr_dir = match config.network_dir.to_str() {
|
||||
|
||||
@@ -101,7 +101,7 @@ impl<'a> std::fmt::Display for ClearDialError<'a> {
|
||||
}
|
||||
|
||||
pub use crate::types::{
|
||||
error, Enr, EnrSyncCommitteeBitfield, GossipTopic, NetworkGlobals, PubsubMessage, Subnet,
|
||||
Enr, EnrSyncCommitteeBitfield, GossipTopic, NetworkGlobals, PubsubMessage, Subnet,
|
||||
SubnetDiscovery,
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::discovery::enr_ext::EnrExt;
|
||||
use crate::discovery::peer_id_to_node_id;
|
||||
use crate::rpc::{GoodbyeReason, MetaData, Protocol, RPCError, RpcErrorResponse};
|
||||
use crate::service::TARGET_SUBNET_PEERS;
|
||||
use crate::{error, metrics, Gossipsub, NetworkGlobals, PeerId, Subnet, SubnetDiscovery};
|
||||
use crate::{metrics, Gossipsub, NetworkGlobals, PeerId, Subnet, SubnetDiscovery};
|
||||
use delay_map::HashSetDelay;
|
||||
use discv5::Enr;
|
||||
use libp2p::identify::Info as IdentifyInfo;
|
||||
@@ -144,7 +144,7 @@ impl<E: EthSpec> PeerManager<E> {
|
||||
cfg: config::Config,
|
||||
network_globals: Arc<NetworkGlobals<E>>,
|
||||
log: &slog::Logger,
|
||||
) -> error::Result<Self> {
|
||||
) -> Result<Self, String> {
|
||||
let config::Config {
|
||||
discovery_enabled,
|
||||
metrics_enabled,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::types::{GossipEncoding, GossipKind, GossipTopic};
|
||||
use crate::{error, TopicHash};
|
||||
use crate::TopicHash;
|
||||
use gossipsub::{IdentTopic as Topic, PeerScoreParams, PeerScoreThresholds, TopicScoreParams};
|
||||
use std::cmp::max;
|
||||
use std::collections::HashMap;
|
||||
@@ -84,7 +84,7 @@ impl<E: EthSpec> PeerScoreSettings<E> {
|
||||
thresholds: &PeerScoreThresholds,
|
||||
enr_fork_id: &EnrForkId,
|
||||
current_slot: Slot,
|
||||
) -> error::Result<PeerScoreParams> {
|
||||
) -> Result<PeerScoreParams, String> {
|
||||
let mut params = PeerScoreParams {
|
||||
decay_interval: self.decay_interval,
|
||||
decay_to_zero: self.decay_to_zero,
|
||||
@@ -175,7 +175,7 @@ impl<E: EthSpec> PeerScoreSettings<E> {
|
||||
&self,
|
||||
active_validators: usize,
|
||||
current_slot: Slot,
|
||||
) -> error::Result<(TopicScoreParams, TopicScoreParams, TopicScoreParams)> {
|
||||
) -> Result<(TopicScoreParams, TopicScoreParams, TopicScoreParams), String> {
|
||||
let (aggregators_per_slot, committees_per_slot) =
|
||||
self.expected_aggregator_count_per_slot(active_validators)?;
|
||||
let multiple_bursts_per_subnet_per_epoch =
|
||||
@@ -256,7 +256,7 @@ impl<E: EthSpec> PeerScoreSettings<E> {
|
||||
fn expected_aggregator_count_per_slot(
|
||||
&self,
|
||||
active_validators: usize,
|
||||
) -> error::Result<(f64, usize)> {
|
||||
) -> Result<(f64, usize), String> {
|
||||
let committees_per_slot = E::get_committee_count_per_slot_with(
|
||||
active_validators,
|
||||
self.max_committees_per_slot,
|
||||
|
||||
@@ -20,7 +20,7 @@ use crate::types::{
|
||||
};
|
||||
use crate::EnrExt;
|
||||
use crate::Eth2Enr;
|
||||
use crate::{error, metrics, Enr, NetworkGlobals, PubsubMessage, TopicHash};
|
||||
use crate::{metrics, Enr, NetworkGlobals, PubsubMessage, TopicHash};
|
||||
use api_types::{AppRequestId, PeerRequestId, RequestId, Response};
|
||||
use futures::stream::StreamExt;
|
||||
use gossipsub::{
|
||||
@@ -170,7 +170,7 @@ impl<E: EthSpec> Network<E> {
|
||||
executor: task_executor::TaskExecutor,
|
||||
mut ctx: ServiceContext<'_>,
|
||||
log: &slog::Logger,
|
||||
) -> error::Result<(Self, Arc<NetworkGlobals<E>>)> {
|
||||
) -> Result<(Self, Arc<NetworkGlobals<E>>), String> {
|
||||
let log = log.new(o!("service"=> "libp2p"));
|
||||
|
||||
let config = ctx.config.clone();
|
||||
@@ -515,7 +515,7 @@ impl<E: EthSpec> Network<E> {
|
||||
/// - Starts listening in the given ports.
|
||||
/// - Dials boot-nodes and libp2p peers.
|
||||
/// - Subscribes to starting gossipsub topics.
|
||||
async fn start(&mut self, config: &crate::NetworkConfig) -> error::Result<()> {
|
||||
async fn start(&mut self, config: &crate::NetworkConfig) -> Result<(), String> {
|
||||
let enr = self.network_globals.local_enr();
|
||||
info!(self.log, "Libp2p Starting"; "peer_id" => %enr.peer_id(), "bandwidth_config" => format!("{}-{}", config.network_load, NetworkLoad::from(config.network_load).name));
|
||||
debug!(self.log, "Attempting to open listening ports"; config.listen_addrs(), "discovery_enabled" => !config.disable_discovery, "quic_enabled" => !config.disable_quic_support);
|
||||
@@ -920,7 +920,7 @@ impl<E: EthSpec> Network<E> {
|
||||
&mut self,
|
||||
active_validators: usize,
|
||||
current_slot: Slot,
|
||||
) -> error::Result<()> {
|
||||
) -> Result<(), String> {
|
||||
let (beacon_block_params, beacon_aggregate_proof_params, beacon_attestation_subnet_params) =
|
||||
self.score_settings
|
||||
.get_dynamic_topic_params(active_validators, current_slot)?;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use crate::multiaddr::Protocol;
|
||||
use crate::rpc::methods::MetaDataV3;
|
||||
use crate::rpc::{MetaData, MetaDataV1, MetaDataV2};
|
||||
use crate::types::{
|
||||
error, EnrAttestationBitfield, EnrSyncCommitteeBitfield, GossipEncoding, GossipKind,
|
||||
};
|
||||
use crate::types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield, GossipEncoding, GossipKind};
|
||||
use crate::{GossipTopic, NetworkConfig};
|
||||
use futures::future::Either;
|
||||
use gossipsub;
|
||||
@@ -83,7 +81,7 @@ pub fn build_transport(
|
||||
|
||||
// Useful helper functions for debugging. Currently not used in the client.
|
||||
#[allow(dead_code)]
|
||||
fn keypair_from_hex(hex_bytes: &str) -> error::Result<Keypair> {
|
||||
fn keypair_from_hex(hex_bytes: &str) -> Result<Keypair, String> {
|
||||
let hex_bytes = if let Some(stripped) = hex_bytes.strip_prefix("0x") {
|
||||
stripped.to_string()
|
||||
} else {
|
||||
@@ -91,18 +89,18 @@ fn keypair_from_hex(hex_bytes: &str) -> error::Result<Keypair> {
|
||||
};
|
||||
|
||||
hex::decode(hex_bytes)
|
||||
.map_err(|e| format!("Failed to parse p2p secret key bytes: {:?}", e).into())
|
||||
.map_err(|e| format!("Failed to parse p2p secret key bytes: {:?}", e))
|
||||
.and_then(keypair_from_bytes)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn keypair_from_bytes(mut bytes: Vec<u8>) -> error::Result<Keypair> {
|
||||
fn keypair_from_bytes(mut bytes: Vec<u8>) -> Result<Keypair, String> {
|
||||
secp256k1::SecretKey::try_from_bytes(&mut bytes)
|
||||
.map(|secret| {
|
||||
let keypair: secp256k1::Keypair = secret.into();
|
||||
keypair.into()
|
||||
})
|
||||
.map_err(|e| format!("Unable to parse p2p secret key: {:?}", e).into())
|
||||
.map_err(|e| format!("Unable to parse p2p secret key: {:?}", e))
|
||||
}
|
||||
|
||||
/// Loads a private key from disk. If this fails, a new key is
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
// generates error types
|
||||
|
||||
use error_chain::error_chain;
|
||||
|
||||
error_chain! {}
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod error;
|
||||
mod globals;
|
||||
mod pubsub;
|
||||
mod subnet;
|
||||
|
||||
Reference in New Issue
Block a user