mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
Do not filter validators by status if filter is an empty list (#7884)
69d2feb12a/apis/beacon/states/validators.yaml (L128-L130) says we need to not filter if the filter is an empty list.
Add a check for `statuses.is_empty()`.
This commit is contained in:
@@ -18,8 +18,18 @@ pub fn get_beacon_state_validators<T: BeaconChainTypes>(
|
||||
|state, execution_optimistic, finalized| {
|
||||
let epoch = state.current_epoch();
|
||||
let far_future_epoch = chain.spec.far_future_epoch;
|
||||
let ids_filter_set: Option<HashSet<&ValidatorId>> =
|
||||
query_ids.as_ref().map(HashSet::from_iter);
|
||||
|
||||
// Map [] to None, indicating that no filtering should be applied (return all
|
||||
// validators).
|
||||
let ids_filter_set: Option<HashSet<&ValidatorId>> = query_ids
|
||||
.as_ref()
|
||||
.filter(|list| !list.is_empty())
|
||||
.map(HashSet::from_iter);
|
||||
|
||||
let statuses_filter_set: Option<HashSet<&ValidatorStatus>> = query_statuses
|
||||
.as_ref()
|
||||
.filter(|list| !list.is_empty())
|
||||
.map(HashSet::from_iter);
|
||||
|
||||
Ok((
|
||||
state
|
||||
@@ -42,10 +52,11 @@ pub fn get_beacon_state_validators<T: BeaconChainTypes>(
|
||||
far_future_epoch,
|
||||
);
|
||||
|
||||
let status_matches = query_statuses.as_ref().is_none_or(|statuses| {
|
||||
statuses.contains(&status)
|
||||
|| statuses.contains(&status.superstatus())
|
||||
});
|
||||
let status_matches =
|
||||
statuses_filter_set.as_ref().is_none_or(|statuses| {
|
||||
statuses.contains(&status)
|
||||
|| statuses.contains(&status.superstatus())
|
||||
});
|
||||
|
||||
if status_matches {
|
||||
Some(ValidatorData {
|
||||
|
||||
@@ -1079,7 +1079,7 @@ impl ApiTester {
|
||||
.get_beacon_states_validators(
|
||||
state_id.0,
|
||||
Some(validator_index_ids.as_slice()),
|
||||
None,
|
||||
Some(statuses.as_slice()),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
@@ -1089,20 +1089,28 @@ impl ApiTester {
|
||||
.get_beacon_states_validators(
|
||||
state_id.0,
|
||||
Some(validator_pubkey_ids.as_slice()),
|
||||
None,
|
||||
Some(statuses.as_slice()),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.map(|res| res.data);
|
||||
let post_result_index_ids = self
|
||||
.client
|
||||
.post_beacon_states_validators(state_id.0, Some(validator_index_ids), None)
|
||||
.post_beacon_states_validators(
|
||||
state_id.0,
|
||||
Some(validator_index_ids),
|
||||
Some(statuses.clone()),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.map(|res| res.data);
|
||||
let post_result_pubkey_ids = self
|
||||
.client
|
||||
.post_beacon_states_validators(state_id.0, Some(validator_pubkey_ids), None)
|
||||
.post_beacon_states_validators(
|
||||
state_id.0,
|
||||
Some(validator_pubkey_ids),
|
||||
Some(statuses.clone()),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.map(|res| res.data);
|
||||
@@ -1113,7 +1121,13 @@ impl ApiTester {
|
||||
|
||||
let mut validators = Vec::with_capacity(validator_indices.len());
|
||||
|
||||
for i in validator_indices {
|
||||
let expected_indices = if validator_indices.is_empty() {
|
||||
(0..state.validators().len() as u64).collect()
|
||||
} else {
|
||||
validator_indices.clone()
|
||||
};
|
||||
|
||||
for i in expected_indices {
|
||||
if i >= state.validators().len() as u64 {
|
||||
continue;
|
||||
}
|
||||
@@ -1123,8 +1137,8 @@ impl ApiTester {
|
||||
epoch,
|
||||
far_future_epoch,
|
||||
);
|
||||
if statuses.contains(&status)
|
||||
|| statuses.is_empty()
|
||||
if statuses.is_empty()
|
||||
|| statuses.contains(&status)
|
||||
|| statuses.contains(&status.superstatus())
|
||||
{
|
||||
validators.push(ValidatorData {
|
||||
|
||||
@@ -366,7 +366,7 @@ pub struct ValidatorIdentityData {
|
||||
// this proposal:
|
||||
//
|
||||
// https://hackmd.io/bQxMDRt1RbS1TLno8K4NPg?view
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ValidatorStatus {
|
||||
PendingInitialized,
|
||||
|
||||
Reference in New Issue
Block a user