mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +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:
@@ -927,18 +927,32 @@ impl ApiTester {
|
||||
.map(|res| res.data);
|
||||
|
||||
let expected = state_opt.map(|(state, _execution_optimistic, _finalized)| {
|
||||
let mut validators = Vec::with_capacity(validator_indices.len());
|
||||
// If validator_indices is empty, return balances for all validators
|
||||
if validator_indices.is_empty() {
|
||||
state
|
||||
.balances()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, balance)| ValidatorBalanceData {
|
||||
index: index as u64,
|
||||
balance: *balance,
|
||||
})
|
||||
.collect()
|
||||
} else {
|
||||
// Same behaviour as before for the else branch
|
||||
let mut validators = Vec::with_capacity(validator_indices.len());
|
||||
|
||||
for i in validator_indices {
|
||||
if i < state.balances().len() as u64 {
|
||||
validators.push(ValidatorBalanceData {
|
||||
index: i,
|
||||
balance: *state.balances().get(i as usize).unwrap(),
|
||||
});
|
||||
for i in validator_indices {
|
||||
if i < state.balances().len() as u64 {
|
||||
validators.push(ValidatorBalanceData {
|
||||
index: i,
|
||||
balance: *state.balances().get(i as usize).unwrap(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
validators
|
||||
validators
|
||||
}
|
||||
});
|
||||
|
||||
assert_eq!(result_index_ids, expected, "{:?}", state_id);
|
||||
|
||||
Reference in New Issue
Block a user