diff --git a/Cargo.lock b/Cargo.lock index d559c2f1fe3..2bbbb5e8647 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2518,14 +2518,16 @@ version = "0.1.0" dependencies = [ "derivative", "either", + "enr", "eth2_keystore", "ethereum_serde_utils", "ethereum_ssz", "ethereum_ssz_derive", "futures", "futures-util", - "lighthouse_network", + "libp2p-identity", "mediatype", + "multiaddr", "pretty_reqwest_error", "proto_array", "reqwest", @@ -2535,7 +2537,6 @@ dependencies = [ "serde_json", "slashing_protection", "ssz_types", - "store", "tokio", "types", "zeroize", @@ -2980,7 +2981,6 @@ dependencies = [ "builder_client", "bytes", "eth2", - "eth2_network_config", "ethereum_serde_utils", "ethereum_ssz", "ethers-core", @@ -5309,6 +5309,7 @@ dependencies = [ "dirs", "discv5", "either", + "eth2", "ethereum_ssz", "ethereum_ssz_derive", "fnv", @@ -9486,7 +9487,6 @@ name = "validator_test_rig" version = "0.1.0" dependencies = [ "eth2", - "logging", "mockito", "regex", "sensitive_url", @@ -9583,7 +9583,6 @@ dependencies = [ "bytes", "eth2", "headers", - "metrics", "safe_arith", "serde", "serde_array_query", diff --git a/beacon_node/beacon_chain/src/attestation_rewards.rs b/beacon_node/beacon_chain/src/attestation_rewards.rs index 97fe8dccd4d..c235143336a 100644 --- a/beacon_node/beacon_chain/src/attestation_rewards.rs +++ b/beacon_node/beacon_chain/src/attestation_rewards.rs @@ -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 state_processing::common::base::{self, SqrtTotalActiveBalance}; diff --git a/beacon_node/beacon_chain/src/beacon_block_reward.rs b/beacon_node/beacon_chain/src/beacon_block_reward.rs index 591102126fe..8808a3f1210 100644 --- a/beacon_node/beacon_chain/src/beacon_block_reward.rs +++ b/beacon_node/beacon_chain/src/beacon_block_reward.rs @@ -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 state_processing::common::attesting_indices_base; use state_processing::{ diff --git a/beacon_node/beacon_chain/src/sync_committee_rewards.rs b/beacon_node/beacon_chain/src/sync_committee_rewards.rs index e3ff5f4ab27..cf4cf1fff21 100644 --- a/beacon_node/beacon_chain/src/sync_committee_rewards.rs +++ b/beacon_node/beacon_chain/src/sync_committee_rewards.rs @@ -1,6 +1,6 @@ use crate::{BeaconChain, BeaconChainError, BeaconChainTypes}; -use eth2::lighthouse::SyncCommitteeReward; +use eth2::types::SyncCommitteeReward; use safe_arith::SafeArith; use state_processing::per_block_processing::altair::sync_committee::compute_sync_aggregate_rewards; use std::collections::HashMap; diff --git a/beacon_node/beacon_chain/tests/rewards.rs b/beacon_node/beacon_chain/tests/rewards.rs index 06e0cf890e4..b75b06caffb 100644 --- a/beacon_node/beacon_chain/tests/rewards.rs +++ b/beacon_node/beacon_chain/tests/rewards.rs @@ -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; diff --git a/beacon_node/execution_layer/Cargo.toml b/beacon_node/execution_layer/Cargo.toml index 580eac3c882..f56159c7b55 100644 --- a/beacon_node/execution_layer/Cargo.toml +++ b/beacon_node/execution_layer/Cargo.toml @@ -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 } diff --git a/beacon_node/http_api/Cargo.toml b/beacon_node/http_api/Cargo.toml index a4352f1c3d9..b13517f27eb 100644 --- a/beacon_node/http_api/Cargo.toml +++ b/beacon_node/http_api/Cargo.toml @@ -50,7 +50,6 @@ warp_utils = { workspace = true } [dev-dependencies] genesis = { workspace = true } proto_array = { workspace = true } -serde_json = { workspace = true } [[test]] name = "bn_http_api_tests" diff --git a/beacon_node/http_api/src/database.rs b/beacon_node/http_api/src/database.rs index aa8b0e8ffca..8a50ec45b08 100644 --- a/beacon_node/http_api/src/database.rs +++ b/beacon_node/http_api/src/database.rs @@ -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( chain: Arc>, diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index b6ad8da128e..1b8cdc56051 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -16,6 +16,7 @@ mod builder_states; mod database; mod light_client; mod metrics; +mod peer; mod produce_block; mod proposer_duties; mod publish_attestations; @@ -3022,15 +3023,13 @@ pub fn serve( }; // 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(), })); } } @@ -3071,12 +3070,9 @@ pub fn serve( }; // 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().is_none_or(|states| { states.iter().any(|state_param| *state_param == state) @@ -3128,9 +3124,8 @@ pub fn serve( .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, @@ -4089,7 +4084,7 @@ pub fn serve( .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(), }) @@ -4109,15 +4104,14 @@ pub fn serve( |task_spawner: TaskSpawner, network_globals: Arc>| { 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::>()) + }); + } + Ok(peers) }) }, ); diff --git a/beacon_node/http_api/src/peer.rs b/beacon_node/http_api/src/peer.rs new file mode 100644 index 00000000000..c9aea9d87cf --- /dev/null +++ b/beacon_node/http_api/src/peer.rs @@ -0,0 +1,13 @@ +use lighthouse_network::PeerInfo; +use serde::Serialize; +use types::EthSpec; + +/// Information returned by `peers` and `connected_peers`. +#[derive(Debug, Clone, Serialize)] +#[serde(bound = "E: EthSpec")] +pub(crate) struct Peer { + /// The Peer's ID + pub peer_id: String, + /// The PeerInfo associated with the peer. + pub peer_info: PeerInfo, +} diff --git a/beacon_node/http_api/src/standard_block_rewards.rs b/beacon_node/http_api/src/standard_block_rewards.rs index 372a2765da4..2f78649d78f 100644 --- a/beacon_node/http_api/src/standard_block_rewards.rs +++ b/beacon_node/http_api/src/standard_block_rewards.rs @@ -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 diff --git a/beacon_node/http_api/src/sync_committee_rewards.rs b/beacon_node/http_api/src/sync_committee_rewards.rs index e5a9d9daeae..d7e8a1f9efa 100644 --- a/beacon_node/http_api/src/sync_committee_rewards.rs +++ b/beacon_node/http_api/src/sync_committee_rewards.rs @@ -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 state_processing::BlockReplayer; use std::sync::Arc; use tracing::debug; diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 2020130d18e..ddeda8b66d8 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -5686,19 +5686,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 @@ -7254,8 +7241,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() diff --git a/beacon_node/lighthouse_network/Cargo.toml b/beacon_node/lighthouse_network/Cargo.toml index d60bfc37355..8cae529de04 100644 --- a/beacon_node/lighthouse_network/Cargo.toml +++ b/beacon_node/lighthouse_network/Cargo.toml @@ -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 } diff --git a/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs b/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs index 4cbff59ce24..4cb94ca3837 100644 --- a/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs +++ b/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs @@ -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}, @@ -522,7 +523,7 @@ impl PeerInfo { } /// 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. @@ -531,6 +532,15 @@ pub enum ConnectionDirection { Outgoing, } +impl From 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 { @@ -624,3 +634,14 @@ impl Serialize for PeerConnectionStatus { } } } + +impl From for PeerState { + fn from(status: PeerConnectionStatus) -> Self { + match status { + Connected { .. } => PeerState::Connected, + Dialing { .. } => PeerState::Connecting, + Disconnecting { .. } => PeerState::Disconnecting, + Disconnected { .. } | Banned { .. } | Unknown => PeerState::Disconnected, + } + } +} diff --git a/beacon_node/lighthouse_network/src/types/mod.rs b/beacon_node/lighthouse_network/src/types/mod.rs index db92f05b8fd..868cdb6eb9f 100644 --- a/beacon_node/lighthouse_network/src/types/mod.rs +++ b/beacon_node/lighthouse_network/src/types/mod.rs @@ -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 = BitVector<::SyncCommitteeSu pub type Enr = discv5::enr::Enr; +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::{ all_topics_at_fork, core_topics_to_subscribe, is_fork_non_core_topic, subnet_from_topic_hash, GossipEncoding, GossipKind, GossipTopic, TopicConfig, diff --git a/common/eth2/Cargo.toml b/common/eth2/Cargo.toml index a1bc9d025bd..35dd806fb35 100644 --- a/common/eth2/Cargo.toml +++ b/common/eth2/Cargo.toml @@ -3,19 +3,20 @@ name = "eth2" version = "0.1.0" authors = ["Paul Hauner "] edition = { workspace = true } -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] derivative = { workspace = true } either = { 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 } @@ -25,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 } diff --git a/common/eth2/src/lib.rs b/common/eth2/src/lib.rs index 73e9d57abc0..358fe12a847 100644 --- a/common/eth2/src/lib.rs +++ b/common/eth2/src/lib.rs @@ -16,11 +16,12 @@ pub mod types; use self::mixin::{RequestAccept, ResponseOptional}; use self::types::{Error as ResponseError, *}; +use ::types::fork_versioned_response::ExecutionOptimisticFinalizedForkVersionedResponse; use derivative::Derivative; use either::Either; 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::{ @@ -36,7 +37,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); @@ -329,7 +329,6 @@ impl BeaconNodeHttpClient { } /// Perform a HTTP POST request, returning a JSON response. - #[cfg(feature = "lighthouse")] async fn post_with_response( &self, url: U, @@ -1602,33 +1601,34 @@ impl BeaconNodeHttpClient { /// `POST beacon/rewards/sync_committee` pub async fn post_beacon_rewards_sync_committee( &self, - rewards: &[Option>], - ) -> Result<(), Error> { + block_id: BlockId, + validators: &[ValidatorId], + ) -> Result>, Error> { let mut path = self.eth_path(V1)?; path.path_segments_mut() .map_err(|()| Error::InvalidUrl(self.server.clone()))? .push("beacon") .push("rewards") - .push("sync_committee"); - - self.post(path, &rewards).await?; + .push("sync_committee") + .push(&block_id.to_string()); - Ok(()) + self.post_with_response(path, &validators).await } /// `GET beacon/rewards/blocks` - pub async fn get_beacon_rewards_blocks(&self, epoch: Epoch) -> Result<(), Error> { + pub async fn get_beacon_rewards_blocks( + &self, + block_id: BlockId, + ) -> Result, Error> { let mut path = self.eth_path(V1)?; path.path_segments_mut() .map_err(|()| Error::InvalidUrl(self.server.clone()))? .push("beacon") .push("rewards") - .push("blocks"); - - path.query_pairs_mut() - .append_pair("epoch", &epoch.to_string()); + .push("blocks") + .push(&block_id.to_string()); self.get(path).await } @@ -1636,19 +1636,19 @@ impl BeaconNodeHttpClient { /// `POST beacon/rewards/attestations` pub async fn post_beacon_rewards_attestations( &self, - attestations: &[ValidatorId], - ) -> Result<(), Error> { + epoch: Epoch, + validators: &[ValidatorId], + ) -> Result { let mut path = self.eth_path(V1)?; path.path_segments_mut() .map_err(|()| Error::InvalidUrl(self.server.clone()))? .push("beacon") .push("rewards") - .push("attestations"); - - self.post(path, &attestations).await?; + .push("attestations") + .push(&epoch.to_string()); - Ok(()) + self.post_with_response(path, &validators).await } // GET builder/states/{state_id}/expected_withdrawals diff --git a/common/eth2/src/lighthouse.rs b/common/eth2/src/lighthouse.rs index badc4857c4c..a9f2f471b0f 100644 --- a/common/eth2/src/lighthouse.rs +++ b/common/eth2/src/lighthouse.rs @@ -1,52 +1,33 @@ //! This module contains endpoints that are non-standard and only available on Lighthouse servers. mod attestation_performance; -pub mod attestation_rewards; 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, - }, + lighthouse::sync_state::SyncState, + 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, }; -pub use attestation_rewards::StandardAttestationRewards; 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; // Define "legacy" implementations of `Option` which use four bytes for encoding the union // selector. 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 { - /// The Peer's ID - pub peer_id: String, - /// The PeerInfo associated with the peer. - pub peer_info: PeerInfo, -} - /// The results of validators voting during an epoch. /// /// Provides information about the current and previous epochs. @@ -234,15 +215,6 @@ impl From 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, Error> { @@ -380,19 +352,6 @@ impl BeaconNodeHttpClient { self.get_opt::<(), _>(path).await.map(|opt| opt.is_some()) } - /// `GET lighthouse/database/info` - pub async fn get_lighthouse_database_info(&self) -> Result { - let mut path = self.server.full.clone(); - - path.path_segments_mut() - .map_err(|()| Error::InvalidUrl(self.server.clone()))? - .push("lighthouse") - .push("database") - .push("info"); - - self.get(path).await - } - /// `POST lighthouse/database/reconstruct` pub async fn post_lighthouse_database_reconstruct(&self) -> Result { let mut path = self.server.full.clone(); diff --git a/common/eth2/src/lighthouse/attestation_rewards.rs b/common/eth2/src/lighthouse/attestation_rewards.rs deleted file mode 100644 index fa3f93d06f8..00000000000 --- a/common/eth2/src/lighthouse/attestation_rewards.rs +++ /dev/null @@ -1,55 +0,0 @@ -use serde::{Deserialize, Serialize}; -use serde_utils::quoted_u64::Quoted; - -// Details about the rewards paid for attestations -// All rewards in GWei - -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] -pub struct IdealAttestationRewards { - // Validator's effective balance in gwei - #[serde(with = "serde_utils::quoted_u64")] - pub effective_balance: u64, - // Ideal attester's reward for head vote in gwei - #[serde(with = "serde_utils::quoted_u64")] - pub head: u64, - // Ideal attester's reward for target vote in gwei - #[serde(with = "serde_utils::quoted_u64")] - pub target: u64, - // Ideal attester's reward for source vote in gwei - #[serde(with = "serde_utils::quoted_u64")] - pub source: u64, - // Ideal attester's inclusion_delay reward in gwei (phase0 only) - #[serde(skip_serializing_if = "Option::is_none")] - pub inclusion_delay: Option>, - // Ideal attester's inactivity penalty in gwei - #[serde(with = "serde_utils::quoted_i64")] - pub inactivity: i64, -} - -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] -pub struct TotalAttestationRewards { - // one entry for every validator based on their attestations in the epoch - #[serde(with = "serde_utils::quoted_u64")] - pub validator_index: u64, - // attester's reward for head vote in gwei - #[serde(with = "serde_utils::quoted_i64")] - pub head: i64, - // attester's reward for target vote in gwei - #[serde(with = "serde_utils::quoted_i64")] - pub target: i64, - // attester's reward for source vote in gwei - #[serde(with = "serde_utils::quoted_i64")] - pub source: i64, - // attester's inclusion_delay reward in gwei (phase0 only) - #[serde(skip_serializing_if = "Option::is_none")] - pub inclusion_delay: Option>, - // attester's inactivity penalty in gwei - #[serde(with = "serde_utils::quoted_i64")] - pub inactivity: i64, -} - -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] -pub struct StandardAttestationRewards { - pub ideal_rewards: Vec, - pub total_rewards: Vec, -} diff --git a/common/eth2/src/lighthouse/standard_block_rewards.rs b/common/eth2/src/lighthouse/standard_block_rewards.rs deleted file mode 100644 index 15fcdc60667..00000000000 --- a/common/eth2/src/lighthouse/standard_block_rewards.rs +++ /dev/null @@ -1,26 +0,0 @@ -use serde::{Deserialize, Serialize}; - -// Details about the rewards for a single block -// All rewards in GWei -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] -pub struct StandardBlockReward { - // proposer of the block, the proposer index who receives these rewards - #[serde(with = "serde_utils::quoted_u64")] - pub proposer_index: u64, - // total block reward in gwei, - // equal to attestations + sync_aggregate + proposer_slashings + attester_slashings - #[serde(with = "serde_utils::quoted_u64")] - pub total: u64, - // block reward component due to included attestations in gwei - #[serde(with = "serde_utils::quoted_u64")] - pub attestations: u64, - // block reward component due to included sync_aggregate in gwei - #[serde(with = "serde_utils::quoted_u64")] - pub sync_aggregate: u64, - // block reward component due to included proposer_slashings in gwei - #[serde(with = "serde_utils::quoted_u64")] - pub proposer_slashings: u64, - // block reward component due to included attester_slashings in gwei - #[serde(with = "serde_utils::quoted_u64")] - pub attester_slashings: u64, -} diff --git a/common/eth2/src/lighthouse/sync_committee_rewards.rs b/common/eth2/src/lighthouse/sync_committee_rewards.rs deleted file mode 100644 index 66a721dc229..00000000000 --- a/common/eth2/src/lighthouse/sync_committee_rewards.rs +++ /dev/null @@ -1,13 +0,0 @@ -use serde::{Deserialize, Serialize}; - -// Details about the rewards paid to sync committee members for attesting headers -// All rewards in GWei - -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] -pub struct SyncCommitteeReward { - #[serde(with = "serde_utils::quoted_u64")] - pub validator_index: u64, - // sync committee reward in gwei for the validator - #[serde(with = "serde_utils::quoted_i64")] - pub reward: i64, -} diff --git a/beacon_node/lighthouse_network/src/types/sync_state.rs b/common/eth2/src/lighthouse/sync_state.rs similarity index 100% rename from beacon_node/lighthouse_network/src/types/sync_state.rs rename to common/eth2/src/lighthouse/sync_state.rs diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index 59374f629d6..5cdbf80b05f 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -5,11 +5,13 @@ 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; +use serde_utils::quoted_u64::Quoted; use ssz::{Decode, DecodeError}; use ssz_derive::{Decode, Encode}; use std::fmt::{self, Display}; @@ -578,7 +580,7 @@ pub struct ChainHeadData { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct IdentityData { pub peer_id: String, - pub enr: Enr, + pub enr: Enr, pub p2p_addresses: Vec, pub discovery_addresses: Vec, pub metadata: MetaData, @@ -861,19 +863,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; @@ -906,15 +895,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; @@ -2066,6 +2046,90 @@ pub struct BlobsBundle { pub blobs: BlobsList, } +/// Details about the rewards paid to sync committee members for attesting headers +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +pub struct SyncCommitteeReward { + #[serde(with = "serde_utils::quoted_u64")] + pub validator_index: u64, + /// sync committee reward in gwei for the validator + #[serde(with = "serde_utils::quoted_i64")] + pub reward: i64, +} + +/// Details about the rewards for a single block +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +pub struct StandardBlockReward { + /// proposer of the block, the proposer index who receives these rewards + #[serde(with = "serde_utils::quoted_u64")] + pub proposer_index: u64, + /// total block reward in gwei, + /// equal to attestations + sync_aggregate + proposer_slashings + attester_slashings + #[serde(with = "serde_utils::quoted_u64")] + pub total: u64, + /// block reward component due to included attestations in gwei + #[serde(with = "serde_utils::quoted_u64")] + pub attestations: u64, + /// block reward component due to included sync_aggregate in gwei + #[serde(with = "serde_utils::quoted_u64")] + pub sync_aggregate: u64, + /// block reward component due to included proposer_slashings in gwei + #[serde(with = "serde_utils::quoted_u64")] + pub proposer_slashings: u64, + /// block reward component due to included attester_slashings in gwei + #[serde(with = "serde_utils::quoted_u64")] + pub attester_slashings: u64, +} + +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +pub struct IdealAttestationRewards { + /// Validator's effective balance in gwei + #[serde(with = "serde_utils::quoted_u64")] + pub effective_balance: u64, + /// Ideal attester's reward for head vote in gwei + #[serde(with = "serde_utils::quoted_u64")] + pub head: u64, + /// Ideal attester's reward for target vote in gwei + #[serde(with = "serde_utils::quoted_u64")] + pub target: u64, + /// Ideal attester's reward for source vote in gwei + #[serde(with = "serde_utils::quoted_u64")] + pub source: u64, + /// Ideal attester's inclusion_delay reward in gwei (phase0 only) + #[serde(skip_serializing_if = "Option::is_none")] + pub inclusion_delay: Option>, + /// Ideal attester's inactivity penalty in gwei + #[serde(with = "serde_utils::quoted_i64")] + pub inactivity: i64, +} + +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +pub struct TotalAttestationRewards { + /// one entry for every validator based on their attestations in the epoch + #[serde(with = "serde_utils::quoted_u64")] + pub validator_index: u64, + /// attester's reward for head vote in gwei + #[serde(with = "serde_utils::quoted_i64")] + pub head: i64, + /// attester's reward for target vote in gwei + #[serde(with = "serde_utils::quoted_i64")] + pub target: i64, + /// attester's reward for source vote in gwei + #[serde(with = "serde_utils::quoted_i64")] + pub source: i64, + /// attester's inclusion_delay reward in gwei (phase0 only) + #[serde(skip_serializing_if = "Option::is_none")] + pub inclusion_delay: Option>, + /// attester's inactivity penalty in gwei + #[serde(with = "serde_utils::quoted_i64")] + pub inactivity: i64, +} + +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +pub struct StandardAttestationRewards { + pub ideal_rewards: Vec, + pub total_rewards: Vec, +} + #[cfg(test)] mod test { use super::*; diff --git a/common/warp_utils/Cargo.toml b/common/warp_utils/Cargo.toml index ec2d23686b1..32a540a69d8 100644 --- a/common/warp_utils/Cargo.toml +++ b/common/warp_utils/Cargo.toml @@ -9,7 +9,6 @@ edition = { workspace = true } bytes = { workspace = true } eth2 = { workspace = true } headers = "0.3.2" -metrics = { workspace = true } safe_arith = { workspace = true } serde = { workspace = true } serde_array_query = "0.1.0" diff --git a/testing/validator_test_rig/Cargo.toml b/testing/validator_test_rig/Cargo.toml index bdbdac95d8b..f28a423433b 100644 --- a/testing/validator_test_rig/Cargo.toml +++ b/testing/validator_test_rig/Cargo.toml @@ -5,7 +5,6 @@ edition = { workspace = true } [dependencies] eth2 = { workspace = true } -logging = { workspace = true } mockito = { workspace = true } regex = { workspace = true } sensitive_url = { workspace = true }