From 64f041562ec9938352c1b1ba92621e8390502e74 Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 30 Oct 2024 19:41:00 -0300 Subject: [PATCH] cleanup --- ibft/storage/store.go | 8 +- .../ssv/validator/non_committee_validator.go | 23 +----- .../validator/non_committee_validator_test.go | 73 ------------------- 3 files changed, 5 insertions(+), 99 deletions(-) delete mode 100644 protocol/v2/ssv/validator/non_committee_validator_test.go diff --git a/ibft/storage/store.go b/ibft/storage/store.go index bf15ee2164..d0248f996d 100644 --- a/ibft/storage/store.go +++ b/ibft/storage/store.go @@ -162,7 +162,7 @@ func (i *ibftStorage) UpdateParticipants(identifier convert.MessageID, slot phas existingParticipants, err := i.getParticipants(txn, identifier, slot) if err != nil { - return false, fmt.Errorf("could not get participants %w", err) + return false, fmt.Errorf("get participants %w", err) } mergedParticipants := mergeParticipants(existingParticipants, newParticipants) @@ -171,7 +171,7 @@ func (i *ibftStorage) UpdateParticipants(identifier convert.MessageID, slot phas } if err := i.saveParticipants(txn, identifier, slot, mergedParticipants); err != nil { - return false, fmt.Errorf("could not save participants: %w", err) + return false, fmt.Errorf("save participants: %w", err) } if err := txn.Commit(); err != nil { @@ -224,10 +224,10 @@ func (i *ibftStorage) getParticipants(txn basedb.ReadWriter, identifier convert. func (i *ibftStorage) saveParticipants(txn basedb.ReadWriter, identifier convert.MessageID, slot phase0.Slot, operators []spectypes.OperatorID) error { bytes, err := encodeOperators(operators) if err != nil { - return err + return fmt.Errorf("encode operators: %w", err) } if err := i.save(txn, bytes, participantsKey, identifier[:], uInt64ToByteSlice(uint64(slot))); err != nil { - return fmt.Errorf("could not save participants: %w", err) + return fmt.Errorf("save to DB: %w", err) } return nil diff --git a/protocol/v2/ssv/validator/non_committee_validator.go b/protocol/v2/ssv/validator/non_committee_validator.go index 8c3dfdcae0..22eddea356 100644 --- a/protocol/v2/ssv/validator/non_committee_validator.go +++ b/protocol/v2/ssv/validator/non_committee_validator.go @@ -157,7 +157,7 @@ func (ncv *CommitteeObserver) ProcessMessage(msg *queue.SSVMessage) error { updated, err := roleStorage.UpdateParticipants(msgID, slot, quorum) if err != nil { - return fmt.Errorf("could not save participants: %w", err) + return fmt.Errorf("update participants: %w", err) } if !updated { @@ -186,27 +186,6 @@ func (ncv *CommitteeObserver) ProcessMessage(msg *queue.SSVMessage) error { return nil } -func mergeQuorums(quorum1, quorum2 []spectypes.OperatorID) []spectypes.OperatorID { - seen := make(map[spectypes.OperatorID]struct{}) - - for _, operatorID := range quorum1 { - seen[operatorID] = struct{}{} - } - - for _, operatorID := range quorum2 { - seen[operatorID] = struct{}{} - } - - result := make([]spectypes.OperatorID, 0, len(seen)) - for operatorID := range seen { - result = append(result, operatorID) - } - - slices.Sort(result) - - return result -} - func (ncv *CommitteeObserver) getBeaconRoles(msg *queue.SSVMessage, root phase0.Root) []convert.RunnerRole { if msg.MsgID.GetRoleType() == spectypes.RoleCommittee { attester := ncv.attesterRoots.Get(root) diff --git a/protocol/v2/ssv/validator/non_committee_validator_test.go b/protocol/v2/ssv/validator/non_committee_validator_test.go deleted file mode 100644 index 61be08f1ba..0000000000 --- a/protocol/v2/ssv/validator/non_committee_validator_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package validator - -import ( - "testing" - - spectypes "github.com/ssvlabs/ssv-spec/types" - "github.com/stretchr/testify/require" -) - -func Test_mergeQuorums(t *testing.T) { - tests := []struct { - name string - quorum1 []spectypes.OperatorID - quorum2 []spectypes.OperatorID - expected []spectypes.OperatorID - }{ - { - name: "Both quorums empty", - quorum1: []spectypes.OperatorID{}, - quorum2: []spectypes.OperatorID{}, - expected: []spectypes.OperatorID{}, - }, - { - name: "First quorum empty", - quorum1: []spectypes.OperatorID{}, - quorum2: []spectypes.OperatorID{1, 2, 3}, - expected: []spectypes.OperatorID{1, 2, 3}, - }, - { - name: "Second quorum empty", - quorum1: []spectypes.OperatorID{1, 2, 3}, - quorum2: []spectypes.OperatorID{}, - expected: []spectypes.OperatorID{1, 2, 3}, - }, - { - name: "No duplicates", - quorum1: []spectypes.OperatorID{1, 3, 5}, - quorum2: []spectypes.OperatorID{2, 4, 6}, - expected: []spectypes.OperatorID{1, 2, 3, 4, 5, 6}, - }, - { - name: "With duplicates", - quorum1: []spectypes.OperatorID{1, 2, 3, 5}, - quorum2: []spectypes.OperatorID{3, 4, 5, 6}, - expected: []spectypes.OperatorID{1, 2, 3, 4, 5, 6}, - }, - { - name: "All duplicates", - quorum1: []spectypes.OperatorID{1, 2, 3}, - quorum2: []spectypes.OperatorID{1, 2, 3}, - expected: []spectypes.OperatorID{1, 2, 3}, - }, - { - name: "Unsorted input quorums", - quorum1: []spectypes.OperatorID{5, 1, 3}, - quorum2: []spectypes.OperatorID{4, 2, 6}, - expected: []spectypes.OperatorID{1, 2, 3, 4, 5, 6}, - }, - { - name: "Large quorum size", - quorum1: []spectypes.OperatorID{1, 3, 5, 7, 9, 11, 13}, - quorum2: []spectypes.OperatorID{2, 4, 6, 8, 10, 12, 14}, - expected: []spectypes.OperatorID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := mergeQuorums(tt.quorum1, tt.quorum2) - require.Equal(t, tt.expected, result) - }) - } -}