Skip to content

Commit

Permalink
calculate subnet for committee instead of validator
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Oct 16, 2024
1 parent 0476e21 commit 62b6950
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
38 changes: 29 additions & 9 deletions operator/validator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,14 +521,21 @@ func (c *controller) StartValidators() {
}

var ownShares []*ssvtypes.SSVShare
var activeSubnetsPubKeys = make([][]byte, 0, len(shares))
var pubKeysToFetch [][]byte
for _, share := range shares {
if c.operatorDataStore.GetOperatorID() != 0 && share.BelongsToOperator(c.operatorDataStore.GetOperatorID()) {
ownShares = append(ownShares, share)
}
shareSubnet := byte(commons.ValidatorSubnet(hex.EncodeToString(share.ValidatorPubKey[:])))
if bytes.Contains(c.network.ActiveSubnets(), []byte{shareSubnet}) {
activeSubnetsPubKeys = append(activeSubnetsPubKeys, share.ValidatorPubKey[:])
committeeSubnet := byte(commons.CommitteeSubnet(share.CommitteeID()))
if bytes.Contains(c.network.ActiveSubnets(), []byte{committeeSubnet}) {
pubKeysToFetch = append(pubKeysToFetch, share.ValidatorPubKey[:])
}

if !c.networkConfig.PastAlanFork() {
validatorSubnet := byte(commons.ValidatorSubnet(hex.EncodeToString(share.ValidatorPubKey[:])))
if bytes.Contains(c.network.ActiveSubnets(), []byte{validatorSubnet}) {
pubKeysToFetch = append(pubKeysToFetch, share.ValidatorPubKey[:])
}
}
}

Expand Down Expand Up @@ -561,15 +568,15 @@ func (c *controller) StartValidators() {
}
if !hasMetadata {
start := time.Now()
err := c.fetchAndUpdateValidatorsMetadata(c.logger, activeSubnetsPubKeys, c.beacon)
err := c.fetchAndUpdateValidatorsMetadata(c.logger, pubKeysToFetch, c.beacon)
if err != nil {
c.logger.Error("failed to update validators metadata after setup",
zap.Int("shares", len(activeSubnetsPubKeys)),
zap.Int("shares", len(pubKeysToFetch)),
fields.Took(time.Since(start)),
zap.Error(err))
} else {
c.logger.Debug("updated validators metadata after setup",
zap.Int("shares", len(activeSubnetsPubKeys)),
zap.Int("shares", len(pubKeysToFetch)),
fields.Took(time.Since(start)))
}
}
Expand Down Expand Up @@ -1147,8 +1154,21 @@ func (c *controller) UpdateValidatorMetaDataLoop() {
return true
}

shareSubnet := byte(commons.ValidatorSubnet(hex.EncodeToString(share.ValidatorPubKey[:])))
if !bytes.Contains(c.network.ActiveSubnets(), []byte{shareSubnet}) {
belongsToOwnSubnet := false

committeeSubnet := byte(commons.CommitteeSubnet(share.CommitteeID()))
if bytes.Contains(c.network.ActiveSubnets(), []byte{committeeSubnet}) {
belongsToOwnSubnet = true
}

if !c.networkConfig.PastAlanFork() {
validatorSubnet := byte(commons.ValidatorSubnet(hex.EncodeToString(share.ValidatorPubKey[:])))
if bytes.Contains(c.network.ActiveSubnets(), []byte{validatorSubnet}) {
belongsToOwnSubnet = true
}
}

if !belongsToOwnSubnet {
// skip validators out of own subnets
return true
}
Expand Down
2 changes: 1 addition & 1 deletion operator/validator/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestSetupValidatorsExporter(t *testing.T) {

var subnets []byte
for _, share := range sharesWithMetadata {
subnets = append(subnets, byte(commons.ValidatorSubnet(hex.EncodeToString(share.ValidatorPubKey[:]))))
subnets = append(subnets, byte(commons.CommitteeSubnet(share.CommitteeID())))
}
slices.Sort(subnets)

Expand Down
2 changes: 1 addition & 1 deletion protocol/v2/types/ssvshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (s *SSVShare) HasQuorum(cnt uint64) bool {
}

func (s *SSVShare) Quorum() uint64 {
q, _ := ComputeQuorumAndPartialQuorum(uint64(len((s.Committee))))
q, _ := ComputeQuorumAndPartialQuorum(uint64(len(s.Committee)))
return q
}

Expand Down

0 comments on commit 62b6950

Please sign in to comment.