mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-04-19 03:01:06 -04:00
**What type of PR is this?** Other **What does this PR do? Why is it needed?** Follow up to https://github.com/OffchainLabs/prysm/pull/16215 this pr improves logging, fixes stuttering in package naming, adds additional unit tests, and deduplicates fallback node code. **Which issues(s) does this PR fix?** fixes a potential race if reconnecting to the same host very quickly which has a stale connection still. **Other notes for review** **Acknowledgements** - [x] I have read [CONTRIBUTING.md](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md). - [x] I have included a uniquely named [changelog fragment file](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md#maintaining-changelogmd). - [x] I have added a description with sufficient context for reviewers to understand this PR. - [x] I have tested that my changes work as expected and I added a testing plan to the PR description (if applicable).
47 lines
1.6 KiB
Go
47 lines
1.6 KiB
Go
package beacon_api
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"strconv"
|
|
|
|
"github.com/OffchainLabs/prysm/v7/api/server/structs"
|
|
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func (c *beaconApiValidatorClient) subscribeCommitteeSubnets(ctx context.Context, in *ethpb.CommitteeSubnetsSubscribeRequest, duties []*ethpb.ValidatorDuty) error {
|
|
if in == nil {
|
|
return errors.New("committee subnets subscribe request is nil")
|
|
}
|
|
|
|
if len(in.CommitteeIds) != len(in.Slots) || len(in.CommitteeIds) != len(in.IsAggregator) || len(in.CommitteeIds) != len(duties) {
|
|
return errors.New("arrays `in.CommitteeIds`, `in.Slots`, `in.IsAggregator` and `duties` don't have the same length")
|
|
}
|
|
|
|
jsonCommitteeSubscriptions := make([]*structs.BeaconCommitteeSubscription, len(in.CommitteeIds))
|
|
for index := range in.CommitteeIds {
|
|
jsonCommitteeSubscriptions[index] = &structs.BeaconCommitteeSubscription{
|
|
CommitteeIndex: strconv.FormatUint(uint64(in.CommitteeIds[index]), 10),
|
|
CommitteesAtSlot: strconv.FormatUint(duties[index].CommitteesAtSlot, 10),
|
|
Slot: strconv.FormatUint(uint64(in.Slots[index]), 10),
|
|
IsAggregator: in.IsAggregator[index],
|
|
ValidatorIndex: strconv.FormatUint(uint64(duties[index].ValidatorIndex), 10),
|
|
}
|
|
}
|
|
|
|
committeeSubscriptionsBytes, err := json.Marshal(jsonCommitteeSubscriptions)
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to marshal committees subscriptions")
|
|
}
|
|
|
|
return c.handler.Post(
|
|
ctx,
|
|
"/eth/v1/validator/beacon_committee_subscriptions",
|
|
nil,
|
|
bytes.NewBuffer(committeeSubscriptionsBytes),
|
|
nil,
|
|
)
|
|
}
|