Skip to content

Commit

Permalink
rename spec share to domain share where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
iurii-ssv committed Jan 23, 2025
1 parent ba4b807 commit fdeb284
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions migrations/migration_5_gob.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type Metadata struct {
Liquidated bool
}

func storageShareGOBToSpecShare(share *storageShareGOB) (*types.SSVShare, error) {
func storageShareGOBToDomainShare(share *storageShareGOB) (*types.SSVShare, error) {

Check warning on line 62 in migrations/migration_5_gob.go

View check run for this annotation

Codecov / codecov/patch

migrations/migration_5_gob.go#L62

Added line #L62 was not covered by tests
committee := make([]*spectypes.ShareMember, len(share.Committee))
for i, c := range share.Committee {
committee[i] = &spectypes.ShareMember{
Expand All @@ -75,7 +75,7 @@ func storageShareGOBToSpecShare(share *storageShareGOB) (*types.SSVShare, error)
var validatorPubKey spectypes.ValidatorPK
copy(validatorPubKey[:], share.ValidatorPubKey)

specShare := &types.SSVShare{
domainShare := &types.SSVShare{

Check warning on line 78 in migrations/migration_5_gob.go

View check run for this annotation

Codecov / codecov/patch

migrations/migration_5_gob.go#L78

Added line #L78 was not covered by tests
Share: spectypes.Share{
ValidatorPubKey: validatorPubKey,
SharePubKey: share.SharePubKey,
Expand All @@ -89,10 +89,10 @@ func storageShareGOBToSpecShare(share *storageShareGOB) (*types.SSVShare, error)
}

if share.BeaconMetadata != nil {
specShare.ValidatorIndex = share.BeaconMetadata.Index
specShare.Status = share.BeaconMetadata.Status
specShare.ActivationEpoch = share.BeaconMetadata.ActivationEpoch
domainShare.ValidatorIndex = share.BeaconMetadata.Index
domainShare.Status = share.BeaconMetadata.Status
domainShare.ActivationEpoch = share.BeaconMetadata.ActivationEpoch

Check warning on line 94 in migrations/migration_5_gob.go

View check run for this annotation

Codecov / codecov/patch

migrations/migration_5_gob.go#L92-L94

Added lines #L92 - L94 were not covered by tests
}

return specShare, nil
return domainShare, nil

Check warning on line 97 in migrations/migration_5_gob.go

View check run for this annotation

Codecov / codecov/patch

migrations/migration_5_gob.go#L97

Added line #L97 was not covered by tests
}
6 changes: 3 additions & 3 deletions migrations/migration_5_share_gob_to_ssz.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ var migration_5_change_share_format_from_gob_to_ssz = Migration{
return fmt.Errorf("have already seen GOB share with the same share ID: %s", sID)
}
sharesGOB[sID] = shareGOB
share, err := storageShareGOBToSpecShare(shareGOB)
share, err := storageShareGOBToDomainShare(shareGOB)

Check warning on line 53 in migrations/migration_5_share_gob_to_ssz.go

View check run for this annotation

Codecov / codecov/patch

migrations/migration_5_share_gob_to_ssz.go#L48-L53

Added lines #L48 - L53 were not covered by tests
if err != nil {
return fmt.Errorf("convert storage share to spec share: %w", err)
return fmt.Errorf("convert gob storage share to domain share: %w", err)

Check warning on line 55 in migrations/migration_5_share_gob_to_ssz.go

View check run for this annotation

Codecov / codecov/patch

migrations/migration_5_share_gob_to_ssz.go#L55

Added line #L55 was not covered by tests
}
shareSSZ := storage.FromSpecShare(share)
shareSSZ := storage.FromDomainShare(share)
key := storage.SharesDBKey(shareSSZ.ValidatorPubKey[:])

Check warning on line 58 in migrations/migration_5_share_gob_to_ssz.go

View check run for this annotation

Codecov / codecov/patch

migrations/migration_5_share_gob_to_ssz.go#L57-L58

Added lines #L57 - L58 were not covered by tests
value, err := shareSSZ.Encode()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions network/p2p/p2p_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,16 @@ func generateShares(t *testing.T, count int) []*ssvtypes.SSVShare {

for i := 0; i < count; i++ {
validatorIndex := phase0.ValidatorIndex(i)
specShare := *spectestingutils.TestingShare(spectestingutils.Testing4SharesSet(), validatorIndex)
domainShare := *spectestingutils.TestingShare(spectestingutils.Testing4SharesSet(), validatorIndex)

var pk spectypes.ValidatorPK
_, err := cryptorand.Read(pk[:])
require.NoError(t, err)

specShare.ValidatorPubKey = pk
domainShare.ValidatorPubKey = pk

share := &ssvtypes.SSVShare{
Share: specShare,
Share: domainShare,
Status: eth2apiv1.ValidatorStateActiveOngoing,
Liquidated: false,
}
Expand Down
14 changes: 7 additions & 7 deletions registry/storage/shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ func (s *sharesStorage) loadFromDB() error {
return fmt.Errorf("failed to deserialize share: %w", err)
}

share, err := ToSpecShare(val)
share, err := ToDomainShare(val)
if err != nil {
return fmt.Errorf("failed to convert storage share to spec share: %w", err)
return fmt.Errorf("failed to convert storage share to domain share: %w", err)

Check warning on line 151 in registry/storage/shares.go

View check run for this annotation

Codecov / codecov/patch

registry/storage/shares.go#L151

Added line #L151 was not covered by tests
}

s.shares[hex.EncodeToString(val.ValidatorPubKey[:])] = share
Expand Down Expand Up @@ -253,7 +253,7 @@ func (s *sharesStorage) Save(rw basedb.ReadWriter, shares ...*types.SSVShare) er

func (s *sharesStorage) saveToDB(rw basedb.ReadWriter, shares ...*types.SSVShare) error {
return s.db.Using(rw).SetMany(s.storagePrefix, len(shares), func(i int) (basedb.Obj, error) {
share := FromSpecShare(shares[i])
share := FromDomainShare(shares[i])
value, err := share.Encode()
if err != nil {
return basedb.Obj{}, fmt.Errorf("failed to serialize share: %w", err)
Expand All @@ -262,7 +262,7 @@ func (s *sharesStorage) saveToDB(rw basedb.ReadWriter, shares ...*types.SSVShare
})
}

func FromSpecShare(share *types.SSVShare) *Share {
func FromDomainShare(share *types.SSVShare) *Share {
committee := make([]*storageOperator, len(share.Committee))
for i, c := range share.Committee {
committee[i] = &storageOperator{
Expand All @@ -288,7 +288,7 @@ func FromSpecShare(share *types.SSVShare) *Share {
}
}

func ToSpecShare(stShare *Share) (*types.SSVShare, error) {
func ToDomainShare(stShare *Share) (*types.SSVShare, error) {
committee := make([]*spectypes.ShareMember, len(stShare.Committee))
for i, c := range stShare.Committee {
committee[i] = &spectypes.ShareMember{
Expand All @@ -304,7 +304,7 @@ func ToSpecShare(stShare *Share) (*types.SSVShare, error) {
var validatorPubKey spectypes.ValidatorPK
copy(validatorPubKey[:], stShare.ValidatorPubKey)

specShare := &types.SSVShare{
domainShare := &types.SSVShare{
Share: spectypes.Share{
ValidatorIndex: phase0.ValidatorIndex(stShare.ValidatorIndex),
ValidatorPubKey: validatorPubKey,
Expand All @@ -320,7 +320,7 @@ func ToSpecShare(stShare *Share) (*types.SSVShare, error) {
Liquidated: stShare.Liquidated,
}

return specShare, nil
return domainShare, nil
}

var errShareNotFound = errors.New("share not found")
Expand Down

0 comments on commit fdeb284

Please sign in to comment.