mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-05 05:44:30 +00:00
Anchor pre-PR: Decouple eth2 (#6770)
* decouple `eth2` from `store` and `lighthouse_network` Co-authored-by: Pawan Dhananjay <pawandhananjay@gmail.com> * remove unused dependency --------- Co-authored-by: Pawan Dhananjay <pawandhananjay@gmail.com> Co-authored-by: Jimmy Chen <jimmy@sigmaprime.io>
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -2563,14 +2563,16 @@ name = "eth2"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"derivative",
|
||||
"enr",
|
||||
"eth2_keystore",
|
||||
"ethereum_serde_utils",
|
||||
"ethereum_ssz",
|
||||
"ethereum_ssz_derive",
|
||||
"futures",
|
||||
"futures-util",
|
||||
"lighthouse_network",
|
||||
"libp2p-identity",
|
||||
"mediatype",
|
||||
"multiaddr",
|
||||
"pretty_reqwest_error",
|
||||
"procfs",
|
||||
"proto_array",
|
||||
@@ -2582,7 +2584,6 @@ dependencies = [
|
||||
"serde_json",
|
||||
"slashing_protection",
|
||||
"ssz_types",
|
||||
"store",
|
||||
"tokio",
|
||||
"types",
|
||||
"zeroize",
|
||||
@@ -3023,7 +3024,6 @@ dependencies = [
|
||||
"builder_client",
|
||||
"bytes",
|
||||
"eth2",
|
||||
"eth2_network_config",
|
||||
"ethereum_serde_utils",
|
||||
"ethereum_ssz",
|
||||
"ethers-core",
|
||||
@@ -5314,6 +5314,7 @@ dependencies = [
|
||||
"dirs",
|
||||
"discv5",
|
||||
"either",
|
||||
"eth2",
|
||||
"ethereum_ssz",
|
||||
"ethereum_ssz_derive",
|
||||
"fnv",
|
||||
|
||||
@@ -12,7 +12,6 @@ arc-swap = "1.6.0"
|
||||
builder_client = { path = "../builder_client" }
|
||||
bytes = { workspace = true }
|
||||
eth2 = { workspace = true }
|
||||
eth2_network_config = { workspace = true }
|
||||
ethereum_serde_utils = { workspace = true }
|
||||
ethereum_ssz = { workspace = true }
|
||||
ethers-core = { workspace = true }
|
||||
|
||||
@@ -30,6 +30,7 @@ rand = { workspace = true }
|
||||
safe_arith = { workspace = true }
|
||||
sensitive_url = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
slog = { workspace = true }
|
||||
slot_clock = { workspace = true }
|
||||
state_processing = { workspace = true }
|
||||
@@ -48,7 +49,6 @@ warp_utils = { workspace = true }
|
||||
genesis = { workspace = true }
|
||||
logging = { workspace = true }
|
||||
proto_array = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
[[test]]
|
||||
name = "bn_http_api_tests"
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
use beacon_chain::store::metadata::CURRENT_SCHEMA_VERSION;
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use eth2::lighthouse::DatabaseInfo;
|
||||
use serde::Serialize;
|
||||
use std::sync::Arc;
|
||||
use store::{AnchorInfo, BlobInfo, Split, StoreConfig};
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct DatabaseInfo {
|
||||
pub schema_version: u64,
|
||||
pub config: StoreConfig,
|
||||
pub split: Split,
|
||||
pub anchor: AnchorInfo,
|
||||
pub blob_info: BlobInfo,
|
||||
}
|
||||
|
||||
pub fn info<T: BeaconChainTypes>(
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
|
||||
@@ -3059,9 +3059,9 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
peer_id: peer_id.to_string(),
|
||||
enr: peer_info.enr().map(|enr| enr.to_base64()),
|
||||
last_seen_p2p_address: address,
|
||||
direction: api_types::PeerDirection::from_connection_direction(dir),
|
||||
state: api_types::PeerState::from_peer_connection_status(
|
||||
peer_info.connection_status(),
|
||||
direction: api_types::PeerDirection::from((*dir).clone()),
|
||||
state: api_types::PeerState::from(
|
||||
peer_info.connection_status().clone(),
|
||||
),
|
||||
}));
|
||||
}
|
||||
@@ -3104,10 +3104,9 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
|
||||
// the eth2 API spec implies only peers we have been connected to at some point should be included.
|
||||
if let Some(dir) = peer_info.connection_direction() {
|
||||
let direction =
|
||||
api_types::PeerDirection::from_connection_direction(dir);
|
||||
let state = api_types::PeerState::from_peer_connection_status(
|
||||
peer_info.connection_status(),
|
||||
let direction = api_types::PeerDirection::from((*dir).clone());
|
||||
let state = api_types::PeerState::from(
|
||||
peer_info.connection_status().clone(),
|
||||
);
|
||||
|
||||
let state_matches = query.state.as_ref().map_or(true, |states| {
|
||||
@@ -3160,9 +3159,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.read()
|
||||
.peers()
|
||||
.for_each(|(_, peer_info)| {
|
||||
let state = api_types::PeerState::from_peer_connection_status(
|
||||
peer_info.connection_status(),
|
||||
);
|
||||
let state =
|
||||
api_types::PeerState::from(peer_info.connection_status().clone());
|
||||
match state {
|
||||
api_types::PeerState::Connected => connected += 1,
|
||||
api_types::PeerState::Connecting => connecting += 1,
|
||||
@@ -4175,15 +4173,18 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
|task_spawner: TaskSpawner<T::EthSpec>,
|
||||
network_globals: Arc<NetworkGlobals<T::EthSpec>>| {
|
||||
task_spawner.blocking_json_task(Priority::P1, move || {
|
||||
Ok(network_globals
|
||||
.peers
|
||||
.read()
|
||||
.peers()
|
||||
.map(|(peer_id, peer_info)| eth2::lighthouse::Peer {
|
||||
let mut peers = vec![];
|
||||
for (peer_id, peer_info) in network_globals.peers.read().peers() {
|
||||
peers.push(eth2::lighthouse::Peer {
|
||||
peer_id: peer_id.to_string(),
|
||||
peer_info: peer_info.clone(),
|
||||
})
|
||||
.collect::<Vec<_>>())
|
||||
peer_info: serde_json::to_value(peer_info).map_err(|e| {
|
||||
warp_utils::reject::custom_not_found(format!(
|
||||
"unable to serialize peer_info: {e:?}",
|
||||
))
|
||||
})?,
|
||||
});
|
||||
}
|
||||
Ok(peers)
|
||||
})
|
||||
},
|
||||
);
|
||||
@@ -4199,15 +4200,18 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
|task_spawner: TaskSpawner<T::EthSpec>,
|
||||
network_globals: Arc<NetworkGlobals<T::EthSpec>>| {
|
||||
task_spawner.blocking_json_task(Priority::P1, move || {
|
||||
Ok(network_globals
|
||||
.peers
|
||||
.read()
|
||||
.connected_peers()
|
||||
.map(|(peer_id, peer_info)| eth2::lighthouse::Peer {
|
||||
let mut peers = vec![];
|
||||
for (peer_id, peer_info) in network_globals.peers.read().connected_peers() {
|
||||
peers.push(eth2::lighthouse::Peer {
|
||||
peer_id: peer_id.to_string(),
|
||||
peer_info: peer_info.clone(),
|
||||
})
|
||||
.collect::<Vec<_>>())
|
||||
peer_info: serde_json::to_value(peer_info).map_err(|e| {
|
||||
warp_utils::reject::custom_not_found(format!(
|
||||
"unable to serialize peer_info: {e:?}",
|
||||
))
|
||||
})?,
|
||||
});
|
||||
}
|
||||
Ok(peers)
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
@@ -35,6 +35,7 @@ use state_processing::per_slot_processing;
|
||||
use state_processing::state_advance::partial_state_advance;
|
||||
use std::convert::TryInto;
|
||||
use std::sync::Arc;
|
||||
use store::{AnchorInfo, Split};
|
||||
use tokio::time::Duration;
|
||||
use tree_hash::TreeHash;
|
||||
use types::application_domain::ApplicationDomain;
|
||||
@@ -5646,10 +5647,16 @@ impl ApiTester {
|
||||
pub async fn test_get_lighthouse_database_info(self) -> Self {
|
||||
let info = self.client.get_lighthouse_database_info().await.unwrap();
|
||||
|
||||
assert_eq!(info.anchor, self.chain.store.get_anchor_info());
|
||||
assert_eq!(info.split, self.chain.store.get_split_info());
|
||||
assert_eq!(
|
||||
info.schema_version,
|
||||
serde_json::from_value::<AnchorInfo>(info.get("anchor").unwrap().clone()).unwrap(),
|
||||
self.chain.store.get_anchor_info()
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::from_value::<Split>(info.get("split").unwrap().clone()).unwrap(),
|
||||
self.chain.store.get_split_info()
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::from_value::<u64>(info.get("schema_version").unwrap().clone()).unwrap(),
|
||||
store::metadata::CURRENT_SCHEMA_VERSION.as_u64()
|
||||
);
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ directory = { workspace = true }
|
||||
dirs = { workspace = true }
|
||||
discv5 = { workspace = true }
|
||||
either = { workspace = true }
|
||||
eth2 = { workspace = true }
|
||||
ethereum_ssz = { workspace = true }
|
||||
ethereum_ssz_derive = { workspace = true }
|
||||
fnv = { workspace = true }
|
||||
|
||||
@@ -4,6 +4,7 @@ use super::sync_status::SyncStatus;
|
||||
use crate::discovery::Eth2Enr;
|
||||
use crate::{rpc::MetaData, types::Subnet};
|
||||
use discv5::Enr;
|
||||
use eth2::types::{PeerDirection, PeerState};
|
||||
use libp2p::core::multiaddr::{Multiaddr, Protocol};
|
||||
use serde::{
|
||||
ser::{SerializeStruct, Serializer},
|
||||
@@ -506,6 +507,15 @@ pub enum ConnectionDirection {
|
||||
Outgoing,
|
||||
}
|
||||
|
||||
impl From<ConnectionDirection> for PeerDirection {
|
||||
fn from(direction: ConnectionDirection) -> Self {
|
||||
match direction {
|
||||
ConnectionDirection::Incoming => PeerDirection::Inbound,
|
||||
ConnectionDirection::Outgoing => PeerDirection::Outbound,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Connection Status of the peer.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub enum PeerConnectionStatus {
|
||||
@@ -599,3 +609,14 @@ impl Serialize for PeerConnectionStatus {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PeerConnectionStatus> for PeerState {
|
||||
fn from(status: PeerConnectionStatus) -> Self {
|
||||
match status {
|
||||
Connected { .. } => PeerState::Connected,
|
||||
Dialing { .. } => PeerState::Connecting,
|
||||
Disconnecting { .. } => PeerState::Disconnecting,
|
||||
Disconnected { .. } | Banned { .. } | Unknown => PeerState::Disconnected,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
mod globals;
|
||||
mod pubsub;
|
||||
mod subnet;
|
||||
mod sync_state;
|
||||
mod topics;
|
||||
|
||||
use types::{BitVector, EthSpec};
|
||||
@@ -11,10 +10,10 @@ pub type EnrSyncCommitteeBitfield<E> = BitVector<<E as EthSpec>::SyncCommitteeSu
|
||||
|
||||
pub type Enr = discv5::enr::Enr<discv5::enr::CombinedKey>;
|
||||
|
||||
pub use eth2::lighthouse::sync_state::{BackFillState, SyncState};
|
||||
pub use globals::NetworkGlobals;
|
||||
pub use pubsub::{PubsubMessage, SnappyTransform};
|
||||
pub use subnet::{Subnet, SubnetDiscovery};
|
||||
pub use sync_state::{BackFillState, SyncState};
|
||||
pub use topics::{
|
||||
attestation_sync_committee_topics, core_topics_to_subscribe, fork_core_topics,
|
||||
subnet_from_topic_hash, GossipEncoding, GossipKind, GossipTopic, ALTAIR_CORE_TOPICS,
|
||||
|
||||
@@ -7,14 +7,16 @@ edition = { workspace = true }
|
||||
|
||||
[dependencies]
|
||||
derivative = { workspace = true }
|
||||
enr = { version = "0.13.0", features = ["ed25519"] }
|
||||
eth2_keystore = { workspace = true }
|
||||
ethereum_serde_utils = { workspace = true }
|
||||
ethereum_ssz = { workspace = true }
|
||||
ethereum_ssz_derive = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
futures-util = "0.3.8"
|
||||
lighthouse_network = { workspace = true }
|
||||
libp2p-identity = { version = "0.2", features = ["peerid"] }
|
||||
mediatype = "0.19.13"
|
||||
multiaddr = "0.18.2"
|
||||
pretty_reqwest_error = { workspace = true }
|
||||
proto_array = { workspace = true }
|
||||
reqwest = { workspace = true }
|
||||
@@ -24,7 +26,6 @@ serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
slashing_protection = { workspace = true }
|
||||
ssz_types = { workspace = true }
|
||||
store = { workspace = true }
|
||||
types = { workspace = true }
|
||||
zeroize = { workspace = true }
|
||||
|
||||
@@ -37,4 +38,4 @@ procfs = { version = "0.15.1", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["lighthouse"]
|
||||
lighthouse = ["psutil", "procfs"]
|
||||
lighthouse = ["dep:psutil", "dep:procfs"]
|
||||
|
||||
@@ -16,10 +16,11 @@ pub mod types;
|
||||
|
||||
use self::mixin::{RequestAccept, ResponseOptional};
|
||||
use self::types::{Error as ResponseError, *};
|
||||
use ::types::fork_versioned_response::ExecutionOptimisticFinalizedForkVersionedResponse;
|
||||
use derivative::Derivative;
|
||||
use futures::Stream;
|
||||
use futures_util::StreamExt;
|
||||
use lighthouse_network::PeerId;
|
||||
use libp2p_identity::PeerId;
|
||||
use pretty_reqwest_error::PrettyReqwestError;
|
||||
pub use reqwest;
|
||||
use reqwest::{
|
||||
@@ -35,7 +36,6 @@ use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::path::PathBuf;
|
||||
use std::time::Duration;
|
||||
use store::fork_versioned_response::ExecutionOptimisticFinalizedForkVersionedResponse;
|
||||
|
||||
pub const V1: EndpointVersion = EndpointVersion(1);
|
||||
pub const V2: EndpointVersion = EndpointVersion(2);
|
||||
|
||||
@@ -6,18 +6,16 @@ mod block_packing_efficiency;
|
||||
mod block_rewards;
|
||||
mod standard_block_rewards;
|
||||
mod sync_committee_rewards;
|
||||
pub mod sync_state;
|
||||
|
||||
use crate::{
|
||||
types::{
|
||||
DepositTreeSnapshot, Epoch, EthSpec, FinalizedExecutionBlock, GenericResponse, ValidatorId,
|
||||
},
|
||||
types::{DepositTreeSnapshot, Epoch, FinalizedExecutionBlock, GenericResponse, ValidatorId},
|
||||
BeaconNodeHttpClient, DepositData, Error, Eth1Data, Hash256, Slot,
|
||||
};
|
||||
use proto_array::core::ProtoArray;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz::four_byte_option_impl;
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use store::{AnchorInfo, BlobInfo, Split, StoreConfig};
|
||||
|
||||
pub use attestation_performance::{
|
||||
AttestationPerformance, AttestationPerformanceQuery, AttestationPerformanceStatistics,
|
||||
@@ -27,7 +25,6 @@ pub use block_packing_efficiency::{
|
||||
BlockPackingEfficiency, BlockPackingEfficiencyQuery, ProposerInfo, UniqueAttestation,
|
||||
};
|
||||
pub use block_rewards::{AttestationRewards, BlockReward, BlockRewardMeta, BlockRewardsQuery};
|
||||
pub use lighthouse_network::{types::SyncState, PeerInfo};
|
||||
pub use standard_block_rewards::StandardBlockReward;
|
||||
pub use sync_committee_rewards::SyncCommitteeReward;
|
||||
|
||||
@@ -37,14 +34,12 @@ four_byte_option_impl!(four_byte_option_u64, u64);
|
||||
four_byte_option_impl!(four_byte_option_hash256, Hash256);
|
||||
|
||||
/// Information returned by `peers` and `connected_peers`.
|
||||
// TODO: this should be deserializable..
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub struct Peer<E: EthSpec> {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Peer {
|
||||
/// The Peer's ID
|
||||
pub peer_id: String,
|
||||
/// The PeerInfo associated with the peer.
|
||||
pub peer_info: PeerInfo<E>,
|
||||
pub peer_info: serde_json::Value,
|
||||
}
|
||||
|
||||
/// The results of validators voting during an epoch.
|
||||
@@ -88,6 +83,7 @@ pub struct ValidatorInclusionData {
|
||||
pub is_previous_epoch_head_attester: bool,
|
||||
}
|
||||
|
||||
use crate::lighthouse::sync_state::SyncState;
|
||||
#[cfg(target_os = "linux")]
|
||||
use {
|
||||
psutil::cpu::os::linux::CpuTimesExt, psutil::memory::os::linux::VirtualMemoryExt,
|
||||
@@ -356,15 +352,6 @@ impl From<Eth1Block> for FinalizedExecutionBlock {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct DatabaseInfo {
|
||||
pub schema_version: u64,
|
||||
pub config: StoreConfig,
|
||||
pub split: Split,
|
||||
pub anchor: AnchorInfo,
|
||||
pub blob_info: BlobInfo,
|
||||
}
|
||||
|
||||
impl BeaconNodeHttpClient {
|
||||
/// `GET lighthouse/health`
|
||||
pub async fn get_lighthouse_health(&self) -> Result<GenericResponse<Health>, Error> {
|
||||
@@ -503,7 +490,7 @@ impl BeaconNodeHttpClient {
|
||||
}
|
||||
|
||||
/// `GET lighthouse/database/info`
|
||||
pub async fn get_lighthouse_database_info(&self) -> Result<DatabaseInfo, Error> {
|
||||
pub async fn get_lighthouse_database_info(&self) -> Result<serde_json::Value, Error> {
|
||||
let mut path = self.server.full.clone();
|
||||
|
||||
path.path_segments_mut()
|
||||
|
||||
@@ -5,8 +5,9 @@ use crate::{
|
||||
Error as ServerError, CONSENSUS_BLOCK_VALUE_HEADER, CONSENSUS_VERSION_HEADER,
|
||||
EXECUTION_PAYLOAD_BLINDED_HEADER, EXECUTION_PAYLOAD_VALUE_HEADER,
|
||||
};
|
||||
use lighthouse_network::{ConnectionDirection, Enr, Multiaddr, PeerConnectionStatus};
|
||||
use enr::{CombinedKey, Enr};
|
||||
use mediatype::{names, MediaType, MediaTypeList};
|
||||
use multiaddr::Multiaddr;
|
||||
use reqwest::header::HeaderMap;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde_json::Value;
|
||||
@@ -578,7 +579,7 @@ pub struct ChainHeadData {
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct IdentityData {
|
||||
pub peer_id: String,
|
||||
pub enr: Enr,
|
||||
pub enr: Enr<CombinedKey>,
|
||||
pub p2p_addresses: Vec<Multiaddr>,
|
||||
pub discovery_addresses: Vec<Multiaddr>,
|
||||
pub metadata: MetaData,
|
||||
@@ -853,19 +854,6 @@ pub enum PeerState {
|
||||
Disconnecting,
|
||||
}
|
||||
|
||||
impl PeerState {
|
||||
pub fn from_peer_connection_status(status: &PeerConnectionStatus) -> Self {
|
||||
match status {
|
||||
PeerConnectionStatus::Connected { .. } => PeerState::Connected,
|
||||
PeerConnectionStatus::Dialing { .. } => PeerState::Connecting,
|
||||
PeerConnectionStatus::Disconnecting { .. } => PeerState::Disconnecting,
|
||||
PeerConnectionStatus::Disconnected { .. }
|
||||
| PeerConnectionStatus::Banned { .. }
|
||||
| PeerConnectionStatus::Unknown => PeerState::Disconnected,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for PeerState {
|
||||
type Err = String;
|
||||
|
||||
@@ -898,15 +886,6 @@ pub enum PeerDirection {
|
||||
Outbound,
|
||||
}
|
||||
|
||||
impl PeerDirection {
|
||||
pub fn from_connection_direction(direction: &ConnectionDirection) -> Self {
|
||||
match direction {
|
||||
ConnectionDirection::Incoming => PeerDirection::Inbound,
|
||||
ConnectionDirection::Outgoing => PeerDirection::Outbound,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for PeerDirection {
|
||||
type Err = String;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user