mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +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| {
|
|state, execution_optimistic, finalized| {
|
||||||
let epoch = state.current_epoch();
|
let epoch = state.current_epoch();
|
||||||
let far_future_epoch = chain.spec.far_future_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((
|
Ok((
|
||||||
state
|
state
|
||||||
@@ -42,10 +52,11 @@ pub fn get_beacon_state_validators<T: BeaconChainTypes>(
|
|||||||
far_future_epoch,
|
far_future_epoch,
|
||||||
);
|
);
|
||||||
|
|
||||||
let status_matches = query_statuses.as_ref().is_none_or(|statuses| {
|
let status_matches =
|
||||||
statuses.contains(&status)
|
statuses_filter_set.as_ref().is_none_or(|statuses| {
|
||||||
|| statuses.contains(&status.superstatus())
|
statuses.contains(&status)
|
||||||
});
|
|| statuses.contains(&status.superstatus())
|
||||||
|
});
|
||||||
|
|
||||||
if status_matches {
|
if status_matches {
|
||||||
Some(ValidatorData {
|
Some(ValidatorData {
|
||||||
|
|||||||
@@ -1079,7 +1079,7 @@ impl ApiTester {
|
|||||||
.get_beacon_states_validators(
|
.get_beacon_states_validators(
|
||||||
state_id.0,
|
state_id.0,
|
||||||
Some(validator_index_ids.as_slice()),
|
Some(validator_index_ids.as_slice()),
|
||||||
None,
|
Some(statuses.as_slice()),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -1089,20 +1089,28 @@ impl ApiTester {
|
|||||||
.get_beacon_states_validators(
|
.get_beacon_states_validators(
|
||||||
state_id.0,
|
state_id.0,
|
||||||
Some(validator_pubkey_ids.as_slice()),
|
Some(validator_pubkey_ids.as_slice()),
|
||||||
None,
|
Some(statuses.as_slice()),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.map(|res| res.data);
|
.map(|res| res.data);
|
||||||
let post_result_index_ids = self
|
let post_result_index_ids = self
|
||||||
.client
|
.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
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.map(|res| res.data);
|
.map(|res| res.data);
|
||||||
let post_result_pubkey_ids = self
|
let post_result_pubkey_ids = self
|
||||||
.client
|
.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
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.map(|res| res.data);
|
.map(|res| res.data);
|
||||||
@@ -1113,7 +1121,13 @@ impl ApiTester {
|
|||||||
|
|
||||||
let mut validators = Vec::with_capacity(validator_indices.len());
|
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 {
|
if i >= state.validators().len() as u64 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1123,8 +1137,8 @@ impl ApiTester {
|
|||||||
epoch,
|
epoch,
|
||||||
far_future_epoch,
|
far_future_epoch,
|
||||||
);
|
);
|
||||||
if statuses.contains(&status)
|
if statuses.is_empty()
|
||||||
|| statuses.is_empty()
|
|| statuses.contains(&status)
|
||||||
|| statuses.contains(&status.superstatus())
|
|| statuses.contains(&status.superstatus())
|
||||||
{
|
{
|
||||||
validators.push(ValidatorData {
|
validators.push(ValidatorData {
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ pub struct ValidatorIdentityData {
|
|||||||
// this proposal:
|
// this proposal:
|
||||||
//
|
//
|
||||||
// https://hackmd.io/bQxMDRt1RbS1TLno8K4NPg?view
|
// 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")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum ValidatorStatus {
|
pub enum ValidatorStatus {
|
||||||
PendingInitialized,
|
PendingInitialized,
|
||||||
|
|||||||
Reference in New Issue
Block a user