mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-05-02 03:02:54 -04:00
* 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
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package aggregation
|
|
|
|
import (
|
|
"math/rand"
|
|
"testing"
|
|
"time"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
|
)
|
|
|
|
func bitlistWithAllBitsSet(t testing.TB, length uint64) bitfield.Bitlist {
|
|
b := bitfield.NewBitlist(length)
|
|
for i := uint64(0); i < length; i++ {
|
|
b.SetBitAt(i, true)
|
|
}
|
|
return b
|
|
}
|
|
|
|
func bitlistsWithSingleBitSet(t testing.TB, n, length uint64) []bitfield.Bitlist {
|
|
lists := make([]bitfield.Bitlist, n)
|
|
for i := uint64(0); i < n; i++ {
|
|
b := bitfield.NewBitlist(length)
|
|
b.SetBitAt(i%length, true)
|
|
lists[i] = b
|
|
}
|
|
return lists
|
|
}
|
|
|
|
func bitlistsWithMultipleBitSet(t testing.TB, n, length, count uint64) []bitfield.Bitlist {
|
|
seed := time.Now().UnixNano()
|
|
t.Logf("bitlistsWithMultipleBitSet random seed: %v", seed)
|
|
rand.Seed(seed)
|
|
lists := make([]bitfield.Bitlist, n)
|
|
for i := uint64(0); i < n; i++ {
|
|
b := bitfield.NewBitlist(length)
|
|
keys := rand.Perm(int(length))
|
|
for _, key := range keys[:count] {
|
|
b.SetBitAt(uint64(key), true)
|
|
}
|
|
lists[i] = b
|
|
}
|
|
return lists
|
|
}
|
|
|
|
func makeAttestationsFromBitlists(t testing.TB, bl []bitfield.Bitlist) []*ethpb.Attestation {
|
|
atts := make([]*ethpb.Attestation, len(bl))
|
|
for i, b := range bl {
|
|
atts[i] = ðpb.Attestation{
|
|
AggregationBits: b,
|
|
Data: nil,
|
|
Signature: bls.NewAggregateSignature().Marshal(),
|
|
}
|
|
}
|
|
return atts
|
|
}
|