Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions beacon_node/beacon_chain/src/attestation_rewards.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes};
use eth2::lighthouse::attestation_rewards::{IdealAttestationRewards, TotalAttestationRewards};
use eth2::lighthouse::StandardAttestationRewards;
use eth2::types::ValidatorId;
use eth2::types::{
IdealAttestationRewards, StandardAttestationRewards, TotalAttestationRewards, ValidatorId,
};
use safe_arith::SafeArith;
use serde_utils::quoted_u64::Quoted;
use slog::debug;
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/beacon_block_reward.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes, StateSkipConfig};
use attesting_indices_base::get_attesting_indices;
use eth2::lighthouse::StandardBlockReward;
use eth2::types::StandardBlockReward;
use safe_arith::SafeArith;
use slog::error;
use state_processing::common::attesting_indices_base;
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/sync_committee_rewards.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes};

use eth2::lighthouse::SyncCommitteeReward;
use eth2::types::SyncCommitteeReward;
use safe_arith::SafeArith;
use slog::error;
use state_processing::per_block_processing::altair::sync_committee::compute_sync_aggregate_rewards;
Expand Down
4 changes: 1 addition & 3 deletions beacon_node/beacon_chain/tests/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use beacon_chain::{
types::{Epoch, EthSpec, Keypair, MinimalEthSpec},
BlockError, ChainConfig, StateSkipConfig, WhenSlotSkipped,
};
use eth2::lighthouse::attestation_rewards::TotalAttestationRewards;
use eth2::lighthouse::StandardAttestationRewards;
use eth2::types::ValidatorId;
use eth2::types::{StandardAttestationRewards, TotalAttestationRewards, ValidatorId};
use state_processing::{BlockReplayError, BlockReplayer};
use std::array::IntoIter;
use std::collections::HashMap;
Expand Down
1 change: 0 additions & 1 deletion beacon_node/execution_layer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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 }
Expand All @@ -50,7 +51,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"
Expand Down
12 changes: 11 additions & 1 deletion beacon_node/http_api/src/database.rs
Original file line number Diff line number Diff line change
@@ -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>>,
Expand Down
38 changes: 16 additions & 22 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod builder_states;
mod database;
mod light_client;
mod metrics;
mod peer;
mod produce_block;
mod proposer_duties;
mod publish_attestations;
Expand Down Expand Up @@ -3092,15 +3093,13 @@ 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().as_ref() {
if let Some(&dir) = peer_info.connection_direction() {
return Ok(api_types::GenericResponse::from(api_types::PeerData {
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: dir.into(),
state: peer_info.connection_status().clone().into(),
}));
}
}
Expand Down Expand Up @@ -3141,12 +3140,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(),
);
if let Some(&dir) = peer_info.connection_direction() {
let direction = dir.into();
let state = peer_info.connection_status().clone().into();

let state_matches = query.state.as_ref().map_or(true, |states| {
states.iter().any(|state_param| *state_param == state)
Expand Down Expand Up @@ -3198,9 +3194,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,
Expand Down Expand Up @@ -4211,7 +4206,7 @@ pub fn serve<T: BeaconChainTypes>(
.peers
.read()
.peers()
.map(|(peer_id, peer_info)| eth2::lighthouse::Peer {
.map(|(peer_id, peer_info)| peer::Peer {
peer_id: peer_id.to_string(),
peer_info: peer_info.clone(),
})
Expand All @@ -4231,15 +4226,14 @@ 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(peer::Peer {
peer_id: peer_id.to_string(),
peer_info: peer_info.clone(),
})
.collect::<Vec<_>>())
});
}
Ok(peers)
})
},
);
Expand Down
13 changes: 13 additions & 0 deletions beacon_node/http_api/src/peer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use serde::Serialize;
use lighthouse_network::PeerInfo;
use types::EthSpec;

/// Information returned by `peers` and `connected_peers`.
#[derive(Debug, Clone, Serialize)]
#[serde(bound = "E: EthSpec")]
pub(crate) struct Peer<E: EthSpec> {
/// The Peer's ID
pub peer_id: String,
/// The PeerInfo associated with the peer.
pub peer_info: PeerInfo<E>,
}
2 changes: 1 addition & 1 deletion beacon_node/http_api/src/standard_block_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::sync_committee_rewards::get_state_before_applying_block;
use crate::BlockId;
use crate::ExecutionOptimistic;
use beacon_chain::{BeaconChain, BeaconChainTypes};
use eth2::lighthouse::StandardBlockReward;
use eth2::types::StandardBlockReward;
use std::sync::Arc;
use warp_utils::reject::unhandled_error;
/// The difference between block_rewards and beacon_block_rewards is the later returns block
Expand Down
3 changes: 1 addition & 2 deletions beacon_node/http_api/src/sync_committee_rewards.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{BlockId, ExecutionOptimistic};
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes};
use eth2::lighthouse::SyncCommitteeReward;
use eth2::types::ValidatorId;
use eth2::types::{SyncCommitteeReward, ValidatorId};
use slog::{debug, Logger};
use state_processing::BlockReplayer;
use std::sync::Arc;
Expand Down
16 changes: 1 addition & 15 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -5674,19 +5675,6 @@ impl ApiTester {
self
}

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,
store::metadata::CURRENT_SCHEMA_VERSION.as_u64()
);

self
}

pub async fn test_post_lighthouse_database_reconstruct(self) -> Self {
let response = self
.client
Expand Down Expand Up @@ -7225,8 +7213,6 @@ async fn lighthouse_endpoints() {
.await
.test_get_lighthouse_staking()
.await
.test_get_lighthouse_database_info()
.await
.test_post_lighthouse_database_reconstruct()
.await
.test_post_lighthouse_liveness()
Expand Down
1 change: 1 addition & 0 deletions beacon_node/lighthouse_network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -517,7 +518,7 @@ impl<E: EthSpec> PeerInfo<E> {
}

/// Connection Direction of connection.
#[derive(Debug, Clone, Serialize, AsRefStr)]
#[derive(Debug, Clone, Copy, Serialize, AsRefStr)]
#[strum(serialize_all = "snake_case")]
pub enum ConnectionDirection {
/// The connection was established by a peer dialing us.
Expand All @@ -526,6 +527,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 {
Expand Down Expand Up @@ -619,3 +629,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,
}
}
}
3 changes: 1 addition & 2 deletions beacon_node/lighthouse_network/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod globals;
mod pubsub;
mod subnet;
mod sync_state;
mod topics;

use types::{BitVector, EthSpec};
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions common/eth2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ name = "eth2"
version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = { workspace = true }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[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 }
Expand All @@ -24,7 +25,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 }

Expand Down
Loading
Loading