mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Add proposer sync contribution type (#9106)
* Add `proposerSyncContributions` * Update BUILD.bazel * Add dedup and tests * Update BUILD.bazel * Revert grpc changes
This commit is contained in:
@@ -10,7 +10,8 @@ go_library(
|
||||
"exit.go",
|
||||
"log.go",
|
||||
"proposer.go",
|
||||
"proposer_utils.go",
|
||||
"proposer_attestations.go",
|
||||
"proposer_sync_aggregate.go",
|
||||
"server.go",
|
||||
"status.go",
|
||||
],
|
||||
@@ -41,6 +42,7 @@ go_library(
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//proto/eth/v1:go_default_library",
|
||||
"//proto/eth/v1alpha1:go_default_library",
|
||||
"//proto/prysm/v2:go_default_library",
|
||||
"//shared/aggregation:go_default_library",
|
||||
"//shared/aggregation/attestations:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
@@ -77,8 +79,9 @@ go_test(
|
||||
"assignments_test.go",
|
||||
"attester_test.go",
|
||||
"exit_test.go",
|
||||
"proposer_attestations_test.go",
|
||||
"proposer_sync_aggregate_test.go",
|
||||
"proposer_test.go",
|
||||
"proposer_utils_test.go",
|
||||
"server_test.go",
|
||||
"status_test.go",
|
||||
"validator_test.go",
|
||||
@@ -108,6 +111,7 @@ go_test(
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//proto/eth/v1:go_default_library",
|
||||
"//proto/eth/v1alpha1:go_default_library",
|
||||
"//proto/prysm/v2:go_default_library",
|
||||
"//shared/aggregation/attestations:go_default_library",
|
||||
"//shared/attestationutil:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
|
||||
72
beacon-chain/rpc/validator/proposer_sync_aggregate.go
Normal file
72
beacon-chain/rpc/validator/proposer_sync_aggregate.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
eth "github.com/prysmaticlabs/prysm/proto/prysm/v2"
|
||||
)
|
||||
|
||||
type proposerSyncContributions []*eth.SyncCommitteeContribution
|
||||
|
||||
// filterByBlockRoot separates sync aggregate list into a valid group.
|
||||
// The valid group contains the input block root.
|
||||
func (cs proposerSyncContributions) filterByBlockRoot(r [32]byte) proposerSyncContributions {
|
||||
matchedSyncContributions := make([]*eth.SyncCommitteeContribution, 0, len(cs))
|
||||
for _, c := range cs {
|
||||
if bytes.Equal(c.BlockRoot, r[:]) {
|
||||
matchedSyncContributions = append(matchedSyncContributions, c)
|
||||
}
|
||||
}
|
||||
return matchedSyncContributions
|
||||
}
|
||||
|
||||
// filterBySubIndex separates sync aggregate list into a valid group.
|
||||
// The valid group contains the matching sub committee index.
|
||||
func (cs proposerSyncContributions) filterBySubIndex(i uint64) proposerSyncContributions {
|
||||
matchedSyncContributions := make([]*eth.SyncCommitteeContribution, 0, len(cs))
|
||||
for _, c := range cs {
|
||||
if c.SubcommitteeIndex == i {
|
||||
matchedSyncContributions = append(matchedSyncContributions, c)
|
||||
}
|
||||
}
|
||||
return matchedSyncContributions
|
||||
}
|
||||
|
||||
// dedup removes duplicate sync contributions (ones with the same bits set on).
|
||||
// Important: not only exact duplicates are removed, but proper subsets are removed too
|
||||
// (their known bits are redundant and are already contained in their supersets).
|
||||
func (cs proposerSyncContributions) dedup() proposerSyncContributions {
|
||||
if len(cs) < 2 {
|
||||
return cs
|
||||
}
|
||||
contributionsBySubIdx := make(map[uint64][]*eth.SyncCommitteeContribution, len(cs))
|
||||
for _, c := range cs {
|
||||
contributionsBySubIdx[c.SubcommitteeIndex] = append(contributionsBySubIdx[c.SubcommitteeIndex], c)
|
||||
}
|
||||
|
||||
uniqContributions := make([]*eth.SyncCommitteeContribution, 0, len(cs))
|
||||
for _, cs := range contributionsBySubIdx {
|
||||
for i := 0; i < len(cs); i++ {
|
||||
a := cs[i]
|
||||
for j := i + 1; j < len(cs); j++ {
|
||||
b := cs[j]
|
||||
if a.AggregationBits.Contains(b.AggregationBits) {
|
||||
// a contains b, b is redundant.
|
||||
cs[j] = cs[len(cs)-1]
|
||||
cs[len(cs)-1] = nil
|
||||
cs = cs[:len(cs)-1]
|
||||
j--
|
||||
} else if b.AggregationBits.Contains(a.GetAggregationBits()) {
|
||||
// b contains a, a is redundant.
|
||||
cs[i] = cs[len(cs)-1]
|
||||
cs[len(cs)-1] = nil
|
||||
cs = cs[:len(cs)-1]
|
||||
i--
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
uniqContributions = append(uniqContributions, cs...)
|
||||
}
|
||||
return uniqContributions
|
||||
}
|
||||
342
beacon-chain/rpc/validator/proposer_sync_aggregate_test.go
Normal file
342
beacon-chain/rpc/validator/proposer_sync_aggregate_test.go
Normal file
@@ -0,0 +1,342 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
v2 "github.com/prysmaticlabs/prysm/proto/prysm/v2"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
)
|
||||
|
||||
func TestProposerSyncContributions_FilterByBlockRoot(t *testing.T) {
|
||||
rootA := [32]byte{'a'}
|
||||
rootB := [32]byte{'b'}
|
||||
tests := []struct {
|
||||
name string
|
||||
cs proposerSyncContributions
|
||||
want proposerSyncContributions
|
||||
}{
|
||||
{
|
||||
name: "empty list",
|
||||
cs: proposerSyncContributions{},
|
||||
want: proposerSyncContributions{},
|
||||
},
|
||||
{
|
||||
name: "single item, not found",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.NewBitvector128()},
|
||||
},
|
||||
want: proposerSyncContributions{},
|
||||
},
|
||||
{
|
||||
name: "single item with filter, found",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootA[:], Slot: 0},
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootB[:], Slot: 1},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootA[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "multiple items with filter, found",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootA[:], Slot: 0},
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootB[:], Slot: 1},
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootA[:], Slot: 2},
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootB[:], Slot: 3},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootA[:], Slot: 0},
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootA[:], Slot: 2},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cs := tt.cs.filterByBlockRoot(rootA)
|
||||
assert.DeepEqual(t, tt.want, cs)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProposerSyncContributions_FilterBySubcommitteeID(t *testing.T) {
|
||||
rootA := [32]byte{'a'}
|
||||
rootB := [32]byte{'b'}
|
||||
tests := []struct {
|
||||
name string
|
||||
cs proposerSyncContributions
|
||||
want proposerSyncContributions
|
||||
}{
|
||||
{
|
||||
name: "empty list",
|
||||
cs: proposerSyncContributions{},
|
||||
want: proposerSyncContributions{},
|
||||
},
|
||||
{
|
||||
name: "single item, not found",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.NewBitvector128(), SubcommitteeIndex: 1},
|
||||
},
|
||||
want: proposerSyncContributions{},
|
||||
},
|
||||
{
|
||||
name: "single item with filter",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootA[:], SubcommitteeIndex: 0},
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootB[:], SubcommitteeIndex: 1},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootA[:]},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "multiple items with filter",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootA[:], SubcommitteeIndex: 0},
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootB[:], SubcommitteeIndex: 1},
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootB[:], SubcommitteeIndex: 0},
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootB[:], SubcommitteeIndex: 2},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootA[:], SubcommitteeIndex: 0},
|
||||
&v2.SyncCommitteeContribution{BlockRoot: rootB[:], SubcommitteeIndex: 0},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cs := tt.cs.filterBySubIndex(0)
|
||||
assert.DeepEqual(t, tt.want, cs)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProposerSyncContributions_Dedup(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cs proposerSyncContributions
|
||||
want proposerSyncContributions
|
||||
}{
|
||||
{
|
||||
name: "nil list",
|
||||
cs: nil,
|
||||
want: proposerSyncContributions(nil),
|
||||
},
|
||||
{
|
||||
name: "empty list",
|
||||
cs: proposerSyncContributions{},
|
||||
want: proposerSyncContributions{},
|
||||
},
|
||||
{
|
||||
name: "single item",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.NewBitvector128()},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.NewBitvector128()},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "two items no duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10111110, 0x01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01111111, 0x01}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01111111, 0x01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10111110, 0x01}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "two items with duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0xba, 0x01}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0xba, 0x01}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0xba, 0x01}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sorted no duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00101011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100000, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00010000, 0b1}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00101011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100000, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00010000, 0b1}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sorted with duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "all equal",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unsorted no duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00100010, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00010000, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00100010, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00010000, 0b1}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unsorted with duplicates",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10100101, 0b1}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no proper subset (same root)",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00011001, 0b1}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00011001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b10000001, 0b1}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "proper subset (same root)",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no proper subset (different index)",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000101, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b10000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00011001, 0b1}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00011001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b10000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000101, 0b1}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "proper subset (different index 1)",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00000011, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00000001, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b01101101, 0b1}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "proper subset (different index 2)",
|
||||
cs: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b00001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
},
|
||||
want: proposerSyncContributions{
|
||||
&v2.SyncCommitteeContribution{SubcommitteeIndex: 1, AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
&v2.SyncCommitteeContribution{AggregationBits: bitfield.Bitvector128{0b11001111, 0b1}},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cs := tt.cs.dedup()
|
||||
sort.Slice(cs, func(i, j int) bool {
|
||||
if cs[i].AggregationBits.Count() == cs[j].AggregationBits.Count() {
|
||||
if cs[i].SubcommitteeIndex == cs[j].SubcommitteeIndex {
|
||||
return bytes.Compare(cs[i].AggregationBits, cs[j].AggregationBits) <= 0
|
||||
}
|
||||
return cs[i].SubcommitteeIndex > cs[j].SubcommitteeIndex
|
||||
}
|
||||
return cs[i].AggregationBits.Count() > cs[j].AggregationBits.Count()
|
||||
})
|
||||
assert.DeepEqual(t, tt.want, cs)
|
||||
})
|
||||
}
|
||||
}
|
||||
4
deps.bzl
4
deps.bzl
@@ -2778,8 +2778,8 @@ def prysm_deps():
|
||||
go_repository(
|
||||
name = "com_github_prysmaticlabs_go_bitfield",
|
||||
importpath = "github.com/prysmaticlabs/go-bitfield",
|
||||
sum = "h1:46gKr69IlRpv/ENdlzG0SWo5nMLKJxS3tI5NOSdZndQ=",
|
||||
version = "v0.0.0-20210607200045-4da71aaf6c2d",
|
||||
sum = "h1:yALGBNFMp40DeD3qGGRgiC0FWePzy0FIhxWEXoco3ZA=",
|
||||
version = "v0.0.0-20210628171552-0c86d791fc37",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_prysmaticlabs_prombbolt",
|
||||
|
||||
2
go.mod
2
go.mod
@@ -88,7 +88,7 @@ require (
|
||||
github.com/prometheus/prom2json v1.3.0
|
||||
github.com/prometheus/tsdb v0.10.0 // indirect
|
||||
github.com/prysmaticlabs/eth2-types v0.0.0-20210303084904-c9735a06829d
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20210607200045-4da71aaf6c2d
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20210628171552-0c86d791fc37
|
||||
github.com/prysmaticlabs/prombbolt v0.0.0-20210126082820-9b7adba6db7c
|
||||
github.com/prysmaticlabs/protoc-gen-go-cast v0.0.0-20210504233148-1e141af6a0a1
|
||||
github.com/r3labs/sse v0.0.0-20210224172625-26fe804710bc
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1069,8 +1069,8 @@ github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20210420143944-f4dfc9744288/go
|
||||
github.com/prysmaticlabs/eth2-types v0.0.0-20210303084904-c9735a06829d h1:1dN7YAqMN3oAJ0LceWcyv/U4jHLh+5urnSnr4br6zg4=
|
||||
github.com/prysmaticlabs/eth2-types v0.0.0-20210303084904-c9735a06829d/go.mod h1:kOmQ/zdobQf7HUohDTifDNFEZfNaSCIY5fkONPL+dWU=
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20210108222456-8e92c3709aa0/go.mod h1:hCwmef+4qXWjv0jLDbQdWnL0Ol7cS7/lCSS26WR+u6s=
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20210607200045-4da71aaf6c2d h1:46gKr69IlRpv/ENdlzG0SWo5nMLKJxS3tI5NOSdZndQ=
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20210607200045-4da71aaf6c2d/go.mod h1:hCwmef+4qXWjv0jLDbQdWnL0Ol7cS7/lCSS26WR+u6s=
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20210628171552-0c86d791fc37 h1:yALGBNFMp40DeD3qGGRgiC0FWePzy0FIhxWEXoco3ZA=
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20210628171552-0c86d791fc37/go.mod h1:hCwmef+4qXWjv0jLDbQdWnL0Ol7cS7/lCSS26WR+u6s=
|
||||
github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210622145107-ca3041e1b380 h1:KzQOksIZB8poBiMk8h5Txzbp/OoBLFhS3H20ZN06hWg=
|
||||
github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210622145107-ca3041e1b380/go.mod h1:IOyTYjcIO0rkmnGBfJTL0NJ11exy/Tc2QEuv7hCXp24=
|
||||
github.com/prysmaticlabs/prombbolt v0.0.0-20210126082820-9b7adba6db7c h1:9PHRCuO/VN0s9k+RmLykho7AjDxblNYI5bYKed16NPU=
|
||||
|
||||
Reference in New Issue
Block a user