Use State Instead of Cached Registry (#2372)

* fix state reads

* add method to retrieve validator from state

* lint

* batch update attestation

* handle nil case

* add test

* lint

* batch update attestation

* use state instead

* fix test
This commit is contained in:
Nishant Das 2019-04-24 23:46:06 +08:00 committed by Raul Jordan
parent 54f6fffb58
commit 941810ee7b

View File

@ -95,12 +95,17 @@ func (a *Service) IncomingAttestationFeed() *event.Feed {
// Attestation` be the attestation with the highest slot number in `store`
// from the validator with the given `validator_index`
func (a *Service) LatestAttestation(ctx context.Context, index uint64) (*pb.Attestation, error) {
validator, err := a.beaconDB.ValidatorFromState(ctx, index)
bState, err := a.beaconDB.HeadState(ctx)
if err != nil {
return nil, err
}
pubKey := bytesutil.ToBytes48(validator.Pubkey)
// return error if it's an invalid validator index.
if index >= uint64(len(bState.ValidatorRegistry)) {
return nil, fmt.Errorf("invalid validator index %d", index)
}
pubKey := bytesutil.ToBytes48(bState.ValidatorRegistry[index].Pubkey)
a.store.RLock()
defer a.store.RUnlock()
if _, exists := a.store.m[pubKey]; !exists {