Skip to content

Commit b8bd6f4

Browse files
mooselumphdmanc
andcommitted
fix(assignment): nil pointer dereference (#1634)
* Fix assignment pointer error * Update core/v2/assignment_test.go Co-authored-by: Daniel Mancia <[email protected]> --------- Co-authored-by: Daniel Mancia <[email protected]>
1 parent 01f5c30 commit b8bd6f4

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

core/v2/assignment.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ func AddAssignmentsForQuorum(
115115
for _, id := range orderedOps {
116116
newAssignmentIndicesCount := len(dummyAssignments[id].Indices)
117117

118+
if _, ok := assignments[id]; !ok {
119+
newAssignments[id] = &Assignment{
120+
Indices: make([]uint32, 0, newAssignmentIndicesCount),
121+
}
122+
continue
123+
}
124+
118125
if newAssignmentIndicesCount > len(assignments[id].Indices) {
119126
newAssignmentIndicesCount = len(assignments[id].Indices)
120127
}

core/v2/assignment_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,61 @@ func TestTwoQuorums(t *testing.T) {
153153
}
154154
}
155155

156+
func TestTwoQuorumsReverseOrder(t *testing.T) {
157+
158+
stakes := map[core.QuorumID]map[core.OperatorID]int{
159+
1: {
160+
mock.MakeOperatorId(0): 1,
161+
mock.MakeOperatorId(1): 10,
162+
mock.MakeOperatorId(2): 1,
163+
mock.MakeOperatorId(3): 1,
164+
mock.MakeOperatorId(4): 3,
165+
},
166+
0: {
167+
mock.MakeOperatorId(0): 2,
168+
mock.MakeOperatorId(1): 1,
169+
mock.MakeOperatorId(2): 10,
170+
mock.MakeOperatorId(3): 1,
171+
},
172+
}
173+
174+
dat, err := mock.NewChainDataMock(stakes)
175+
assert.NoError(t, err)
176+
177+
state := dat.GetTotalOperatorState(context.Background(), 0)
178+
179+
assignmentsBothQuorums, err := corev2.GetAssignmentsForBlob(state.OperatorState, blobParams, []core.QuorumID{0, 1})
180+
assert.NoError(t, err)
181+
assert.Len(t, assignmentsBothQuorums, 5)
182+
183+
assignmentsQuorum0, err := corev2.GetAssignmentsForBlob(state.OperatorState, blobParams, []core.QuorumID{1})
184+
assert.NoError(t, err)
185+
assert.Len(t, assignmentsQuorum0, 5)
186+
187+
assignmentsQuorum1, err := corev2.GetAssignmentsForBlob(state.OperatorState, blobParams, []core.QuorumID{0})
188+
assert.NoError(t, err)
189+
assert.Len(t, assignmentsQuorum1, 4)
190+
191+
// Check that the length of the assignment for each operator is equal to the maximum of the assignments for that operator in each quorum
192+
for id := range assignmentsBothQuorums {
193+
194+
// Get the bigger assignemnt between the two quorums
195+
maxChunks := uint32(0)
196+
assignment, ok := assignmentsQuorum0[id]
197+
if ok {
198+
maxChunks = assignment.NumChunks()
199+
}
200+
assignment, ok = assignmentsQuorum1[id]
201+
if ok {
202+
if assignment.NumChunks() > maxChunks {
203+
maxChunks = assignment.NumChunks()
204+
}
205+
}
206+
fmt.Println(id, assignmentsBothQuorums[id].NumChunks(), maxChunks)
207+
assert.LessOrEqual(t, assignmentsBothQuorums[id].NumChunks(), maxChunks)
208+
}
209+
}
210+
156211
func TestManyQuorums(t *testing.T) {
157212

158213
testCases := []uint8{1, 2, 3, 4, 5, 10, 15, 20, 50, 100, 200, 255}

0 commit comments

Comments
 (0)