github.com/prysmaticlabs/prysm@v1.4.4/shared/aggregation/sync_contribution/contribution.go (about) 1 package sync_contribution 2 3 import ( 4 "github.com/pkg/errors" 5 v2 "github.com/prysmaticlabs/prysm/proto/prysm/v2" 6 "github.com/prysmaticlabs/prysm/shared/aggregation" 7 "github.com/sirupsen/logrus" 8 ) 9 10 const ( 11 // NaiveAggregation is an aggregation strategy without any optimizations. 12 NaiveAggregation SyncContributionAggregationStrategy = "naive" 13 14 // MaxCoverAggregation is a strategy based on Maximum Coverage greedy algorithm. 15 MaxCoverAggregation SyncContributionAggregationStrategy = "max_cover" 16 ) 17 18 // SyncContributionAggregationStrategy defines SyncContribution aggregation strategy. 19 type SyncContributionAggregationStrategy string 20 21 var _ = logrus.WithField("prefix", "aggregation.sync_contribution") 22 23 // ErrInvalidSyncContributionCount is returned when insufficient number 24 // of sync contributions is provided for aggregation. 25 var ErrInvalidSyncContributionCount = errors.New("invalid number of sync contributions") 26 27 // Aggregate aggregates sync contributions. The minimal number of sync contributions is returned. 28 // Aggregation occurs in-place i.e. contents of input array will be modified. Should you need to 29 // preserve input sync contributions, clone them before aggregating. 30 func Aggregate(cs []*v2.SyncCommitteeContribution) ([]*v2.SyncCommitteeContribution, error) { 31 strategy := NaiveAggregation 32 switch strategy { 33 case "", NaiveAggregation: 34 return naiveSyncContributionAggregation(cs) 35 case MaxCoverAggregation: 36 // TODO: Implement max cover aggregation for sync contributions. 37 return nil, errors.New("no implemented") 38 default: 39 return nil, errors.Wrapf(aggregation.ErrInvalidStrategy, "%q", strategy) 40 } 41 }