mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 03:31:45 +00:00
Empty list [] to return all validators balances (#7474)
The endpoint `/eth/v1/beacon/states/head/validator_balances` returns an empty data when the data field is `[]`. According to the beacon API spec, it should return the balances of all validators: Reference: https://ethereum.github.io/beacon-APIs/#/Beacon/postStateValidatorBalances `If the supplied list is empty (i.e. the body is []) or no body is supplied then balances will be returned for all validators.` This PR changes so that: `curl -X 'POST' 'http://localhost:5052/eth/v1/beacon/states/head/validator_balances' -d '[]' | jq` returns balances of all validators.
This commit is contained in:
@@ -709,7 +709,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.clone()
|
||||
.and(warp::path("validator_balances"))
|
||||
.and(warp::path::end())
|
||||
.and(warp_utils::json::json())
|
||||
.and(warp_utils::json::json_no_body())
|
||||
.then(
|
||||
|state_id: StateId,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
|
||||
@@ -81,8 +81,13 @@ pub fn get_beacon_state_validator_balances<T: BeaconChainTypes>(
|
||||
.map_state_and_execution_optimistic_and_finalized(
|
||||
&chain,
|
||||
|state, execution_optimistic, finalized| {
|
||||
let ids_filter_set: Option<HashSet<&ValidatorId>> =
|
||||
optional_ids.map(|f| HashSet::from_iter(f.iter()));
|
||||
let ids_filter_set: Option<HashSet<&ValidatorId>> = match optional_ids {
|
||||
// if optional_ids (the request data body) is [], returns a `None`, so that later when calling .is_none_or() will return True
|
||||
// Hence, all validators will pass through .filter(), and balances of all validators are returned, in accordance to the spec
|
||||
Some([]) => None,
|
||||
Some(ids) => Some(HashSet::from_iter(ids.iter())),
|
||||
None => None,
|
||||
};
|
||||
|
||||
Ok((
|
||||
state
|
||||
|
||||
Reference in New Issue
Block a user