Fetch validators without balances, for faster response from Prysm nodes

This commit is contained in:
Jim McDonald 2020-09-30 13:24:12 +01:00
parent 702e4d5964
commit 8d29b15618
No known key found for this signature in database
GPG Key ID: 89CEB61B2AD2A5E7
4 changed files with 35 additions and 10 deletions

View File

@ -1,5 +1,6 @@
Development
- do not continue if attempt to acquire a semaphore fails
- fetch validators without balances, for (much) faster response from Prysm
0.6.1
- update documentation for account managers, explaining the difference between Dirk and wallet

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.14
require (
cloud.google.com/go v0.66.0 // indirect
github.com/OneOfOne/xxhash v1.2.5 // indirect
github.com/attestantio/go-eth2-client v0.6.6
github.com/attestantio/go-eth2-client v0.6.7
github.com/aws/aws-sdk-go v1.34.31
github.com/ferranbt/fastssz v0.0.0-20200826142241-3a913c5a1313
github.com/fsnotify/fsnotify v1.4.9 // indirect

2
go.sum
View File

@ -66,6 +66,8 @@ github.com/attestantio/go-eth2-client v0.6.5 h1:IaPJfxOTqHdkfmeuy6MntsuLEoJipf7V
github.com/attestantio/go-eth2-client v0.6.5/go.mod h1:lYEayGHzZma9HMUJgyxFIzDWRck8n2IedP7KTkIwe0g=
github.com/attestantio/go-eth2-client v0.6.6 h1:rgqG4KDyLDw75vOqnFnJ/nAXzkp6EDFaOctMzPJYNWI=
github.com/attestantio/go-eth2-client v0.6.6/go.mod h1:lYEayGHzZma9HMUJgyxFIzDWRck8n2IedP7KTkIwe0g=
github.com/attestantio/go-eth2-client v0.6.7 h1:QphgX2XL8HMxZ3wo7RSyBhBJr9eKHNJU0GLWtVmxYG8=
github.com/attestantio/go-eth2-client v0.6.7/go.mod h1:lYEayGHzZma9HMUJgyxFIzDWRck8n2IedP7KTkIwe0g=
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.33.5/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=

View File

@ -146,7 +146,7 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) {
func (s *Service) UpdateAccountsState(ctx context.Context) error {
validatorIDs := make([]eth2client.ValidatorIDProvider, 0, len(s.accounts))
for _, account := range s.accounts {
if !account.state.IsAttesting() {
if !account.state.HasActivated() {
validatorIDs = append(validatorIDs, account)
}
}
@ -155,10 +155,21 @@ func (s *Service) UpdateAccountsState(ctx context.Context) error {
log.Trace().Msg("No unactivated keys")
return nil
}
validators, err := s.validatorsProvider.Validators(ctx, "head", validatorIDs)
if err != nil {
return errors.Wrap(err, "failed to obtain validators")
log.Trace().Int("total", len(s.accounts)).Int("unactivated", len(validatorIDs)).Msg("Updating state of unactivated keys")
validators := make(map[uint64]*api.Validator)
var err error
if validatorsWithoutBalanceProvider, isProvider := s.validatorsProvider.(eth2client.ValidatorsWithoutBalanceProvider); isProvider {
validators, err = validatorsWithoutBalanceProvider.ValidatorsWithoutBalance(ctx, "head", validatorIDs)
if err != nil {
return errors.Wrap(err, "failed to obtain validators without balances")
}
} else {
validators, err = s.validatorsProvider.Validators(ctx, "head", validatorIDs)
if err != nil {
return errors.Wrap(err, "failed to obtain validators")
}
}
log.Trace().Int("received", len(validators)).Msg("Received state of known unactivated keys")
s.mutex.Lock()
s.updateAccountStates(ctx, s.accounts, validators)
@ -212,10 +223,22 @@ func (s *Service) RefreshAccounts(ctx context.Context) error {
return nil
}
validators, err := s.validatorsProvider.Validators(ctx, "head", validatorIDs)
if err != nil {
return errors.Wrap(err, "failed to obtain validators")
log.Trace().Int("accounts", len(validatorIDs)).Msg("Obtaining validator state of accounts")
validators := make(map[uint64]*api.Validator)
var err error
if validatorsWithoutBalanceProvider, isProvider := s.validatorsProvider.(eth2client.ValidatorsWithoutBalanceProvider); isProvider {
validators, err = validatorsWithoutBalanceProvider.ValidatorsWithoutBalance(ctx, "head", validatorIDs)
if err != nil {
return errors.Wrap(err, "failed to obtain validators without balances")
}
} else {
validators, err = s.validatorsProvider.Validators(ctx, "head", validatorIDs)
if err != nil {
return errors.Wrap(err, "failed to obtain validators")
}
}
log.Trace().Int("received", len(validators)).Msg("Received state of accounts")
s.updateAccountStates(ctx, accounts, validators)
s.mutex.Lock()
@ -356,8 +379,7 @@ func (s *Service) updateAccountStates(ctx context.Context, accounts map[[48]byte
validatorStateCounts := make(map[string]uint64)
for pubKey, account := range accounts {
validator, exists := validatorsByPubKey[pubKey]
if exists {
if validator, exists := validatorsByPubKey[pubKey]; exists {
account.index = validator.Index
account.state = validator.State
}