mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
beacon-chain/rpc: use BalanceAtIndex instead of Balances to reduce memory copy (#13279)
* beacon-chain/rpc: use BalanceAtIndex instead of Balances Signed-off-by: jsvisa <delweng@gmail.com> * beacon-chain/rpc: stream use BalanceAtIndex is sufficient Signed-off-by: jsvisa <delweng@gmail.com> * beacon-chain/rpc: fix commit review Signed-off-by: jsvisa <delweng@gmail.com> * beacon-chain/rpc: http2 -> httputil Signed-off-by: jsvisa <delweng@gmail.com> --------- Signed-off-by: jsvisa <delweng@gmail.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
parent
bdfa06ed65
commit
0eb08a4f96
@ -97,7 +97,6 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
epoch := slots.ToEpoch(st.Slot())
|
||||
allBalances := st.Balances()
|
||||
|
||||
// Exit early if no matching validators were found or we don't want to further filter validators by status.
|
||||
if len(readOnlyVals) == 0 || len(statuses) == 0 {
|
||||
@ -108,11 +107,16 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
|
||||
httputil.HandleError(w, "Could not get validator status: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
containers[i] = valContainerFromReadOnlyVal(val, primitives.ValidatorIndex(i), allBalances[i], valStatus)
|
||||
} else {
|
||||
containers[i] = valContainerFromReadOnlyVal(val, ids[i], allBalances[ids[i]], valStatus)
|
||||
id := primitives.ValidatorIndex(i)
|
||||
if len(ids) > 0 {
|
||||
id = ids[i]
|
||||
}
|
||||
balance, err := st.BalanceAtIndex(id)
|
||||
if err != nil {
|
||||
httputil.HandleError(w, "Could not get validator balance: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
containers[i] = valContainerFromReadOnlyVal(val, id, balance, valStatus)
|
||||
}
|
||||
resp := &GetValidatorsResponse{
|
||||
Data: containers,
|
||||
@ -146,11 +150,16 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
if filteredStatuses[valStatus] || filteredStatuses[valSubStatus] {
|
||||
var container *ValidatorContainer
|
||||
if len(ids) == 0 {
|
||||
container = valContainerFromReadOnlyVal(val, primitives.ValidatorIndex(i), allBalances[i], valSubStatus)
|
||||
} else {
|
||||
container = valContainerFromReadOnlyVal(val, ids[i], allBalances[ids[i]], valSubStatus)
|
||||
id := primitives.ValidatorIndex(i)
|
||||
if len(ids) > 0 {
|
||||
id = ids[i]
|
||||
}
|
||||
balance, err := st.BalanceAtIndex(id)
|
||||
if err != nil {
|
||||
httputil.HandleError(w, "Could not get validator balance: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
container = valContainerFromReadOnlyVal(val, id, balance, valSubStatus)
|
||||
valContainers = append(valContainers, container)
|
||||
}
|
||||
}
|
||||
|
@ -325,7 +325,11 @@ func (is *infostream) generateValidatorInfo(
|
||||
info.Status, info.TransitionTimestamp = is.calculateStatusAndTransition(validator, coreTime.CurrentEpoch(headState))
|
||||
|
||||
// Balance
|
||||
info.Balance = headState.Balances()[info.Index]
|
||||
if balance, err := headState.BalanceAtIndex(info.Index); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
info.Balance = balance
|
||||
}
|
||||
|
||||
// Effective balance (for attesting states)
|
||||
if info.Status == ethpb.ValidatorStatus_ACTIVE ||
|
||||
|
Loading…
Reference in New Issue
Block a user