mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
90542c21dc
* implements max k-coverage greedy algorithm * updates go-bitfield dependency * gazelle * update base aggregate * re-arrange to shared * clean references to atts in max cover * max_cover: updates visibility * fixes tests * attestations related methods * Merge branch 'master' into attaggregation-max-cover * better op order * fix comments * removes debug stringer methods * Merge refs/heads/master into attaggregation-max-cover * log random seed * Merge branch 'attaggregation-max-cover' of github.com:prysmaticlabs/prysm into attaggregation-max-cover * Merge refs/heads/master into attaggregation-max-cover * adds more comments * Merge branch 'attaggregation-max-cover' of github.com:prysmaticlabs/prysm into attaggregation-max-cover * fixes typo
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package aggregation
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
)
|
|
|
|
// ErrInvalidAttestationCount is returned when insufficient number
|
|
// of attestations is provided for aggregation.
|
|
var ErrInvalidAttestationCount = errors.New("invalid number of attestations")
|
|
|
|
// NewAttestationsMaxCover returns initialized Maximum Coverage problem.
|
|
func NewAttestationsMaxCover(atts []*ethpb.Attestation) (*MaxCoverProblem, error) {
|
|
candidates, err := candidateListFromAttestations(atts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &MaxCoverProblem{candidates}, nil
|
|
}
|
|
|
|
// candidateListFromAttestations transforms list of attestations into candidate sets.
|
|
func candidateListFromAttestations(atts []*ethpb.Attestation) (MaxCoverCandidates, error) {
|
|
if len(atts) == 0 {
|
|
return nil, errors.Wrap(ErrInvalidAttestationCount, "cannot create list of candidates")
|
|
}
|
|
// Assert that all attestations have the same bitlist length.
|
|
for i := 1; i < len(atts); i++ {
|
|
if atts[i-1].AggregationBits.Len() != atts[i].AggregationBits.Len() {
|
|
return nil, ErrBitsDifferentLen
|
|
}
|
|
}
|
|
candidates := make([]*MaxCoverCandidate, len(atts))
|
|
for i := 0; i < len(atts); i++ {
|
|
candidates[i] = &MaxCoverCandidate{
|
|
key: i,
|
|
bits: &atts[i].AggregationBits,
|
|
}
|
|
}
|
|
return candidates, nil
|
|
}
|