prysm-pulse/shared/aggregation/sync_contribution/contribution.go
Raul Jordan 9145310647
Eliminate Proto V2 Namespace (#9297)
* get rid of v2 in prysm codebase

* replace block2

* builds

* terence comments

* gazelle
2021-07-28 21:23:44 +00:00

42 lines
1.6 KiB
Go

package sync_contribution
import (
"github.com/pkg/errors"
v2 "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/aggregation"
"github.com/sirupsen/logrus"
)
const (
// NaiveAggregation is an aggregation strategy without any optimizations.
NaiveAggregation SyncContributionAggregationStrategy = "naive"
// MaxCoverAggregation is a strategy based on Maximum Coverage greedy algorithm.
MaxCoverAggregation SyncContributionAggregationStrategy = "max_cover"
)
// SyncContributionAggregationStrategy defines SyncContribution aggregation strategy.
type SyncContributionAggregationStrategy string
var _ = logrus.WithField("prefix", "aggregation.sync_contribution")
// ErrInvalidSyncContributionCount is returned when insufficient number
// of sync contributions is provided for aggregation.
var ErrInvalidSyncContributionCount = errors.New("invalid number of sync contributions")
// Aggregate aggregates sync contributions. The minimal number of sync contributions is returned.
// Aggregation occurs in-place i.e. contents of input array will be modified. Should you need to
// preserve input sync contributions, clone them before aggregating.
func Aggregate(cs []*v2.SyncCommitteeContribution) ([]*v2.SyncCommitteeContribution, error) {
strategy := NaiveAggregation
switch strategy {
case "", NaiveAggregation:
return naiveSyncContributionAggregation(cs)
case MaxCoverAggregation:
// TODO: Implement max cover aggregation for sync contributions.
return nil, errors.New("no implemented")
default:
return nil, errors.Wrapf(aggregation.ErrInvalidStrategy, "%q", strategy)
}
}