Browse Source

AddPart always verifies

pull/1586/head
Ethan Buchman 7 years ago
parent
commit
e5220360c5
3 changed files with 9 additions and 11 deletions
  1. +3
    -3
      consensus/state.go
  2. +3
    -5
      types/part_set.go
  3. +3
    -3
      types/part_set_test.go

+ 3
- 3
consensus/state.go View File

@ -584,7 +584,7 @@ func (cs *ConsensusState) handleMsg(mi msgInfo) {
err = cs.setProposal(msg.Proposal) err = cs.setProposal(msg.Proposal)
case *BlockPartMessage: case *BlockPartMessage:
// if the proposal is complete, we'll enterPrevote or tryFinalizeCommit // if the proposal is complete, we'll enterPrevote or tryFinalizeCommit
_, err = cs.addProposalBlockPart(msg.Height, msg.Part, peerID != "")
_, err = cs.addProposalBlockPart(msg.Height, msg.Part)
if err != nil && msg.Round != cs.Round { if err != nil && msg.Round != cs.Round {
err = nil err = nil
} }
@ -1298,7 +1298,7 @@ func (cs *ConsensusState) defaultSetProposal(proposal *types.Proposal) error {
// NOTE: block is not necessarily valid. // NOTE: block is not necessarily valid.
// Asynchronously triggers either enterPrevote (before we timeout of propose) or tryFinalizeCommit, once we have the full block. // Asynchronously triggers either enterPrevote (before we timeout of propose) or tryFinalizeCommit, once we have the full block.
func (cs *ConsensusState) addProposalBlockPart(height int64, part *types.Part, verify bool) (added bool, err error) {
func (cs *ConsensusState) addProposalBlockPart(height int64, part *types.Part) (added bool, err error) {
// Blocks might be reused, so round mismatch is OK // Blocks might be reused, so round mismatch is OK
if cs.Height != height { if cs.Height != height {
return false, nil return false, nil
@ -1309,7 +1309,7 @@ func (cs *ConsensusState) addProposalBlockPart(height int64, part *types.Part, v
return false, nil // TODO: bad peer? Return error? return false, nil // TODO: bad peer? Return error?
} }
added, err = cs.ProposalBlockParts.AddPart(part, verify)
added, err = cs.ProposalBlockParts.AddPart(part)
if err != nil { if err != nil {
return added, err return added, err
} }


+ 3
- 5
types/part_set.go View File

@ -176,7 +176,7 @@ func (ps *PartSet) Total() int {
return ps.total return ps.total
} }
func (ps *PartSet) AddPart(part *Part, verify bool) (bool, error) {
func (ps *PartSet) AddPart(part *Part) (bool, error) {
ps.mtx.Lock() ps.mtx.Lock()
defer ps.mtx.Unlock() defer ps.mtx.Unlock()
@ -191,10 +191,8 @@ func (ps *PartSet) AddPart(part *Part, verify bool) (bool, error) {
} }
// Check hash proof // Check hash proof
if verify {
if !part.Proof.Verify(part.Index, ps.total, part.Hash(), ps.Hash()) {
return false, ErrPartSetInvalidProof
}
if !part.Proof.Verify(part.Index, ps.total, part.Hash(), ps.Hash()) {
return false, ErrPartSetInvalidProof
} }
// Add part // Add part


+ 3
- 3
types/part_set_test.go View File

@ -34,7 +34,7 @@ func TestBasicPartSet(t *testing.T) {
for i := 0; i < partSet.Total(); i++ { for i := 0; i < partSet.Total(); i++ {
part := partSet.GetPart(i) part := partSet.GetPart(i)
//t.Logf("\n%v", part) //t.Logf("\n%v", part)
added, err := partSet2.AddPart(part, true)
added, err := partSet2.AddPart(part)
if !added || err != nil { if !added || err != nil {
t.Errorf("Failed to add part %v, error: %v", i, err) t.Errorf("Failed to add part %v, error: %v", i, err)
} }
@ -74,7 +74,7 @@ func TestWrongProof(t *testing.T) {
// Test adding a part with wrong trail. // Test adding a part with wrong trail.
part := partSet.GetPart(0) part := partSet.GetPart(0)
part.Proof.Aunts[0][0] += byte(0x01) part.Proof.Aunts[0][0] += byte(0x01)
added, err := partSet2.AddPart(part, true)
added, err := partSet2.AddPart(part)
if added || err == nil { if added || err == nil {
t.Errorf("Expected to fail adding a part with bad trail.") t.Errorf("Expected to fail adding a part with bad trail.")
} }
@ -82,7 +82,7 @@ func TestWrongProof(t *testing.T) {
// Test adding a part with wrong bytes. // Test adding a part with wrong bytes.
part = partSet.GetPart(1) part = partSet.GetPart(1)
part.Bytes[0] += byte(0x01) part.Bytes[0] += byte(0x01)
added, err = partSet2.AddPart(part, true)
added, err = partSet2.AddPart(part)
if added || err == nil { if added || err == nil {
t.Errorf("Expected to fail adding a part with bad bytes.") t.Errorf("Expected to fail adding a part with bad bytes.")
} }


Loading…
Cancel
Save