Skip to content

Commit

Permalink
Close beacon node connection when done, and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhly committed May 8, 2020
1 parent 4e97a2a commit 91ce0fc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions validator/accounts/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ func FetchAccountStatuses(ctx context.Context, keyPairs map[string]*keystore.Key
defer span.End()

var err error
beaconNodeRPC, err := beaconNodeRPCProvider()
beaconConn, err := beaconNodeRPCProvider()
if err != nil {
return nil, errors.Wrap(err, "Cannot connect to Beacon Node.")
}
defer beaconConn.Close()

const RequestLimit = 3
const ConnLimit = 3
statuses := make([]*ethpb.ValidatorStatusResponse, 0, len(keyPairs))
errorChannel := make(chan error, RequestLimit)
statusChannel := make(chan *ethpb.ValidatorStatusResponse, RequestLimit)
errorChannel := make(chan error, ConnLimit)
statusChannel := make(chan *ethpb.ValidatorStatusResponse, ConnLimit)

for _, key := range keyPairs {
go fetchValidatorStatus(ctx, beaconNodeRPC, key.PublicKey.Marshal(), statusChannel, errorChannel)
go fetchValidatorStatus(ctx, beaconConn, key.PublicKey.Marshal(), statusChannel, errorChannel)
}

for i := 0; i < len(keyPairs); i++ {
Expand All @@ -51,6 +52,8 @@ func FetchAccountStatuses(ctx context.Context, keyPairs map[string]*keystore.Key
}

// Sort responses by status
// XXX: This sort does not work right now. We need to have the
// public key of the validator indicated in the response.
sort.Slice(statuses, func(i, j int) bool {
return statuses[i].Status < statuses[j].Status
})
Expand Down

0 comments on commit 91ce0fc

Please sign in to comment.