Skip to content

Commit 574b204

Browse files
authored
decouple eth2 from store and lighthouse_network (#6680)
- #6452 (partially) Remove dependencies on `store` and `lighthouse_network` from `eth2`. This was achieved as follows: - depend on `enr` and `multiaddr` directly instead of using `lighthouse_network`'s reexports. - make `lighthouse_network` responsible for converting between API and internal types. - in two cases, remove complex internal types and use the generic `serde_json::Value` instead - this is not ideal, but should be fine for now, as this affects two internal non-spec endpoints which are meant for debugging, unstable, and subject to change without notice anyway. Inspired by #6679. The alternative is to move all relevant types to `eth2` or `types` instead - what do you think?
1 parent a6bdc47 commit 574b204

File tree

26 files changed

+190
-246
lines changed

26 files changed

+190
-246
lines changed

Cargo.lock

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon_node/beacon_chain/src/attestation_rewards.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes};
2-
use eth2::lighthouse::attestation_rewards::{IdealAttestationRewards, TotalAttestationRewards};
3-
use eth2::lighthouse::StandardAttestationRewards;
4-
use eth2::types::ValidatorId;
2+
use eth2::types::{
3+
IdealAttestationRewards, StandardAttestationRewards, TotalAttestationRewards, ValidatorId,
4+
};
55
use safe_arith::SafeArith;
66
use serde_utils::quoted_u64::Quoted;
77
use state_processing::common::base::{self, SqrtTotalActiveBalance};

beacon_node/beacon_chain/src/beacon_block_reward.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes, StateSkipConfig};
22
use attesting_indices_base::get_attesting_indices;
3-
use eth2::lighthouse::StandardBlockReward;
3+
use eth2::types::StandardBlockReward;
44
use safe_arith::SafeArith;
55
use state_processing::common::attesting_indices_base;
66
use state_processing::{

beacon_node/beacon_chain/src/sync_committee_rewards.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes};
22

3-
use eth2::lighthouse::SyncCommitteeReward;
3+
use eth2::types::SyncCommitteeReward;
44
use safe_arith::SafeArith;
55
use state_processing::per_block_processing::altair::sync_committee::compute_sync_aggregate_rewards;
66
use std::collections::HashMap;

beacon_node/beacon_chain/tests/rewards.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use beacon_chain::{
99
types::{Epoch, EthSpec, Keypair, MinimalEthSpec},
1010
BlockError, ChainConfig, StateSkipConfig, WhenSlotSkipped,
1111
};
12-
use eth2::lighthouse::attestation_rewards::TotalAttestationRewards;
13-
use eth2::lighthouse::StandardAttestationRewards;
14-
use eth2::types::ValidatorId;
12+
use eth2::types::{StandardAttestationRewards, TotalAttestationRewards, ValidatorId};
1513
use state_processing::{BlockReplayError, BlockReplayer};
1614
use std::array::IntoIter;
1715
use std::collections::HashMap;

beacon_node/execution_layer/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ arc-swap = "1.6.0"
1212
builder_client = { path = "../builder_client" }
1313
bytes = { workspace = true }
1414
eth2 = { workspace = true }
15-
eth2_network_config = { workspace = true }
1615
ethereum_serde_utils = { workspace = true }
1716
ethereum_ssz = { workspace = true }
1817
ethers-core = { workspace = true }

beacon_node/http_api/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ warp_utils = { workspace = true }
5050
[dev-dependencies]
5151
genesis = { workspace = true }
5252
proto_array = { workspace = true }
53-
serde_json = { workspace = true }
5453

5554
[[test]]
5655
name = "bn_http_api_tests"

beacon_node/http_api/src/database.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
use beacon_chain::store::metadata::CURRENT_SCHEMA_VERSION;
22
use beacon_chain::{BeaconChain, BeaconChainTypes};
3-
use eth2::lighthouse::DatabaseInfo;
3+
use serde::Serialize;
44
use std::sync::Arc;
5+
use store::{AnchorInfo, BlobInfo, Split, StoreConfig};
6+
7+
#[derive(Debug, Serialize)]
8+
pub struct DatabaseInfo {
9+
pub schema_version: u64,
10+
pub config: StoreConfig,
11+
pub split: Split,
12+
pub anchor: AnchorInfo,
13+
pub blob_info: BlobInfo,
14+
}
515

616
pub fn info<T: BeaconChainTypes>(
717
chain: Arc<BeaconChain<T>>,

beacon_node/http_api/src/lib.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mod builder_states;
1616
mod database;
1717
mod light_client;
1818
mod metrics;
19+
mod peer;
1920
mod produce_block;
2021
mod proposer_duties;
2122
mod publish_attestations;
@@ -3022,15 +3023,13 @@ pub fn serve<T: BeaconChainTypes>(
30223023
};
30233024

30243025
// the eth2 API spec implies only peers we have been connected to at some point should be included.
3025-
if let Some(dir) = peer_info.connection_direction().as_ref() {
3026+
if let Some(&dir) = peer_info.connection_direction() {
30263027
return Ok(api_types::GenericResponse::from(api_types::PeerData {
30273028
peer_id: peer_id.to_string(),
30283029
enr: peer_info.enr().map(|enr| enr.to_base64()),
30293030
last_seen_p2p_address: address,
3030-
direction: api_types::PeerDirection::from_connection_direction(dir),
3031-
state: api_types::PeerState::from_peer_connection_status(
3032-
peer_info.connection_status(),
3033-
),
3031+
direction: dir.into(),
3032+
state: peer_info.connection_status().clone().into(),
30343033
}));
30353034
}
30363035
}
@@ -3071,12 +3070,9 @@ pub fn serve<T: BeaconChainTypes>(
30713070
};
30723071

30733072
// the eth2 API spec implies only peers we have been connected to at some point should be included.
3074-
if let Some(dir) = peer_info.connection_direction() {
3075-
let direction =
3076-
api_types::PeerDirection::from_connection_direction(dir);
3077-
let state = api_types::PeerState::from_peer_connection_status(
3078-
peer_info.connection_status(),
3079-
);
3073+
if let Some(&dir) = peer_info.connection_direction() {
3074+
let direction = dir.into();
3075+
let state = peer_info.connection_status().clone().into();
30803076

30813077
let state_matches = query.state.as_ref().is_none_or(|states| {
30823078
states.iter().any(|state_param| *state_param == state)
@@ -3128,9 +3124,8 @@ pub fn serve<T: BeaconChainTypes>(
31283124
.read()
31293125
.peers()
31303126
.for_each(|(_, peer_info)| {
3131-
let state = api_types::PeerState::from_peer_connection_status(
3132-
peer_info.connection_status(),
3133-
);
3127+
let state =
3128+
api_types::PeerState::from(peer_info.connection_status().clone());
31343129
match state {
31353130
api_types::PeerState::Connected => connected += 1,
31363131
api_types::PeerState::Connecting => connecting += 1,
@@ -4089,7 +4084,7 @@ pub fn serve<T: BeaconChainTypes>(
40894084
.peers
40904085
.read()
40914086
.peers()
4092-
.map(|(peer_id, peer_info)| eth2::lighthouse::Peer {
4087+
.map(|(peer_id, peer_info)| peer::Peer {
40934088
peer_id: peer_id.to_string(),
40944089
peer_info: peer_info.clone(),
40954090
})
@@ -4109,15 +4104,14 @@ pub fn serve<T: BeaconChainTypes>(
41094104
|task_spawner: TaskSpawner<T::EthSpec>,
41104105
network_globals: Arc<NetworkGlobals<T::EthSpec>>| {
41114106
task_spawner.blocking_json_task(Priority::P1, move || {
4112-
Ok(network_globals
4113-
.peers
4114-
.read()
4115-
.connected_peers()
4116-
.map(|(peer_id, peer_info)| eth2::lighthouse::Peer {
4107+
let mut peers = vec![];
4108+
for (peer_id, peer_info) in network_globals.peers.read().connected_peers() {
4109+
peers.push(peer::Peer {
41174110
peer_id: peer_id.to_string(),
41184111
peer_info: peer_info.clone(),
4119-
})
4120-
.collect::<Vec<_>>())
4112+
});
4113+
}
4114+
Ok(peers)
41214115
})
41224116
},
41234117
);

beacon_node/http_api/src/peer.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use lighthouse_network::PeerInfo;
2+
use serde::Serialize;
3+
use types::EthSpec;
4+
5+
/// Information returned by `peers` and `connected_peers`.
6+
#[derive(Debug, Clone, Serialize)]
7+
#[serde(bound = "E: EthSpec")]
8+
pub(crate) struct Peer<E: EthSpec> {
9+
/// The Peer's ID
10+
pub peer_id: String,
11+
/// The PeerInfo associated with the peer.
12+
pub peer_info: PeerInfo<E>,
13+
}

0 commit comments

Comments
 (0)