Skip to content

Commit 4a72065

Browse files
committed
sbft: check signature count on blocks
Change-Id: I66113390aa1b0993359c16187c689f3f9389da23 Signed-off-by: Simon Schubert <[email protected]>
1 parent f4dcb08 commit 4a72065

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

orderer/sbft/simplebft/batch.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (s *SBFT) makeBatch(seq uint64, prevHash []byte, data [][]byte) *Batch {
4141
}
4242
}
4343

44-
func (s *SBFT) checkBatch(b *Batch, checkData bool) (*BatchHeader, error) {
44+
func (s *SBFT) checkBatch(b *Batch, checkData bool, needSigs bool) (*BatchHeader, error) {
4545
batchheader := &BatchHeader{}
4646
err := proto.Unmarshal(b.Header, batchheader)
4747
if err != nil {
@@ -55,6 +55,14 @@ func (s *SBFT) checkBatch(b *Batch, checkData bool) (*BatchHeader, error) {
5555
}
5656
}
5757

58+
if batchheader.PrevHash == nil {
59+
// TODO check against root hash, which should be part of constructor
60+
} else if needSigs {
61+
if len(b.Signatures) < s.oneCorrectQuorum() {
62+
return nil, fmt.Errorf("insufficient number of signatures on batch: need %d, got %d", s.oneCorrectQuorum(), len(b.Signatures))
63+
}
64+
}
65+
5866
bh := b.Hash()
5967
for r, sig := range b.Signatures {
6068
err = s.sys.CheckSig(bh, r, sig)

orderer/sbft/simplebft/connection.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (s *SBFT) Connection(replica uint64) {
3939
// commit, checkpoint so that the reconnecting replica can
4040
// catch up on the in-flight batch.
4141

42-
batchheader, err := s.checkBatch(&batch, false)
42+
batchheader, err := s.checkBatch(&batch, false, true)
4343
if err != nil {
4444
panic(err)
4545
}
@@ -60,7 +60,7 @@ func (s *SBFT) Connection(replica uint64) {
6060
}
6161

6262
func (s *SBFT) handleHello(h *Hello, src uint64) {
63-
bh, err := s.checkBatch(h.Batch, false)
63+
bh, err := s.checkBatch(h.Batch, false, true)
6464
if err != nil {
6565
log.Warningf("invalid hello batch from %d: %s", src, err)
6666
return

orderer/sbft/simplebft/newview.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (s *SBFT) handleNewView(nv *NewView, src uint64) {
128128
return
129129
}
130130

131-
_, err = s.checkBatch(nv.Batch, true)
131+
_, err = s.checkBatch(nv.Batch, true, false)
132132
if err != nil {
133133
log.Warningf("invalid new view from %d: invalid batch, %s",
134134
src, err)

orderer/sbft/simplebft/preprepare.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ func (s *SBFT) handlePreprepare(pp *Preprepare, src uint64) {
5959
return
6060
}
6161

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

orderer/sbft/simplebft/testsys_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (t *testSystemAdapter) Restore(key string, out proto.Message) bool {
170170

171171
func (t *testSystemAdapter) LastBatch() *Batch {
172172
if len(t.batches) == 0 {
173-
return t.receiver.(*SBFT).makeBatch(0, []byte("ROOTHASH"), nil)
173+
return t.receiver.(*SBFT).makeBatch(0, nil, nil)
174174
} else {
175175
return t.batches[len(t.batches)-1]
176176
}

0 commit comments

Comments
 (0)