mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 05:47:59 -05:00
SubscribeCommitteeSubnets fields length check (#6359)
* SubscribeCommitteeSubnets fields length check A case where `len(req.Slots) != len(req.CommitteeIds)` but `len(req.CommitteeIds) == len(req.IsAggregator)` should also throw an error. Without this fix only 2 length inequalities will throw the error. Greetings from PwC Switzerland * Added diff length SubscribeCommitteeSubnets test * Merge branch 'master' into patch-1
This commit is contained in:
@@ -194,7 +194,7 @@ func (vs *Server) SubscribeCommitteeSubnets(ctx context.Context, req *ethpb.Comm
|
||||
ctx, span := trace.StartSpan(ctx, "AttesterServer.SubscribeCommitteeSubnets")
|
||||
defer span.End()
|
||||
|
||||
if len(req.Slots) != len(req.CommitteeIds) && len(req.CommitteeIds) != len(req.IsAggregator) {
|
||||
if len(req.Slots) != len(req.CommitteeIds) || len(req.CommitteeIds) != len(req.IsAggregator) {
|
||||
return nil, status.Error(codes.InvalidArgument, "request fields are not the same length")
|
||||
}
|
||||
if len(req.Slots) == 0 {
|
||||
|
||||
@@ -659,6 +659,45 @@ func TestServer_SubscribeCommitteeSubnets_NoSlots(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_SubscribeCommitteeSubnets_DifferentLengthSlots(t *testing.T) {
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
// fixed seed
|
||||
s := rand.NewSource(10)
|
||||
randGen := rand.New(s)
|
||||
|
||||
attesterServer := &Server{
|
||||
HeadFetcher: &mock.ChainService{},
|
||||
P2P: &mockp2p.MockBroadcaster{},
|
||||
BeaconDB: db,
|
||||
AttestationCache: cache.NewAttestationCache(),
|
||||
AttPool: attestations.NewPool(),
|
||||
OperationNotifier: (&mock.ChainService{}).OperationNotifier(),
|
||||
}
|
||||
|
||||
var slots []uint64
|
||||
var comIdxs []uint64
|
||||
var isAggregator []bool
|
||||
|
||||
for i := uint64(100); i < 200; i++ {
|
||||
slots = append(slots, i)
|
||||
comIdxs = append(comIdxs, uint64(randGen.Int63n(64)))
|
||||
boolVal := randGen.Uint64()%2 == 0
|
||||
isAggregator = append(isAggregator, boolVal)
|
||||
}
|
||||
|
||||
slots = append(slots, 321)
|
||||
|
||||
_, err := attesterServer.SubscribeCommitteeSubnets(context.Background(), ðpb.CommitteeSubnetsSubscribeRequest{
|
||||
Slots: slots,
|
||||
CommitteeIds: comIdxs,
|
||||
IsAggregator: isAggregator,
|
||||
})
|
||||
if err == nil || !strings.Contains(err.Error(), "request fields are not the same length") {
|
||||
t.Fatalf("Expected request fields are not the same length error, received: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_SubscribeCommitteeSubnets_MultipleSlots(t *testing.T) {
|
||||
db := dbutil.SetupDB(t)
|
||||
// fixed seed
|
||||
|
||||
Reference in New Issue
Block a user