Skip to content

Commit 0b3c50b

Browse files
committed
chore: review feedback
1 parent d24ddcf commit 0b3c50b

2 files changed

Lines changed: 87 additions & 89 deletions

File tree

consensus/propagation/catchup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (blockProp *Reactor) retryWants(currentHeight int64, currentRound int32) {
3131
// only re-request original parts that are missing, not parity parts.
3232
missing := prop.block.BitArray().Not()
3333
if missing.IsEmpty() {
34-
// this should never be hit due to the check above.
34+
blockProp.Logger.Error("no missing parts yet block is incomplete", "height", height, "round", round)
3535
continue
3636
}
3737

types/part_set_test.go

Lines changed: 86 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -135,47 +135,46 @@ func TestEncoding(t *testing.T) {
135135
require.NoError(t, err)
136136
}
137137

138-
// todo: re-enable this test after we fix the proof validation
139-
// func TestWrongProof(t *testing.T) {
140-
// // Construct random data of size partSize * 100
141-
// data := cmtrand.Bytes(testPartSize * 100)
142-
// partSet := NewPartSetFromData(data, testPartSize)
143-
144-
// // Test adding a part with wrong data.
145-
// partSet2 := NewPartSetFromHeader(partSet.Header())
146-
147-
// // Test adding a part with wrong trail.
148-
// part := partSet.GetPart(0)
149-
// part.Proof.Aunts[0][0] += byte(0x01)
150-
// added, err := partSet2.AddPart(part)
151-
// if added || err == nil {
152-
// t.Errorf("expected to fail adding a part with bad trail.")
153-
// }
154-
155-
// // Test adding a part with wrong bytes.
156-
// part = partSet.GetPart(1)
157-
// part.Bytes[0] += byte(0x01)
158-
// added, err = partSet2.AddPart(part)
159-
// if added || err == nil {
160-
// t.Errorf("expected to fail adding a part with bad bytes.")
161-
// }
162-
163-
// // Test adding a part with wrong proof index.
164-
// part = partSet.GetPart(2)
165-
// part.Proof.Index = 1
166-
// added, err = partSet2.AddPart(part)
167-
// if added || err == nil {
168-
// t.Errorf("expected to fail adding a part with bad proof index.")
169-
// }
170-
171-
// // Test adding a part with wrong proof total.
172-
// part = partSet.GetPart(3)
173-
// part.Proof.Total = int64(partSet.Total() - 1)
174-
// added, err = partSet2.AddPart(part)
175-
// if added || err == nil {
176-
// t.Errorf("expected to fail adding a part with bad proof total.")
177-
// }
178-
// }
138+
func TestWrongProof(t *testing.T) {
139+
// Construct random data of size partSize * 100
140+
data := cmtrand.Bytes(testPartSize * 100)
141+
partSet := NewPartSetFromData(data, testPartSize)
142+
143+
// Test adding a part with wrong data.
144+
partSet2 := NewPartSetFromHeader(partSet.Header())
145+
146+
// Test adding a part with wrong trail.
147+
part := partSet.GetPart(0)
148+
part.Proof.Aunts[0][0] += byte(0x01)
149+
added, err := partSet2.AddPart(part)
150+
if added || err == nil {
151+
t.Errorf("expected to fail adding a part with bad trail.")
152+
}
153+
154+
// Test adding a part with wrong bytes.
155+
part = partSet.GetPart(1)
156+
part.Bytes[0] += byte(0x01)
157+
added, err = partSet2.AddPart(part)
158+
if added || err == nil {
159+
t.Errorf("expected to fail adding a part with bad bytes.")
160+
}
161+
162+
// Test adding a part with wrong proof index.
163+
part = partSet.GetPart(2)
164+
part.Proof.Index = 1
165+
added, err = partSet2.AddPart(part)
166+
if added || err == nil {
167+
t.Errorf("expected to fail adding a part with bad proof index.")
168+
}
169+
170+
// Test adding a part with wrong proof total.
171+
part = partSet.GetPart(3)
172+
part.Proof.Total = int64(partSet.Total() - 1)
173+
added, err = partSet2.AddPart(part)
174+
if added || err == nil {
175+
t.Errorf("expected to fail adding a part with bad proof total.")
176+
}
177+
}
179178

180179
func TestPartSetHeaderValidateBasic(t *testing.T) {
181180
testCases := []struct {
@@ -198,53 +197,52 @@ func TestPartSetHeaderValidateBasic(t *testing.T) {
198197
}
199198
}
200199

201-
// todo: re-enable this test after we find out where the proof is not being added
202-
// func TestPartValidateBasic(t *testing.T) {
203-
// testCases := []struct {
204-
// testName string
205-
// malleatePart func(*Part)
206-
// expectErr bool
207-
// }{
208-
// {"Good Part", func(pt *Part) {}, false},
209-
// {"Too big part", func(pt *Part) { pt.Bytes = make([]byte, BlockPartSizeBytes+1) }, true},
210-
// {"Good small last part", func(pt *Part) {
211-
// pt.Index = 1
212-
// pt.Bytes = make([]byte, BlockPartSizeBytes-1)
213-
// pt.Proof.Total = 2
214-
// pt.Proof.Index = 1
215-
// }, false},
216-
// {"Too small inner part", func(pt *Part) {
217-
// pt.Index = 0
218-
// pt.Bytes = make([]byte, BlockPartSizeBytes-1)
219-
// pt.Proof.Index = 1
220-
// pt.Proof.Total = 2
221-
// },
222-
223-
// true},
224-
// {"Too big proof", func(pt *Part) {
225-
// pt.Proof = merkle.Proof{
226-
// Total: 2,
227-
// Index: 1,
228-
// LeafHash: make([]byte, 1024*1024),
229-
// }
230-
// }, true},
231-
// {"Index mismatch", func(pt *Part) {
232-
// pt.Index = 1
233-
// pt.Proof.Index = 0
234-
// }, true},
235-
// }
236-
237-
// for _, tc := range testCases {
238-
// tc := tc
239-
// t.Run(tc.testName, func(t *testing.T) {
240-
// data := cmtrand.Bytes(testPartSize * 100)
241-
// ps := NewPartSetFromData(data, testPartSize)
242-
// part := ps.GetPart(0)
243-
// tc.malleatePart(part)
244-
// assert.Equal(t, tc.expectErr, part.ValidateBasic() != nil, "Validate Basic had an unexpected result")
245-
// })
246-
// }
247-
// }
200+
func TestPartValidateBasic(t *testing.T) {
201+
testCases := []struct {
202+
testName string
203+
malleatePart func(*Part)
204+
expectErr bool
205+
}{
206+
{"Good Part", func(pt *Part) {}, false},
207+
{"Too big part", func(pt *Part) { pt.Bytes = make([]byte, BlockPartSizeBytes+1) }, true},
208+
{"Good small last part", func(pt *Part) {
209+
pt.Index = 1
210+
pt.Bytes = make([]byte, BlockPartSizeBytes-1)
211+
pt.Proof.Total = 2
212+
pt.Proof.Index = 1
213+
}, false},
214+
{"Too small inner part", func(pt *Part) {
215+
pt.Index = 0
216+
pt.Bytes = make([]byte, BlockPartSizeBytes-1)
217+
pt.Proof.Index = 1
218+
pt.Proof.Total = 2
219+
},
220+
221+
true},
222+
{"Too big proof", func(pt *Part) {
223+
pt.Proof = merkle.Proof{
224+
Total: 2,
225+
Index: 1,
226+
LeafHash: make([]byte, 1024*1024),
227+
}
228+
}, true},
229+
{"Index mismatch", func(pt *Part) {
230+
pt.Index = 1
231+
pt.Proof.Index = 0
232+
}, true},
233+
}
234+
235+
for _, tc := range testCases {
236+
tc := tc
237+
t.Run(tc.testName, func(t *testing.T) {
238+
data := cmtrand.Bytes(testPartSize * 100)
239+
ps := NewPartSetFromData(data, testPartSize)
240+
part := ps.GetPart(0)
241+
tc.malleatePart(part)
242+
assert.Equal(t, tc.expectErr, part.ValidateBasic() != nil, "Validate Basic had an unexpected result")
243+
})
244+
}
245+
}
248246

249247
func TestParSetHeaderProtoBuf(t *testing.T) {
250248
testCases := []struct {

0 commit comments

Comments
 (0)