@@ -14,7 +14,6 @@ import (
14
14
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
15
15
"github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/attestations"
16
16
"github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/attestations/mock"
17
- "github.com/prysmaticlabs/prysm/v5/config/features"
18
17
"github.com/prysmaticlabs/prysm/v5/config/params"
19
18
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
20
19
"github.com/prysmaticlabs/prysm/v5/crypto/bls/blst"
@@ -26,162 +25,6 @@ import (
26
25
"github.com/prysmaticlabs/prysm/v5/time/slots"
27
26
)
28
27
29
- func TestProposer_ProposerAtts_sort (t * testing.T ) {
30
- feat := features .Get ()
31
- feat .DisableCommitteeAwarePacking = true
32
- reset := features .InitWithReset (feat )
33
- defer reset ()
34
-
35
- type testData struct {
36
- slot primitives.Slot
37
- bits bitfield.Bitlist
38
- }
39
- getAtts := func (data []testData ) proposerAtts {
40
- var atts proposerAtts
41
- for _ , att := range data {
42
- atts = append (atts , util .HydrateAttestation (& ethpb.Attestation {
43
- Data : & ethpb.AttestationData {Slot : att .slot }, AggregationBits : att .bits }))
44
- }
45
- return atts
46
- }
47
-
48
- t .Run ("no atts" , func (t * testing.T ) {
49
- atts := getAtts ([]testData {})
50
- want := getAtts ([]testData {})
51
- atts , err := atts .sort ()
52
- if err != nil {
53
- t .Error (err )
54
- }
55
- require .DeepEqual (t , want , atts )
56
- })
57
-
58
- t .Run ("single att" , func (t * testing.T ) {
59
- atts := getAtts ([]testData {
60
- {4 , bitfield.Bitlist {0b11100000 , 0b1 }},
61
- })
62
- want := getAtts ([]testData {
63
- {4 , bitfield.Bitlist {0b11100000 , 0b1 }},
64
- })
65
- atts , err := atts .sort ()
66
- if err != nil {
67
- t .Error (err )
68
- }
69
- require .DeepEqual (t , want , atts )
70
- })
71
-
72
- t .Run ("single att per slot" , func (t * testing.T ) {
73
- atts := getAtts ([]testData {
74
- {1 , bitfield.Bitlist {0b11000000 , 0b1 }},
75
- {4 , bitfield.Bitlist {0b11100000 , 0b1 }},
76
- })
77
- want := getAtts ([]testData {
78
- {4 , bitfield.Bitlist {0b11100000 , 0b1 }},
79
- {1 , bitfield.Bitlist {0b11000000 , 0b1 }},
80
- })
81
- atts , err := atts .sort ()
82
- if err != nil {
83
- t .Error (err )
84
- }
85
- require .DeepEqual (t , want , atts )
86
- })
87
-
88
- t .Run ("two atts on one of the slots" , func (t * testing.T ) {
89
- atts := getAtts ([]testData {
90
- {1 , bitfield.Bitlist {0b11000000 , 0b1 }},
91
- {4 , bitfield.Bitlist {0b11100000 , 0b1 }},
92
- {4 , bitfield.Bitlist {0b11110000 , 0b1 }},
93
- })
94
- want := getAtts ([]testData {
95
- {4 , bitfield.Bitlist {0b11110000 , 0b1 }},
96
- {4 , bitfield.Bitlist {0b11100000 , 0b1 }},
97
- {1 , bitfield.Bitlist {0b11000000 , 0b1 }},
98
- })
99
- atts , err := atts .sort ()
100
- if err != nil {
101
- t .Error (err )
102
- }
103
- require .DeepEqual (t , want , atts )
104
- })
105
-
106
- t .Run ("compare to native sort" , func (t * testing.T ) {
107
- // The max-cover based approach will select 0b00001100 instead, despite lower bit count
108
- // (since it has two new/unknown bits).
109
- t .Run ("max-cover" , func (t * testing.T ) {
110
- atts := getAtts ([]testData {
111
- {1 , bitfield.Bitlist {0b11000011 , 0b1 }},
112
- {1 , bitfield.Bitlist {0b11001000 , 0b1 }},
113
- {1 , bitfield.Bitlist {0b00001100 , 0b1 }},
114
- })
115
- want := getAtts ([]testData {
116
- {1 , bitfield.Bitlist {0b11000011 , 0b1 }},
117
- {1 , bitfield.Bitlist {0b00001100 , 0b1 }},
118
- {1 , bitfield.Bitlist {0b11001000 , 0b1 }},
119
- })
120
- atts , err := atts .sort ()
121
- if err != nil {
122
- t .Error (err )
123
- }
124
- require .DeepEqual (t , want , atts )
125
- })
126
- })
127
-
128
- t .Run ("multiple slots" , func (t * testing.T ) {
129
- atts := getAtts ([]testData {
130
- {2 , bitfield.Bitlist {0b11100000 , 0b1 }},
131
- {4 , bitfield.Bitlist {0b11100000 , 0b1 }},
132
- {1 , bitfield.Bitlist {0b11000000 , 0b1 }},
133
- {4 , bitfield.Bitlist {0b11110000 , 0b1 }},
134
- {1 , bitfield.Bitlist {0b11100000 , 0b1 }},
135
- {3 , bitfield.Bitlist {0b11000000 , 0b1 }},
136
- })
137
- want := getAtts ([]testData {
138
- {4 , bitfield.Bitlist {0b11110000 , 0b1 }},
139
- {4 , bitfield.Bitlist {0b11100000 , 0b1 }},
140
- {3 , bitfield.Bitlist {0b11000000 , 0b1 }},
141
- {2 , bitfield.Bitlist {0b11100000 , 0b1 }},
142
- {1 , bitfield.Bitlist {0b11100000 , 0b1 }},
143
- {1 , bitfield.Bitlist {0b11000000 , 0b1 }},
144
- })
145
- atts , err := atts .sort ()
146
- if err != nil {
147
- t .Error (err )
148
- }
149
- require .DeepEqual (t , want , atts )
150
- })
151
-
152
- t .Run ("follows max-cover" , func (t * testing.T ) {
153
- // Items at slot 4, must be first split into two lists by max-cover, with
154
- // 0b10000011 scoring higher (as it provides more info in addition to already selected
155
- // attestations) than 0b11100001 (despite naive bit count suggesting otherwise). Then,
156
- // both selected and non-selected attestations must be additionally sorted by bit count.
157
- atts := getAtts ([]testData {
158
- {4 , bitfield.Bitlist {0b00000001 , 0b1 }},
159
- {4 , bitfield.Bitlist {0b11100001 , 0b1 }},
160
- {1 , bitfield.Bitlist {0b11000000 , 0b1 }},
161
- {2 , bitfield.Bitlist {0b11100000 , 0b1 }},
162
- {4 , bitfield.Bitlist {0b10000011 , 0b1 }},
163
- {4 , bitfield.Bitlist {0b11111000 , 0b1 }},
164
- {1 , bitfield.Bitlist {0b11100000 , 0b1 }},
165
- {3 , bitfield.Bitlist {0b11000000 , 0b1 }},
166
- })
167
- want := getAtts ([]testData {
168
- {4 , bitfield.Bitlist {0b11111000 , 0b1 }},
169
- {4 , bitfield.Bitlist {0b10000011 , 0b1 }},
170
- {4 , bitfield.Bitlist {0b11100001 , 0b1 }},
171
- {4 , bitfield.Bitlist {0b00000001 , 0b1 }},
172
- {3 , bitfield.Bitlist {0b11000000 , 0b1 }},
173
- {2 , bitfield.Bitlist {0b11100000 , 0b1 }},
174
- {1 , bitfield.Bitlist {0b11100000 , 0b1 }},
175
- {1 , bitfield.Bitlist {0b11000000 , 0b1 }},
176
- })
177
- atts , err := atts .sort ()
178
- if err != nil {
179
- t .Error (err )
180
- }
181
- require .DeepEqual (t , want , atts )
182
- })
183
- }
184
-
185
28
func TestProposer_ProposerAtts_committeeAwareSort (t * testing.T ) {
186
29
type testData struct {
187
30
slot primitives.Slot
0 commit comments