Skip to content

Commit

Permalink
sbft: check signature count on blocks
Browse files Browse the repository at this point in the history
Change-Id: I66113390aa1b0993359c16187c689f3f9389da23
Signed-off-by: Simon Schubert <sis@zurich.ibm.com>
  • Loading branch information
corecode committed Nov 16, 2016
1 parent f4dcb08 commit 4a72065
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
10 changes: 9 additions & 1 deletion orderer/sbft/simplebft/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *SBFT) makeBatch(seq uint64, prevHash []byte, data [][]byte) *Batch {
}
}

func (s *SBFT) checkBatch(b *Batch, checkData bool) (*BatchHeader, error) {
func (s *SBFT) checkBatch(b *Batch, checkData bool, needSigs bool) (*BatchHeader, error) {
batchheader := &BatchHeader{}
err := proto.Unmarshal(b.Header, batchheader)
if err != nil {
Expand All @@ -55,6 +55,14 @@ func (s *SBFT) checkBatch(b *Batch, checkData bool) (*BatchHeader, error) {
}
}

if batchheader.PrevHash == nil {
// TODO check against root hash, which should be part of constructor
} else if needSigs {
if len(b.Signatures) < s.oneCorrectQuorum() {
return nil, fmt.Errorf("insufficient number of signatures on batch: need %d, got %d", s.oneCorrectQuorum(), len(b.Signatures))
}
}

bh := b.Hash()
for r, sig := range b.Signatures {
err = s.sys.CheckSig(bh, r, sig)
Expand Down
4 changes: 2 additions & 2 deletions orderer/sbft/simplebft/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *SBFT) Connection(replica uint64) {
// commit, checkpoint so that the reconnecting replica can
// catch up on the in-flight batch.

batchheader, err := s.checkBatch(&batch, false)
batchheader, err := s.checkBatch(&batch, false, true)
if err != nil {
panic(err)
}
Expand All @@ -60,7 +60,7 @@ func (s *SBFT) Connection(replica uint64) {
}

func (s *SBFT) handleHello(h *Hello, src uint64) {
bh, err := s.checkBatch(h.Batch, false)
bh, err := s.checkBatch(h.Batch, false, true)
if err != nil {
log.Warningf("invalid hello batch from %d: %s", src, err)
return
Expand Down
2 changes: 1 addition & 1 deletion orderer/sbft/simplebft/newview.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (s *SBFT) handleNewView(nv *NewView, src uint64) {
return
}

_, err = s.checkBatch(nv.Batch, true)
_, err = s.checkBatch(nv.Batch, true, false)
if err != nil {
log.Warningf("invalid new view from %d: invalid batch, %s",
src, err)
Expand Down
4 changes: 2 additions & 2 deletions orderer/sbft/simplebft/preprepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func (s *SBFT) handlePreprepare(pp *Preprepare, src uint64) {
return
}

batchheader, err := s.checkBatch(pp.Batch, true)
batchheader, err := s.checkBatch(pp.Batch, true, false)
if err != nil || batchheader.Seq != pp.Seq.Seq {
log.Infof("preprepare %v batch head inconsistent from %d", pp.Seq, src)
log.Infof("preprepare %v batch head inconsistent from %d: %s", pp.Seq, src, err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion orderer/sbft/simplebft/testsys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (t *testSystemAdapter) Restore(key string, out proto.Message) bool {

func (t *testSystemAdapter) LastBatch() *Batch {
if len(t.batches) == 0 {
return t.receiver.(*SBFT).makeBatch(0, []byte("ROOTHASH"), nil)
return t.receiver.(*SBFT).makeBatch(0, nil, nil)
} else {
return t.batches[len(t.batches)-1]
}
Expand Down

0 comments on commit 4a72065

Please sign in to comment.