From e5220360c5305164fa24e6e7ee9d812f3e1582eb Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 17 May 2018 13:17:50 -0400 Subject: [PATCH] AddPart always verifies --- consensus/state.go | 6 +++--- types/part_set.go | 8 +++----- types/part_set_test.go | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index 7592269bf..191993356 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -584,7 +584,7 @@ func (cs *ConsensusState) handleMsg(mi msgInfo) { err = cs.setProposal(msg.Proposal) case *BlockPartMessage: // 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 { err = nil } @@ -1298,7 +1298,7 @@ func (cs *ConsensusState) defaultSetProposal(proposal *types.Proposal) error { // NOTE: block is not necessarily valid. // 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 if cs.Height != height { 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? } - added, err = cs.ProposalBlockParts.AddPart(part, verify) + added, err = cs.ProposalBlockParts.AddPart(part) if err != nil { return added, err } diff --git a/types/part_set.go b/types/part_set.go index cad3a03fe..18cfe802c 100644 --- a/types/part_set.go +++ b/types/part_set.go @@ -176,7 +176,7 @@ func (ps *PartSet) Total() int { return ps.total } -func (ps *PartSet) AddPart(part *Part, verify bool) (bool, error) { +func (ps *PartSet) AddPart(part *Part) (bool, error) { ps.mtx.Lock() defer ps.mtx.Unlock() @@ -191,10 +191,8 @@ func (ps *PartSet) AddPart(part *Part, verify bool) (bool, error) { } // 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 diff --git a/types/part_set_test.go b/types/part_set_test.go index 76b538c1f..545b4d42b 100644 --- a/types/part_set_test.go +++ b/types/part_set_test.go @@ -34,7 +34,7 @@ func TestBasicPartSet(t *testing.T) { for i := 0; i < partSet.Total(); i++ { part := partSet.GetPart(i) //t.Logf("\n%v", part) - added, err := partSet2.AddPart(part, true) + added, err := partSet2.AddPart(part) if !added || err != nil { 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. part := partSet.GetPart(0) part.Proof.Aunts[0][0] += byte(0x01) - added, err := partSet2.AddPart(part, true) + added, err := partSet2.AddPart(part) if added || err == nil { 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. part = partSet.GetPart(1) part.Bytes[0] += byte(0x01) - added, err = partSet2.AddPart(part, true) + added, err = partSet2.AddPart(part) if added || err == nil { t.Errorf("Expected to fail adding a part with bad bytes.") }