mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-21 23:08:23 +00:00
merge upstream
This commit is contained in:
@@ -17,6 +17,7 @@ mod proposer_duties;
|
||||
mod publish_blocks;
|
||||
mod state_id;
|
||||
mod sync_committees;
|
||||
mod ui;
|
||||
mod validator_inclusion;
|
||||
mod version;
|
||||
|
||||
@@ -2940,6 +2941,18 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
},
|
||||
);
|
||||
|
||||
// GET lighthouse/ui/validator_count
|
||||
let get_lighthouse_ui_validator_count = warp::path("lighthouse")
|
||||
.and(warp::path("ui"))
|
||||
.and(warp::path("validator_count"))
|
||||
.and(warp::path::end())
|
||||
.and(chain_filter.clone())
|
||||
.and_then(|chain: Arc<BeaconChain<T>>| {
|
||||
blocking_json_task(move || {
|
||||
ui::get_validator_count(chain).map(api_types::GenericResponse::from)
|
||||
})
|
||||
});
|
||||
|
||||
// GET lighthouse/syncing
|
||||
let get_lighthouse_syncing = warp::path("lighthouse")
|
||||
.and(warp::path("syncing"))
|
||||
@@ -3408,6 +3421,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.or(get_lighthouse_attestation_performance.boxed())
|
||||
.or(get_lighthouse_block_packing_efficiency.boxed())
|
||||
.or(get_lighthouse_merge_readiness.boxed())
|
||||
.or(get_lighthouse_ui_validator_count.boxed())
|
||||
.or(get_events.boxed()),
|
||||
)
|
||||
.boxed()
|
||||
|
||||
71
beacon_node/http_api/src/ui.rs
Normal file
71
beacon_node/http_api/src/ui.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes};
|
||||
use eth2::types::ValidatorStatus;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use warp_utils::reject::beacon_chain_error;
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
|
||||
pub struct ValidatorCountResponse {
|
||||
pub active_ongoing: u64,
|
||||
pub active_exiting: u64,
|
||||
pub active_slashed: u64,
|
||||
pub pending_initialized: u64,
|
||||
pub pending_queued: u64,
|
||||
pub withdrawal_possible: u64,
|
||||
pub withdrawal_done: u64,
|
||||
pub exited_unslashed: u64,
|
||||
pub exited_slashed: u64,
|
||||
}
|
||||
|
||||
pub fn get_validator_count<T: BeaconChainTypes>(
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
) -> Result<ValidatorCountResponse, warp::Rejection> {
|
||||
let spec = &chain.spec;
|
||||
let mut active_ongoing = 0;
|
||||
let mut active_exiting = 0;
|
||||
let mut active_slashed = 0;
|
||||
let mut pending_initialized = 0;
|
||||
let mut pending_queued = 0;
|
||||
let mut withdrawal_possible = 0;
|
||||
let mut withdrawal_done = 0;
|
||||
let mut exited_unslashed = 0;
|
||||
let mut exited_slashed = 0;
|
||||
|
||||
chain
|
||||
.with_head(|head| {
|
||||
let state = &head.beacon_state;
|
||||
let epoch = state.current_epoch();
|
||||
for validator in state.validators() {
|
||||
let status =
|
||||
ValidatorStatus::from_validator(validator, epoch, spec.far_future_epoch);
|
||||
|
||||
match status {
|
||||
ValidatorStatus::ActiveOngoing => active_ongoing += 1,
|
||||
ValidatorStatus::ActiveExiting => active_exiting += 1,
|
||||
ValidatorStatus::ActiveSlashed => active_slashed += 1,
|
||||
ValidatorStatus::PendingInitialized => pending_initialized += 1,
|
||||
ValidatorStatus::PendingQueued => pending_queued += 1,
|
||||
ValidatorStatus::WithdrawalPossible => withdrawal_possible += 1,
|
||||
ValidatorStatus::WithdrawalDone => withdrawal_done += 1,
|
||||
ValidatorStatus::ExitedUnslashed => exited_unslashed += 1,
|
||||
ValidatorStatus::ExitedSlashed => exited_slashed += 1,
|
||||
// Since we are not invoking `superset`, all other variants will be 0.
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
Ok::<(), BeaconChainError>(())
|
||||
})
|
||||
.map_err(beacon_chain_error)?;
|
||||
|
||||
Ok(ValidatorCountResponse {
|
||||
active_ongoing,
|
||||
active_exiting,
|
||||
active_slashed,
|
||||
pending_initialized,
|
||||
pending_queued,
|
||||
withdrawal_possible,
|
||||
withdrawal_done,
|
||||
exited_unslashed,
|
||||
exited_slashed,
|
||||
})
|
||||
}
|
||||
@@ -2122,7 +2122,7 @@ impl ApiTester {
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_blinded_block_production<Payload: ExecPayload<E>>(&self) {
|
||||
pub async fn test_blinded_block_production<Payload: AbstractExecPayload<E>>(&self) {
|
||||
let fork = self.chain.canonical_head.cached_head().head_fork();
|
||||
let genesis_validators_root = self.chain.genesis_validators_root;
|
||||
|
||||
@@ -2182,7 +2182,7 @@ impl ApiTester {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn test_blinded_block_production_no_verify_randao<Payload: ExecPayload<E>>(
|
||||
pub async fn test_blinded_block_production_no_verify_randao<Payload: AbstractExecPayload<E>>(
|
||||
self,
|
||||
) -> Self {
|
||||
for _ in 0..E::slots_per_epoch() {
|
||||
@@ -2206,7 +2206,9 @@ impl ApiTester {
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_blinded_block_production_verify_randao_invalid<Payload: ExecPayload<E>>(
|
||||
pub async fn test_blinded_block_production_verify_randao_invalid<
|
||||
Payload: AbstractExecPayload<E>,
|
||||
>(
|
||||
self,
|
||||
) -> Self {
|
||||
let fork = self.chain.canonical_head.cached_head().head_fork();
|
||||
@@ -2664,7 +2666,7 @@ impl ApiTester {
|
||||
|
||||
let (proposer_index, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -2673,14 +2675,11 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
let expected_fee_recipient = Address::from_low_u64_be(proposer_index as u64);
|
||||
assert_eq!(
|
||||
payload.execution_payload_header.fee_recipient,
|
||||
expected_fee_recipient
|
||||
);
|
||||
assert_eq!(payload.execution_payload_header.gas_limit, 11_111_111);
|
||||
assert_eq!(payload.fee_recipient(), expected_fee_recipient);
|
||||
assert_eq!(payload.gas_limit(), 11_111_111);
|
||||
|
||||
// If this cache is empty, it indicates fallback was not used, so the payload came from the
|
||||
// mock builder.
|
||||
@@ -2707,7 +2706,7 @@ impl ApiTester {
|
||||
|
||||
let (proposer_index, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -2716,14 +2715,11 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
let expected_fee_recipient = Address::from_low_u64_be(proposer_index as u64);
|
||||
assert_eq!(
|
||||
payload.execution_payload_header.fee_recipient,
|
||||
expected_fee_recipient
|
||||
);
|
||||
assert_eq!(payload.execution_payload_header.gas_limit, 30_000_000);
|
||||
assert_eq!(payload.fee_recipient(), expected_fee_recipient);
|
||||
assert_eq!(payload.gas_limit(), 30_000_000);
|
||||
|
||||
// This cache should not be populated because fallback should not have been used.
|
||||
assert!(self
|
||||
@@ -2753,7 +2749,7 @@ impl ApiTester {
|
||||
|
||||
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -2762,12 +2758,9 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
assert_eq!(
|
||||
payload.execution_payload_header.fee_recipient,
|
||||
test_fee_recipient
|
||||
);
|
||||
assert_eq!(payload.fee_recipient(), test_fee_recipient);
|
||||
|
||||
// This cache should not be populated because fallback should not have been used.
|
||||
assert!(self
|
||||
@@ -2801,11 +2794,11 @@ impl ApiTester {
|
||||
.beacon_state
|
||||
.latest_execution_payload_header()
|
||||
.unwrap()
|
||||
.block_hash;
|
||||
.block_hash();
|
||||
|
||||
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -2814,12 +2807,9 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
assert_eq!(
|
||||
payload.execution_payload_header.parent_hash,
|
||||
expected_parent_hash
|
||||
);
|
||||
assert_eq!(payload.parent_hash(), expected_parent_hash);
|
||||
|
||||
// If this cache is populated, it indicates fallback to the local EE was correctly used.
|
||||
assert!(self
|
||||
@@ -2856,7 +2846,7 @@ impl ApiTester {
|
||||
|
||||
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -2865,12 +2855,9 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
assert_eq!(
|
||||
payload.execution_payload_header.prev_randao,
|
||||
expected_prev_randao
|
||||
);
|
||||
assert_eq!(payload.prev_randao(), expected_prev_randao);
|
||||
|
||||
// If this cache is populated, it indicates fallback to the local EE was correctly used.
|
||||
assert!(self
|
||||
@@ -2901,12 +2888,12 @@ impl ApiTester {
|
||||
.beacon_state
|
||||
.latest_execution_payload_header()
|
||||
.unwrap()
|
||||
.block_number
|
||||
.block_number()
|
||||
+ 1;
|
||||
|
||||
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -2915,12 +2902,9 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
assert_eq!(
|
||||
payload.execution_payload_header.block_number,
|
||||
expected_block_number
|
||||
);
|
||||
assert_eq!(payload.block_number(), expected_block_number);
|
||||
|
||||
// If this cache is populated, it indicates fallback to the local EE was correctly used.
|
||||
assert!(self
|
||||
@@ -2951,11 +2935,11 @@ impl ApiTester {
|
||||
.beacon_state
|
||||
.latest_execution_payload_header()
|
||||
.unwrap()
|
||||
.timestamp;
|
||||
.timestamp();
|
||||
|
||||
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -2964,9 +2948,9 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
assert!(payload.execution_payload_header.timestamp > min_expected_timestamp);
|
||||
assert!(payload.timestamp() > min_expected_timestamp);
|
||||
|
||||
// If this cache is populated, it indicates fallback to the local EE was correctly used.
|
||||
assert!(self
|
||||
@@ -2991,7 +2975,7 @@ impl ApiTester {
|
||||
|
||||
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -3000,7 +2984,7 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
// If this cache is populated, it indicates fallback to the local EE was correctly used.
|
||||
assert!(self
|
||||
@@ -3028,7 +3012,7 @@ impl ApiTester {
|
||||
|
||||
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -3037,7 +3021,7 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
// If this cache is populated, it indicates fallback to the local EE was correctly used.
|
||||
assert!(self
|
||||
@@ -3071,7 +3055,7 @@ impl ApiTester {
|
||||
.get_test_randao(next_slot, next_slot.epoch(E::slots_per_epoch()))
|
||||
.await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(next_slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -3080,7 +3064,7 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
// This cache should not be populated because fallback should not have been used.
|
||||
assert!(self
|
||||
@@ -3100,7 +3084,7 @@ impl ApiTester {
|
||||
.get_test_randao(next_slot, next_slot.epoch(E::slots_per_epoch()))
|
||||
.await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(next_slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -3109,7 +3093,7 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
// If this cache is populated, it indicates fallback to the local EE was correctly used.
|
||||
assert!(self
|
||||
@@ -3149,7 +3133,7 @@ impl ApiTester {
|
||||
.get_test_randao(next_slot, next_slot.epoch(E::slots_per_epoch()))
|
||||
.await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(next_slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -3158,7 +3142,7 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
// If this cache is populated, it indicates fallback to the local EE was correctly used.
|
||||
assert!(self
|
||||
@@ -3188,7 +3172,7 @@ impl ApiTester {
|
||||
.get_test_randao(next_slot, next_slot.epoch(E::slots_per_epoch()))
|
||||
.await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(next_slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -3197,7 +3181,7 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
// This cache should not be populated because fallback should not have been used.
|
||||
assert!(self
|
||||
@@ -3231,7 +3215,7 @@ impl ApiTester {
|
||||
|
||||
let (proposer_index, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -3240,13 +3224,10 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
let expected_fee_recipient = Address::from_low_u64_be(proposer_index as u64);
|
||||
assert_eq!(
|
||||
payload.execution_payload_header.fee_recipient,
|
||||
expected_fee_recipient
|
||||
);
|
||||
assert_eq!(payload.fee_recipient(), expected_fee_recipient);
|
||||
|
||||
// If this cache is populated, it indicates fallback to the local EE was correctly used.
|
||||
assert!(self
|
||||
@@ -3275,7 +3256,7 @@ impl ApiTester {
|
||||
|
||||
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload = self
|
||||
let payload: BlindedPayload<E> = self
|
||||
.client
|
||||
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
|
||||
.await
|
||||
@@ -3284,7 +3265,7 @@ impl ApiTester {
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.into();
|
||||
|
||||
// If this cache is populated, it indicates fallback to the local EE was correctly used.
|
||||
assert!(self
|
||||
|
||||
Reference in New Issue
Block a user